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

144 lines
4.1 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(..))
import CommonControls exposing (exampleHtml, quickBrownFox, romeoAndJulietQuotation)
import Css
2021-10-27 22:01:16 +03:00
import Debug.Control as Control exposing (Control)
import Debug.Control.Extra as ControlExtra
2020-03-31 23:33:05 +03:00
import Example exposing (Example)
import Html.Styled as Html exposing (Html)
import Html.Styled.Attributes as Attributes exposing (css)
import KeyboardSupport exposing (Direction(..), Key(..))
import Nri.Ui.Colors.V1 as Colors
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 ]
, 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 =
[ ( "caption", Text.caption )
, ( "smallBody", Text.smallBody )
, ( "mediumBody", Text.mediumBody )
, ( "ugMediumBody", Text.ugMediumBody )
]
|> List.map viewPreview
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 =
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\"" ]
2021-10-27 22:01:16 +03:00
, Control.view UpdateControl state.control
|> Html.fromUnstyled
2020-03-31 23:33:05 +03:00
, Heading.h2 [ Heading.style Heading.Top ] [ Html.text "Paragraph styles" ]
, viewExamples
[ ( "mediumBody", Text.mediumBody )
, ( "smallBody", Text.smallBody )
, ( "smallBodyGray", Text.smallBodyGray )
, ( "caption", Text.caption )
]
attributes
2020-03-31 23:33:05 +03:00
, Heading.h2 [ Heading.style Heading.Top ] [ 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
2021-11-06 00:06:32 +03:00
viewPreview : ( String, List (Text.Attribute msg) -> Html msg ) -> Html msg
viewPreview ( name, view ) =
view [ Text.plaintext name ]
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 =
{ control : Control (List (Text.Attribute Msg))
}
{-| -}
init : State
init =
{ control =
ControlExtra.list
|> ControlExtra.listItem "content" controlContent
2021-10-27 22:26:40 +03:00
|> ControlExtra.listItem "noBreak"
(Control.map Text.noBreak (Control.bool False))
|> ControlExtra.optionalListItem "css"
(Control.value
(Text.css
[ Css.border3 (Css.px 1) Css.solid Colors.aqua
, Css.color Colors.aquaDark
]
)
)
2021-10-27 22:01:16 +03:00
}
controlContent : Control (Text.Attribute msg)
controlContent =
Control.choice
[ ( "HTML"
, Control.value (Text.html exampleHtml)
)
, ( "plain text (short)"
, Control.string quickBrownFox
|> Control.map Text.plaintext
)
, ( "plain text (long)"
, Control.stringTextarea romeoAndJulietQuotation
|> Control.map Text.plaintext
)
, ( "markdown"
, Control.string romeoAndJulietQuotation
|> Control.map Text.markdown
)
]
2021-10-27 22:01:16 +03:00
{-| -}
type Msg
= UpdateControl (Control (List (Text.Attribute Msg)))
{-| -}
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
case msg of
UpdateControl newControl ->
( { state | control = newControl }, Cmd.none )