2018-07-27 09:25:25 +03:00
|
|
|
module Examples.DisclosureIndicator exposing (Msg, State, example, init, update)
|
|
|
|
|
|
|
|
{- \
|
|
|
|
@docs Msg, State, example, init, update,
|
|
|
|
-}
|
|
|
|
|
|
|
|
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 Msg
|
|
|
|
= DisclosureIndicatorToggle Bool
|
|
|
|
| InlineDisclosureIndicatorToggle Bool
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
{ disclosed : Bool
|
|
|
|
, inlineDisclosed : Bool
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
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 =
|
|
|
|
[ Html.h3 [] [ Html.text "Panel indicator" ]
|
2019-05-07 21:37:14 +03:00
|
|
|
, Html.button
|
|
|
|
[ css
|
|
|
|
[ Css.borderStyle Css.none
|
|
|
|
, Css.outline Css.none
|
|
|
|
, Css.fontSize (Css.px 20)
|
|
|
|
]
|
|
|
|
, onClick (DisclosureIndicatorToggle (not state.disclosed))
|
2018-07-27 09:25:25 +03:00
|
|
|
]
|
2019-05-07 22:12:13 +03:00
|
|
|
[ DisclosureIndicator.view { isOpen = state.disclosed }
|
2019-05-07 21:37:14 +03:00
|
|
|
, Html.text "Item with detail"
|
2018-07-27 09:25:25 +03:00
|
|
|
]
|
|
|
|
, Html.h3 [] [ Html.text "Inline indicator" ]
|
|
|
|
, Html.p []
|
|
|
|
[ Html.text
|
|
|
|
"""
|
|
|
|
The inline variant of the indicator is smaller and occupies
|
|
|
|
less vertical space so it can be inlined in lists or tables
|
|
|
|
without breaking text flow. Also, it rotates from right to
|
|
|
|
down direction when expanding.
|
|
|
|
"""
|
|
|
|
]
|
2019-05-07 21:37:14 +03:00
|
|
|
, Html.button
|
|
|
|
[ css
|
|
|
|
[ Css.displayFlex
|
|
|
|
, Css.alignItems Css.center
|
|
|
|
, Css.borderStyle Css.none
|
|
|
|
, Css.outline Css.none
|
|
|
|
, Fonts.baseFont
|
|
|
|
, Css.fontSize (Css.px 16)
|
|
|
|
]
|
|
|
|
, onClick (InlineDisclosureIndicatorToggle (not state.inlineDisclosed))
|
2018-07-27 09:25:25 +03:00
|
|
|
]
|
2019-05-07 22:12:13 +03:00
|
|
|
[ DisclosureIndicator.viewInline { isOpen = state.inlineDisclosed }
|
2019-05-07 21:37:14 +03:00
|
|
|
, Html.text "Item with detail"
|
2018-07-27 09:25:25 +03:00
|
|
|
]
|
|
|
|
]
|
2018-10-23 19:55:30 +03:00
|
|
|
|> List.map (Html.map parentMessage)
|
2018-07-27 09:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
{ disclosed = False
|
|
|
|
, inlineDisclosed = False
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
DisclosureIndicatorToggle disclosed ->
|
|
|
|
( { state | disclosed = disclosed }, Cmd.none )
|
|
|
|
|
|
|
|
InlineDisclosureIndicatorToggle disclosed ->
|
|
|
|
( { state | inlineDisclosed = disclosed }, Cmd.none )
|