0 | ||| Types and utilities for laying out components in a grid.
  1 | module Text.CSS.Grid
  2 |
  3 | import Data.List
  4 | import Text.CSS.Length
  5 | import Text.CSS.Percentage
  6 |
  7 | --------------------------------------------------------------------------------
  8 | --          Flex Values
  9 | --------------------------------------------------------------------------------
 10 |
 11 | public export
 12 | record Flex where
 13 |   constructor MkFlex
 14 |   value : Bits16
 15 |
 16 | export %inline
 17 | fr : Cast Flex a => Bits16 -> a
 18 | fr = cast . MkFlex
 19 |
 20 | export
 21 | Interpolation Flex where
 22 |   interpolate f = "\{show f.value}fr"
 23 |
 24 | --------------------------------------------------------------------------------
 25 | --          MinMax Values
 26 | --------------------------------------------------------------------------------
 27 |
 28 | public export
 29 | data MinMaxValue : Type where
 30 |   Auto       : MinMaxValue
 31 |   MML        : Length     -> MinMaxValue
 32 |   MMP        : Percentage -> MinMaxValue
 33 |   MMF        : Flex       -> MinMaxValue
 34 |   MinContent : MinMaxValue
 35 |   MaxContent : MinMaxValue
 36 |
 37 | export %inline
 38 | Cast Length MinMaxValue where
 39 |   cast = MML
 40 |
 41 | export %inline
 42 | Cast Percentage MinMaxValue where
 43 |   cast = MMP
 44 |
 45 | export %inline
 46 | Cast Flex MinMaxValue where
 47 |   cast = MMF
 48 |
 49 | export
 50 | Interpolation MinMaxValue where
 51 |   interpolate Auto       = "auto"
 52 |   interpolate MinContent = "min-content"
 53 |   interpolate MaxContent = "max-content"
 54 |   interpolate (MML x)    = interpolate x
 55 |   interpolate (MMP x)    = interpolate x
 56 |   interpolate (MMF x)    = interpolate x
 57 |
 58 | --------------------------------------------------------------------------------
 59 | --          GridValue
 60 | --------------------------------------------------------------------------------
 61 |
 62 | namespace GridValue
 63 |   public export
 64 |   data GridValue : Type where
 65 |     GL         : Length -> GridValue
 66 |     GP         : Percentage -> GridValue
 67 |     GF         : Flex -> GridValue
 68 |     MinMax     : (min,max : MinMaxValue) -> GridValue
 69 |     MaxContent : GridValue
 70 |     MinContent : GridValue
 71 |
 72 | export
 73 | Interpolation GridValue where
 74 |   interpolate (GL x)           = interpolate x
 75 |   interpolate (GP x)           = interpolate x
 76 |   interpolate (GF x)           = interpolate x
 77 |   interpolate (MinMax min max) = "minmax(\{min}, \{max})"
 78 |   interpolate MaxContent       = "max-content"
 79 |   interpolate MinContent       = "min-content"
 80 |
 81 | export
 82 | Interpolation (List GridValue) where
 83 |   interpolate = fastConcat . intersperse " " . map interpolate
 84 |
 85 | export %inline
 86 | Cast Length GridValue where
 87 |   cast = GL
 88 |
 89 | export %inline
 90 | Cast Percentage GridValue where
 91 |   cast = GP
 92 |
 93 | export %inline
 94 | Cast Flex GridValue where
 95 |   cast = GF
 96 |
 97 | --------------------------------------------------------------------------------
 98 | --          GridPosition
 99 | --------------------------------------------------------------------------------
100 |
101 | public export
102 | data GridPosition : Type where
103 |   At     : Bits32 -> GridPosition
104 |   FromTo : Bits32 -> Bits32 -> GridPosition
105 |
106 | export
107 | Interpolation GridPosition where
108 |   interpolate (At x)       = show x
109 |   interpolate (FromTo x y) = "\{show x} / \{show y}"
110 |