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

108 lines
3.2 KiB
Elm
Raw Normal View History

2020-04-01 02:00:29 +03:00
module Examples.Heading exposing (example, State, Msg)
{-|
2020-04-01 02:00:29 +03:00
@docs example, State, Msg
-}
import Category exposing (Category(..))
2022-03-23 21:01:51 +03:00
import CommonControls
import Css
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)
import Html.Styled as Html
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Heading.V2 as Heading
2022-01-29 00:12:17 +03:00
import ViewHelpers exposing (viewExamples)
2020-04-01 02:00:29 +03:00
{-| -}
example : Example State Msg
example =
2020-09-09 21:43:10 +03:00
{ name = "Heading"
, version = 2
2020-06-19 23:41:28 +03:00
, categories = [ Text, Layout ]
, 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-23 20:55:53 +03:00
\state ->
2022-03-23 21:01:51 +03:00
let
attributes =
List.map Tuple.second (Control.currentValue state.control)
in
2022-03-23 20:55:53 +03:00
[ ControlView.view
{ update = UpdateControl
, settings = state.control
, toExampleCode =
\settings ->
2022-03-23 21:01:51 +03:00
let
toExampleCode name =
{ sectionName = name
, code =
"Heading."
++ name
++ "\n ["
++ String.join "\n , " (List.map Tuple.first settings)
++ "\n ]"
++ "\n (TODO: Html content)"
}
in
[ toExampleCode "h1"
, toExampleCode "h2"
, toExampleCode "h3"
, toExampleCode "h4"
, toExampleCode "h5"
]
2022-03-23 20:55:53 +03:00
}
, viewExamples
2022-03-23 21:01:51 +03:00
[ ( "h1", Heading.h1 attributes [ Html.text "This is the main page heading." ] )
, ( "h2", Heading.h2 attributes [ Html.text "This is a tagline" ] )
, ( "h3", Heading.h3 attributes [ Html.text "This is a subHeading" ] )
, ( "h4", Heading.h4 attributes [ Html.text "This is a smallHeading" ] )
, ( "h5", Heading.h5 attributes [ Html.text "This is also a smallHeading" ] )
2022-01-29 00:12:17 +03:00
]
2020-03-31 23:33:05 +03:00
]
}
2022-03-23 20:55:53 +03:00
{-| -}
type alias State =
{ control : Control Settings
}
init : State
init =
{ control =
ControlExtra.list
2022-03-23 21:01:51 +03:00
|> CommonControls.css { moduleName = "Heading", use = Heading.css }
2022-03-23 21:04:27 +03:00
|> ControlExtra.optionalBoolListItem "error" ( "Heading.error", Heading.error )
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 )