noredink-ui/styleguide-app/ModuleExample.elm

226 lines
4.3 KiB
Elm
Raw Normal View History

2018-02-13 00:32:38 +03:00
module ModuleExample
exposing
( Category(..)
, ModuleExample
, ModuleMessages
, categoryForDisplay
, categoryFromString
, styles
, view
)
import Css exposing (..)
import Css.Foreign exposing (Snippet)
import DEPRECATED.Css.File exposing (Stylesheet, compile, stylesheet)
import DEPRECATED.Css.Namespace
2018-02-13 00:32:38 +03:00
import Html exposing (Html, img)
import Html.Attributes
import Html.CssHelpers
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 =
{ filename : String
, content : List (Html msg)
, category : Category
}
{-| -}
type alias ModuleMessages moduleMsg parentMsg =
{ noOp : parentMsg
, showItWorked : String -> parentMsg
, wrapper : moduleMsg -> parentMsg
}
type Category
= Layout
| Inputs
| Buttons
| Icons
| Behaviors
| Messaging
| Modals
| Writing
| NotesToDeveloper
| Colors
| Text
2018-03-02 00:34:44 +03:00
| TextWriting
2018-03-17 01:33:42 +03:00
| Fonts
2018-02-13 00:32:38 +03:00
| DynamicSymbols
| Pages
| QuestionTypes
{-| Used for route changes
-}
categoryFromString : String -> Result String Category
categoryFromString string =
case string of
"Layout" ->
Ok Layout
"Inputs" ->
Ok Inputs
"Behaviors" ->
Ok Behaviors
"Buttons" ->
Ok Buttons
"Icons" ->
Ok Icons
"Messaging" ->
Ok Messaging
"Modals" ->
Ok Modals
"Writing" ->
Ok Writing
"NotesToDeveloper" ->
Ok NotesToDeveloper
"Colors" ->
Ok Colors
"Text" ->
Ok Text
2018-03-02 00:34:44 +03:00
"TextWriting" ->
Ok TextWriting
2018-03-01 01:04:22 +03:00
2018-03-17 01:33:42 +03:00
"Fonts" ->
Ok Fonts
2018-02-13 00:32:38 +03:00
"DynamicSymbols" ->
Ok DynamicSymbols
"Pages" ->
Ok Pages
"QuestionTypes" ->
Ok QuestionTypes
_ ->
Err "Invalid String"
categoryForDisplay : Category -> String
categoryForDisplay category =
case category of
Layout ->
"Layout"
Inputs ->
"Inputs"
Behaviors ->
"Behaviors"
Buttons ->
"Buttons"
Icons ->
"Icons"
Messaging ->
"Messaging"
Modals ->
"Modals"
Writing ->
"Writing"
NotesToDeveloper ->
"NotesToDeveloper"
Colors ->
"Colors"
Text ->
"Text"
2018-03-02 00:34:44 +03:00
TextWriting ->
"TextWriting"
2018-03-01 01:04:22 +03:00
2018-03-17 01:33:42 +03:00
Fonts ->
"Fonts"
2018-02-13 00:32:38 +03:00
DynamicSymbols ->
"Dynamic Symbols"
Pages ->
"Pages"
QuestionTypes ->
"Question types / Quiz UI"
view : Bool -> ModuleExample msg -> Html msg
view showFocusLink { filename, content } =
Html.div [ class [ Module ] ]
[ Html.div [ class [ ModuleHeader ] ]
[ Html.h2
[ class [ ModuleName ] ]
[ Html.text filename
, Html.text " "
, if showFocusLink then
Html.a
[ Html.Attributes.href <| "#doodad/" ++ filename ]
[ Html.text "(see only this)" ]
else
Html.text ""
]
]
, Html.div [ class [ ModuleBody ] ] content
]
type Classes
= Module
| ModuleHeader
| ModuleName
| ModuleImporting
| ModuleBody
viewStyles : List Snippet
2018-02-13 00:32:38 +03:00
viewStyles =
[ Css.Foreign.class ModuleHeader
2018-02-13 00:32:38 +03:00
[ display block
, backgroundColor glacier
, padding (px 20)
, marginTop (px 20)
]
, Css.Foreign.class ModuleImporting
2018-02-13 00:32:38 +03:00
[ display block
, padding (px 20)
, margin2 (px 20) zero
]
, Css.Foreign.class ModuleBody
2018-02-13 00:32:38 +03:00
[ padding2 (px 20) zero ]
, Css.Foreign.class ModuleName
2018-02-13 00:32:38 +03:00
[ color gray20
, fontFamilies [ qt "Source Code Pro", "Consolas", "Courier", "monospace" ]
, fontSize (px 20)
]
]
styles : Stylesheet
2018-02-13 00:32:38 +03:00
styles =
List.concat
[ viewStyles
]
|> (stylesheet << DEPRECATED.Css.Namespace.namespace "Page-StyleGuide-ModuleExample-")
2018-02-13 00:32:38 +03:00
{ id, class, classList } =
Html.CssHelpers.withNamespace "Page-StyleGuide-ModuleExample-"