forked from LordParsley/elm-ui-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExplorerWithLocale.elm
104 lines (83 loc) · 2.56 KB
/
ExplorerWithLocale.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
module ExplorerWithLocale exposing (main)
import Html exposing (..)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
import UIExplorer exposing (UIExplorerProgram, defaultConfig, explore, storiesOf)
type Locale
= En
| Fr
| De
type Msg
= ChangedLocale Locale
type alias Model =
{ locale : Locale }
initialModel : Model
initialModel =
{ locale = En }
button : String -> String -> Html.Html msg
button label bgColor =
Html.button
[ style "background-color" bgColor, style "padding" "10px" ]
[ Html.text label ]
buttonLabel : Locale -> String
buttonLabel locale =
case locale of
En ->
"confirm password"
Fr ->
"Confirmez le mot de passe"
De ->
"Kennwort bestätigen"
localButtonView : msg -> String -> Html (UIExplorer.Msg msg)
localButtonView onClickMsg label =
li
[ style "font-size" "11px"
, style "margin-right" "8px"
]
[ Html.button
[ onClick (UIExplorer.ExternalMsg <| onClickMsg)
, style "color" "#666"
]
[ text label ]
]
menuViewEnhancer : a -> Html (UIExplorer.Msg Msg) -> Html (UIExplorer.Msg Msg)
menuViewEnhancer _ menuView =
div []
[ ul
[ style "margin-bottom" "8px"
, style "font-size" "9px"
, style "display" "flex"
, style "list-style" "none"
, style "padding" "0px"
]
[ localButtonView (ChangedLocale En) "English"
, localButtonView (ChangedLocale Fr) "Français"
, localButtonView (ChangedLocale De) "Deutsch"
]
, menuView
]
main : UIExplorerProgram Model Msg {} ()
main =
explore
{ customModel = initialModel
, customHeader = Nothing
, update =
\msg m ->
case msg of
ChangedLocale locale ->
( { m | customModel = { locale = locale } }, Cmd.none )
, subscriptions =
\m -> Sub.none
, viewEnhancer = \m stories -> stories
, menuViewEnhancer = menuViewEnhancer
, onModeChanged = Nothing
, documentTitle = Just "This is an example with locale"
, init = \f m -> m
, enableDarkMode = False
}
[ storiesOf
"Button"
[ ( "Primary", \m -> button (buttonLabel m.customModel.locale) "pink", {} )
, ( "Secondary", \m -> button (buttonLabel m.customModel.locale) "violet", {} )
]
]