0 | module Text.CSS.Extra
  1 |
  2 | import public Text.HTML
  3 | import public Text.HTML.DomID
  4 | import public Text.CSS
  5 |
  6 | %default total
  7 |
  8 | --------------------------------------------------------------------------------
  9 | -- Selectors
 10 | --------------------------------------------------------------------------------
 11 |
 12 | export
 13 | attr : (t -> Attribute ()) -> t -> Selector
 14 | attr f v =
 15 |   case f v of
 16 |     Str  n v => Attr n $ Equals v
 17 |     Bool n _ => Attr n Set
 18 |     _        => []
 19 |
 20 | export %inline
 21 | boolAttr : (Bool -> Attribute ()) -> Selector
 22 | boolAttr f = attr f True
 23 |
 24 | export %inline
 25 | domID : DomID -> Declarations -> Rule n
 26 | domID = id . value
 27 |
 28 | export %inline
 29 | attribute : (t -> Attribute ()) -> t -> Declarations -> Rule n
 30 | attribute f = sel . attr f
 31 |
 32 | --------------------------------------------------------------------------------
 33 | -- Borders
 34 | --------------------------------------------------------------------------------
 35 |
 36 | export %inline
 37 | noBorder : Declaration
 38 | noBorder = borderStyle (All None)
 39 |
 40 | export
 41 | border : BorderWidth -> Color -> Declarations
 42 | border w c =
 43 |   [borderStyle (All Solid), borderWidth  (All w), borderColor (All c)]
 44 |
 45 | export %inline
 46 | border1 : Color -> Declarations
 47 | border1 = border 1.px
 48 |
 49 | export %inline
 50 | border2 : Color -> Declarations
 51 | border2 = border 2.px
 52 |
 53 | export %inline
 54 | border3 : Color -> Declarations
 55 | border3 = border 3.px
 56 |
 57 | export
 58 | borderH : BorderWidth -> Color -> Declarations
 59 | borderH w c =
 60 |   [ borderStyle (VH None Solid)
 61 |   , borderWidth (VH 0.px w)
 62 |   , borderColor (VH transparent c)
 63 |   ]
 64 |
 65 | export %inline
 66 | borderH1 : Color -> Declarations
 67 | borderH1 = borderH 1.px
 68 |
 69 | export %inline
 70 | borderH2 : Color -> Declarations
 71 | borderH2 = borderH 2.px
 72 |
 73 | export %inline
 74 | borderH3 : Color -> Declarations
 75 | borderH3 = borderH 3.px
 76 |
 77 | export
 78 | borderV : BorderWidth -> Color -> Declarations
 79 | borderV w c =
 80 |   [ borderStyle (VH Solid None)
 81 |   , borderWidth (VH w 0.px)
 82 |   , borderColor (VH c transparent)
 83 |   ]
 84 |
 85 | export %inline
 86 | borderV1 : Color -> Declarations
 87 | borderV1 = borderV 1.px
 88 |
 89 | export %inline
 90 | borderV2 : Color -> Declarations
 91 | borderV2 = borderV 2.px
 92 |
 93 | export %inline
 94 | borderV3 : Color -> Declarations
 95 | borderV3 = borderV 3.px
 96 |
 97 | export
 98 | borderT : BorderWidth -> Color -> Declarations
 99 | borderT w c =
