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

159 lines
4.7 KiB
Elm
Raw Normal View History

2020-04-01 02:00:29 +03:00
module Examples.Text exposing (example, State, Msg)
2018-02-13 00:32:38 +03:00
{-|
2020-04-01 02:00:29 +03:00
@docs example, State, Msg
2018-02-13 00:32:38 +03:00
-}
import Category exposing (Category(..))
2022-03-15 21:06:13 +03:00
import CommonControls
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)
import Html.Styled as Html exposing (Html)
2022-03-15 21:06:13 +03:00
import Html.Styled.Attributes exposing (css)
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
moduleName : String
moduleName =
"Text"
version : Int
version =
6
2020-04-01 02:00:29 +03:00
{-| -}
example : Example State Msg
2018-02-13 00:32:38 +03:00
example =
{ name = moduleName
, version = version
2020-06-19 23:41:28 +03:00
, categories = [ Text ]
, 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 =
\ellieLinkConfig 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
{ ellieLinkConfig = ellieLinkConfig
, name = moduleName
, version = version
, update = UpdateControl
2022-03-23 19:00:32 +03:00
, settings = state.control
, mainType = "RootHtml.Html msg"
2022-04-13 03:32:46 +03:00
, extraImports = []
2022-03-23 19:00:32 +03:00
, toExampleCode =
\settings ->
2022-03-23 20:38:15 +03:00
let
toExampleCode name =
{ sectionName = name
, code =
moduleName
++ "."
2022-03-23 20:38:15 +03:00
++ 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
}
, Heading.h2 [] [ Html.text "Examples" ]
, Heading.h3 [] [ Html.text "Paragraph styles" ]
, viewExamples
[ ( "mediumBody", Text.mediumBody )
, ( "smallBody", Text.smallBody )
, ( "smallBodyGray", Text.smallBodyGray )
, ( "caption", Text.caption )
]
attributes
, Heading.h3 [] [ Html.text "Paragraph styles for user-authored content" ]
, 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
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 =
{ 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 )
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: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 )