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

86 lines
2.4 KiB
Elm
Raw Normal View History

2020-03-31 22:43:32 +03:00
module Examples.DisclosureIndicator exposing (Msg, State, example)
2019-05-07 22:14:51 +03:00
{-|
2020-03-31 22:43:32 +03:00
@docs Msg, State, example
2019-05-07 22:14:51 +03:00
-}
import Category exposing (Category(..))
import Css
2020-03-31 23:20:03 +03:00
import Example exposing (Example)
import Html.Styled as Html
import Html.Styled.Attributes exposing (css)
2020-04-24 23:04:45 +03:00
import Nri.Ui.Button.V10 as Button
import Nri.Ui.DisclosureIndicator.V2 as DisclosureIndicator
2021-10-27 20:42:23 +03:00
import Nri.Ui.Text.V6 as Text
{-| -}
type alias State =
2019-05-09 19:46:57 +03:00
{ largeState : Bool
, mediumState : Bool
}
{-| -}
2020-03-31 23:20:03 +03:00
example : Example State Msg
2020-03-31 22:43:32 +03:00
example =
2020-09-09 21:43:10 +03:00
{ name = "DisclosureIndicator"
, version = 2
, categories = [ Icons ]
, keyboardSupport = []
2020-03-31 22:43:32 +03:00
, state = init
, update = update
2020-03-31 22:48:26 +03:00
, subscriptions = \_ -> Sub.none
, preview =
[ DisclosureIndicator.medium [] False
, DisclosureIndicator.medium [] True
, DisclosureIndicator.large [] False
, DisclosureIndicator.large [] True
]
2020-03-31 22:43:32 +03:00
, view =
\state ->
2021-10-27 21:54:14 +03:00
[ Text.smallBodyGray [ Text.plaintext "The disclosure indicator is only the caret. It is NOT a button -- you must create a button or clickabletext yourself!" ]
2020-03-31 22:43:32 +03:00
, Html.div [ css [ Css.displayFlex, Css.padding (Css.px 8) ] ]
2020-04-24 23:04:45 +03:00
[ Button.button "Toggle large indicator"
[ Button.onClick ToggleLarge, Button.small, Button.secondary ]
, Button.button "Toggle medium indicator"
[ Button.onClick ToggleMedium, Button.small, Button.secondary ]
2020-03-31 22:43:32 +03:00
]
, Html.div [ css [ Css.displayFlex, Css.alignItems Css.center, Css.marginBottom (Css.px 8) ] ]
[ DisclosureIndicator.large [ Css.marginRight (Css.px 10) ] state.largeState
, Html.text "I'm a 17px caret icon."
]
, Html.div [ css [ Css.displayFlex, Css.alignItems Css.center, Css.marginBottom (Css.px 8) ] ]
[ DisclosureIndicator.medium [ Css.paddingRight (Css.px 8) ] state.mediumState
, Html.text "I'm a 15px caret icon."
]
]
2019-05-07 22:34:33 +03:00
}
2019-05-07 22:27:25 +03:00
2019-05-07 22:34:33 +03:00
{-| -}
init : State
init =
2019-05-09 19:46:57 +03:00
{ largeState = False
, mediumState = False
}
2019-05-07 22:34:33 +03:00
{-| -}
type Msg
2019-05-09 19:46:57 +03:00
= ToggleLarge
| ToggleMedium
2019-05-07 22:34:33 +03:00
{-| -}
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
case msg of
2019-05-09 19:46:57 +03:00
ToggleLarge ->
( { state | largeState = not state.largeState }, Cmd.none )
2019-05-07 22:34:33 +03:00
ToggleMedium ->
( { state | mediumState = not state.mediumState }, Cmd.none )