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

169 lines
5.4 KiB
Elm
Raw Normal View History

2021-10-13 20:44:03 +03:00
module Examples.Container exposing (Msg, State, example)
{-|
@docs Msg, State, example
-}
import Category exposing (Category(..))
import Css
2021-10-22 01:36:55 +03:00
import Debug.Control as Control exposing (Control)
2021-10-22 03:20:29 +03:00
import Debug.Control.Extra as ControlExtra
2021-10-13 20:44:03 +03:00
import Example exposing (Example)
import Html.Styled as Html
import Html.Styled.Attributes exposing (css)
import Html.Styled.Events exposing (onClick)
import KeyboardSupport exposing (Direction(..), Key(..))
import Nri.Ui.Button.V10 as Button
import Nri.Ui.Colors.V1 as Colors
2021-10-21 22:17:48 +03:00
import Nri.Ui.Container.V2 as Container
2021-10-13 20:44:03 +03:00
import Nri.Ui.Heading.V2 as Heading
2021-10-22 01:36:55 +03:00
import Nri.Ui.Svg.V1 as Svg
2021-10-13 20:44:03 +03:00
import Nri.Ui.Text.V5 as Text
2021-10-22 01:36:55 +03:00
import Nri.Ui.UiIcon.V1 as UiIcon
2021-10-13 20:44:03 +03:00
{-| -}
example : Example State Msg
example =
{ name = "Container"
2021-10-22 00:47:50 +03:00
, version = 2
2021-10-13 20:44:03 +03:00
, categories = [ Layout ]
, keyboardSupport = []
, state = init
, update = update
, subscriptions = \_ -> Sub.none
, view =
\state ->
2021-10-22 01:36:55 +03:00
let
attributes =
Control.currentValue state.control
in
[ Control.view UpdateControl state.control
|> Html.fromUnstyled
, Heading.h3 [ Heading.css [ Css.marginTop (Css.px 8) ] ]
2021-10-21 22:17:48 +03:00
[ Html.text "Default Container" ]
, Html.text "Your go-to container."
2021-10-22 01:36:55 +03:00
, Container.view (Container.default :: attributes)
2021-10-13 20:44:03 +03:00
, Heading.h3 [ Heading.css [ Css.marginTop (Css.px 8) ] ]
2021-10-21 22:17:48 +03:00
[ Html.text "Gray Container" ]
2021-10-22 02:49:44 +03:00
, Html.text "A container that doesnt draw too much attention to itself."
2021-10-22 01:36:55 +03:00
, Container.view (Container.gray :: attributes)
2021-10-13 20:44:03 +03:00
, Heading.h3 [ Heading.css [ Css.marginTop (Css.px 8) ] ]
2021-10-21 22:17:48 +03:00
[ Html.text "Pillow Container" ]
, Html.text "When you want something big and soft."
2021-10-22 01:36:55 +03:00
, Container.view (Container.pillow :: attributes)
2021-10-21 22:17:48 +03:00
, Heading.h3 [ Heading.css [ Css.marginTop (Css.px 8) ] ]
[ Html.text "Buttony Container" ]
, Html.text "Used for clickable button card things."
2021-10-22 01:36:55 +03:00
, Container.view (Container.buttony :: attributes)
2021-10-13 20:44:03 +03:00
, Heading.h3 [ Heading.css [ Css.marginTop (Css.px 8) ] ]
[ Html.text "Disabled Container" ]
, Html.text "Used to indicate content is locked/inaccessible"
2021-10-22 01:36:55 +03:00
, Container.view (Container.disabled :: attributes)
2021-10-13 20:44:03 +03:00
, Heading.h3 [ Heading.css [ Css.marginTop (Css.px 8) ] ]
[ Html.text "Invalid Container" ]
, Html.text "Used to indicate content is invalid"
2021-10-22 01:36:55 +03:00
, Container.view (Container.invalid :: attributes)
2021-10-13 20:44:03 +03:00
]
}
2021-10-22 01:36:55 +03:00
{-| -}
type alias State =
{ control : Control (List (Container.Attribute Msg))
}
2021-10-13 20:44:03 +03:00
{-| -}
init : State
init =
2021-10-22 01:36:55 +03:00
{ control =
2021-10-22 03:20:29 +03:00
ControlExtra.list
2021-10-22 03:27:29 +03:00
|> ControlExtra.optionalListItem "paddingPx" controlPaddingPx
|> ControlExtra.optionalListItem "fullHeight" controlFullHeight
|> ControlExtra.optionalListItem "css" controlCss
2021-10-22 03:20:29 +03:00
|> ControlExtra.listItem "content" controlContent
2021-10-22 01:36:55 +03:00
}
2021-10-13 20:44:03 +03:00
2021-10-22 03:27:29 +03:00
controlPaddingPx : Control (Container.Attribute msg)
controlPaddingPx =
Control.map Container.paddingPx (ControlExtra.float 20)
2021-10-22 03:20:29 +03:00
2021-10-22 03:27:29 +03:00
controlFullHeight : Control (Container.Attribute msg)
controlFullHeight =
Control.map Container.fullHeight (Control.bool False)
controlCss : Control (Container.Attribute msg)
controlCss =
Control.map Container.css
(Control.value
[ Css.hover [ Css.backgroundColor Colors.glacier ]
]
)
2021-10-22 01:36:55 +03:00
controlContent : Control (Container.Attribute msg)
controlContent =
Control.choice
[ ( "plain text (short)"
, Control.string "Content, content..."
|> Control.map Container.plaintext
)
, ( "plain text (long)"
2021-10-22 02:49:44 +03:00
, Control.stringTextarea romeoAndJulietQuotation
2021-10-22 01:36:55 +03:00
|> Control.map Container.plaintext
)
, ( "markdown"
2021-10-22 02:49:44 +03:00
, Control.string romeoAndJulietQuotation
2021-10-22 01:36:55 +03:00
|> Control.map Container.markdown
)
, ( "HTML (short)"
, Control.value
(Container.html
[ UiIcon.footsteps
|> Svg.withHeight (Css.px 200)
|> Svg.withColor Colors.grassland
|> Svg.toHtml
]
)
)
]
2021-10-13 20:44:03 +03:00
2021-10-22 02:49:44 +03:00
romeoAndJulietQuotation : String
romeoAndJulietQuotation =
"""
Two households, both alike in dignity,
In fair Verona, where we lay our scene,
From ancient grudge break to new mutiny,
Where civil blood makes civil hands unclean.
From forth the fatal loins of these two foes
A pair of star-crossd lovers take their life;
Whose misadventured piteous overthrows
Do with their death bury their parents strife.
The fearful passage of their death-markd love,
And the continuance of their parents rage,
Which, but their childrens end, nought could remove,
Is now the two hours traffic of our stage;
The which if you with patient ears attend,
What here shall miss, our toil shall strive to mend.
"""
2021-10-13 20:44:03 +03:00
{-| -}
2021-10-22 01:36:55 +03:00
type Msg
= UpdateControl (Control (List (Container.Attribute Msg)))
2021-10-13 20:44:03 +03:00
{-| -}
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
2021-10-22 01:36:55 +03:00
case msg of
UpdateControl newControl ->
( { state | control = newControl }, Cmd.none )