noredink-ui/styleguide-app/ModuleExample.elm

172 lines
3.4 KiB
Elm
Raw Normal View History

2018-09-26 17:02:10 +03:00
module ModuleExample exposing
( Category(..)
, ModuleExample
, ModuleMessages
, categoryForDisplay
, categoryFromString
, view
)
2018-02-13 00:32:38 +03:00
import Css exposing (..)
import Html.Styled as Html exposing (Html, img)
import Html.Styled.Attributes as Attributes
2018-03-17 03:16:16 +03:00
import Nri.Ui.Colors.V1 exposing (..)
2018-02-13 00:32:38 +03:00
type alias ModuleExample msg =
2019-05-03 19:56:43 +03:00
{ name : String
2018-02-13 00:32:38 +03:00
, content : List (Html msg)
, category : Category
}
{-| -}
type alias ModuleMessages moduleMsg parentMsg =
{ noOp : parentMsg
, showItWorked : String -> parentMsg
, wrapper : moduleMsg -> parentMsg
}
type Category
2019-05-03 19:08:23 +03:00
= Tables
2018-02-13 00:32:38 +03:00
| Inputs
| Buttons
| Icons
2019-05-03 19:30:02 +03:00
| Widgets
2018-02-13 00:32:38 +03:00
| Messaging
| Modals
| Colors
| Text
| Pages
2019-05-03 19:10:23 +03:00
| Animations
2018-02-13 00:32:38 +03:00
{-| Used for route changes
-}
categoryFromString : String -> Result String Category
categoryFromString string =
case string of
2019-05-03 19:08:23 +03:00
"Tables" ->
Ok Tables
2018-02-13 00:32:38 +03:00
"Inputs" ->
Ok Inputs
2019-05-03 19:30:02 +03:00
"Widgets" ->
Ok Widgets
2018-02-13 00:32:38 +03:00
"Buttons" ->
Ok Buttons
"Icons" ->
Ok Icons
"Messaging" ->
Ok Messaging
"Modals" ->
Ok Modals
"Colors" ->
Ok Colors
"Text" ->
Ok Text
"Pages" ->
Ok Pages
2019-05-03 19:10:23 +03:00
"Animations" ->
Ok Animations
2018-02-13 00:32:38 +03:00
_ ->
Err "Invalid String"
categoryForDisplay : Category -> String
categoryForDisplay category =
case category of
2019-05-03 19:08:23 +03:00
Tables ->
"Tables"
2018-02-13 00:32:38 +03:00
Inputs ->
"Inputs"
2019-05-03 19:30:02 +03:00
Widgets ->
"Widgets"
2018-02-13 00:32:38 +03:00
Buttons ->
2019-05-03 19:08:23 +03:00
"Buttons and Links"
2018-02-13 00:32:38 +03:00
Icons ->
"Icons"
Messaging ->
2019-05-03 19:20:21 +03:00
"Alerts and Messages"
2018-02-13 00:32:38 +03:00
Modals ->
"Modals"
Colors ->
"Colors"
Text ->
2019-05-03 19:08:23 +03:00
"Text and Fonts"
2018-02-13 00:32:38 +03:00
Pages ->
2019-05-03 19:08:23 +03:00
"Error Pages"
2018-02-13 00:32:38 +03:00
2019-05-03 19:10:23 +03:00
Animations ->
"Animations"
2018-02-13 00:32:38 +03:00
view : Bool -> ModuleExample msg -> Html msg
2019-05-03 19:56:43 +03:00
view showFocusLink { name, content } =
Html.div
2019-08-01 03:00:03 +03:00
[ -- this class makes the axe accessibility checking output easier to parse
String.replace "." "-" name
|> (++) "module-example__"
|> Attributes.class
]
[ Html.styled Html.div
[ display block
, backgroundColor glacier
, padding (px 20)
, marginTop (px 20)
]
[]
[ Html.styled Html.h2
[ color gray20
, fontFamilies [ qt "Source Code Pro", "Consolas", "Courier", "monospace" ]
, fontSize (px 20)
2019-05-03 20:27:23 +03:00
, marginTop zero
, marginBottom zero
]
[]
[ Html.text name ]
, if showFocusLink then
viewLink "see only this" ("#doodad/" ++ name)
else
Html.text ""
, String.replace "." "-" name
|> (++) "https://package.elm-lang.org/packages/NoRedInk/noredink-ui/latest/"
|> viewLink "view docs"
2018-02-13 00:32:38 +03:00
]
, Html.styled Html.div
[ padding2 (px 20) zero ]
[]
content
2018-02-13 00:32:38 +03:00
]
viewLink : String -> String -> Html msg
viewLink text href =
Html.a
[ Attributes.href href
, Attributes.css [ Css.display Css.block ]
]
[ Html.text text
]