Skip to content

Commit df2f99a

Browse files
committed
- distinguish between Length and LenghTemplate (valid length is gap vs. valid lengths in gird-template-columns!)
- improve example
1 parent 950ae98 commit df2f99a

File tree

5 files changed

+72
-64
lines changed

5 files changed

+72
-64
lines changed

TODO.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1+
- complete https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Grid_Layout/Realizing_common_layouts_using_CSS_Grid_Layout
12

2-
see https://codepen.io/clojj/pen/pmwWvL?&editable=true
3+
see https://codepen.io/clojj/pen/pmwWvL?&editable=true
34

4-
spec for sizes
5-
-
5+
- using `units (fr 1)` instead of just `fr 1` is a bit unfortunate, but it enforces CSS Grid validity
66

7-
`Each parameter can be a <length>, a <percentage>, a <flex> value, or one of the keyword values max-content, min-content, or auto.`
7+
- validate templates ? `Result Error err Ok template` as type ?
88

9-
`Some properties allow negative <length>s, while others do not.`
9+
- 'bad' templates can be defined, if the areas column- or row-length differs from any grid-template-rows/columns
1010

11-
see https://developer.mozilla.org/en-US/docs/Web/CSS/grid-template-columns
11+
- 'bad' templates can be defined, if the areas are do not shape a rectangle
1212

13-
rename or remove module `CssGrid`
14-
-
13+
- implement spec for sizes
1514

16-
parameterize by fixed responsive 'profile' ("best-practices" media-queries) ?
17-
-
15+
`Each parameter can be a <length>, a <percentage>, a <flex> value, or one of the keyword values max-content, min-content, or auto.`
1816

19-
test invalid templates.. add some validations ?
20-
-
17+
`Some properties allow negative <length>s, while others do not.`
2118

22-
- 'bad' templates can be defined, if the areas column- or row-length differs from any grid-template-rows/columns
19+
- parameterize by fixed responsive 'profile' ("best-practices" media-queries) ?
2320

24-
- 'bad' templates can be defined, if the areas are do not shape a rectangle

examples/src/Simple.elm renamed to examples/src/InnerView.elm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
module Simple exposing (simpleTemplateBig, viewSimple)
1+
module InnerView exposing (simpleTemplateBig, viewInner)
22

33
import Areas exposing (cont, contLeft, contRight, foot, head, navi)
44
import Css as Css
55
import Css.Media as Media exposing (only, screen)
66
import CssGrid.Areas exposing (GridArea, gridAreaElement)
77
import CssGrid.Simple exposing (ResponsiveTemplate, SimpleTemplate, simpleContainer, simpleTemplate)
8-
import CssGrid.Sizes exposing (fr, gap, px)
8+
import CssGrid.Sizes exposing (fr, gap, px, units)
99
import Html.Styled exposing (Html, div, p, text)
1010
import Html.Styled.Attributes exposing (css)
1111

@@ -18,7 +18,7 @@ simpleTemplateBig =
1818
, [ foot, foot, foot ]
1919
]
2020
(gap (px 3))
21-
[ fr 1, fr 1, fr 1 ]
21+
[ units (fr 1), units (fr 1), units (fr 1) ]
2222

2323

2424
simpleTemplateSmall : SimpleTemplate
@@ -45,15 +45,15 @@ smallScreenTemplate =
4545
( [ only screen [ Media.maxWidth (Css.px 400) ] ], simpleTemplateSmall )
4646

4747

48-
viewSimple : () -> Html.Styled.Html msg
49-
viewSimple _ =
48+
viewInner : () -> Html.Styled.Html msg
49+
viewInner _ =
5050
simpleContainer [ bigScreenTemplate, smallScreenTemplate ]
5151
[]
5252
[ gridAreaElement head (panel <| text "head")
5353
, gridAreaElement navi (panel <| text "navi")
54-
, gridAreaElement contLeft (panel <| p [] [text "left"])
55-
, gridAreaElement cont (panel <| p [] [text "cont"])
56-
, gridAreaElement contRight (panel <| p [] [text "right"])
54+
, gridAreaElement contLeft (panel <| p [] [ text "left" ])
55+
, gridAreaElement cont (panel <| p [] [ text "cont" ])
56+
, gridAreaElement contRight (panel <| p [] [ text "right" ])
5757
, gridAreaElement foot (panel <| text "foot")
5858
]
5959

examples/src/Main.elm

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import CssGrid.Sizes exposing (..)
1313
import Html
1414
import Html.Styled exposing (Attribute, Html, div, fromUnstyled, text, toUnstyled)
1515
import Html.Styled.Attributes exposing (css)
16-
import Simple exposing (viewSimple)
16+
import InnerView exposing (viewInner)
1717

1818

1919
type alias Model =
2020
()
2121

2222

23-
2423
initialModel : Model
2524
initialModel =
2625
()
@@ -37,19 +36,22 @@ view model =
3736
[]
3837
[ gridAreaElement head1 (testPanel "header ")
3938
, gridAreaElement navi1 (testPanel "nav ")
40-
, gridAreaElement cont1 [ fromUnstyled CDN.stylesheet, bootstrapPanel, viewSimple model ]
39+
, gridAreaElement contLeft1 (testPanel "contLeft ")
40+
, gridAreaElement cont1 [ fromUnstyled CDN.stylesheet, bootstrapPanel, viewInner model ]
41+
, gridAreaElement contRight1 (testPanel "contRight ")
4142
, gridAreaElement foot1 (testPanel "footer ")
4243
]
4344

