mirror of
https://github.com/NoRedInk/noredink-ui.git
synced 2024-12-25 06:33:09 +03:00
Use Attribute pattern wrapping a function
This commit is contained in:
parent
f478bcc508
commit
0531a7b0df
@ -55,41 +55,44 @@ import Nri.Ui.Fonts.V1 as Fonts
|
|||||||
|
|
||||||
{-| -}
|
{-| -}
|
||||||
type Attribute
|
type Attribute
|
||||||
= NoBreak
|
= Attribute (Settings -> Settings)
|
||||||
| Css (List Style)
|
|
||||||
|
|
||||||
|
type alias Settings =
|
||||||
|
{ noBreak : Bool
|
||||||
|
, styles : List Css.Style
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
defaultSettings : Settings
|
||||||
|
defaultSettings =
|
||||||
|
{ noBreak = False
|
||||||
|
, styles = []
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
{-| Text with this attribute will never wrap.
|
{-| Text with this attribute will never wrap.
|
||||||
-}
|
-}
|
||||||
noBreak : Attribute
|
noBreak : Attribute
|
||||||
noBreak =
|
noBreak =
|
||||||
NoBreak
|
Attribute (\config -> { config | noBreak = True })
|
||||||
|
|
||||||
|
|
||||||
{-| Add some custom CSS to the text. If you find yourself using this a lot,
|
{-| Add some custom CSS to the text. If you find yourself using this a lot,
|
||||||
please add a stricter attribute to noredink-ui!
|
please add a stricter attribute to noredink-ui!
|
||||||
-}
|
-}
|
||||||
css : List Style -> Attribute
|
css : List Style -> Attribute
|
||||||
css =
|
css styles =
|
||||||
Css
|
Attribute (\config -> { config | styles = config.styles ++ styles })
|
||||||
|
|
||||||
|
|
||||||
styleForAttributes : List Attribute -> Style
|
styleForAttributes : List Attribute -> Style
|
||||||
styleForAttributes attrs =
|
styleForAttributes attrs =
|
||||||
let
|
let
|
||||||
|
config : Settings
|
||||||
config =
|
config =
|
||||||
List.foldl
|
List.foldl (\(Attribute f) acc -> f acc)
|
||||||
(\attr soFar ->
|
defaultSettings
|
||||||
case attr of
|
|
||||||
NoBreak ->
|
|
||||||
{ soFar | noBreak = True }
|
|
||||||
|
|
||||||
Css styles ->
|
|
||||||
{ soFar | styles = soFar.styles ++ styles }
|
|
||||||
)
|
|
||||||
{ noBreak = False
|
|
||||||
, styles = []
|
|
||||||
}
|
|
||||||
attrs
|
attrs
|
||||||
in
|
in
|
||||||
batch
|
batch
|
||||||
|
Loading…
Reference in New Issue
Block a user