Extract and use general buildSettings helper

This commit is contained in:
Tessa Kelly 2021-10-27 10:53:03 -07:00
parent 0531a7b0df
commit 93ec041197

View File

@ -71,6 +71,11 @@ defaultSettings =
} }
buildSettings : List Attribute -> Settings
buildSettings =
List.foldl (\(Attribute f) acc -> f acc) defaultSettings
{-| Text with this attribute will never wrap. {-| Text with this attribute will never wrap.
-} -}
noBreak : Attribute noBreak : Attribute
@ -86,15 +91,8 @@ css styles =
Attribute (\config -> { config | styles = config.styles ++ styles }) Attribute (\config -> { config | styles = config.styles ++ styles })
styleForAttributes : List Attribute -> Style styleForAttributes : Settings -> Style
styleForAttributes attrs = styleForAttributes config =
let
config : Settings
config =
List.foldl (\(Attribute f) acc -> f acc)
defaultSettings
attrs
in
batch batch
[ if config.noBreak then [ if config.noBreak then
whiteSpace noWrap whiteSpace noWrap
@ -109,9 +107,14 @@ styleForAttributes attrs =
-} -}
mediumBody : List Attribute -> List (Html msg) -> Html msg mediumBody : List Attribute -> List (Html msg) -> Html msg
mediumBody attributes content = mediumBody attributes content =
let
settings : Settings
settings =
buildSettings attributes
in
p p
[ paragraphStyles [ paragraphStyles
attributes settings
{ font = Fonts.baseFont { font = Fonts.baseFont
, color = gray20 , color = gray20
, size = 18 , size = 18
@ -134,9 +137,14 @@ mediumBodyGray attributes content =
-} -}
smallBody : List Attribute -> List (Html msg) -> Html msg smallBody : List Attribute -> List (Html msg) -> Html msg
smallBody attributes content = smallBody attributes content =
let
settings : Settings
settings =
buildSettings attributes
in
p p
[ paragraphStyles [ paragraphStyles
attributes settings
{ font = Fonts.baseFont { font = Fonts.baseFont
, color = gray20 , color = gray20
, size = 15 , size = 15
@ -152,9 +160,13 @@ smallBody attributes content =
-} -}
smallBodyGray : List Attribute -> List (Html msg) -> Html msg smallBodyGray : List Attribute -> List (Html msg) -> Html msg
smallBodyGray attributes content = smallBodyGray attributes content =
let
settings : Settings
settings =
buildSettings attributes
in
p p
[ paragraphStyles [ paragraphStyles settings
attributes
{ font = Fonts.baseFont { font = Fonts.baseFont
, color = gray45 , color = gray45
, size = 15 , size = 15
@ -167,7 +179,7 @@ smallBodyGray attributes content =
paragraphStyles : paragraphStyles :
List Attribute Settings
-> ->
{ color : Color { color : Color
, font : Style , font : Style
@ -177,7 +189,7 @@ paragraphStyles :
, weight : Int , weight : Int
} }
-> Html.Styled.Attribute msg -> Html.Styled.Attribute msg
paragraphStyles attributes config = paragraphStyles settings config =
Attrs.css Attrs.css
[ config.font [ config.font
, fontSize (px config.size) , fontSize (px config.size)
@ -199,7 +211,7 @@ paragraphStyles attributes config =
, lastChild , lastChild
[ margin zero [ margin zero
] ]
, styleForAttributes attributes , styleForAttributes settings
] ]
@ -207,9 +219,13 @@ paragraphStyles attributes config =
-} -}
caption : List Attribute -> List (Html msg) -> Html msg caption : List Attribute -> List (Html msg) -> Html msg
caption attributes content = caption attributes content =
let
settings : Settings
settings =
buildSettings attributes
in
p p
[ paragraphStyles [ paragraphStyles settings
attributes
{ font = Fonts.baseFont { font = Fonts.baseFont
, color = gray45 , color = gray45
, size = 13 , size = 13
@ -225,6 +241,11 @@ caption attributes content =
-} -}
ugMediumBody : List Attribute -> List (Html msg) -> Html msg ugMediumBody : List Attribute -> List (Html msg) -> Html msg
ugMediumBody attributes = ugMediumBody attributes =
let
settings : Settings
settings =
buildSettings attributes
in
p p
[ Attrs.css [ Attrs.css
[ Fonts.quizFont [ Fonts.quizFont
@ -233,7 +254,7 @@ ugMediumBody attributes =
, whiteSpace preLine , whiteSpace preLine
, color gray20 , color gray20
, margin zero , margin zero
, styleForAttributes attributes , styleForAttributes settings
] ]
] ]
@ -242,6 +263,11 @@ ugMediumBody attributes =
-} -}
ugSmallBody : List Attribute -> List (Html msg) -> Html msg ugSmallBody : List Attribute -> List (Html msg) -> Html msg
ugSmallBody attributes = ugSmallBody attributes =
let
settings : Settings
settings =
buildSettings attributes
in
p p
[ Attrs.css [ Attrs.css
[ Fonts.quizFont [ Fonts.quizFont
@ -250,7 +276,7 @@ ugSmallBody attributes =
, whiteSpace preLine , whiteSpace preLine
, color gray20 , color gray20
, margin zero , margin zero
, styleForAttributes attributes , styleForAttributes settings
] ]
] ]