@@ -18,6 +18,8 @@ module React.Basic.Emotion
18
18
, unset
19
19
, url
20
20
, color
21
+ , px , 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,77 @@ 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
+ -- | Pixels and subpixels.
169
+ -- |
170
+ -- | WARNING: Approaches to subpixel rendering vary among browser
171
+ -- | implementations. This means that non-integer pixel values may be displayed
172
+ -- | differently in different browsers.
173
+ px' :: Number -> StyleProperty
174
+ px' x = str $ Number .toString x <> " px"
175
+
176
+ -- | Centimeters
177
+ cm :: Number -> StyleProperty
178
+ cm x = str $ Number .toString x <> " cm"
179
+
180
+ -- | Milimeters
181
+ mm :: Number -> StyleProperty
182
+ mm x = str $ Number .toString x <> " mm"
183
+
184
+ -- | Inches (1in ≈ 2.54cm)
185
+ inches :: Number -> StyleProperty
186
+ inches x = str $ Number .toString x <> " in"
187
+
188
+ -- | Points (1pt = 1/72 of 1in)
189
+ pt :: Number -> StyleProperty
190
+ pt x = str $ Number .toString x <> " pt"
191
+
192
+ -- | Picas (1pc = 12 pt)
193
+ pc :: Number -> StyleProperty
194
+ pc x = str $ Number .toString x <> " pc"
195
+
196
+ -- Relative length units
197
+
198
+ -- | Relative to the font-size of the element (2em means 2 times the size of
199
+ -- | the current font).
200
+ em :: Number -> StyleProperty
201
+ em x = str $ Number .toString x <> " em"
202
+
203
+ -- | Relative to the x-height of the current font (rarely used).
204
+ ex :: Number -> StyleProperty
205
+ ex x = str $ Number .toString x <> " ex"
206
+
207
+ -- | Relative to the width of the "0" (zero) character.
208
+ ch :: Number -> StyleProperty
209
+ ch x = str $ Number .toString x <> " ch"
210
+
211
+ -- | Relative to font-size of the root element.
212
+ rem :: Number -> StyleProperty
213
+ rem x = str $ Number .toString x <> " rem"
214
+
215
+ -- | Relative to 1% of the width of the viewport.
216
+ vw :: Number -> StyleProperty
217
+ vw x = str $ Number .toString x <> " vw"
218
+
219
+ -- | Relative to 1% of the height of the viewport.
220
+ vh :: Number -> StyleProperty
221
+ vh x = str $ Number .toString x <> " vh"
222
+
223
+ -- | Relative to 1% of viewport's smaller dimension.
224
+ vmin :: Number -> StyleProperty
225
+ vmin x = str $ Number .toString x <> " vmin"
226
+
227
+ -- | Relative to 1% of viewport's larger dimension.
228
+ vmax :: Number -> StyleProperty
229
+ vmax x = str $ Number .toString x <> " vmax"
230
+
231
+ -- | Relative to the parent element.
232
+ percent :: Number -> StyleProperty
233
+ percent x = str $ Number .toString x <> " %"
0 commit comments