add custom attributes for things like titles

This commit is contained in:
Brian Hicks 2019-08-20 13:08:01 -05:00
parent c43b4aa53d
commit f8f4a81d8a
2 changed files with 31 additions and 10 deletions

View File

@ -2,7 +2,7 @@ module Nri.Ui.Callout.V1 exposing
( Attribute, callout ( Attribute, callout
, sideText , sideText
, containerCss, contentCss , containerCss, contentCss
, Attrs, defaultAttrs , custom
) )
{-| {-|
@ -13,6 +13,8 @@ module Nri.Ui.Callout.V1 exposing
@docs containerCss, contentCss @docs containerCss, contentCss
@docs custom
-} -}
import Css import Css
@ -27,6 +29,7 @@ type Attribute msg
= SideText (Maybe (Html msg)) = SideText (Maybe (Html msg))
| ContentCss (List Css.Style) | ContentCss (List Css.Style)
| ContainerCss (List Css.Style) | ContainerCss (List Css.Style)
| Custom (Html.Attribute msg)
sideText : Html msg -> Attribute msg sideText : Html msg -> Attribute msg
@ -44,17 +47,25 @@ contentCss =
ContentCss ContentCss
custom : Html.Attribute msg -> Attribute msg
custom =
Custom
type alias Attrs msg = type alias Attrs msg =
{ sideText : Maybe (Html msg) { sideText : Maybe (Html msg)
, containerCss : List Css.Style , containerCss : List Css.Style
, contentCss : List Css.Style , contentCss : List Css.Style
, customAttrs : List (Html.Attribute msg)
} }
defaultAttrs : Attrs msg
defaultAttrs = defaultAttrs =
{ sideText = Nothing { sideText = Nothing
, containerCss = [] , containerCss = []
, contentCss = [] , contentCss = []
, customAttrs = []
} }
@ -70,6 +81,9 @@ customize attr attrs =
ContainerCss css -> ContainerCss css ->
{ attrs | containerCss = css } { attrs | containerCss = css }
Custom custom_ ->
{ attrs | customAttrs = custom_ :: attrs.customAttrs }
callout : List (Attribute msg) -> List (Html msg) -> Html msg callout : List (Attribute msg) -> List (Html msg) -> Html msg
callout attrs children = callout attrs children =
@ -78,8 +92,8 @@ callout attrs children =
List.foldl customize defaultAttrs attrs List.foldl customize defaultAttrs attrs
in in
Html.aside Html.aside
[ css finalAttrs.containerCss ([ css finalAttrs.containerCss
, css , css
[ Css.boxSizing Css.borderBox [ Css.boxSizing Css.borderBox
, Css.backgroundColor Colors.sunshine , Css.backgroundColor Colors.sunshine
, Css.displayFlex , Css.displayFlex
@ -89,7 +103,9 @@ callout attrs children =
, Css.border3 (Css.px 1) Css.solid Colors.highlightYellow , Css.border3 (Css.px 1) Css.solid Colors.highlightYellow
, Css.borderRadius (Css.px 4) , Css.borderRadius (Css.px 4)
] ]
] ]
++ finalAttrs.customAttrs
)
[ case finalAttrs.sideText of [ case finalAttrs.sideText of
Just text -> Just text ->
Html.div Html.div

View File

@ -8,7 +8,7 @@ module Examples.Callout exposing (example)
import Css import Css
import Html.Styled as Html import Html.Styled as Html
import Html.Styled.Attributes exposing (href) import Html.Styled.Attributes exposing (href, title)
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample) import ModuleExample as ModuleExample exposing (Category(..), ModuleExample)
import Nri.Ui.Callout.V1 as Callout exposing (callout) import Nri.Ui.Callout.V1 as Callout exposing (callout)
@ -19,9 +19,11 @@ example =
, category = Messaging , category = Messaging
, content = , content =
[ -- PLAIN [ -- PLAIN
Html.h4 [] [ Html.text "Originally Designed Use Case" ] Html.h3 [] [ Html.text "Originally Designed Use Case" ]
, callout , callout
[ Callout.sideText (Html.text "BETA") ] [ Callout.sideText (Html.text "BETA")
, Callout.custom (title "beta warning")
]
[ Html.text "This tab is still a work in progress; some of your student's information may be missing." [ Html.text "This tab is still a work in progress; some of your student's information may be missing."
, Html.br [] [] , Html.br [] []
, Html.text "To share your thoughts and help us improve the experience, " , Html.text "To share your thoughts and help us improve the experience, "
@ -30,20 +32,23 @@ example =
] ]
-- WITH SIDE TEXT -- WITH SIDE TEXT
, Html.h4 [] [ Html.text "Without side text" ] , Html.h3 [] [ Html.text "Without side text" ]
, callout [] , callout
[ Callout.custom (title "no side text") ]
[ Html.text "I feel weird without my side text!" ] [ Html.text "I feel weird without my side text!" ]
-- WITH CSS CUSTOMIZATIONS -- WITH CSS CUSTOMIZATIONS
, Html.h4 [] [ Html.text "With CSS customizations" ] , Html.h3 [] [ Html.text "With CSS customizations" ]
, callout , callout
[ Callout.containerCss [ Css.margin (Css.px 20) ] [ Callout.containerCss [ Css.margin (Css.px 20) ]
, Callout.sideText (Html.text "HMMM") , Callout.sideText (Html.text "HMMM")
, Callout.custom (title "margin")
] ]
[ Html.text "My container styles are customized to add margin around the callout" ] [ Html.text "My container styles are customized to add margin around the callout" ]
, callout , callout
[ Callout.contentCss [ Css.textTransform Css.uppercase ] [ Callout.contentCss [ Css.textTransform Css.uppercase ]
, Callout.sideText (Html.text "WOW!") , Callout.sideText (Html.text "WOW!")
, Callout.custom (title "yelling")
] ]
[ Html.text "My content styles are customized to yell about everything" ] [ Html.text "My content styles are customized to yell about everything" ]
] ]