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

189 lines
5.6 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 exposing (Html)
2021-10-13 20:44:03 +03:00
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
, viewExample
{ name = "Default Container"
, description = "Your go-to container."
}
(Container.default :: attributes)
, viewExample
{ name = "Gray Container"
, description = "A container that doesnt draw too much attention to itself."
}
(Container.gray :: attributes)
, viewExample
{ name = "Pillow Container"
, description = "When you want something big and soft."
}
(Container.pillow :: attributes)
, viewExample
{ name = "Buttony Container"
, description = "Used for clickable button card things."
}
(Container.buttony :: attributes)
, viewExample
{ name = "Disabled Container"
, description = "Used to indicate content is locked/inaccessible"
}
(Container.disabled :: attributes)
, viewExample
{ name = "Invalid Container"
, description = "Used to indicate content is invalid"
}
(Container.invalid :: attributes)
2021-10-13 20:44:03 +03:00
]
}
viewExample : { name : String, description : String } -> List (Container.Attribute msg) -> Html msg
viewExample { name, description } attributes =
Html.section
[ css
[ Css.marginTop (Css.px 8)
, Css.minHeight (Css.px 150)
]
]
[ Heading.h3 [] [ Html.text name ]
, Html.text description
, Container.view attributes
]
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 )