45+
4446
simpleTemplateBig : SimpleTemplate
4547
simpleTemplateBig =
4648
simpleTemplate
47-
[ [ head1, navi1, navi1 ]
49+
[ [ head1, navi1, contRight1 ]
4850
, [ contLeft1, cont1, contRight1 ]
4951
, [ foot1, foot1, foot1 ]
5052
]
51-
(gap (px 3))
52-
[ fr 1, fr 1, fr 1 ]
53+
(gap (px 10))
54+
[ auto, units (fr 1), auto ]
5355

5456

5557
simpleTemplateSmall : SimpleTemplate

src/CssGrid/Simple.elm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module CssGrid.Simple exposing (ResponsiveTemplate, SimpleTemplate, simpleContai
33
import Css exposing (Style, property)
44
import Css.Media exposing (MediaQuery, withMedia)
55
import CssGrid.Areas as Areas exposing (Areas, GridAreaElement, gridAreaElementArea, gridAreaElementChildren)
6-
import CssGrid.Sizes exposing (Gap, Length, gapToString, lengthToString)
6+
import CssGrid.Sizes exposing (Gap, Length, LengthTemplate, gapToString, lengthTemplateToString)
77
import Html.Styled exposing (Attribute, Html, div)
88
import Html.Styled.Attributes exposing (css)
99

@@ -29,10 +29,10 @@ See also this [common layout](https://developer.mozilla.org/en-US/docs/Web/CSS/C
2929
3030
-}
3131
type SimpleTemplate
32-
= SimpleTemplate Areas Gap (List Length)
32+
= SimpleTemplate Areas Gap (List LengthTemplate)
3333

3434

35-
simpleTemplate : Areas -> Gap -> List Length -> SimpleTemplate
35+
simpleTemplate : Areas -> Gap -> List LengthTemplate -> SimpleTemplate
3636
simpleTemplate areas gap columnFractions =
3737
SimpleTemplate areas gap columnFractions
3838

@@ -63,7 +63,7 @@ simpleTemplateToStyle (SimpleTemplate areas gap cols) =
6363
List.map (\gridAreas -> String.join " " (List.map Areas.toString gridAreas)) areas
6464

6565
colSizes =
66-
String.join " " (List.map lengthToString cols)
66+
String.join " " (List.map lengthTemplateToString cols)
6767

6868
templateCols =
6969
case cols of

src/CssGrid/Sizes.elm

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,4 @@
1-
module CssGrid.Sizes exposing (Auto, Gap, Length, MinMax, fr, gap, gapToString, lengthToString, minmax, minmaxToString, px)
2-
3-
-- minmax(min, max)
4-
5-
6-
type MinMax
7-
= MinMax Length Length
8-
9-
10-
minmax : Length -> Length -> MinMax
11-
minmax min max =
12-
MinMax min max
13-
14-
15-
minmaxToString : MinMax -> String
16-
minmaxToString (MinMax min max) =
17-
"minmax(" ++ lengthToString min ++ ", " ++ lengthToString max ++ ")"
18-
19-
20-
{-| auto
21-
-}
22-
type Auto
23-
= Auto
24-
25-
1+
module CssGrid.Sizes exposing (Gap, Length, LengthTemplate, auto, fr, gap, gapToString, lengthTemplateToString, lengthToString, minmax, px, units)
262

273
-- TODO type <percentage>
284

@@ -32,16 +8,16 @@ type Length
328
| Px Int
339

3410

35-
px : Int -> Length
36-
px length =
37-
Px length
38-
39-
4011
fr : Float -> Length
4112
fr length =
4213
Fr length
4314

4415

16+
px : Int -> Length
17+
px length =
18+
Px length
19+
20+
4521
lengthToString : Length -> String
4622
lengthToString length =
4723
case length of
@@ -52,13 +28,47 @@ lengthToString length =
5228
String.fromInt int ++ "px"
5329

5430

31+
type LengthTemplate
32+
= Units Length
33+
| Auto
34+
| MinMax Length Length
35+
36+
37+
units : Length -> LengthTemplate
38+
units =
39+
Units
40+
41+
42+
auto : LengthTemplate
43+
auto =
44+
Auto
45+
46+
47+
minmax : Length -> Length -> LengthTemplate
48+
minmax min max =
49+
MinMax min max
50+
51+
52+
lengthTemplateToString : LengthTemplate -> String
53+
lengthTemplateToString length =
54+
case length of
55+
Units lengthUnits ->
56+
lengthToString lengthUnits
57+
58+
Auto ->
59+
"auto"
60+
61+
MinMax min max ->
62+
"minmax(" ++ lengthToString min ++ ", " ++ lengthToString max ++ ")"
63+
64+
5565
type Gap
5666
= Gap Length
5767

5868

5969
gapToString : Gap -> String
60-
gapToString (Gap value) =
61-
lengthToString value
70+
gapToString (Gap length) =
71+
lengthToString length
6272

6373

6474
gap : Length -> Gap

0 commit comments

Comments
 (0)