Skip to content

Commit 69cd4a0

Browse files
authored
flex-grow and flex-shrink typed as Number (#64)
The `flex` shorthand, `flex-grow`, and `flex-shrink` properties appear to allow `Number`s as values, not just `Int`s. See https://drafts.csswg.org/css-flexbox-1/#flex-property
1 parent b635ec4 commit 69cd4a0

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Notable changes to this project are documented in this file. The format is based
66

77
Breaking changes (😱!!!):
88

9+
- Changed `flex`, `flexGrow`, and `flexShrink` to use `Number` rather than `Int` for the `grow` and `shrink` values - #64 (@andywhite37)
10+
911
New features:
1012

1113
Bugfixes:

src/CSS/Flexbox.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ alignSelf = key $ fromString "align-self"
159159

160160
-------------------------------------------------------------------------------
161161

162-
flex :: forall b. Int -> Int -> Size b -> CSS
162+
flex :: forall b. Number -> Number -> Size b -> CSS
163163
flex g s b = key (fromString "flex") (gs ! ss ! value b)
164164
where gs = fromString (show g) :: Value
165165
ss = fromString (show s) :: Value
@@ -204,10 +204,10 @@ flexFlow d w = key (fromString "flex-flow") (d ! w)
204204

205205
-------------------------------------------------------------------------------
206206

207-
flexGrow :: Int -> CSS
207+
flexGrow :: Number -> CSS
208208
flexGrow i = key (fromString "flex-grow") (fromString (show i) :: Value)
209209

210-
flexShrink :: Int -> CSS
210+
flexShrink :: Number -> CSS
211211
flexShrink i = key (fromString "flex-shrink") (fromString (show i) :: Value)
212212

213213
-------------------------------------------------------------------------------

test/Main.purs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import Prelude
44

55
import Effect (Effect)
66
import Effect.Exception (error, throwException)
7-
import CSS (Rendered, Path(..), Predicate(..), Refinement(..), Selector(..), FontFaceSrc(..), FontFaceFormat(..), renderedSheet, renderedInline, fromString, selector, block, display, render, borderBox, boxSizing, contentBox, blue, color, body, a, p, px, dashed, border, inlineBlock, red, (?), (&), (|>), (|*), (|+), byId, byClass, (@=), (^=), ($=), (*=), (~=), (|=), hover, fontFaceSrc, fontStyle, deg, zIndex, textOverflow, opacity, cursor, transform, transition, easeInOut, cubicBezier, ms)
7+
import CSS (Rendered, Path(..), Predicate(..), Refinement(..), Selector(..), FontFaceSrc(..), FontFaceFormat(..), pct, renderedSheet, renderedInline, fromString, selector, block, display, render, borderBox, boxSizing, contentBox, blue, color, body, a, p, px, dashed, border, inlineBlock, red, (?), (&), (|>), (|*), (|+), byId, byClass, (@=), (^=), ($=), (*=), (~=), (|=), hover, fontFaceSrc, fontStyle, deg, zIndex, textOverflow, opacity, cursor, transform, transition, easeInOut, cubicBezier, ms)
88
import CSS.Cursor as Cursor
9+
import CSS.Flexbox (flex)
910
import CSS.FontStyle as FontStyle
1011
import CSS.Text.Overflow as TextOverflow
1112
import CSS.Transform as Transform
@@ -45,6 +46,10 @@ example7 :: Rendered
4546
example7 = render do
4647
zIndex 11
4748
opacity 0.5
49+
50+
example8 :: Rendered
51+
example8 = render do
52+
flex 0.14 1.0 (pct 0.0)
4853

4954
withSelector :: Rendered
5055
withSelector = render do
@@ -179,6 +184,8 @@ main = do
179184
renderedInline example6 `assertEqual` Just "src: url(\"font.woff\") format(\"woff\")"
180185

181186
renderedInline example7 `assertEqual` Just "z-index: 11; opacity: 0.5"
187+
188+
renderedInline example8 `assertEqual` Just "flex: 0.14 1.0 0.0%"
182189

183190
renderedInline exampleFontStyle1 `assertEqual` Just "font-style: italic"
184191
renderedInline exampleFontStyle2 `assertEqual` Just "font-style: oblique"

0 commit comments

Comments
 (0)