@@ -7,6 +7,7 @@ module React.Basic.Emotion
7
7
, prop
8
8
, element
9
9
, css
10
+ , important
10
11
, nested
11
12
, merge
12
13
, str
@@ -18,15 +19,21 @@ module React.Basic.Emotion
18
19
, unset
19
20
, url
20
21
, color
22
+ , px , px' , cm , mm , inches , pt , pc
23
+ , em , ex , ch , rem , vw , vh , vmin , vmax , percent
21
24
) where
22
25
23
26
import Prelude
27
+
24
28
import Color (Color , cssStringHSLA )
25
29
import Control.Monad.Except (runExcept )
26
30
import Data.Array as Array
27
31
import Data.Either (Either (..))
28
32
import Data.Function.Uncurried (Fn2 , runFn2 )
33
+ import Data.Int as Int
34
+ import Data.Number.Format (toString ) as Number
29
35
import Foreign as F
36
+ import Prim.TypeError (class Warn , Text )
30
37
import React.Basic (JSX , ReactComponent )
31
38
import Type.Row.Homogeneous (class Homogeneous )
32
39
import Unsafe.Coerce (unsafeCoerce )
@@ -113,6 +120,8 @@ foreign import global :: ReactComponent { styles :: Style }
113
120
114
121
foreign import css :: forall r . Homogeneous r StyleProperty => { | r } -> Style
115
122
123
+ foreign import important :: StyleProperty -> StyleProperty
124
+
116
125
nested :: Style -> StyleProperty
117
126
nested = unsafeCoerce
118
127
@@ -122,10 +131,16 @@ merge = unsafeCoerce
122
131
str :: String -> StyleProperty
123
132
str = unsafeCoerce
124
133
125
- int :: Int -> StyleProperty
134
+ int
135
+ :: Warn (Text " `int` is deprecated and may be removed in future versions. Prefer one of the unit combinators like `px` or `em` instead." )
136
+ => Int
137
+ -> StyleProperty
126
138
int = unsafeCoerce
127
139
128
- num :: Number -> StyleProperty
140
+ num
141
+ :: Warn (Text " `int` is deprecated and may be removed in future versions. Prefer one of the unit combinators like `px` or `em` instead." )
142
+ => Number
143
+ -> StyleProperty
129
144
num = unsafeCoerce
130
145
131
146
fallbacks :: Array StyleProperty -> StyleProperty
@@ -145,3 +160,77 @@ url (URL url') = str ("url(" <> url' <> ")")
145
160
146
161
color :: Color -> StyleProperty
147
162
color = str <<< cssStringHSLA
163
+
164
+ -- Absolute length units
165
+
166
+ -- | Pixels. This function does not take a `Number` because approaches to
167
+ -- | subpixel rendering vary among browser implementations.
168
+ px :: Int -> StyleProperty
169
+ px x = str $ Int .toStringAs Int .decimal x <> " px"
170
+
171
+ -- | Pixels and subpixels.
172
+ -- |
173
+ -- | WARNING: Approaches to subpixel rendering vary among browser
174
+ -- | implementations. This means that non-integer pixel values may be displayed
175
+ -- | differently in different browsers.
176
+ px' :: Number -> StyleProperty
177
+ px' x = str $ Number .toString x <> " px"
178
+
179
+ -- | Centimeters
180
+ cm :: Number -> StyleProperty
181
+ cm x = str $ Number .toString x <> " cm"
182
+
183
+ -- | Milimeters
184
+ mm :: Number -> StyleProperty
185
+ mm x = str $ Number .toString x <> " mm"
186
+
187
+ -- | Inches (1in ≈ 2.54cm)
188
+ inches :: Number -> StyleProperty
189
+ inches x = str $ Number .toString x <> " in"
190
+
191
+ -- | Points (1pt = 1/72 of 1in)
192
+ pt :: Number -> StyleProperty
193
+ pt x = str $ Number .toString x <> " pt"
194
+
195
+ -- | Picas (1pc = 12 pt)
196
+ pc :: Number -> StyleProperty
197
+ pc x = str $ Number .toString x <> " pc"
198
+
199
+ -- Relative length units
200
+
201
+ -- | Relative to the font-size of the element (2em means 2 times the size of
202
+ -- | the current font).
203
+ em :: Number -> StyleProperty
204
+ em x = str $ Number .toString x <> " em"
205
+
206
+ -- | Relative to the x-height of the current font (rarely used).
207
+ ex :: Number -> StyleProperty
208
+ ex x = str $ Number .toString x <> " ex"
209
+
210
+ -- | Relative to the width of the "0" (zero) character.
211
+ ch :: Number -> StyleProperty
212
+ ch x = str $ Number .toString x <> " ch"
213
+
214
+ -- | Relative to font-size of the root element.
215
+ rem :: Number -> StyleProperty
216
+ rem x = str $ Number .toString x <> " rem"
217
+
218
+ -- | Relative to 1% of the width of the viewport.
219
+ vw :: Number -> StyleProperty
220
+ vw x = str $ Number .toString x <> " vw"
221
+
222
+ -- | Relative to 1% of the height of the viewport.
223
+ vh :: Number -> StyleProperty
224
+ vh x = str $ Number .toString x <> " vh"
225
+
226
+ -- | Relative to 1% of viewport's smaller dimension.
227
+ vmin :: Number -> StyleProperty
228
+ vmin x = str $ Number .toString x <> " vmin"
229
+
230
+ -- | Relative to 1% of viewport's larger dimension.
231
+ vmax :: Number -> StyleProperty
232
+ vmax x = str $ Number .toString x <> " vmax"
233
+
234
+ -- | Relative to the parent element.
235
+ percent :: Number -> StyleProperty
236
+ percent x = str $ Number .toString x <> " %"
0 commit comments