2021-10-13 20:44:03 +03:00
|
|
|
|
module Examples.Container exposing (Msg, State, example)
|
|
|
|
|
|
|
|
|
|
{-|
|
|
|
|
|
|
|
|
|
|
@docs Msg, State, example
|
|
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
import Category exposing (Category(..))
|
2021-10-27 22:19:29 +03:00
|
|
|
|
import CommonControls exposing (romeoAndJulietQuotation)
|
2021-10-13 20:44:03 +03:00
|
|
|
|
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)
|
2021-10-22 03:32:14 +03:00
|
|
|
|
import Html.Styled as Html exposing (Html)
|
2021-10-13 20:44:03 +03:00
|
|
|
|
import Html.Styled.Attributes exposing (css)
|
|
|
|
|
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
|
|
|
|
|
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
|
2021-11-05 22:35:01 +03:00
|
|
|
|
, preview =
|
|
|
|
|
[ Container.view []
|
|
|
|
|
, Container.view
|
|
|
|
|
[ Container.invalid
|
|
|
|
|
, Container.css [ Css.marginTop (Css.px 8) ]
|
|
|
|
|
]
|
|
|
|
|
, Container.view
|
|
|
|
|
[ Container.disabled
|
|
|
|
|
, Container.css [ Css.marginTop (Css.px 8) ]
|
|
|
|
|
]
|
|
|
|
|
]
|
2021-10-13 20:44:03 +03:00
|
|
|
|
, view =
|
|
|
|
|
\state ->
|
2021-10-22 01:36:55 +03:00
|
|
|
|
let
|
|
|
|
|
attributes =
|
|
|
|
|
Control.currentValue state.control
|
|
|
|
|
in
|
|
|
|
|
[ Control.view UpdateControl state.control
|
|
|
|
|
|> Html.fromUnstyled
|
2021-10-22 03:32:14 +03:00
|
|
|
|
, viewExample
|
|
|
|
|
{ name = "Default Container"
|
|
|
|
|
, description = "Your go-to container."
|
|
|
|
|
}
|
|
|
|
|
(Container.default :: attributes)
|
|
|
|
|
, viewExample
|
|
|
|
|
{ name = "Gray Container"
|
|
|
|
|
, description = "A container that doesn’t 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
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-10-22 03:32:14 +03:00
|
|
|
|
viewExample : { name : String, description : String } -> List (Container.Attribute msg) -> Html msg
|
|
|
|
|
viewExample { name, description } attributes =
|
|
|
|
|
Html.section
|
|
|
|
|
[ css
|
2021-10-22 19:27:14 +03:00
|
|
|
|
[ Css.marginTop (Css.px 20)
|
2021-10-22 03:32:14 +03:00
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
[ 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 "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
|
|
|
|
controlCss : Control (Container.Attribute msg)
|
|
|
|
|
controlCss =
|
|
|
|
|
Control.map Container.css
|
|
|
|
|
(Control.value
|
2021-10-22 19:27:14 +03:00
|
|
|
|
[ Css.minHeight (Css.px 100)
|
|
|
|
|
, Css.hover [ Css.backgroundColor Colors.glacier ]
|
2021-10-22 03:27:29 +03:00
|
|
|
|
]
|
|
|
|
|
)
|
2021-10-22 03:23:59 +03:00
|
|
|
|
|
|
|
|
|
|
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 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 )
|