2020-04-01 02:00:29 +03:00
|
|
|
module Examples.Heading exposing (example, State, Msg)
|
2019-10-01 04:15:26 +03:00
|
|
|
|
|
|
|
{-|
|
|
|
|
|
2020-04-01 02:00:29 +03:00
|
|
|
@docs example, State, Msg
|
2019-10-01 04:15:26 +03:00
|
|
|
|
|
|
|
-}
|
|
|
|
|
2020-03-24 03:33:42 +03:00
|
|
|
import Category exposing (Category(..))
|
2022-03-23 21:01:51 +03:00
|
|
|
import CommonControls
|
2022-03-23 20:55:53 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
|
|
|
import Debug.Control.Extra as ControlExtra
|
|
|
|
import Debug.Control.View as ControlView
|
2020-03-31 23:33:05 +03:00
|
|
|
import Example exposing (Example)
|
2019-10-01 04:15:26 +03:00
|
|
|
import Html.Styled as Html
|
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
2022-01-29 00:12:17 +03:00
|
|
|
import ViewHelpers exposing (viewExamples)
|
2019-10-01 04:15:26 +03:00
|
|
|
|
|
|
|
|
2022-03-29 00:19:42 +03:00
|
|
|
moduleName : String
|
|
|
|
moduleName =
|
|
|
|
"Heading"
|
2020-04-01 02:00:29 +03:00
|
|
|
|
|
|
|
|
2022-03-29 00:19:42 +03:00
|
|
|
version : Int
|
|
|
|
version =
|
|
|
|
2
|
2020-04-01 02:00:29 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
example : Example State Msg
|
2019-10-01 04:15:26 +03:00
|
|
|
example =
|
2022-03-29 00:19:42 +03:00
|
|
|
{ name = moduleName
|
|
|
|
, version = version
|
2020-06-19 23:41:28 +03:00
|
|
|
, categories = [ Text, Layout ]
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2022-03-23 20:55:53 +03:00
|
|
|
, state = init
|
|
|
|
, update = update
|
2020-03-31 23:33:05 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
2021-11-05 22:45:22 +03:00
|
|
|
, preview =
|
|
|
|
[ Heading.h1 [] [ Html.text "h1" ]
|
|
|
|
, Heading.h2 [] [ Html.text "h2" ]
|
|
|
|
, Heading.h3 [] [ Html.text "h3" ]
|
|
|
|
, Heading.h4 [] [ Html.text "h4" ]
|
|
|
|
]
|
2020-03-31 23:33:05 +03:00
|
|
|
, view =
|
2022-03-29 20:41:37 +03:00
|
|
|
\ellieLinkConfig state ->
|
2022-03-23 21:01:51 +03:00
|
|
|
let
|
2022-03-23 21:14:40 +03:00
|
|
|
examples =
|
|
|
|
[ ( "h1", Heading.h1, "This is the main page heading." )
|
|
|
|
, ( "h2", Heading.h2, "This is a tagline" )
|
|
|
|
, ( "h3", Heading.h3, "This is a subHeading" )
|
|
|
|
, ( "h4", Heading.h4, "This is a smallHeading" )
|
|
|
|
, ( "h5", Heading.h5, "This is also a smallHeading" )
|
|
|
|
]
|
|
|
|
|
2022-03-23 21:01:51 +03:00
|
|
|
attributes =
|
|
|
|
List.map Tuple.second (Control.currentValue state.control)
|
|
|
|
in
|
2022-03-23 20:55:53 +03:00
|
|
|
[ ControlView.view
|
2022-03-29 20:41:37 +03:00
|
|
|
{ ellieLinkConfig = ellieLinkConfig
|
|
|
|
, name = moduleName
|
2022-03-29 00:19:42 +03:00
|
|
|
, version = version
|
|
|
|
, update = UpdateControl
|
2022-03-23 20:55:53 +03:00
|
|
|
, settings = state.control
|
|
|
|
, toExampleCode =
|
|
|
|
\settings ->
|
2022-03-23 21:01:51 +03:00
|
|
|
let
|
2022-03-23 21:14:40 +03:00
|
|
|
toExampleCode ( name, _, content ) =
|
2022-03-23 21:01:51 +03:00
|
|
|
{ sectionName = name
|
|
|
|
, code =
|
2022-03-29 00:19:42 +03:00
|
|
|
moduleName
|
|
|
|
++ "."
|
2022-03-23 21:01:51 +03:00
|
|
|
++ name
|
2022-03-23 21:14:40 +03:00
|
|
|
++ "\n [ "
|
2022-03-23 21:01:51 +03:00
|
|
|
++ String.join "\n , " (List.map Tuple.first settings)
|
|
|
|
++ "\n ]"
|
2022-03-23 21:14:40 +03:00
|
|
|
++ ("\n [ Html.text \"" ++ content ++ "\" ]")
|
2022-03-23 21:01:51 +03:00
|
|
|
}
|
|
|
|
in
|
2022-03-23 21:14:40 +03:00
|
|
|
List.map toExampleCode examples
|
2022-03-23 20:55:53 +03:00
|
|
|
}
|
2022-03-23 21:14:40 +03:00
|
|
|
, examples
|
|
|
|
|> List.map
|
|
|
|
(\( name, view, content ) ->
|
|
|
|
( name, view attributes [ Html.text content ] )
|
|
|
|
)
|
|
|
|
|> viewExamples
|
2020-03-31 23:33:05 +03:00
|
|
|
]
|
2019-10-01 04:15:26 +03:00
|
|
|
}
|
2022-03-23 20:55:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type alias State =
|
|
|
|
{ control : Control Settings
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init : State
|
|
|
|
init =
|
|
|
|
{ control =
|
|
|
|
ControlExtra.list
|
2022-03-29 00:19:42 +03:00
|
|
|
|> CommonControls.css { moduleName = moduleName, use = Heading.css }
|
2022-03-23 21:04:27 +03:00
|
|
|
|> ControlExtra.optionalBoolListItem "error" ( "Heading.error", Heading.error )
|
2022-03-23 21:10:18 +03:00
|
|
|
|> ControlExtra.optionalListItem "style" controlStyle
|
2022-03-23 20:55:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-23 21:10:18 +03:00
|
|
|
controlStyle : Control ( String, Heading.Attribute msg )
|
|
|
|
controlStyle =
|
|
|
|
[ ( "Top", Heading.Top )
|
|
|
|
, ( "Tagline", Heading.Tagline )
|
|
|
|
, ( "Subhead", Heading.Subhead )
|
|
|
|
, ( "Small", Heading.Small )
|
|
|
|
]
|
|
|
|
|> List.map
|
|
|
|
(\( name, val ) ->
|
|
|
|
( name
|
|
|
|
, Control.value
|
|
|
|
( "Heading.style Heading." ++ name
|
|
|
|
, Heading.style val
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|> Control.choice
|
|
|
|
|
|
|
|
|
2022-03-23 20:55:53 +03:00
|
|
|
type alias Settings =
|
|
|
|
List ( String, Heading.Attribute Msg )
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
type Msg
|
|
|
|
= UpdateControl (Control Settings)
|
|
|
|
|
|
|
|
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
UpdateControl settings ->
|
|
|
|
( { state | control = settings }, Cmd.none )
|