@charmland/gem 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +13 -0
- package/README.md +24 -2
- package/assets/fonts/Hypography-Italic.woff2 +0 -0
- package/assets/fonts/Hypography-Regular.woff2 +0 -0
- package/assets/fonts/PPFraktionMono-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionMonoItalic-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSans-Variable.ttf +0 -0
- package/assets/fonts/PPFraktionSansItalic-Variable.ttf +0 -0
- package/bin/gem-elm.js +3 -0
- package/dist/browser/boot.d.ts +10 -0
- package/dist/browser/boot.js +14 -0
- package/dist/browser/color-scheme.d.ts +9 -0
- package/dist/browser/color-scheme.js +76 -0
- package/dist/browser/ports.d.ts +37 -0
- package/dist/browser/ports.js +90 -0
- package/dist/browser/router.d.ts +5 -0
- package/dist/browser/router.js +35 -0
- package/dist/browser/runtime.d.ts +12 -0
- package/dist/browser/runtime.js +22 -0
- package/dist/browser/tabs.d.ts +9 -0
- package/dist/browser/tabs.js +69 -0
- package/dist/default/theme.css +4664 -0
- package/dist/default/theme.js +13815 -0
- package/dist/node/build.d.ts +16 -0
- package/dist/node/build.js +48 -0
- package/dist/node/cli.d.ts +2 -0
- package/dist/node/cli.js +21 -0
- package/elm.json +28 -0
- package/package.json +86 -4
- package/src/app/Gem/App.elm +1268 -0
- package/src/app/Gem/CharmSticker.elm +35 -0
- package/src/app/Gem/Components.elm +292 -0
- package/src/app/Gem/Main.elm +17 -0
- package/src/app/Gem/Ports.elm +32 -0
- package/src/app/Gem/Shell.elm +957 -0
- package/src/browser/theme.d.ts +1 -0
- package/src/core/Gem/Node.elm +219 -0
- package/src/core/Gem/Page.elm +560 -0
- package/src/core/Gem/Render.elm +510 -0
- package/src/core/Gem/Slots.elm +11 -0
- package/src/styles/docs.scss +1083 -0
- package/src/styles/fonts.scss +51 -0
- package/src/styles/gem.scss +362 -0
- package/src/styles/theme.scss +8 -0
- package/src/styles/ui/burger.scss +272 -0
- package/src/styles/ui/button.scss +350 -0
- package/src/styles/ui/charmtone.scss +70 -0
- package/src/styles/ui/controls-extra.scss +316 -0
- package/src/styles/ui/controls.scss +110 -0
- package/src/styles/ui/display.scss +359 -0
- package/src/styles/ui/dropdown.scss +341 -0
- package/src/styles/ui/form.scss +314 -0
- package/src/styles/ui/menu.scss +200 -0
- package/src/styles/ui/meter.scss +124 -0
- package/src/styles/ui/modal.scss +545 -0
- package/src/styles/ui/oauth.scss +50 -0
- package/src/styles/ui/page-nav.scss +63 -0
- package/src/styles/ui/reset.scss +111 -0
- package/src/styles/ui/scrollbar.scss +39 -0
- package/src/styles/ui/search.scss +164 -0
- package/src/styles/ui/sidebar.scss +229 -0
- package/src/styles/ui/squircle.scss +60 -0
- package/src/styles/ui/table.scss +97 -0
- package/src/styles/ui/theme.scss +132 -0
- package/src/styles/ui/toast.scss +587 -0
- package/src/styles/ui/toc.scss +128 -0
- package/src/styles/ui/typography.scss +21 -0
- package/src/styles/ui/ui.scss +33 -0
- package/src/ui/Ui/Badge.elm +51 -0
- package/src/ui/Ui/Banner.elm +97 -0
- package/src/ui/Ui/Burger.elm +259 -0
- package/src/ui/Ui/Button.elm +261 -0
- package/src/ui/Ui/Card.elm +32 -0
- package/src/ui/Ui/Cards.elm +15 -0
- package/src/ui/Ui/ChoiceGroup.elm +62 -0
- package/src/ui/Ui/CopyButton.elm +139 -0
- package/src/ui/Ui/Divider.elm +16 -0
- package/src/ui/Ui/Dropdown.elm +600 -0
- package/src/ui/Ui/Empty.elm +41 -0
- package/src/ui/Ui/ErrorBubble.elm +34 -0
- package/src/ui/Ui/Field.elm +45 -0
- package/src/ui/Ui/FormStatus.elm +32 -0
- package/src/ui/Ui/Icon.elm +381 -0
- package/src/ui/Ui/InlineForm.elm +51 -0
- package/src/ui/Ui/Input.elm +113 -0
- package/src/ui/Ui/KeyValue.elm +25 -0
- package/src/ui/Ui/ListRow.elm +67 -0
- package/src/ui/Ui/Loader.elm +32 -0
- package/src/ui/Ui/Logo/Charm.elm +21 -0
- package/src/ui/Ui/Logo/CharmMark.elm +32 -0
- package/src/ui/Ui/Logo/CharmSticker.elm +35 -0
- package/src/ui/Ui/Logo/Discord.elm +26 -0
- package/src/ui/Ui/Logo/GitHub.elm +21 -0
- package/src/ui/Ui/Logo/Google.elm +21 -0
- package/src/ui/Ui/Logo/Hexy.elm +29 -0
- package/src/ui/Ui/Logo/Hyper.elm +42 -0
- package/src/ui/Ui/Logo/Integration.elm +117 -0
- package/src/ui/Ui/Logo/Prism.elm +35 -0
- package/src/ui/Ui/Logos.elm +115 -0
- package/src/ui/Ui/Menu.elm +348 -0
- package/src/ui/Ui/Meter.elm +132 -0
- package/src/ui/Ui/Modal.elm +247 -0
- package/src/ui/Ui/Motion.elm +32 -0
- package/src/ui/Ui/NumberBox.elm +86 -0
- package/src/ui/Ui/OAuthButton.elm +39 -0
- package/src/ui/Ui/PageNav.elm +65 -0
- package/src/ui/Ui/Pager.elm +49 -0
- package/src/ui/Ui/Search.elm +396 -0
- package/src/ui/Ui/SearchBox.elm +78 -0
- package/src/ui/Ui/Section.elm +21 -0
- package/src/ui/Ui/Sidebar.elm +239 -0
- package/src/ui/Ui/Stat.elm +29 -0
- package/src/ui/Ui/Switch.elm +34 -0
- package/src/ui/Ui/Table.elm +89 -0
- package/src/ui/Ui/Tabs.elm +280 -0
- package/src/ui/Ui/ToC.elm +120 -0
- package/src/ui/Ui/Toast.elm +1145 -0
- package/src/ui/Ui/Toolbar.elm +31 -0
- package/src/ui/Ui/TwoStepConfirm.elm +159 -0
- package/src/ui/Ui/Typography.elm +33 -0
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
module Ui.Button exposing
|
|
2
|
+
( Config
|
|
3
|
+
, Size(..)
|
|
4
|
+
, Variant(..)
|
|
5
|
+
, view
|
|
6
|
+
, viewLink
|
|
7
|
+
, withAttributes
|
|
8
|
+
, withBusy
|
|
9
|
+
, withDisabled
|
|
10
|
+
, withIcon
|
|
11
|
+
, withLabel
|
|
12
|
+
, withOnClick
|
|
13
|
+
, withSize
|
|
14
|
+
, withVariant
|
|
15
|
+
, withWide
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
{-| The button. Five variants, three sizes, and a busy state; the
|
|
19
|
+
class names the house stylesheet styles are an implementation detail.
|
|
20
|
+
|
|
21
|
+
Variants follow one rule: `primary` for the main action, `secondary`
|
|
22
|
+
for supporting actions, `ghost` for low emphasis, `danger` for
|
|
23
|
+
destructive (quiet until hovered), `dangerSolid` for destructive
|
|
24
|
+
confirmation buttons.
|
|
25
|
+
|
|
26
|
+
Ui.Button.view
|
|
27
|
+
(Ui.Button.withOnClick Save
|
|
28
|
+
{ label = "Save"
|
|
29
|
+
, variant = Ui.Button.Primary
|
|
30
|
+
, size = Ui.Button.Regular
|
|
31
|
+
, wide = False
|
|
32
|
+
, disabled = False
|
|
33
|
+
, busy = Nothing
|
|
34
|
+
, attributes = []
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
-}
|
|
39
|
+
|
|
40
|
+
import Html exposing (Attribute, Html, button, text)
|
|
41
|
+
import Html.Attributes
|
|
42
|
+
import Html.Events
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
{-| The button's color family.
|
|
46
|
+
-}
|
|
47
|
+
type Variant
|
|
48
|
+
= Primary
|
|
49
|
+
| Secondary
|
|
50
|
+
| Ghost
|
|
51
|
+
| Danger
|
|
52
|
+
| DangerSolid
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
{-| The control height. `Regular` matches toolbar controls, `Compact`
|
|
56
|
+
is the dense size used in tables, pagers, and in-row editors, and `Xs`
|
|
57
|
+
sits beside body copy (the profile's Edit button).
|
|
58
|
+
-}
|
|
59
|
+
type Size
|
|
60
|
+
= Regular
|
|
61
|
+
| Compact
|
|
62
|
+
| Xs
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
{-| Button configuration.
|
|
66
|
+
-}
|
|
67
|
+
type alias Config msg =
|
|
68
|
+
{ label : String
|
|
69
|
+
, variant : Variant
|
|
70
|
+
, size : Size
|
|
71
|
+
, wide : Bool
|
|
72
|
+
, disabled : Bool
|
|
73
|
+
, busy : Maybe String
|
|
74
|
+
, icon : Maybe (Html Never)
|
|
75
|
+
, onClick : msg
|
|
76
|
+
, attributes : List (Attribute msg)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
{-| Set the leading glyph. The icon is `Html Never`: a glyph, not a
|
|
81
|
+
second action.
|
|
82
|
+
-}
|
|
83
|
+
withIcon : Html Never -> Config msg -> Config msg
|
|
84
|
+
withIcon icon config =
|
|
85
|
+
{ config | icon = Just icon }
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
{-| Set the label.
|
|
89
|
+
-}
|
|
90
|
+
withLabel : String -> Config msg -> Config msg
|
|
91
|
+
withLabel label config =
|
|
92
|
+
{ config | label = label }
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
{-| Set the color variant.
|
|
96
|
+
-}
|
|
97
|
+
withVariant : Variant -> Config msg -> Config msg
|
|
98
|
+
withVariant variant config =
|
|
99
|
+
{ config | variant = variant }
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
{-| Set the control height.
|
|
103
|
+
-}
|
|
104
|
+
withSize : Size -> Config msg -> Config msg
|
|
105
|
+
withSize size config =
|
|
106
|
+
{ config | size = size }
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
{-| Stretch to fill the row (checkout buttons, empty-card CTAs).
|
|
110
|
+
-}
|
|
111
|
+
withWide : Bool -> Config msg -> Config msg
|
|
112
|
+
withWide value config =
|
|
113
|
+
{ config | wide = value }
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
{-| Disable the button.
|
|
117
|
+
-}
|
|
118
|
+
withDisabled : Bool -> Config msg -> Config msg
|
|
119
|
+
withDisabled value config =
|
|
120
|
+
{ config | disabled = value }
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
{-| Swap the label for working copy ("Saving…") while the action is in
|
|
124
|
+
flight. The button also disables while busy.
|
|
125
|
+
-}
|
|
126
|
+
withBusy : String -> Config msg -> Config msg
|
|
127
|
+
withBusy label config =
|
|
128
|
+
{ config | busy = Just label }
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
{-| Set the click message.
|
|
132
|
+
-}
|
|
133
|
+
withOnClick : msg -> Config msg -> Config msg
|
|
134
|
+
withOnClick msg config =
|
|
135
|
+
{ config | onClick = msg }
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
{-| Add extra attributes (ids, test selectors, additional handlers).
|
|
139
|
+
-}
|
|
140
|
+
withAttributes : List (Attribute msg) -> Config msg -> Config msg
|
|
141
|
+
withAttributes attrs config =
|
|
142
|
+
{ config | attributes = attrs }
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
{-| Render a button-styled **anchor** — CTAs that navigate. Links
|
|
146
|
+
carry no `onClick` (an anchor's message is the navigation itself), so
|
|
147
|
+
the config is a plain record without one. Disabled links get
|
|
148
|
+
`aria-disabled` (an anchor can't be truly disabled).
|
|
149
|
+
-}
|
|
150
|
+
viewLink :
|
|
151
|
+
{ label : String
|
|
152
|
+
, variant : Variant
|
|
153
|
+
, size : Size
|
|
154
|
+
, wide : Bool
|
|
155
|
+
, disabled : Bool
|
|
156
|
+
, icon : Maybe (Html Never)
|
|
157
|
+
, attributes : List (Attribute msg)
|
|
158
|
+
}
|
|
159
|
+
-> String
|
|
160
|
+
-> Html msg
|
|
161
|
+
viewLink config href =
|
|
162
|
+
let
|
|
163
|
+
sizeAttrs =
|
|
164
|
+
sizeClass config.size
|
|
165
|
+
|> Maybe.map (\cls -> [ ( cls, True ) ])
|
|
166
|
+
|> Maybe.withDefault []
|
|
167
|
+
|
|
168
|
+
disabledAttrs =
|
|
169
|
+
if config.disabled then
|
|
170
|
+
[ Html.Attributes.attribute "aria-disabled" "true" ]
|
|
171
|
+
|
|
172
|
+
else
|
|
173
|
+
[]
|
|
174
|
+
|
|
175
|
+
wideAttrs =
|
|
176
|
+
if config.wide then
|
|
177
|
+
[ ( "wide", True ) ]
|
|
178
|
+
|
|
179
|
+
else
|
|
180
|
+
[]
|
|
181
|
+
in
|
|
182
|
+
Html.a
|
|
183
|
+
([ Html.Attributes.classList
|
|
184
|
+
(( variantClass config.variant, True ) :: (sizeAttrs ++ wideAttrs))
|
|
185
|
+
, Html.Attributes.href href
|
|
186
|
+
]
|
|
187
|
+
++ disabledAttrs
|
|
188
|
+
++ config.attributes
|
|
189
|
+
)
|
|
190
|
+
(Maybe.map (Html.map never) config.icon
|
|
191
|
+
|> Maybe.map List.singleton
|
|
192
|
+
|> Maybe.withDefault []
|
|
193
|
+
|> (\icon -> icon ++ [ text config.label ])
|
|
194
|
+
|> List.map identity
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
variantClass : Variant -> String
|
|
199
|
+
variantClass variant =
|
|
200
|
+
case variant of
|
|
201
|
+
Primary ->
|
|
202
|
+
"primary"
|
|
203
|
+
|
|
204
|
+
Secondary ->
|
|
205
|
+
"secondary"
|
|
206
|
+
|
|
207
|
+
Ghost ->
|
|
208
|
+
"ghost"
|
|
209
|
+
|
|
210
|
+
Danger ->
|
|
211
|
+
"danger"
|
|
212
|
+
|
|
213
|
+
DangerSolid ->
|
|
214
|
+
"danger solid"
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
sizeClass : Size -> Maybe String
|
|
218
|
+
sizeClass size =
|
|
219
|
+
case size of
|
|
220
|
+
Regular ->
|
|
221
|
+
Nothing
|
|
222
|
+
|
|
223
|
+
Compact ->
|
|
224
|
+
Just "compact"
|
|
225
|
+
|
|
226
|
+
Xs ->
|
|
227
|
+
Just "xs"
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
{-| Render the button.
|
|
231
|
+
-}
|
|
232
|
+
view : Config msg -> Html msg
|
|
233
|
+
view config =
|
|
234
|
+
let
|
|
235
|
+
label =
|
|
236
|
+
case config.busy of
|
|
237
|
+
Just busyLabel ->
|
|
238
|
+
busyLabel
|
|
239
|
+
|
|
240
|
+
Nothing ->
|
|
241
|
+
config.label
|
|
242
|
+
|
|
243
|
+
sizeAttrs =
|
|
244
|
+
sizeClass config.size
|
|
245
|
+
|> Maybe.map (\cls -> [ ( cls, True ) ])
|
|
246
|
+
|> Maybe.withDefault []
|
|
247
|
+
in
|
|
248
|
+
button
|
|
249
|
+
([ Html.Attributes.classList
|
|
250
|
+
(( variantClass config.variant, True ) :: sizeAttrs)
|
|
251
|
+
, Html.Attributes.disabled (config.disabled || config.busy /= Nothing)
|
|
252
|
+
, Html.Attributes.type_ "button"
|
|
253
|
+
, Html.Events.onClick config.onClick
|
|
254
|
+
]
|
|
255
|
+
++ config.attributes
|
|
256
|
+
)
|
|
257
|
+
(Maybe.map (Html.map never) config.icon
|
|
258
|
+
|> Maybe.map List.singleton
|
|
259
|
+
|> Maybe.withDefault []
|
|
260
|
+
|> (\icon -> icon ++ [ text label ])
|
|
261
|
+
)
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Ui.Card exposing (Card, view)
|
|
2
|
+
|
|
3
|
+
{-| The link card: a bordered surface with a title and a description,
|
|
4
|
+
optionally an anchor — the shape doc sites use for "pick your tool"
|
|
5
|
+
grids. The shell and the hover affordance come from the stylesheet.
|
|
6
|
+
-}
|
|
7
|
+
|
|
8
|
+
import Html exposing (Html)
|
|
9
|
+
import Html.Attributes as Attr
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
type alias Card =
|
|
13
|
+
{ title : String
|
|
14
|
+
, description : String
|
|
15
|
+
, href : Maybe String
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
view : Card -> Html msg
|
|
20
|
+
view card =
|
|
21
|
+
let
|
|
22
|
+
body =
|
|
23
|
+
[ Html.div [ Attr.class "card-title" ] [ Html.text card.title ]
|
|
24
|
+
, Html.p [ Attr.class "card-desc" ] [ Html.text card.description ]
|
|
25
|
+
]
|
|
26
|
+
in
|
|
27
|
+
case card.href of
|
|
28
|
+
Just href ->
|
|
29
|
+
Html.a [ Attr.class "card", Attr.href href ] body
|
|
30
|
+
|
|
31
|
+
Nothing ->
|
|
32
|
+
Html.div [ Attr.class "card" ] body
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Ui.Cards exposing (view)
|
|
2
|
+
|
|
3
|
+
{-| The cards group: a responsive grid of `Ui.Card`s — the "pick your
|
|
4
|
+
tool" band. The column count follows the container, so the same group
|
|
5
|
+
reads three-up on a page and one-up on a phone.
|
|
6
|
+
-}
|
|
7
|
+
|
|
8
|
+
import Html exposing (Html)
|
|
9
|
+
import Html.Attributes as Attr
|
|
10
|
+
import Ui.Card exposing (Card)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
view : List Card -> Html msg
|
|
14
|
+
view cards =
|
|
15
|
+
Html.div [ Attr.class "cards" ] (List.map Ui.Card.view cards)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Ui.ChoiceGroup exposing (view)
|
|
2
|
+
|
|
3
|
+
{-| The button-group radio: a grid of outline buttons where exactly one
|
|
4
|
+
is active. Used for API-key expiry choices and invite roles — places
|
|
5
|
+
where the choices are few, known, and read better as buttons than as
|
|
6
|
+
a select.
|
|
7
|
+
-}
|
|
8
|
+
|
|
9
|
+
import Html exposing (Attribute, Html, button, div, text)
|
|
10
|
+
import Html.Attributes
|
|
11
|
+
import Html.Events
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
{-| One option: display label and the value the parent owns.
|
|
15
|
+
-}
|
|
16
|
+
type alias Choice value =
|
|
17
|
+
{ label : String
|
|
18
|
+
, value : value
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
{-| Render the group. `columns` lays the buttons out in a grid; pass 2
|
|
23
|
+
for the expiry picker's two-up grid, 1 (or 0) for a single column.
|
|
24
|
+
Selection follows the `active` value; `onSelect` hands it back.
|
|
25
|
+
-}
|
|
26
|
+
view :
|
|
27
|
+
{ choices : List (Choice value)
|
|
28
|
+
, active : value
|
|
29
|
+
, onSelect : value -> msg
|
|
30
|
+
, columns : Int
|
|
31
|
+
, attributes : List (Attribute msg)
|
|
32
|
+
}
|
|
33
|
+
-> Html msg
|
|
34
|
+
view config =
|
|
35
|
+
let
|
|
36
|
+
button_ choice =
|
|
37
|
+
button
|
|
38
|
+
[ Html.Attributes.classList [ ( "active", choice.value == config.active ) ]
|
|
39
|
+
, Html.Attributes.type_ "button"
|
|
40
|
+
, Html.Attributes.attribute "aria-pressed"
|
|
41
|
+
(if choice.value == config.active then
|
|
42
|
+
"true"
|
|
43
|
+
|
|
44
|
+
else
|
|
45
|
+
"false"
|
|
46
|
+
)
|
|
47
|
+
, Html.Events.onClick (config.onSelect choice.value)
|
|
48
|
+
]
|
|
49
|
+
[ text choice.label ]
|
|
50
|
+
|
|
51
|
+
columnStyle =
|
|
52
|
+
[ Html.Attributes.style "display" "grid"
|
|
53
|
+
, Html.Attributes.style "grid-template-columns"
|
|
54
|
+
("repeat("
|
|
55
|
+
++ String.fromInt (max 1 config.columns)
|
|
56
|
+
++ ", 1fr)"
|
|
57
|
+
)
|
|
58
|
+
, Html.Attributes.style "gap" "0.5rem"
|
|
59
|
+
]
|
|
60
|
+
in
|
|
61
|
+
div ([ Html.Attributes.class "expiry" ] ++ columnStyle ++ config.attributes)
|
|
62
|
+
(List.map button_ config.choices)
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
module Ui.CopyButton exposing (Model, Msg, init, update, view)
|
|
2
|
+
|
|
3
|
+
{-| The copy-to-clipboard button: a bare icon that swaps to a check for
|
|
4
|
+
the moment the copy lands, tinted julep. The clipboard write itself
|
|
5
|
+
stays outside Elm — wire `Msg` to a host port (see `update`) and the
|
|
6
|
+
button owns the copied feedback.
|
|
7
|
+
|
|
8
|
+
Host wiring in the reference app:
|
|
9
|
+
|
|
10
|
+
type Msg
|
|
11
|
+
= CopyMsg Ui.CopyButton.Msg
|
|
12
|
+
| ...
|
|
13
|
+
|
|
14
|
+
port copyToClipboard : String -> Cmd msg
|
|
15
|
+
|
|
16
|
+
update msg model =
|
|
17
|
+
case msg of
|
|
18
|
+
CopyMsg subMsg ->
|
|
19
|
+
let
|
|
20
|
+
( copyModel, maybeText ) =
|
|
21
|
+
Ui.CopyButton.update subMsg model.copyModel
|
|
22
|
+
in
|
|
23
|
+
( { model | copyModel = copyModel }
|
|
24
|
+
, Cmd.batch
|
|
25
|
+
[ maybeText
|
|
26
|
+
|> Maybe.map copyToClipboard
|
|
27
|
+
|> Maybe.withDefault Cmd.none
|
|
28
|
+
|> Cmd.map (always CopyMsg)
|
|
29
|
+
, Cmd.map CopyMsg (copyCmd copyModel)
|
|
30
|
+
]
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
-}
|
|
34
|
+
|
|
35
|
+
import Html exposing (Attribute, Html, button)
|
|
36
|
+
import Html.Attributes
|
|
37
|
+
import Html.Events
|
|
38
|
+
import Process
|
|
39
|
+
import Ui.Icon
|
|
40
|
+
import Task
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
{-| The copied flash's lifetime, in milliseconds.
|
|
44
|
+
-}
|
|
45
|
+
copiedFlashMs : Int
|
|
46
|
+
copiedFlashMs =
|
|
47
|
+
1200
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
{-| The text whose copy is still flashing; `Nothing` at rest. Keyed by
|
|
51
|
+
text so one model can drive every copy button on a page: clicking one
|
|
52
|
+
block's control never flashes its neighbours.
|
|
53
|
+
-}
|
|
54
|
+
type alias Model =
|
|
55
|
+
{ copied : Maybe String }
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
{-| A resting button.
|
|
59
|
+
-}
|
|
60
|
+
init : Model
|
|
61
|
+
init =
|
|
62
|
+
{ copied = Nothing }
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
{-| `Copy text` copies; the second field is the text to hand to the
|
|
66
|
+
host port. `Reset text` ends that text's flash.
|
|
67
|
+
-}
|
|
68
|
+
type Msg
|
|
69
|
+
= Copy String
|
|
70
|
+
| Reset String
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
{-| Advance the copied state. The `Cmd` schedules the flash's end;
|
|
74
|
+
fire the returned text through your clipboard port yourself.
|
|
75
|
+
-}
|
|
76
|
+
update : Msg -> Model -> ( Model, Maybe String, Cmd Msg )
|
|
77
|
+
update msg model =
|
|
78
|
+
case msg of
|
|
79
|
+
Copy text ->
|
|
80
|
+
( { model | copied = Just text }
|
|
81
|
+
, Just text
|
|
82
|
+
, Process.sleep (toFloat copiedFlashMs)
|
|
83
|
+
|> Task.perform (always (Reset text))
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
Reset text ->
|
|
87
|
+
if model.copied == Just text then
|
|
88
|
+
( { model | copied = Nothing }, Nothing, Cmd.none )
|
|
89
|
+
|
|
90
|
+
else
|
|
91
|
+
( model, Nothing, Cmd.none )
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
{-| Render the button. `text` is what a click copies; `label` is the
|
|
95
|
+
resting tooltip/aria-label. The copied state's label is handled for
|
|
96
|
+
you.
|
|
97
|
+
-}
|
|
98
|
+
view :
|
|
99
|
+
{ text : String
|
|
100
|
+
, label : String
|
|
101
|
+
, attributes : List (Attribute Msg)
|
|
102
|
+
}
|
|
103
|
+
-> Model
|
|
104
|
+
-> Html Msg
|
|
105
|
+
view config model =
|
|
106
|
+
let
|
|
107
|
+
copied =
|
|
108
|
+
model.copied == Just config.text
|
|
109
|
+
in
|
|
110
|
+
button
|
|
111
|
+
([ Html.Attributes.classList
|
|
112
|
+
[ ( "copy", True )
|
|
113
|
+
, ( "done", copied )
|
|
114
|
+
]
|
|
115
|
+
, Html.Attributes.type_ "button"
|
|
116
|
+
, Html.Attributes.title
|
|
117
|
+
(if copied then
|
|
118
|
+
"Copied"
|
|
119
|
+
|
|
120
|
+
else
|
|
121
|
+
config.label
|
|
122
|
+
)
|
|
123
|
+
, Html.Attributes.attribute "aria-label"
|
|
124
|
+
(if copied then
|
|
125
|
+
"Copied"
|
|
126
|
+
|
|
127
|
+
else
|
|
128
|
+
config.label
|
|
129
|
+
)
|
|
130
|
+
, Html.Events.onClick (Copy config.text)
|
|
131
|
+
]
|
|
132
|
+
++ config.attributes
|
|
133
|
+
)
|
|
134
|
+
[ if copied then
|
|
135
|
+
Ui.Icon.view Ui.Icon.Check
|
|
136
|
+
|
|
137
|
+
else
|
|
138
|
+
Ui.Icon.view Ui.Icon.Copy
|
|
139
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Ui.Divider exposing (view)
|
|
2
|
+
|
|
3
|
+
{-| The "or" divider between the OAuth buttons and the email form on
|
|
4
|
+
the auth screens.
|
|
5
|
+
-}
|
|
6
|
+
|
|
7
|
+
import Html exposing (Attribute, Html, div, text)
|
|
8
|
+
import Html.Attributes
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
{-| Render the divider. Pass custom copy for a different conjunction.
|
|
12
|
+
-}
|
|
13
|
+
view : String -> List (Attribute msg) -> Html msg
|
|
14
|
+
view label attributes =
|
|
15
|
+
div (Html.Attributes.class "divider" :: attributes)
|
|
16
|
+
[ text label ]
|