@@ -18,6 +18,8 @@ module React.Basic.Emotion
18
18
, unset
19
19
, url
20
20
, color
21
+ , px , cm , mm , inches , pt , pc
22
+ , em , ex , ch , rem , vw , vh , vmin , vmax , percent
21
23
) where
22
24
23
25
import Prelude
@@ -27,6 +29,8 @@ import Control.Monad.Except (runExcept)
27
29
import Data.Array as Array
28
30
import Data.Either (Either (..))
29
31
import Data.Function.Uncurried (Fn2 , runFn2 )
32
+ import Data.Int as Int
33
+ import Data.Number.Format (toString ) as Number
30
34
import Foreign as F
31
35
import Prim.TypeError (class Warn , Text )
32
36
import React.Basic (JSX , ReactComponent )
@@ -153,3 +157,69 @@ url (URL url') = str ("url(" <> url' <> ")")
153
157
154
158
color :: Color -> StyleProperty
155
159
color = str <<< cssStringHSLA
160
+
161
+ -- Absolute length units
162
+
163
+ -- | Pixels. This function does not take a `Number` because approaches to
164
+ -- | subpixel rendering vary among browser implementations.
165
+ px :: Int -> StyleProperty
166
+ px x = str $ Int .toStringAs Int .decimal x <> " px"
167
+
168
+ -- | Centimeters
169
+ cm :: Number -> StyleProperty
170
+ cm x = str $ Number .toString x <> " cm"
171
+
172
+ -- | Milimeters
173
+ mm :: Number -> StyleProperty
174
+ mm x = str $ Number .toString x <> " mm"
175
+
176
+ -- | Inches (1in ≈ 2.54cm)
177
+ inches :: Number -> StyleProperty
178
+ inches x = str $ Number .toString x <> " in"
179
+
180
+ -- | Points (1pt = 1/72 of 1in)
181
+ pt :: Number -> StyleProperty
182
+ pt x = str $ Number .toString x <> " pt"
183
+
184
+ -- | Picas (1pc = 12 pt)
185
+ pc :: Number -> StyleProperty
186
+ pc x = str $ Number .toString x <> " pc"
187
+
188
+ -- Relative length units
189
+
190
+ -- | Relative to the font-size of the element (2em means 2 times the size of
191
+ -- | the current font).
192
+ em :: Number -> StyleProperty
193
+ em x = str $ Number .toString x <> " em"
194
+
195
+ -- | Relative to the x-height of the current font (rarely used).
196
+ ex :: Number -> StyleProperty
197
+ ex x = str $ Number .toString x <> " ex"
198
+
199
+ -- | Relative to the width of the "0" (zero) character.
200
+ ch :: Number -> StyleProperty
201
+ ch x = str $ Number .toString x <> " ch"
202
+
203
+ -- | Relative to font-size of the root element.
204
+ rem :: Number -> StyleProperty
205
+ rem x = str $ Number .toString x <> " rem"
206
+
207
+ -- | Relative to 1% of the width of the viewport.
208
+ vw :: Number -> StyleProperty
209
+ vw x = str $ Number .toString x <> " vw"
210
+
211
+ -- | Relative to 1% of the height of the viewport.
212
+ vh :: Number -> StyleProperty
213
+ vh x = str $ Number .toString x <> " vh"
214
+
215
+ -- | Relative to 1% of viewport's smaller dimension.
216
+ vmin :: Number -> StyleProperty
217
+ vmin x = str $ Number .toString x <> " vmin"
218
+
219
+ -- | Relative to 1% of viewport's larger dimension.
220
+ vmax :: Number -> StyleProperty
221
+ vmax x = str $ Number .toString x <> " vmax"
222
+
223
+ -- | Relative to the parent element.
224
+ percent :: Number -> StyleProperty
225
+ percent x = str $ Number .toString x <> " %"
0 commit comments