100 |   [ borderStyle (Top Solid)
101 |   , borderWidth (Top w)
102 |   , borderColor (Top c)
103 |   ]
104 |
105 | export %inline
106 | borderT1 : Color -> Declarations
107 | borderT1 = borderT 1.px
108 |
109 | export %inline
110 | borderT2 : Color -> Declarations
111 | borderT2 = borderT 2.px
112 |
113 | export %inline
114 | borderT3 : Color -> Declarations
115 | borderT3 = borderT 3.px
116 |
117 | export
118 | borderR : BorderWidth -> Color -> Declarations
119 | borderR w c =
120 |   [ borderStyle (Right Solid)
121 |   , borderWidth (Right w)
122 |   , borderColor (Right c)
123 |   ]
124 |
125 | export %inline
126 | borderR1 : Color -> Declarations
127 | borderR1 = borderR 1.px
128 |
129 | export %inline
130 | borderR2 : Color -> Declarations
131 | borderR2 = borderR 2.px
132 |
133 | export %inline
134 | borderR3 : Color -> Declarations
135 | borderR3 = borderR 3.px
136 |
137 | export
138 | borderB : BorderWidth -> Color -> Declarations
139 | borderB w c =
140 |   [ borderStyle (Bottom Solid)
141 |   , borderWidth (Bottom w)
142 |   , borderColor (Bottom c)
143 |   ]
144 |
145 | export %inline
146 | borderB1 : Color -> Declarations
147 | borderB1 = borderB 1.px
148 |
149 | export %inline
150 | borderB2 : Color -> Declarations
151 | borderB2 = borderB 2.px
152 |
153 | export %inline
154 | borderB3 : Color -> Declarations
155 | borderB3 = borderB 3.px
156 |
157 | export
158 | borderL : BorderWidth -> Color -> Declarations
159 | borderL w c =
160 |   [ borderStyle (Left Solid)
161 |   , borderWidth (Left w)
162 |   , borderColor (Left c)
163 |   ]
164 |
165 | export %inline
166 | borderL1 : Color -> Declarations
167 | borderL1 = borderL 1.px
168 |
169 | export %inline
170 | borderL2 : Color -> Declarations
171 | borderL2 = borderL 2.px
172 |
173 | export %inline
174 | borderL3 : Color -> Declarations
175 | borderL3 = borderL 3.px
176 |
177 | export
178 | borderHB : BorderWidth -> Color -> Declarations
179 | borderHB w c =
180 |   [ borderStyle (THB None Solid Solid)
181 |   , borderWidth (THB 0.px w w)
182 |   , borderColor (THB transparent c c)
183 |   ]
184 |
185 | export %inline
186 | borderHB1 : Color -> Declarations
187 | borderHB1 = borderHB 1.px
188 |
189 | export %inline
190 | borderHB2 : Color -> Declarations
191 | borderHB2 = borderHB 2.px
192 |
193 | export %inline
194 | borderHB3 : Color -> Declarations
195 | borderHB3 = borderHB 3.px
196 |
197 | export
198 | round2 : Declaration
199 | round2 = borderRadius 2.px
200 |
201 | export
202 | round4 : Declaration
203 | round4 = borderRadius 4.px
204 |
205 | export
206 | round8 : Declaration
207 | round8 = borderRadius 8.px
208 |
209 | export
210 | round16 : Declaration
211 | round16 = borderRadius 16.px
212 |
213 | export
214 | round32 : Declaration
215 | round32 = borderRadius 32.px
216 |
217 | export
218 | round : Declaration
219 | round = borderRadius 50.perc
220 |
221 | --------------------------------------------------------------------------------
222 | -- Padding
223 | --------------------------------------------------------------------------------
224 |
225 | export
226 | noPadding : Declaration
227 | noPadding = padding (All 0.px)
228 |
229 | --------------------------------------------------------------------------------
230 | -- Margin
231 | --------------------------------------------------------------------------------
232 |
233 | export
234 | noMargin : Declaration
235 | noMargin = margin (All 0.px)
236 |
237 | --------------------------------------------------------------------------------
238 | -- Elem Dimensions
239 | --------------------------------------------------------------------------------
240 |
241 | export
242 | exactWidth : Width -> Declarations
243 | exactWidth w = [minWidth w, maxWidth w, width w]
244 |
245 | export
246 | exactHeight : Width -> Declarations
247 | exactHeight h = [minHeight h, maxHeight h, height h]
248 |
249 | --------------------------------------------------------------------------------
250 | -- Flex Containers
251 | --------------------------------------------------------------------------------
252 |
253 | export
254 | noflex : Declaration
255 | noflex = flex "0 0 auto"
256 |
257 | export
258 | flex1 : Declaration
259 | flex1 = flex "1"
260 |
261 | export
262 | flex2 : Declaration
263 | flex2 = flex "2"
264 |
265 | export
266 | flex3 : Declaration
267 | flex3 = flex "3"
268 |
269 | export
270 | flex4 : Declaration
271 | flex4 = flex "4"
272 |
273 | export
274 | flexRow : Declarations
275 | flexRow = [display Flex, flexDirection Row]
276 |
277 | export
278 | startRow : Declarations
279 | startRow = alignItems Start :: flexRow
280 |
281 | export
282 | centerRow : Declarations
283 | centerRow = alignItems Center :: flexRow
284 |
285 | export
286 | endRow : Declarations
287 | endRow = alignItems Center :: flexRow
288 |
289 | export
290 | stretchRow : Declarations
291 | stretchRow = alignItems Stretch :: flexRow
292 |
293 | export
294 | flexCol : Declarations
295 | flexCol = [display Flex, flexDirection Column]
296 |
297 | export
298 | startCol : Declarations
299 | startCol = alignItems Start :: flexCol
300 |
301 | export
302 | centerCol : Declarations
303 | centerCol = alignItems Center :: flexCol
304 |
305 | export
306 | endCol : Declarations
307 | endCol = alignItems Center :: flexCol
308 |
309 | export
310 | stretchCol : Declarations
311 | stretchCol = alignItems Stretch :: flexCol
312 |
313 | parameters {default 0.5.em gap : Length}
314 |
315 |   export
316 |   flexSepRow : Declarations
317 |   flexSepRow = [display Flex, columnGap gap, flexDirection Row]
318 |
319 |   export
320 |   startSepRow : Declarations
321 |   startSepRow = alignItems Start :: flexSepRow
322 |
323 |   export
324 |   centerSepRow : Declarations
325 |   centerSepRow = alignItems Center :: flexSepRow
326 |
327 |   export
328 |   endSepRow : Declarations
329 |   endSepRow = alignItems Center :: flexSepRow
330 |
331 |   export
332 |   stretchSepRow : Declarations
333 |   stretchSepRow = alignItems Stretch :: flexSepRow
334 |
335 |   export
336 |   flexSepCol : Declarations
337 |   flexSepCol = [display Flex, rowGap gap, flexDirection Column]
338 |
339 |   export
340 |   startSepCol : Declarations
341 |   startSepCol = alignItems Start :: flexSepCol
342 |
343 |   export
344 |   centerSepCol : Declarations
345 |   centerSepCol = alignItems Center :: flexSepCol
346 |
347 |   export
348 |   endSepCol : Declarations
349 |   endSepCol = alignItems Center :: flexSepCol
350 |
351 |   export
352 |   stretchSepCol : Declarations
353 |   stretchSepCol = alignItems Stretch :: flexSepCol
354 |