@@ -7,6 +7,7 @@ module React.Basic.Emotion
77 , prop
88 , element
99 , css
10+ , important
1011 , nested
1112 , merge
1213 , str
@@ -18,15 +19,21 @@ module React.Basic.Emotion
1819 , unset
1920 , url
2021 , color
22+ , px , px' , cm , mm , inches , pt , pc
23+ , em , ex , ch , rem , vw , vh , vmin , vmax , percent
2124 ) where
2225
2326import Prelude
27+
2428import Color (Color , cssStringHSLA )
2529import Control.Monad.Except (runExcept )
2630import Data.Array as Array
2731import Data.Either (Either (..))
2832import Data.Function.Uncurried (Fn2 , runFn2 )
33+ import Data.Int as Int
34+ import Data.Number.Format (toString ) as Number
2935import Foreign as F
36+ import Prim.TypeError (class Warn , Text )
3037import React.Basic (JSX , ReactComponent )
3138import Type.Row.Homogeneous (class Homogeneous )
3239import Unsafe.Coerce (unsafeCoerce )
@@ -113,6 +120,8 @@ foreign import global :: ReactComponent { styles :: Style }
113120
114121foreign import css :: forall r . Homogeneous r StyleProperty => { | r } -> Style
115122
123+ foreign import important :: StyleProperty -> StyleProperty
124+
116125nested :: Style -> StyleProperty
117126nested = unsafeCoerce
118127
@@ -122,10 +131,16 @@ merge = unsafeCoerce
122131str :: String -> StyleProperty
123132str = unsafeCoerce
124133
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
126138int = unsafeCoerce
127139
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
129144num = unsafeCoerce
130145
131146fallbacks :: Array StyleProperty -> StyleProperty
@@ -145,3 +160,77 @@ url (URL url') = str ("url(" <> url' <> ")")
145160
146161color :: Color -> StyleProperty
147162color = 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