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

153 lines
3.9 KiB
Elm
Raw Normal View History

2022-05-20 21:57:47 +03:00
module Examples.BreadCrumbs exposing (example, State, Msg)
{-|
@docs example, State, Msg
-}
2022-05-24 19:52:46 +03:00
import Accessibility.Styled exposing (..)
2022-05-20 21:57:47 +03:00
import Category exposing (Category(..))
2022-05-24 19:52:46 +03:00
import Css
2022-05-24 20:27:15 +03:00
import Debug.Control as Control exposing (Control)
import Debug.Control.Extra as ControlExtra
import Debug.Control.View as ControlView
2022-05-20 21:57:47 +03:00
import Example exposing (Example)
2022-05-24 19:52:46 +03:00
import Html.Styled.Attributes exposing (css)
2022-05-24 20:27:15 +03:00
import Nri.Ui.BreadCrumbs.V1 as BreadCrumbs exposing (BreadCrumb, BreadCrumbs)
2022-05-24 19:52:46 +03:00
import Nri.Ui.Colors.V1 as Colors
import Nri.Ui.Fonts.V1 as Fonts
import Nri.Ui.Svg.V1 as Svg
import Nri.Ui.Text.V6 as Text
2022-05-24 19:52:46 +03:00
import Nri.Ui.UiIcon.V1 as UiIcon
2022-05-24 20:50:11 +03:00
import CommonControls
2022-05-20 21:57:47 +03:00
{-| -}
type alias State =
2022-05-24 20:27:15 +03:00
Control Settings
2022-05-20 21:57:47 +03:00
2022-05-24 20:27:15 +03:00
moduleName : String
moduleName =
"BreadCrumbs"
version : Int
version =
1
2022-05-20 21:57:47 +03:00
{-| -}
example : Example State Msg
example =
2022-05-24 20:27:15 +03:00
{ name = moduleName
, version = version
2022-05-20 21:57:47 +03:00
, categories = [ Layout ]
, keyboardSupport = []
2022-05-24 20:27:15 +03:00
, state = init
, update = update
2022-05-20 21:57:47 +03:00
, subscriptions = \_ -> Sub.none
2022-05-24 19:52:46 +03:00
, preview =
[ previewContainer [ previewText "🏠 Home" ]
, previewContainer [ previewText "🏠 Home", previewArrowRight, previewText "🟠 Category " ]
, previewContainer [ previewText "🏠", previewArrowRight, previewText "🟠", previewArrowRight, previewText "🟣 Sub-Category " ]
]
2022-05-20 21:57:47 +03:00
, view =
2022-05-24 20:27:15 +03:00
\ellieLinkConfig state ->
[ ControlView.view
{ ellieLinkConfig = ellieLinkConfig
, name = moduleName
, version = version
, update = UpdateControl
, settings = state
, mainType = "RootHtml.Html msg"
, extraImports = []
, toExampleCode =
\a ->
-- TODO: implement
-- List { sectionName : String, code : String }
[]
}
, BreadCrumbs.view
{ aTagAttributes = \_ -> []
, isCurrentRoute = \_ -> False
}
(Control.currentValue state).breadCrumbs
]
2022-05-20 21:57:47 +03:00
}
2022-05-24 19:52:46 +03:00
previewContainer : List (Html msg) -> Html msg
previewContainer =
span
[ css
[ Css.displayFlex
, Css.alignItems Css.center
, Fonts.baseFont
, Css.fontSize (Css.px 10)
, Css.fontWeight (Css.int 600)
, Css.color Colors.navy
]
]
previewText : String -> Html msg
previewText name =
span [ css [ Css.margin (Css.px 2) ] ] [ text name ]
previewArrowRight : Html msg
previewArrowRight =
UiIcon.arrowRight
|> Svg.withColor Colors.gray75
|> Svg.withHeight (Css.px 10)
|> Svg.withWidth (Css.px 8)
|> Svg.withCss [ Css.flexShrink Css.zero ]
|> Svg.toHtml
2022-05-24 20:27:15 +03:00
{-| -}
type Msg
= UpdateControl (Control Settings)
update : Msg -> State -> ( State, Cmd Msg )
update msg state =
case msg of
UpdateControl control ->
( control, Cmd.none )
type alias Settings =
{ breadCrumbs : BreadCrumbs ()
}
init : Control Settings
init =
Control.record Settings
|> Control.field "BreadCrumbs" controlBreadCrumbs
controlBreadCrumbs : Control (BreadCrumbs ())
controlBreadCrumbs =
Control.map BreadCrumbs.init controlBreadCrumb
controlBreadCrumb : Control (BreadCrumb ())
controlBreadCrumb =
Control.record (\icon iconStyle text -> {
icon = icon,
iconStyle = iconStyle,
text =text,
id = "unique-id",
route = ()
})
2022-05-24 20:50:11 +03:00
|> Control.field "icon" (Control.maybe False (Control.map Tuple.second CommonControls.uiIcon))
|> Control.field "iconStyle" (Control.choice
[ ("Default", Control.value BreadCrumbs.Default)
, ("Circled", Control.value BreadCrumbs.Circled)
])
|> Control.field "text" (Control.string "Home")