2020-04-01 02:00:29 +03:00
|
|
|
module Examples.Text exposing (example, State, Msg)
|
2018-02-13 00:32:38 +03:00
|
|
|
|
2018-03-08 01:36:52 +03:00
|
|
|
{-|
|
|
|
|
|
2020-04-01 02:00:29 +03:00
|
|
|
@docs example, State, Msg
|
2018-03-08 01:36:52 +03:00
|
|
|
|
2018-02-13 00:32:38 +03:00
|
|
|
-}
|
|
|
|
|
2020-03-24 03:33:42 +03:00
|
|
|
import Category exposing (Category(..))
|
2022-03-15 21:06:13 +03:00
|
|
|
import CommonControls
|
2020-07-13 18:11:33 +03:00
|
|
|
import Css
|
2021-10-27 22:01:16 +03:00
|
|
|
import Debug.Control as Control exposing (Control)
|
|
|
|
import Debug.Control.Extra as ControlExtra
|
2022-03-23 19:00:32 +03:00
|
|
|
import Debug.Control.View as ControlView
|
2020-03-31 23:33:05 +03:00
|
|
|
import Example exposing (Example)
|
2021-10-27 22:19:29 +03:00
|
|
|
import Html.Styled as Html exposing (Html)
|
2022-03-15 21:06:13 +03:00
|
|
|
import Html.Styled.Attributes exposing (css)
|
2019-07-23 17:53:43 +03:00
|
|
|
import Nri.Ui.Heading.V2 as Heading
|
2021-10-27 20:42:23 +03:00
|
|
|
import Nri.Ui.Text.V6 as Text
|
2018-02-13 00:32:38 +03:00
|
|
|
|
|
|
|
|
2020-04-01 02:00:29 +03:00
|
|
|
{-| -}
|
|
|
|
example : Example State Msg
|
2018-02-13 00:32:38 +03:00
|
|
|
example =
|
2020-09-09 21:43:10 +03:00
|
|
|
{ name = "Text"
|
2021-10-27 20:42:23 +03:00
|
|
|
, version = 6
|
2020-06-19 23:41:28 +03:00
|
|
|
, categories = [ Text ]
|
2020-06-20 00:45:32 +03:00
|
|
|
, keyboardSupport = []
|
2021-10-27 22:01:16 +03:00
|
|
|
, state = init
|
|
|
|
, update = update
|
2020-03-31 23:33:05 +03:00
|
|
|
, subscriptions = \_ -> Sub.none
|
2021-11-06 00:06:32 +03:00
|
|
|
, preview =
|
2022-03-23 20:39:45 +03:00
|
|
|
[ Text.caption [ Text.plaintext "caption" ]
|
|
|
|
, Text.smallBody [ Text.plaintext "smallBody" ]
|
|
|
|
, Text.mediumBody [ Text.plaintext "mediumBody" ]
|
|
|
|
, Text.ugMediumBody [ Text.plaintext "ugMediumBody" ]
|
2021-11-06 00:06:32 +03:00
|
|
|
]
|
2020-03-31 23:33:05 +03:00
|
|
|
, view =
|
2021-10-27 22:01:16 +03:00
|
|
|
\state ->
|
2020-03-31 23:33:05 +03:00
|
|
|
let
|
2021-10-27 22:01:16 +03:00
|
|
|
attributes =
|
2022-03-23 20:46:12 +03:00
|
|
|
List.map Tuple.second (Control.currentValue state.control)
|
2020-03-31 23:33:05 +03:00
|
|
|
in
|
2021-10-27 21:54:14 +03:00
|
|
|
[ Text.caption [ Text.plaintext "NOTE: When using these styles, please read the documentation in the Elm module about \"Understanding spacing\"" ]
|
2022-03-23 19:00:32 +03:00
|
|
|
, ControlView.view
|
|
|
|
{ update = UpdateControl
|
|
|
|
, settings = state.control
|
|
|
|
, toExampleCode =
|
|
|
|
\settings ->
|
2022-03-23 20:38:15 +03:00
|
|
|
let
|
|
|
|
toExampleCode name =
|
|
|
|
{ sectionName = name
|
|
|
|
, code =
|
|
|
|
"Text."
|
|
|
|
++ name
|
|
|
|
++ "\n [ "
|
2022-03-23 20:46:12 +03:00
|
|
|
++ String.join "\n , " (List.map Tuple.first settings)
|
2022-03-23 20:38:15 +03:00
|
|
|
++ "\n ]"
|
|
|
|
}
|
|
|
|
in
|
|
|
|
[ toExampleCode "mediumBody"
|
|
|
|
, toExampleCode "smallBody"
|
|
|
|
, toExampleCode "smallBodyGray"
|
|
|
|
, toExampleCode "caption"
|
|
|
|
, toExampleCode "ugMediumBody"
|
|
|
|
, toExampleCode "ugSmallBody"
|
|
|
|
]
|
2022-03-23 19:00:32 +03:00
|
|
|
}
|
2022-03-23 20:51:50 +03:00
|
|
|
, Heading.h2 [] [ Html.text "Examples" ]
|
|
|
|
, Heading.h3 [] [ Html.text "Paragraph styles" ]
|
2021-10-27 22:19:29 +03:00
|
|
|
, viewExamples
|
|
|
|
[ ( "mediumBody", Text.mediumBody )
|
|
|
|
, ( "smallBody", Text.smallBody )
|
|
|
|
, ( "smallBodyGray", Text.smallBodyGray )
|
|
|
|
, ( "caption", Text.caption )
|
|
|
|
]
|
|
|
|
attributes
|
2022-03-23 20:51:50 +03:00
|
|
|
, Heading.h3 [] [ Html.text "Paragraph styles for user-authored content" ]
|
2021-10-27 22:19:29 +03:00
|
|
|
, viewExamples
|
|
|
|
[ ( "ugMediumBody", Text.ugMediumBody )
|
|
|
|
, ( "ugSmallBody", Text.ugSmallBody )
|
|
|
|
]
|
|
|
|
attributes
|
2020-03-31 23:33:05 +03:00
|
|
|
]
|
2018-02-13 00:32:38 +03:00
|
|
|
}
|
2021-10-27 22:01:16 +03:00
|
|
|
|
|
|
|
|
2021-10-27 22:19:29 +03:00
|
|
|
viewExamples : List ( String, List (Text.Attribute msg) -> Html msg ) -> List (Text.Attribute msg) -> Html msg
|
|
|
|
viewExamples examples attributes =
|
|
|
|
let
|
|
|
|
viewExample ( name, view ) =
|
|
|
|
Html.tr []
|
|
|
|
[ Html.th [] [ Html.text name ]
|
|
|
|
, Html.td [] [ view attributes ]
|
|
|
|
]
|
|
|
|
in
|
|
|
|
Html.table [ css [ Css.width (Css.pct 100) ] ]
|
|
|
|
[ Html.tbody [] <|
|
|
|
|
List.map viewExample examples
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-10-27 22:01:16 +03:00
|
|
|
{-| -}
|
|
|
|
type alias State =
|
2022-03-23 20:46:12 +03:00
|
|
|
{ control : Control (List ( String, Text.Attribute Msg ))
|
2021-10-27 22:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
init : State
|
|
|
|
init =
|
2021-10-27 22:19:29 +03:00
|
|
|
{ control =
|
|
|
|
ControlExtra.list
|
|
|
|
|> ControlExtra.listItem "content" controlContent
|
2022-03-23 20:44:35 +03:00
|
|
|
|> ControlExtra.optionalBoolListItem "noBreak"
|
|
|
|
( "Text.noBreak True", Text.noBreak True )
|
|
|
|
|> CommonControls.css { moduleName = "Text", use = Text.css }
|
2021-10-27 22:01:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-23 20:44:35 +03:00
|
|
|
controlContent : Control ( String, Text.Attribute msg )
|
2021-10-27 22:19:29 +03:00
|
|
|
controlContent =
|
2022-03-10 02:59:41 +03:00
|
|
|
CommonControls.content
|
|
|
|
{ moduleName = "Text"
|
|
|
|
, plaintext = Text.plaintext
|
2022-03-18 03:30:50 +03:00
|
|
|
, markdown = Just Text.markdown
|
2022-03-10 02:59:41 +03:00
|
|
|
, html = Text.html
|
|
|
|
, httpError = Nothing
|
|
|
|
}
|
2021-10-27 22:19:29 +03:00
|
|
|
|
|
|
|
|
2021-10-27 22:01:16 +03:00
|
|
|
{-| -}
|
|
|
|
type Msg
|
2022-03-23 20:46:12 +03:00
|
|
|
= UpdateControl (Control (List ( String, Text.Attribute Msg )))
|
2021-10-27 22:01:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-| -}
|
|
|
|
update : Msg -> State -> ( State, Cmd Msg )
|
|
|
|
update msg state =
|
|
|
|
case msg of
|
|
|
|
UpdateControl newControl ->
|
|
|
|
( { state | control = newControl }, Cmd.none )
|