git.iko.soy/typeable/elm-ui
on master help sign in
Give border a unique constructor
commitd4175a31f15b17a39aaf599d42290ce98d2ab4f0 authorMatthew Griffith <mdg.griffith@gmail.com> dateFri 14 Sep 2018, 11:16 (8 years ago) parent1511221
2 files changed+116−21
src/Element/Border.elm+90−21 src/Internal/Model.elm+26
src/Element/Border.elm+90−21
@@ -41,38 +41,81 @@ import Internal.Style as Style exposing (classes)
4141{-| -}
4242color : Color -> Attr decorative msg
4343color clr =
44− Internal.StyleClass Flag.borderColor (Internal.Colored ("border-color-" ++ Internal.formatColorClass clr) "border-color" clr)
44+ Internal.StyleClass
45+ Flag.borderColor
46+ (Internal.Colored
47+ ("bc-" ++ Internal.formatColorClass clr)
48+ "border-color"
49+ clr
50+ )
4551
4652
4753{-| -}
4854width : Int -> Attribute msg
4955width v =
50− Internal.StyleClass Flag.borderWidth (Internal.Single ("border-" ++ String.fromInt v) "border-width" (String.fromInt v ++ "px"))
56+ Internal.StyleClass
57+ Flag.borderWidth
58+ (Internal.BorderWidth
59+ ("b-" ++ String.fromInt v)
60+ v
61+ v
62+ v
63+ v
64+ )
5165
5266
5367{-| Set horizontal and vertical borders.
5468-}
5569widthXY : Int -> Int -> Attribute msg
5670widthXY x y =
57− Internal.StyleClass Flag.borderWidth (Internal.Single ("border-" ++ String.fromInt x ++ "-" ++ String.fromInt y) "border-width" (String.fromInt y ++ "px " ++ String.fromInt x ++ "px"))
71+ Internal.StyleClass
72+ Flag.borderWidth
73+ (Internal.BorderWidth
74+ ("b-"
75+ ++ String.fromInt x
76+ ++ "-"
77+ ++ String.fromInt y
78+ )
79+ y
80+ x
81+ y
82+ x
83+ )
5884
5985
6086{-| -}
61−widthEach : { bottom : Int, left : Int, right : Int, top : Int } -> Attribute msg
87+widthEach :
88+ { bottom : Int
89+ , left : Int
90+ , right : Int
91+ , top : Int
92+ }
93+ -> Attribute msg
6294widthEach { bottom, top, left, right } =
63− Internal.StyleClass Flag.borderWidth
64− (Internal.Single ("border-" ++ String.fromInt top ++ "-" ++ String.fromInt right ++ String.fromInt bottom ++ "-" ++ String.fromInt left)
65− "border-width"
66− (String.fromInt top
67− ++ "px "
68− ++ String.fromInt right
69− ++ "px "
70− ++ String.fromInt bottom
71− ++ "px "
72− ++ String.fromInt left
73− ++ "px"
95+ if top == bottom && left == right then
96+ if top == right then
97+ width top
98+
99+ else
100+ widthXY left top
101+
102+ else
103+ Internal.StyleClass Flag.borderWidth
104+ (Internal.BorderWidth
105+ ("b-"
106+ ++ String.fromInt top
107+ ++ "-"
108+ ++ String.fromInt right
109+ ++ "-"
110+ ++ String.fromInt bottom
111+ ++ "-"
112+ ++ String.fromInt left
113+ )
114+ top
115+ right
116+ bottom
117+ left
74118 )
75− )
76119
77120
78121
@@ -105,14 +148,34 @@ dotted =
105148-}
106149rounded : Int -> Attribute msg
107150rounded radius =
108− Internal.StyleClass Flag.borderRound (Internal.Single ("border-radius-" ++ String.fromInt radius) "border-radius" (String.fromInt radius ++ "px"))
151+ Internal.StyleClass
152+ Flag.borderRound
153+ (Internal.Single
154+ ("br-" ++ String.fromInt radius)
155+ "border-radius"
156+ (String.fromInt radius ++ "px")
157+ )
109158
110159
111160{-| -}
112−roundEach : { topLeft : Int, topRight : Int, bottomLeft : Int, bottomRight : Int } -> Attribute msg
161+roundEach :
162+ { topLeft : Int
163+ , topRight : Int
164+ , bottomLeft : Int
165+ , bottomRight : Int
166+ }
167+ -> Attribute msg
113168roundEach { topLeft, topRight, bottomLeft, bottomRight } =
114169 Internal.StyleClass Flag.borderRound
115− (Internal.Single ("border-radius-" ++ String.fromInt topLeft ++ "-" ++ String.fromInt topRight ++ String.fromInt bottomLeft ++ "-" ++ String.fromInt bottomRight)
170+ (Internal.Single
171+ ("br-"
172+ ++ String.fromInt topLeft
173+ ++ "-"
174+ ++ String.fromInt topRight
175+ ++ String.fromInt bottomLeft
176+ ++ "-"
177+ ++ String.fromInt bottomRight
178+ )
116179 "border-radius"
117180 (String.fromInt topLeft
118181 ++ "px "
@@ -168,7 +231,10 @@ shadow almostShade =
168231 }
169232 in
170233 Internal.StyleClass Flag.shadows <|
171− Internal.Single (Internal.boxShadowName shade) "box-shadow" (Internal.formatBoxShadow shade)
234+ Internal.Single
235+ (Internal.boxShadowName shade)
236+ "box-shadow"
237+ (Internal.formatBoxShadow shade)
172238
173239
174240{-| -}
@@ -190,7 +256,10 @@ innerShadow almostShade =
190256 }
191257 in
192258 Internal.StyleClass Flag.shadows <|
193− Internal.Single (Internal.boxShadowName shade) "box-shadow" (Internal.formatBoxShadow shade)
259+ Internal.Single
260+ (Internal.boxShadowName shade)
261+ "box-shadow"
262+ (Internal.formatBoxShadow shade)
194263
195264
196265
src/Internal/Model.elm+26
@@ -181,6 +181,7 @@ type Style
181181 | Single String String String
182182 | Colored String String Color
183183 | SpacingStyle String Int Int
184+ | BorderWidth String Int Int Int Int
184185 | PaddingStyle String Int Int Int Int
185186 | GridTemplateStyle
186187 { spacing : ( Length, Length )
@@ -329,6 +330,7 @@ unstyled =
329330 Unstyled << always
330331
331332
333+
332334finalizeNode has node attributes children embedMode parentContext =
333335 let
334336 createNode nodeName attrs =
@@ -2446,6 +2448,27 @@ toStyleSheetString options stylesheet =
24462448 )
24472449 ]
24482450
2451+ BorderWidth cls top right bottom left ->
2452+ let
2453+ class =
2454+ "."
2455+ ++ cls
2456+ in
2457+ renderStyle
2458+ maybePseudo
2459+ class
2460+ [ Property "border-width"
2461+ (String.fromInt top
2462+ ++ "px "
2463+ ++ String.fromInt right
2464+ ++ "px "
2465+ ++ String.fromInt bottom
2466+ ++ "px "
2467+ ++ String.fromInt left
2468+ ++ "px"
2469+ )
2470+ ]
2471+
24492472 GridTemplateStyle template ->
24502473 let
24512474 class =
@@ -2793,6 +2816,9 @@ getStyleName style =
27932816 PaddingStyle cls top right bottom left ->
27942817 cls
27952818
2819+ BorderWidth cls top right bottom left ->
2820+ cls
2821+
27962822 GridTemplateStyle template ->
27972823 "grid-rows-"
27982824 ++ String.join "-" (List.map lengthClassName template.rows)