noredink-ui/styleguide-app/Examples/IconExamples.elm

163 lines
3.9 KiB
Elm
Raw Normal View History

2022-03-21 23:32:55 +03:00
module Examples.IconExamples exposing
( preview
, Settings, init, Msg, update, viewSettings
2022-03-21 23:32:55 +03:00
, view, viewWithCustomStyles
)
{-|
@docs preview
@docs Settings, init, Msg, update, viewSettings
2022-03-21 23:32:55 +03:00
@docs view, viewWithCustomStyles
-}
2019-10-01 03:16:29 +03:00
import Css
2022-03-21 18:31:34 +03:00
import Css.Global
2019-10-01 03:16:29 +03:00
import Html.Styled as Html exposing (Html)
2022-03-15 21:06:13 +03:00
import Html.Styled.Attributes exposing (css)
2022-03-21 23:32:55 +03:00
import Nri.Ui.Checkbox.V5 as Checkbox
2019-10-01 03:16:29 +03:00
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Heading.V2 as Heading
import Nri.Ui.Svg.V1 as Svg
2021-10-27 20:42:23 +03:00
import Nri.Ui.Text.V6 as Text
2019-10-01 03:16:29 +03:00
2022-03-21 23:32:55 +03:00
{-| -}
2021-11-05 21:48:09 +03:00
preview : List Svg.Svg -> List (Html msg)
preview icons =
[ Html.div
[ css
[ Css.displayFlex
2021-11-05 22:04:46 +03:00
, Css.flexWrap Css.wrap
, Css.property "gap" "10px"
2021-11-05 21:48:09 +03:00
, Css.color Colors.gray45
]
]
(List.map
2021-11-05 22:04:46 +03:00
(Svg.withWidth (Css.px 30) >> Svg.withHeight (Css.px 30) >> Svg.toHtml)
2021-11-05 21:48:09 +03:00
icons
)
]
2022-03-21 23:32:55 +03:00
{-| -}
type alias Settings =
{ showIconName : Bool }
{-| -}
init : Settings
init =
{ showIconName = False }
{-| -}
type Msg
= ShowNames Bool
{-| -}
update : Msg -> Settings -> ( Settings, Cmd msg )
update msg settings =
case msg of
ShowNames showIconName ->
( { settings | showIconName = showIconName }
, Cmd.none
)
{-| -}
viewSettings : Settings -> Html Msg
viewSettings { showIconName } =
2022-03-21 23:32:55 +03:00
Checkbox.viewWithLabel
{ identifier = "show-icon-name-checkbox"
, label = "Show names"
, setterMsg = ShowNames
2022-03-21 23:32:55 +03:00
, selected = Checkbox.selectedFromBool showIconName
, disabled = False
, theme = Checkbox.Square
}
{-| -}
view : Settings -> String -> List ( String, Svg.Svg ) -> Html msg
view settings headerText icons =
let
defaultStyles =
[ Css.height (Css.px 25)
, Css.width (Css.px 25)
, Css.margin (Css.px 4)
, Css.color Colors.gray45
]
in
viewWithCustomStyles settings
headerText
(List.map (\( name, svg ) -> ( name, svg, defaultStyles )) icons)
{-| -}
viewWithCustomStyles : Settings -> String -> List ( String, Svg.Svg, List Css.Style ) -> Html msg
viewWithCustomStyles { showIconName } headerText icons =
2022-03-21 18:31:34 +03:00
Html.section
[ css
[ Css.displayFlex
, Css.alignItems Css.center
, Css.property "gap" "10px"
, Css.marginTop (Css.px 10)
]
2022-03-21 18:31:34 +03:00
]
[ Heading.h2
[ Heading.css
2022-03-21 18:31:34 +03:00
[ Css.width (Css.px 150)
, Css.fontSize (Css.px 16)
2022-03-21 18:31:34 +03:00
, Css.lineHeight (Css.num 1.2)
, Css.fontWeight (Css.int 700)
]
]
[ Html.text headerText ]
2022-03-21 18:31:34 +03:00
, Html.div
[ css
[ Css.displayFlex
, Css.flexWrap Css.wrap
, Css.property "gap" "10px"
]
]
(List.map (viewIcon showIconName) icons)
2019-10-01 03:16:29 +03:00
]
viewIcon : Bool -> ( String, Svg.Svg, List Css.Style ) -> Html msg
viewIcon showIconName ( name, icon, style ) =
2019-10-01 03:16:29 +03:00
Html.div
[ css
[ Css.displayFlex
2019-10-01 03:16:29 +03:00
, Css.alignItems Css.center
2022-03-21 18:31:34 +03:00
, Css.backgroundColor Colors.gray96
, Css.borderRadius (Css.px 8)
, Css.padding2 (Css.px 5) (Css.px 10)
, Css.hover
[ Css.backgroundColor Colors.glacier
, Css.color Colors.azure
, Css.Global.descendants
[ Css.Global.selector "svg"
[ Css.color Colors.azure
]
]
]
2019-10-01 03:16:29 +03:00
]
]
2022-01-18 22:40:46 +03:00
[ icon
|> Svg.withCss style
|> Svg.toHtml
2022-03-21 18:31:34 +03:00
, Text.smallBody
[ Text.plaintext name
, Text.css <|
if showIconName then
[]
else
[ Css.display Css.none ]
2022-03-21 18:31:34 +03:00
]
2019-10-01 03:16:29 +03:00
]