2020-03-31 22:43:32 +03:00
|
|
|
module Examples.DisclosureIndicator exposing (Msg, State, example)
|
2018-07-27 09:25:25 +03:00
|
|
|
|
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
|
|
|
|
2018-07-27 09:25:25 +03:00
|
|
|
-}
|
|
|
|
|
2020-03-24 03:33:42 +03:00
|
|
|
import Category exposing (Category(..))
|
2022-03-22 19:11:43 +03:00
|
|
|
import Css exposing (Style)
|
|
|
|
import Debug.Control as Control exposing (Control)
|
2022-03-22 19:15:40 +03:00
|
|
|
import Debug.Control.Extra as ControlExtra
|
2022-03-22 19:11:43 +03:00
|
|
|
import Debug.Control.View as ControlView
|
2020-03-31 23:20:03 +03:00
|
|
|
import Example exposing (Example)
|
2018-07-27 09:25:25 +03:00
|
|
|
import Html.Styled as Html
|
|
|
|
import Html.Styled.Attributes exposing (css)
|
2019-05-07 21:25:25 +03:00
|
|
|
import Nri.Ui.DisclosureIndicator.V2 as DisclosureIndicator
|
2021-10-27 20:42:23 +03:00
|
|
|
import Nri.Ui.Text.V6 as Text
|
2018-07-27 09:25:25 +03:00
|
|
|
|
|
|
|
|
2022-03-25 17:41:28 +03:00
|
|
|
moduleName : String
|
|
|
|
moduleName =
|
|
|
|
"DisclosureIndicator"
|
|
|
|
|
|
|
|
|
|
|
|
version : Int
|
|
|
|
version =
|
|
|
|
2
|
|
|
|
|
|
|
|
|
2018-07-27 09:25:25 +03:00
|
|
|
{-| -}
|
2020-03-31 23:20:03 +03:00
|
|
|
example : Example State Msg
|
2020-03-31 22:43:32 +03:00
|
|
|
example =
|
2022-03-25 17:41:28 +03:00
|
|
|
{ name = moduleName
|
|
|
|
, version = version
|
2021-11-12 01:49:46 +03:00
|
|
|
, categories = [ Icons ]
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2020-03-31 22:43:32 +03:00
|
|
|
, state = init
|
|
|
|
, update = update
|
2020-03-31 22:48:26 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
2021-11-05 22:37:22 +03:00
|
|
|
, preview =
|
|
|
|
[ DisclosureIndicator.medium [] False
|
|
|
|
, DisclosureIndicator.medium [] True
|
|
|
|
, DisclosureIndicator.large [] False
|
|
|
|
, DisclosureIndicator.large [] True
|
|
|
|
]
|
2020-03-31 22:43:32 +03:00
|
|
|
, view =
|
2022-03-29 20:19:32 +03:00
|
|
|
\ellieLinkConfig state ->
|
2022-03-22 19:15:40 +03:00
|
|
|
let
|
|
|
|
attributes =
|
|
|
|
Control.currentValue state.settings
|
|
|
|
in
|
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!" ]
|
2022-03-22 19:11:43 +03:00
|
|
|
, ControlView.view
|
2022-03-29 20:19:32 +03:00
|
|
|
{ ellieLinkConfig = ellieLinkConfig
|
|
|
|
, name = moduleName
|
2022-03-25 17:41:28 +03:00
|
|
|
, version = version
|
|
|
|
, update = UpdateSettings
|
2022-03-22 19:11:43 +03:00
|
|
|
, settings = state.settings
|
|
|
|
, toExampleCode =
|
|
|
|
\settings ->
|
|
|
|
let
|
|
|
|
toCode viewName =
|
2022-03-25 17:41:28 +03:00
|
|
|
moduleName
|
|
|
|
++ "."
|
2022-03-22 19:11:43 +03:00
|
|
|
++ viewName
|
|
|
|
++ " "
|
|
|
|
++ Tuple.first settings.css
|
|
|
|
++ " "
|
|
|
|
++ Tuple.first settings.isOpen
|
|
|
|
in
|
|
|
|
[ { sectionName = "Large"
|
|
|
|
, code = toCode "large"
|
|
|
|
}
|
|
|
|
, { sectionName = "medium"
|
|
|
|
, code = toCode "medium"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2020-03-31 22:43:32 +03:00
|
|
|
, Html.div [ css [ Css.displayFlex, Css.alignItems Css.center, Css.marginBottom (Css.px 8) ] ]
|
2022-03-22 19:15:40 +03:00
|
|
|
[ DisclosureIndicator.large
|
2022-03-22 19:20:49 +03:00
|
|
|
(Tuple.second attributes.css)
|
2022-03-22 19:15:40 +03:00
|
|
|
(Tuple.second attributes.isOpen)
|
2022-03-22 19:22:54 +03:00
|
|
|
, Html.text "large is a 17px caret icon."
|
2020-03-31 22:43:32 +03:00
|
|
|
]
|
|
|
|
, Html.div [ css [ Css.displayFlex, Css.alignItems Css.center, Css.marginBottom (Css.px 8) ] ]
|
2022-03-22 19:15:40 +03:00
|
|
|
[ DisclosureIndicator.medium
|
2022-03-22 19:20:49 +03:00
|
|
|
(Tuple.second attributes.css)
|
2022-03-22 19:15:40 +03:00
|
|
|
(Tuple.second attributes.isOpen)
|
2022-03-22 19:22:54 +03:00
|
|
|
, Html.text "medium is a 15px caret icon."
|
2020-03-31 22:43:32 +03:00
|
|
|
]
|
2019-07-11 20:22:00 +03:00
|
|
|
]
|
2019-05-07 22:34:33 +03:00
|
|
|
}
|
2019-05-07 22:27:25 +03:00
|
|
|
|
2019-05-07 22:34:33 +03:00
|
|
|
|
2022-03-22 19:11:43 +03:00
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
{ settings : Control Settings
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-27 09:25:25 +03:00
|
|
|
{-| -}
|
|
|
|
init : State
|
|
|
|
init =
|
2022-03-22 19:11:43 +03:00
|
|
|
{ settings = initSettings
|
2018-07-27 09:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-22 19:11:43 +03:00
|
|
|
type alias Settings =
|
|
|
|
{ css : ( String, List Style )
|
|
|
|
, isOpen : ( String, Bool )
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initSettings : Control Settings
|
|
|
|
initSettings =
|
|
|
|
Control.record Settings
|
2022-03-22 19:20:49 +03:00
|
|
|
|> Control.field "css"
|
|
|
|
(Control.choice
|
|
|
|
[ ( "[ Css.marginRight (Css.px 8) ]"
|
|
|
|
, Control.value
|
|
|
|
( "[ Css.marginRight (Css.px 8) ]"
|
|
|
|
, [ Css.marginRight (Css.px 8) ]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
, ( "[]", Control.value ( "[]", [] ) )
|
|
|
|
]
|
|
|
|
)
|
2022-03-22 19:15:40 +03:00
|
|
|
|> Control.field "isOpen" (ControlExtra.bool False)
|
2022-03-22 19:11:43 +03:00
|
|
|
|
|
|
|
|
2019-05-07 22:34:33 +03:00
|
|
|
{-| -}
|
|
|
|
type Msg
|
2022-03-22 19:11:43 +03:00
|
|
|
= UpdateSettings (Control Settings)
|
2019-05-07 22:34:33 +03:00
|
|
|
|
|
|
|
|
2018-07-27 09:25:25 +03:00
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
2022-03-22 19:11:43 +03:00
|
|
|
UpdateSettings settings ->
|
|
|
|
( { state | settings = settings }, Cmd.none )
|