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

176 lines
5.8 KiB
Elm
Raw Normal View History

2020-03-31 22:43:32 +03:00
module Examples.ClickableSvg exposing (Msg, State, example)
2020-03-09 19:38:16 +03:00
{-|
2020-03-31 22:43:32 +03:00
@docs Msg, State, example
2020-03-09 19:38:16 +03:00
-}
2020-06-19 23:41:28 +03:00
import AtomicDesignType exposing (AtomicDesignType(..))
import Category exposing (Category(..))
2020-03-09 19:38:16 +03:00
import Color exposing (Color)
import Css
2020-03-31 23:20:03 +03:00
import Example exposing (Example)
2020-03-09 19:38:16 +03:00
import Examples.IconExamples as IconExamples
import Html.Styled as Html
import Html.Styled.Attributes as Attributes
import Html.Styled.Events as Events
import KeyboardSupport exposing (Direction(..), Key(..))
2020-03-09 19:38:16 +03:00
import Nri.Ui.ClickableSvg.V1 as ClickableSvg
import Nri.Ui.Colors.Extra exposing (fromCssColor, toCssColor)
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Heading.V2 as Heading
2020-04-24 23:11:09 +03:00
import Nri.Ui.Select.V7 as Select
2020-03-09 19:38:16 +03:00
import Nri.Ui.Svg.V1 as Svg
import Nri.Ui.UiIcon.V1 as UiIcon
{-| -}
2020-03-31 23:20:03 +03:00
example : Example State Msg
2020-03-31 22:43:32 +03:00
example =
2020-03-09 19:38:16 +03:00
{ name = "Nri.Ui.ClickableSvg.V1"
2020-03-31 22:43:32 +03:00
, categories = [ Buttons, Icons ]
2020-06-20 00:16:10 +03:00
, atomicDesignType = Molecule
, keyboardSupport = []
2020-03-31 22:43:32 +03:00
, state = init
, update = update
2020-03-31 22:48:26 +03:00
, subscriptions = \_ -> Sub.none
2020-03-31 22:43:32 +03:00
, view =
\state ->
[ viewExample "ClickableSvg.button \"Back\" UiIcon.arrowLeft [ ClickableSvg.onClick OnClickMsg ]" <|
ClickableSvg.button "Back"
2020-03-31 22:43:32 +03:00
UiIcon.arrowLeft
[ ClickableSvg.onClick (ShowItWorked "You clicked the back button!") ]
, viewExample "ClickableSvg.link \"Back\" UiIcon.arrowLeft [ ClickableSvg.linkSpa \"some_link\" ]" <|
ClickableSvg.link "Back" UiIcon.arrowLeft [ ClickableSvg.linkSpa "some_link" ]
, viewExample "ClickableSvg.button \"Disabled\" UiIcon.arrowLeft [ ClickableSvg.disabled True ]" <|
ClickableSvg.button "Disabled" UiIcon.arrowLeft [ ClickableSvg.disabled True ]
, viewExample "ClickableSvg.link \"Disabled\" UiIcon.arrowLeft [ ClickableSvg.disabled True ]" <|
ClickableSvg.link "Disabled" UiIcon.arrowLeft [ ClickableSvg.disabled True ]
, viewExample
"""
ClickableSvg.button "Go to tutorial"
UiIcon.footsteps
[ ClickableSvg.width (Css.px 30)
, ClickableSvg.height (Css.px 30)
, ClickableSvg.onClick (ShowItWorked "You clicked the tutorials button!")
, ClickableSvg.custom [ Attributes.id "clickable-svg-customized-example-id" ]
, ClickableSvg.css [ Css.border3 (Css.px 1) Css.dashed Colors.azure ]
]
"""
<|
ClickableSvg.button "Go to tutorial"
2020-03-31 22:43:32 +03:00
UiIcon.footsteps
[ ClickableSvg.width (Css.px 30)
, ClickableSvg.height (Css.px 30)
2020-03-31 22:43:32 +03:00
, ClickableSvg.onClick (ShowItWorked "You clicked the tutorials button!")
, ClickableSvg.custom [ Attributes.id "clickable-svg-customized-example-id" ]
, ClickableSvg.css [ Css.border3 (Css.px 1) Css.dashed Colors.azure ]
2020-03-31 22:43:32 +03:00
]
2020-06-09 23:47:53 +03:00
, viewExample
"""
ClickableSvg.button "Preview"
UiIcon.preview
[ ClickableSvg.width (Css.px 20)
, ClickableSvg.height (Css.px 20)
, ClickableSvg.onClick (ShowItWorked "You clicked the preview button!")
, ClickableSvg.withTooltipAbove { id = "preview", isOpen = state.tooltipPreview, onShow = SetPreviewTooltip }
]
"""
<|
ClickableSvg.button "Preview"
UiIcon.preview
[ ClickableSvg.width (Css.px 20)
, ClickableSvg.height (Css.px 20)
, ClickableSvg.onClick (ShowItWorked "You clicked the preview button!")
, ClickableSvg.withTooltipAbove
{ id = "preview"
, isOpen = state.tooltipPreview
, onShow = SetPreviewTooltip
}
]
, viewExample
"""
ClickableSvg.button "Share"
UiIcon.share
[ ClickableSvg.width (Css.px 20)
, ClickableSvg.height (Css.px 20)
, ClickableSvg.onClick (ShowItWorked "You clicked the Share button!")
, ClickableSvg.withTooltipBelow { id = "share", isOpen = state.tooltipShareTo, onShow = SetShareTooltip }
]
"""
<|
ClickableSvg.button "Share"
UiIcon.share
[ ClickableSvg.width (Css.px 20)
, ClickableSvg.height (Css.px 20)
, ClickableSvg.onClick (ShowItWorked "You clicked the share button!")
, ClickableSvg.withTooltipBelow
{ id = "share"
, isOpen = state.tooltipShareTo
, onShow = SetShareTooltip
}
]
2020-03-09 21:05:28 +03:00
]
2020-03-09 19:38:16 +03:00
}
viewExample : String -> Html.Html msg -> Html.Html msg
viewExample code html =
Html.div
[ Attributes.css [ Css.displayFlex, Css.alignItems Css.center ] ]
[ html
, viewCode code
]
2020-03-09 20:55:43 +03:00
viewCode : String -> Html.Html msg
viewCode renderStrategy =
2020-03-09 20:50:00 +03:00
Html.code
2020-03-09 19:38:16 +03:00
[ Attributes.css
[ Css.width (Css.px 400)
, Css.marginLeft (Css.px 20)
2020-03-09 19:38:16 +03:00
]
]
2020-03-09 20:55:43 +03:00
[ Html.pre [] [ Html.text renderStrategy ] ]
2020-03-09 19:38:16 +03:00
{-| -}
type alias State =
2020-06-09 23:47:53 +03:00
{ tooltipPreview : Bool
, tooltipShareTo : Bool
}
2020-03-09 19:38:16 +03:00
{-| -}
init : State
init =
2020-06-09 23:47:53 +03:00
{ tooltipPreview = False
, tooltipShareTo = False
}
2020-03-09 19:38:16 +03:00
{-| -}
type Msg
2020-03-31 22:43:32 +03:00
= ShowItWorked String
2020-06-09 23:47:53 +03:00
| SetPreviewTooltip Bool
| SetShareTooltip Bool
2020-03-09 19:38:16 +03:00
{-| -}
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
2020-03-31 22:43:32 +03:00
case msg of
ShowItWorked message ->
let
_ =
Debug.log "ClickableSvg" message
in
( state, Cmd.none )
2020-06-09 23:47:53 +03:00
SetPreviewTooltip bool ->
( { state | tooltipPreview = bool }, Cmd.none )
SetShareTooltip bool ->
( { state | tooltipShareTo = bool }, Cmd.none )