2018-07-27 09:25:25 +03:00
|
|
|
module Examples.DisclosureIndicator exposing (Msg, State, example, init, update)
|
|
|
|
|
2019-05-07 22:14:51 +03:00
|
|
|
{-|
|
|
|
|
|
|
|
|
@docs Msg, State, example, init, update
|
|
|
|
|
2018-07-27 09:25:25 +03:00
|
|
|
-}
|
|
|
|
|
|
|
|
import Css
|
|
|
|
import Html.Styled as Html
|
|
|
|
import Html.Styled.Attributes exposing (css)
|
|
|
|
import Html.Styled.Events exposing (onClick)
|
|
|
|
import ModuleExample as ModuleExample exposing (Category(..), ModuleExample)
|
2019-05-07 21:25:25 +03:00
|
|
|
import Nri.Ui.DisclosureIndicator.V2 as DisclosureIndicator
|
2019-05-07 21:37:14 +03:00
|
|
|
import Nri.Ui.Fonts.V1 as Fonts
|
2018-07-27 09:25:25 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
2019-05-07 22:14:51 +03:00
|
|
|
{ mediumState : Bool
|
|
|
|
, smallState : Bool
|
2018-07-27 09:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example : (Msg -> msg) -> State -> ModuleExample msg
|
|
|
|
example parentMessage state =
|
2019-05-07 21:25:25 +03:00
|
|
|
{ name = "Nri.Ui.DisclosureIndicator.V2"
|
2019-05-03 19:30:02 +03:00
|
|
|
, category = Widgets
|
2018-07-27 09:25:25 +03:00
|
|
|
, content =
|
2019-05-07 22:34:33 +03:00
|
|
|
[ viewExample ToggleMedium
|
|
|
|
state.mediumState
|
|
|
|
(Css.px 20)
|
|
|
|
(DisclosureIndicator.view
|
|
|
|
{ isOpen = state.mediumState
|
|
|
|
, size = Css.px 15
|
|
|
|
, styles = [ Css.marginRight (Css.px 10) ]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
DisclosureIndicator.view
|
|
|
|
{ isOpen = state.mediumState
|
|
|
|
, size = Css.px 15
|
|
|
|
, styles = [ Css.marginRight (Css.px 10) ]
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
, viewExample ToggleSmall
|
|
|
|
state.smallState
|
|
|
|
(Css.px 16)
|
|
|
|
(DisclosureIndicator.view
|
|
|
|
{ isOpen = state.smallState
|
|
|
|
, size = Css.px 9
|
|
|
|
, styles = [ Css.paddingRight (Css.px 8) ]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
DisclosureIndicator.view
|
|
|
|
{ isOpen = state.smallState
|
|
|
|
, size = Css.px 9
|
|
|
|
, styles = [ Css.paddingRight (Css.px 8) ]
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
]
|
|
|
|
|> List.map (Html.map parentMessage)
|
|
|
|
}
|
2019-05-07 22:27:25 +03:00
|
|
|
|
2019-05-07 22:34:33 +03:00
|
|
|
|
|
|
|
viewExample : msg -> Bool -> Css.Px -> Html.Html msg -> String -> Html.Html msg
|
|
|
|
viewExample toggle isOpen fontSize disclosureView disclosureCode =
|
|
|
|
Html.div []
|
|
|
|
[ Html.div []
|
2019-05-07 22:27:25 +03:00
|
|
|
[ Html.button
|
|
|
|
[ css
|
|
|
|
[ Css.displayFlex
|
|
|
|
, Css.alignItems Css.center
|
|
|
|
, Css.borderStyle Css.none
|
|
|
|
, Css.outline Css.none
|
|
|
|
, Fonts.baseFont
|
2019-05-07 22:34:33 +03:00
|
|
|
, Css.fontSize fontSize
|
2019-05-07 22:27:25 +03:00
|
|
|
]
|
2019-05-07 22:34:33 +03:00
|
|
|
, onClick toggle
|
2019-05-07 22:27:25 +03:00
|
|
|
]
|
2019-05-07 22:34:33 +03:00
|
|
|
[ disclosureView
|
|
|
|
, Html.text "Open for code example"
|
2019-05-07 22:27:25 +03:00
|
|
|
]
|
2018-07-27 09:25:25 +03:00
|
|
|
]
|
2019-05-07 22:34:33 +03:00
|
|
|
, if isOpen then
|
|
|
|
code disclosureCode
|
2019-05-07 22:27:25 +03:00
|
|
|
|
|
|
|
else
|
|
|
|
Html.text ""
|
2018-07-27 09:25:25 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-05-07 22:27:25 +03:00
|
|
|
code : String -> Html.Html msg
|
|
|
|
code copy =
|
|
|
|
Html.code
|
|
|
|
[ css
|
|
|
|
[ Css.fontSize (Css.px 12)
|
|
|
|
, Css.whiteSpace Css.pre
|
|
|
|
]
|
|
|
|
]
|
|
|
|
[ Html.text copy ]
|
|
|
|
|
|
|
|
|
2018-07-27 09:25:25 +03:00
|
|
|
{-| -}
|
|
|
|
init : State
|
|
|
|
init =
|
2019-05-07 22:14:51 +03:00
|
|
|
{ mediumState = False
|
|
|
|
, smallState = False
|
2018-07-27 09:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-07 22:34:33 +03:00
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= ToggleMedium
|
|
|
|
| ToggleSmall
|
|
|
|
|
|
|
|
|
2018-07-27 09:25:25 +03:00
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
2019-05-07 22:34:33 +03:00
|
|
|
ToggleMedium ->
|
|
|
|
( { state | mediumState = not state.mediumState }, Cmd.none )
|
2018-07-27 09:25:25 +03:00
|
|
|
|
2019-05-07 22:34:33 +03:00
|
|
|
ToggleSmall ->
|
|
|
|
( { state | smallState = not state.smallState }, Cmd.none )
|