git.iko.soy/rowtype-yoga/psfp
on fb93bc9 help sign in
185 lines 7.2 kB history raw
1module PSLayout where
3import Prelude
4import Color as Color
5import Data.Maybe (Maybe(..), fromMaybe)
6import Data.Tuple.Nested ((/\))
7import Effect (Effect)
8import MDX (MDX)
9import MDXProvider (MdxProviderProps)
10import Milkis.Impl (FetchImpl)
11import React.Basic (ReactComponent)
12import React.Basic.DOM as R
13import React.Basic.Emotion as Emotion
14import React.Basic.Hooks (ReactChildren, element, reactComponentWithChildren, useState')
15import React.Basic.Hooks as React
16import Yoga ((/>), (</), (</*))
17import Yoga as Y
18import Yoga.Block as Block
19import Yoga.Block.Atom.Toggle.Types (TogglePosition(..))
20import Yoga.Block.Container as Container
21import Yoga.Block.Container.Style (DarkOrLightMode(..), colour)
22import Yoga.Block.Icon.SVG as Icon
23import Yoga.Block.Internal (_0)
24import Yoga.Block.Modal as Modal
26type SiteQueryResult =
27 { siteMetadata ∷
28 { title ∷ String
29 , menuLinks ∷ Array { name ∷ String, link ∷ String }
30 }
31 }
33data ShowModal
34 = ShowModal Modal.Props
35 | HideModal
37mkLayout ∷
38 FetchImpl ->
39 Effect
40 ( ReactComponent
41 { children ∷ ReactChildren MDX
42 , siteInfo ∷ SiteQueryResult
43 , mdxProviderComponent ∷ ReactComponent MdxProviderProps
44 }
45 )
46mkLayout fetchImpl = do
47 -- mdxProviderComponent <- mkMdxProviderComponent (apiCompiler fetchImpl)
48 reactComponentWithChildren "MDXLayout" \{ children, siteInfo, mdxProviderComponent } -> React.do
49 darkOrLightMode /\ setDarkOrLightMode <- useState' Nothing
50 togglePosition /\ setTogglePosition <- useState' ToggleIsLeft
51 let
52 themeToMaybeTogglePosition =
53 darkOrLightMode
54 <#> case _ of
55 DarkMode -> ToggleIsRight
56 LightMode -> ToggleIsLeft
57 darkThemeToggle =
58 Block.toggle
59 Y.</> do
60 { className: "dark-light-toggle"
61 , css:
62 Emotion.css
63 { marginRight: Emotion.str "0"
64 , marginLeft: Emotion.str "auto"
65 }
66 , setTogglePosition:
67 case _ of
68 ToggleIsLeft -> setDarkOrLightMode (Just LightMode)
69 ToggleIsRight -> setDarkOrLightMode (Just DarkMode)
70 , togglePosition: themeToMaybeTogglePosition # fromMaybe togglePosition
71 , left:
72 Block.icon
73 Y.</> do
74 { icon: Icon.moon
75 , stroke: Emotion.str "#eef"
76 }
77 , right:
78 Block.icon
79 Y.</> do
80 { icon: Icon.sun
81 , stroke: Emotion.str "yellow"
82 }
83 , backgroundLeft:
84 Color.hsl 205.0 1.0 0.80
85 , backgroundRight:
86 Color.hsl 250.0 1.0 0.1
87 }
88 header =
89 Block.box
90 </ { className: "top-box"
91 , css:
92 Emotion.css
93 { background: Emotion.str colour.backgroundLayer5
94 }
95 }
96 /> [ Block.cluster
97 </* { justify: "space-between"
98 , className: "header"
99 , space: "var(--s-2)"
100 , css: Emotion.css { width: Emotion.percent 100.0 }
101 }
102 /> do
103 [ Y.styled
104 R.span'
105 { className: "blog-header"
106 , css:
107 Emotion.css
108 { fontSize: Emotion.str "min(var(--s3), calc(var(--s1) + 1vw))"
109 , textTransform: Emotion.str "uppercase"
110 , letterSpacing: Emotion.str "calc(min(var(--s0) + 3vw), var(--s2) * -1.7)"
111 , fontWeight: Emotion.str "300"
112 , color: Emotion.str colour.text
113 }
114 }
115 [ R.text siteInfo.siteMetadata.title ]
116 , darkThemeToggle
117 ]
118 ]
119 pure
120 $ element Container.component
121 { themeVariant: darkOrLightMode
122 , onPreferredSystemThemeChange:
123 case _ of
124 LightMode -> setTogglePosition ToggleIsLeft
125 DarkMode -> setTogglePosition ToggleIsRight
126 , content:
127 Y.styled Block.stack
128 { className: "blog-content"
129 , space: _0
130 , splitAfter: 2
131 , css:
132 Emotion.css
133 { minHeight: Emotion.vh 100.0
134 , background: Emotion.str colour.background
135 , borderRadius: Emotion.str "0 var(--s1) var(--s1) 0"
136 }
137 }
138 [ header
139 , Block.centre
140 </* { className: "centre"
141 , padding: _0
142 , gutters: _0
143 , css: Emotion.css { maxWidth: Emotion.ch 90.0 }
144 }
145 /> [ Block.box
146 </ do
147 { padding: Emotion.px 16
148 , css:
149 Emotion.css
150 { "& > p:first-of-type:first-letter":
151 Emotion.nested
152 $ Emotion.css
153 { overflow: Emotion.str "visible"
154 , float: Emotion.str "left"
155 , fontSize: Emotion.str "min(calc(var(--s0) * 1 + 8.03vw), var(--s5))"
156 , fontFamily: Emotion.str "Cormorant Garamond"
157 , lineHeight: Emotion.str "min(calc(var(--s-1) + 2px + 3vw), var(--s3))"
158 , marginTop: Emotion.str "min(calc(var(--s-1) + 1.5vw), var(--s2))"
159 , marginRight: Emotion.var "--s-2"
160 , "&:::selection":
161 Emotion.nested
162 $ Emotion.css
163 { color: Emotion.str colour.highlightText
164 , background: Emotion.str "green" -- colour.highlight
165 }
166 }
167 }
168 }
169 /> [ element mdxProviderComponent
170 { children
171 }
172 ]
173 ]
174 , Y.styled Block.box
175 { className: "blog-footer"
176 , css:
177 Emotion.css
178 { background: Emotion.str colour.backgroundLayer1
179 , borderTop: Emotion.str $ "1px solid " <> colour.backgroundLayer3
180 , color: Emotion.str colour.text
181 }
182 }
183 [ R.text "Mark Eibes" ]
184 ]
185 }