@charmland/gem 0.0.0-stage → 0.1.0

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.
Files changed (121) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +13 -0
  3. package/README.md +24 -2
  4. package/assets/fonts/Hypography-Italic.woff2 +0 -0
  5. package/assets/fonts/Hypography-Regular.woff2 +0 -0
  6. package/assets/fonts/PPFraktionMono-Variable.ttf +0 -0
  7. package/assets/fonts/PPFraktionMonoItalic-Variable.ttf +0 -0
  8. package/assets/fonts/PPFraktionSans-Variable.ttf +0 -0
  9. package/assets/fonts/PPFraktionSansItalic-Variable.ttf +0 -0
  10. package/bin/gem-elm.js +3 -0
  11. package/dist/browser/boot.d.ts +10 -0
  12. package/dist/browser/boot.js +14 -0
  13. package/dist/browser/color-scheme.d.ts +9 -0
  14. package/dist/browser/color-scheme.js +76 -0
  15. package/dist/browser/ports.d.ts +37 -0
  16. package/dist/browser/ports.js +90 -0
  17. package/dist/browser/router.d.ts +5 -0
  18. package/dist/browser/router.js +35 -0
  19. package/dist/browser/runtime.d.ts +12 -0
  20. package/dist/browser/runtime.js +22 -0
  21. package/dist/browser/tabs.d.ts +9 -0
  22. package/dist/browser/tabs.js +69 -0
  23. package/dist/default/theme.css +4664 -0
  24. package/dist/default/theme.js +13652 -0
  25. package/dist/node/build.d.ts +16 -0
  26. package/dist/node/build.js +48 -0
  27. package/dist/node/cli.d.ts +2 -0
  28. package/dist/node/cli.js +21 -0
  29. package/elm.json +28 -0
  30. package/package.json +86 -4
  31. package/src/app/Gem/App.elm +1275 -0
  32. package/src/app/Gem/CharmSticker.elm +35 -0
  33. package/src/app/Gem/Components.elm +292 -0
  34. package/src/app/Gem/Main.elm +17 -0
  35. package/src/app/Gem/Ports.elm +32 -0
  36. package/src/app/Gem/Shell.elm +964 -0
  37. package/src/browser/theme.d.ts +1 -0
  38. package/src/core/Gem/Node.elm +219 -0
  39. package/src/core/Gem/Page.elm +409 -0
  40. package/src/core/Gem/Render.elm +472 -0
  41. package/src/core/Gem/Slots.elm +11 -0
  42. package/src/styles/docs.scss +1083 -0
  43. package/src/styles/fonts.scss +51 -0
  44. package/src/styles/gem.scss +362 -0
  45. package/src/styles/theme.scss +8 -0
  46. package/src/styles/ui/burger.scss +272 -0
  47. package/src/styles/ui/button.scss +350 -0
  48. package/src/styles/ui/charmtone.scss +70 -0
  49. package/src/styles/ui/controls-extra.scss +316 -0
  50. package/src/styles/ui/controls.scss +110 -0
  51. package/src/styles/ui/display.scss +359 -0
  52. package/src/styles/ui/dropdown.scss +341 -0
  53. package/src/styles/ui/form.scss +314 -0
  54. package/src/styles/ui/menu.scss +200 -0
  55. package/src/styles/ui/meter.scss +124 -0
  56. package/src/styles/ui/modal.scss +545 -0
  57. package/src/styles/ui/oauth.scss +50 -0
  58. package/src/styles/ui/page-nav.scss +63 -0
  59. package/src/styles/ui/reset.scss +111 -0
  60. package/src/styles/ui/scrollbar.scss +39 -0
  61. package/src/styles/ui/search.scss +164 -0
  62. package/src/styles/ui/sidebar.scss +229 -0
  63. package/src/styles/ui/squircle.scss +60 -0
  64. package/src/styles/ui/table.scss +97 -0
  65. package/src/styles/ui/theme.scss +132 -0
  66. package/src/styles/ui/toast.scss +587 -0
  67. package/src/styles/ui/toc.scss +128 -0
  68. package/src/styles/ui/typography.scss +21 -0
  69. package/src/styles/ui/ui.scss +33 -0
  70. package/src/ui/Ui/Badge.elm +51 -0
  71. package/src/ui/Ui/Banner.elm +97 -0
  72. package/src/ui/Ui/Burger.elm +259 -0
  73. package/src/ui/Ui/Button.elm +261 -0
  74. package/src/ui/Ui/Card.elm +32 -0
  75. package/src/ui/Ui/Cards.elm +15 -0
  76. package/src/ui/Ui/ChoiceGroup.elm +62 -0
  77. package/src/ui/Ui/CopyButton.elm +139 -0
  78. package/src/ui/Ui/Divider.elm +16 -0
  79. package/src/ui/Ui/Dropdown.elm +600 -0
  80. package/src/ui/Ui/Empty.elm +41 -0
  81. package/src/ui/Ui/ErrorBubble.elm +34 -0
  82. package/src/ui/Ui/Field.elm +45 -0
  83. package/src/ui/Ui/FormStatus.elm +32 -0
  84. package/src/ui/Ui/Icon.elm +381 -0
  85. package/src/ui/Ui/InlineForm.elm +51 -0
  86. package/src/ui/Ui/Input.elm +113 -0
  87. package/src/ui/Ui/KeyValue.elm +25 -0
  88. package/src/ui/Ui/ListRow.elm +67 -0
  89. package/src/ui/Ui/Loader.elm +32 -0
  90. package/src/ui/Ui/Logo/Charm.elm +21 -0
  91. package/src/ui/Ui/Logo/CharmMark.elm +32 -0
  92. package/src/ui/Ui/Logo/CharmSticker.elm +35 -0
  93. package/src/ui/Ui/Logo/Discord.elm +26 -0
  94. package/src/ui/Ui/Logo/GitHub.elm +21 -0
  95. package/src/ui/Ui/Logo/Google.elm +21 -0
  96. package/src/ui/Ui/Logo/Hexy.elm +29 -0
  97. package/src/ui/Ui/Logo/Hyper.elm +42 -0
  98. package/src/ui/Ui/Logo/Integration.elm +117 -0
  99. package/src/ui/Ui/Logo/Prism.elm +35 -0
  100. package/src/ui/Ui/Logos.elm +115 -0
  101. package/src/ui/Ui/Menu.elm +348 -0
  102. package/src/ui/Ui/Meter.elm +132 -0
  103. package/src/ui/Ui/Modal.elm +247 -0
  104. package/src/ui/Ui/Motion.elm +32 -0
  105. package/src/ui/Ui/NumberBox.elm +86 -0
  106. package/src/ui/Ui/OAuthButton.elm +39 -0
  107. package/src/ui/Ui/PageNav.elm +65 -0
  108. package/src/ui/Ui/Pager.elm +49 -0
  109. package/src/ui/Ui/Search.elm +396 -0
  110. package/src/ui/Ui/SearchBox.elm +78 -0
  111. package/src/ui/Ui/Section.elm +21 -0
  112. package/src/ui/Ui/Sidebar.elm +239 -0
  113. package/src/ui/Ui/Stat.elm +29 -0
  114. package/src/ui/Ui/Switch.elm +34 -0
  115. package/src/ui/Ui/Table.elm +89 -0
  116. package/src/ui/Ui/Tabs.elm +280 -0
  117. package/src/ui/Ui/ToC.elm +120 -0
  118. package/src/ui/Ui/Toast.elm +1145 -0
  119. package/src/ui/Ui/Toolbar.elm +31 -0
  120. package/src/ui/Ui/TwoStepConfirm.elm +159 -0
  121. package/src/ui/Ui/Typography.elm +33 -0
@@ -0,0 +1,600 @@
1
+ module Ui.Dropdown exposing
2
+ ( Action
3
+ , Choice
4
+ , Config
5
+ , Option
6
+ , Search
7
+ , choiceValue
8
+ , measure
9
+ , option
10
+ , subscriptions
11
+ , typed
12
+ , view
13
+ , withAction
14
+ , withAttributes
15
+ , withCompact
16
+ , withFlip
17
+ , withId
18
+ , withOnSelect
19
+ , withOnToggle
20
+ , withOpen
21
+ , withOptions
22
+ , withSearch
23
+ , withSelected
24
+ , withTrigger
25
+ )
26
+
27
+ {-| A generic dropdown widget. Pass a list of options (label + value),
28
+ the currently selected value, whether the menu is open, and message
29
+ constructors for toggling, selecting, and flipping.
30
+
31
+ Call `measure id` from your update when the dropdown opens to detect
32
+ whether the menu should flip above the activator.
33
+
34
+ Call `subscriptions id open onDismiss` from the parent so a press
35
+ outside the widget closes it. (`subscriptions` also serves any other
36
+ open overlay whose root carries the given id.)
37
+
38
+ Pass `Just search` to show a filter field above the options (useful
39
+ when the list is long). Filtering is case-insensitive on labels and
40
+ optional detail lines.
41
+
42
+ Pass `Just action` to pin a footer control to the bottom of the menu
43
+ (e.g. "Create team" in the sidebar picker).
44
+
45
+ Set `compact = True` for the dense height used next to table actions
46
+ and pagers. Default (`False`) matches toolbar buttons and one-line
47
+ inputs.
48
+
49
+ For typed selections see `typed` — it wraps this widget so hosts stop
50
+ translating strings at the boundary.
51
+
52
+ -}
53
+
54
+ import Browser.Dom
55
+ import Browser.Events
56
+ import Html exposing (Attribute, Html, button, div, input, span, text)
57
+ import Html.Attributes as Attr exposing (attribute, class, classList, placeholder, type_, value)
58
+ import Html.Events exposing (onClick, onInput)
59
+ import Json.Decode as Decode exposing (Decoder)
60
+ import Ui.Icon
61
+ import Task
62
+
63
+
64
+ type alias Option =
65
+ { label : String
66
+ , value : String
67
+ , detail : Maybe String
68
+ }
69
+
70
+
71
+ {-| An option with no secondary line. Use this for simple lists
72
+ (date ranges, roles); set `detail` on the record for a subtitle.
73
+ -}
74
+ option : String -> String -> Option
75
+ option label value =
76
+ { label = label, value = value, detail = Nothing }
77
+
78
+
79
+ {-| Config for the optional search field rendered at the top of the
80
+ open menu. The parent owns the query string.
81
+ -}
82
+ type alias Search msg =
83
+ { query : String
84
+ , placeholder : String
85
+ , onInput : String -> msg
86
+ , onClear : msg
87
+ }
88
+
89
+
90
+ {-| A footer control pinned to the bottom of the open menu.
91
+ -}
92
+ type alias Action msg =
93
+ { label : String
94
+ , onClick : msg
95
+ }
96
+
97
+
98
+ {-| Dismisses the open menu when the pointer is pressed outside the
99
+ dropdown. Pass the same `id` given to `view`. Also works for any
100
+ other open overlay that has that id on its root node.
101
+ -}
102
+ subscriptions : String -> Bool -> msg -> Sub msg
103
+ subscriptions dropdownId open onDismiss =
104
+ if open then
105
+ Browser.Events.onMouseDown (outsideDecoder dropdownId onDismiss)
106
+
107
+ else
108
+ Sub.none
109
+
110
+
111
+ {-| Succeeds with `onDismiss` when the event target is not inside the
112
+ element with `dropdownId`.
113
+ -}
114
+ outsideDecoder : String -> msg -> Decoder msg
115
+ outsideDecoder dropdownId onDismiss =
116
+ Decode.field "target" (isOutside dropdownId)
117
+ |> Decode.andThen
118
+ (\outside ->
119
+ if outside then
120
+ Decode.succeed onDismiss
121
+
122
+ else
123
+ Decode.fail "inside dropdown"
124
+ )
125
+
126
+
127
+ {-| Walks up from the event target. `False` once we hit `dropdownId`,
128
+ `True` if we run out of ancestors.
129
+ -}
130
+ isOutside : String -> Decoder Bool
131
+ isOutside dropdownId =
132
+ Decode.oneOf
133
+ [ Decode.field "id" Decode.string
134
+ |> Decode.andThen
135
+ (\id ->
136
+ if id == dropdownId then
137
+ Decode.succeed False
138
+
139
+ else
140
+ Decode.fail "not this node"
141
+ )
142
+ , Decode.lazy (\_ -> Decode.field "parentNode" (isOutside dropdownId))
143
+ , Decode.succeed True
144
+ ]
145
+
146
+
147
+ {-| Measures the dropdown button and viewport to determine if the
148
+ menu should flip above the activator. Pass a message constructor to
149
+ wrap the resulting Bool.
150
+ -}
151
+ measure : (Bool -> msg) -> String -> Cmd msg
152
+ measure toMsg dropdownId =
153
+ let
154
+ buttonId =
155
+ dropdownId ++ "-button"
156
+
157
+ menuId =
158
+ dropdownId ++ "-menu"
159
+ in
160
+ Task.attempt
161
+ (\result ->
162
+ case result of
163
+ Ok ( button, menu, viewport ) ->
164
+ let
165
+ menuHeight : Float
166
+ menuHeight =
167
+ menu.element.height
168
+
169
+ spaceBelow : Float
170
+ spaceBelow =
171
+ viewport.viewport.height
172
+ - button.element.y
173
+ - button.element.height
174
+
175
+ shouldFlip : Bool
176
+ shouldFlip =
177
+ spaceBelow < menuHeight && button.element.y > menuHeight
178
+ in
179
+ toMsg shouldFlip
180
+
181
+ Err _ ->
182
+ toMsg False
183
+ )
184
+ (Task.map3
185
+ (\button menu viewport -> ( button, menu, viewport ))
186
+ (Browser.Dom.getElement buttonId)
187
+ (Browser.Dom.getElement menuId)
188
+ Browser.Dom.getViewport
189
+ )
190
+
191
+
192
+ {-| Dropdown configuration. `open` and `flip` live in the parent's
193
+ model; see the module docs for the `measure`/`subscriptions` dance
194
+ that keeps them truthful.
195
+ -}
196
+ type alias Config msg =
197
+ { options : List Option
198
+ , selected : String
199
+ , trigger : String
200
+ , open : Bool
201
+ , flip : Bool
202
+ , id : String
203
+ , onToggle : msg
204
+ , onSelect : String -> msg
205
+ , search : Maybe (Search msg)
206
+ , action : Maybe (Action msg)
207
+ , compact : Bool
208
+ , triggerIcon : Maybe (Html Never)
209
+ , attributes : List (Attribute msg)
210
+ }
211
+
212
+
213
+ {-| Set the option list.
214
+ -}
215
+ withOptions : List Option -> Config msg -> Config msg
216
+ withOptions options config =
217
+ { config | options = options }
218
+
219
+
220
+ {-| Set the selected value.
221
+ -}
222
+ withSelected : String -> Config msg -> Config msg
223
+ withSelected selected config =
224
+ { config | selected = selected }
225
+
226
+
227
+ {-| Set the trigger's label. Used when nothing is selected — a menu that acts
228
+ rather than picks (an "Open in …" handoff) names itself here.
229
+ -}
230
+ withTrigger : String -> Config msg -> Config msg
231
+ withTrigger trigger config =
232
+ { config | trigger = trigger }
233
+
234
+
235
+ {-| Set whether the menu is open (parent-owned state).
236
+ -}
237
+ withOpen : Bool -> Config msg -> Config msg
238
+ withOpen open config =
239
+ { config | open = open }
240
+
241
+
242
+ {-| Set the flip flag (see `measure`).
243
+ -}
244
+ withFlip : Bool -> Config msg -> Config msg
245
+ withFlip flip config =
246
+ { config | flip = flip }
247
+
248
+
249
+ {-| Set the widget id — the anchor `measure`/`subscriptions` key on.
250
+ -}
251
+ withId : String -> Config msg -> Config msg
252
+ withId id config =
253
+ { config | id = id }
254
+
255
+
256
+ {-| Set the toggle message (open/close requests).
257
+ -}
258
+ withOnToggle : msg -> Config msg -> Config msg
259
+ withOnToggle onToggle config =
260
+ { config | onToggle = onToggle }
261
+
262
+
263
+ {-| Set the selection message.
264
+ -}
265
+ withOnSelect : (String -> msg) -> Config msg -> Config msg
266
+ withOnSelect onSelect config =
267
+ { config | onSelect = onSelect }
268
+
269
+
270
+ {-| Add a search field above the options.
271
+ -}
272
+ withSearch : Search msg -> Config msg -> Config msg
273
+ withSearch search config =
274
+ { config | search = Just search }
275
+
276
+
277
+ {-| Pin a footer action control to the bottom of the menu.
278
+ -}
279
+ withAction : Action msg -> Config msg -> Config msg
280
+ withAction action config =
281
+ { config | action = Just action }
282
+
283
+
284
+ {-| Use the dense height (table actions, pagers).
285
+ -}
286
+ withCompact : Bool -> Config msg -> Config msg
287
+ withCompact compact config =
288
+ { config | compact = compact }
289
+
290
+
291
+ {-| Add extra attributes (ids, test selectors, additional handlers).
292
+ -}
293
+ withAttributes : List (Attribute msg) -> Config msg -> Config msg
294
+ withAttributes attributes config =
295
+ { config | attributes = config.attributes ++ attributes }
296
+
297
+
298
+ {-| Render the dropdown.
299
+ -}
300
+ view : Config msg -> Html msg
301
+ view config =
302
+ let
303
+ selectedOption =
304
+ config.options
305
+ |> List.filter (\o -> o.value == config.selected)
306
+ |> List.head
307
+
308
+ selectedLabel =
309
+ selectedOption
310
+ |> Maybe.map .label
311
+ |> Maybe.withDefault
312
+ (if String.isEmpty config.trigger then
313
+ "Select…"
314
+
315
+ else
316
+ config.trigger
317
+ )
318
+
319
+ selectedDetail =
320
+ selectedOption
321
+ |> Maybe.andThen .detail
322
+
323
+ query =
324
+ config.search
325
+ |> Maybe.map .query
326
+ |> Maybe.withDefault ""
327
+
328
+ filtered =
329
+ if String.isEmpty (String.trim query) then
330
+ config.options
331
+
332
+ else
333
+ let
334
+ needle =
335
+ String.toLower (String.trim query)
336
+ in
337
+ List.filter (matchesQuery needle) config.options
338
+
339
+ hasAction =
340
+ case config.action of
341
+ Just _ ->
342
+ True
343
+
344
+ Nothing ->
345
+ False
346
+ in
347
+ div
348
+ ([ Attr.id config.id
349
+ , classList
350
+ [ ( "dropdown", True )
351
+ , ( "open", config.open )
352
+ , ( "flip", config.flip )
353
+ , ( "compact", config.compact )
354
+ ]
355
+ ]
356
+ ++ config.attributes
357
+ )
358
+ [ button
359
+ [ Attr.id (config.id ++ "-button")
360
+ , onClick config.onToggle
361
+ , attribute "aria-haspopup" "true"
362
+ , attribute "aria-label" selectedLabel
363
+ , attribute "aria-expanded"
364
+ (if config.open then
365
+ "true"
366
+
367
+ else
368
+ "false"
369
+ )
370
+ ]
371
+ (case config.triggerIcon of
372
+ Just icon ->
373
+ [ span [ class "trigger-icon" ] [ Html.map never icon ] ]
374
+
375
+ Nothing ->
376
+ [ span [ class "copy" ] (labelNodes selectedLabel selectedDetail)
377
+ , Ui.Icon.view Ui.Icon.Chevron
378
+ ]
379
+ )
380
+ , div
381
+ [ class "menu"
382
+ , Attr.id (config.id ++ "-menu")
383
+ ]
384
+ (searchNodes config.search
385
+ ++ optionNodes filtered config.onSelect query hasAction config.selected
386
+ ++ actionNodes config.action
387
+ )
388
+ ]
389
+
390
+
391
+ {-| True when the query matches the option label or detail.
392
+ -}
393
+ matchesQuery : String -> Option -> Bool
394
+ matchesQuery needle o =
395
+ String.contains needle (String.toLower o.label)
396
+ || String.contains needle (String.toLower (Maybe.withDefault "" o.detail))
397
+
398
+
399
+ {-| Renders the optional search field at the top of the open menu.
400
+ -}
401
+ searchNodes : Maybe (Search msg) -> List (Html msg)
402
+ searchNodes maybeSearch =
403
+ case maybeSearch of
404
+ Nothing ->
405
+ []
406
+
407
+ Just cfg ->
408
+ let
409
+ hasText =
410
+ not (String.isEmpty cfg.query)
411
+ in
412
+ [ div [ class "search" ]
413
+ [ input
414
+ [ type_ "search"
415
+ , class "query"
416
+ , placeholder cfg.placeholder
417
+ , value cfg.query
418
+ , onInput cfg.onInput
419
+ ]
420
+ []
421
+ , button
422
+ [ classList [ ( "clear", True ), ( "visible", hasText ) ]
423
+ , type_ "button"
424
+ , onClick cfg.onClear
425
+ , attribute "aria-label" "Clear search"
426
+ , attribute "tabindex"
427
+ (if hasText then
428
+ "0"
429
+
430
+ else
431
+ "-1"
432
+ )
433
+ ]
434
+ [ Ui.Icon.view Ui.Icon.Clear ]
435
+ ]
436
+ ]
437
+
438
+
439
+ optionNodes : List Option -> (String -> msg) -> String -> Bool -> String -> List (Html msg)
440
+ optionNodes options onSelect query hasAction selectedValue =
441
+ if List.isEmpty options then
442
+ if hasAction && String.isEmpty (String.trim query) then
443
+ []
444
+
445
+ else
446
+ [ div [ class "empty" ] [ text "No matches" ] ]
447
+
448
+ else
449
+ List.map
450
+ (\opt ->
451
+ button
452
+ [ classList
453
+ [ ( "option", True )
454
+ , ( "current", opt.value == selectedValue )
455
+ ]
456
+ , type_ "button"
457
+ , attribute "aria-current"
458
+ (if opt.value == selectedValue then
459
+ "true"
460
+
461
+ else
462
+ "false"
463
+ )
464
+ , onClick (onSelect opt.value)
465
+ ]
466
+ (labelNodes opt.label opt.detail)
467
+ )
468
+ options
469
+
470
+
471
+ {-| Renders the optional footer action at the bottom of the menu.
472
+ -}
473
+ actionNodes : Maybe (Action msg) -> List (Html msg)
474
+ actionNodes maybeAction =
475
+ case maybeAction of
476
+ Nothing ->
477
+ []
478
+
479
+ Just cfg ->
480
+ [ button
481
+ [ class "action"
482
+ , type_ "button"
483
+ , onClick cfg.onClick
484
+ ]
485
+ [ span [ class "plus", attribute "aria-hidden" "true" ] [ text "+" ]
486
+ , text cfg.label
487
+ ]
488
+ ]
489
+
490
+
491
+ {-| Label plus an optional detail line, used by both the activator
492
+ and each menu option.
493
+ -}
494
+ labelNodes : String -> Maybe String -> List (Html msg)
495
+ labelNodes label maybeDetail =
496
+ span [ class "label" ] [ text label ]
497
+ :: (case maybeDetail of
498
+ Just detail ->
499
+ [ span [ class "detail" ] [ text detail ] ]
500
+
501
+ Nothing ->
502
+ []
503
+ )
504
+
505
+
506
+
507
+ -- Typed wrapper
508
+
509
+
510
+ {-| One entry in a typed dropdown: the label shown, the string the
511
+ widget talks in, and the typed value it selects. The widget speaks
512
+ strings; this translates at that boundary so hosts never parse.
513
+ -}
514
+ type alias Choice a =
515
+ { label : String
516
+ , value : String
517
+ , item : a
518
+ }
519
+
520
+
521
+ {-| The typed dropdown's configuration: the same shape as `view`'s,
522
+ but options and selection are typed and `onSelect` hands back the
523
+ chosen item. The `fallback` is returned only if the incoming selected
524
+ string matches no choice — unreachable when the string round-trips
525
+ from `choiceValue`, but Elm demands a total function.
526
+ -}
527
+ typed :
528
+ { choices : List (Choice a)
529
+ , selected : a
530
+ , fallback : a
531
+ , trigger : String
532
+ , open : Bool
533
+ , flip : Bool
534
+ , id : String
535
+ , onToggle : msg
536
+ , onSelect : a -> msg
537
+ , search : Maybe (Search msg)
538
+ , action : Maybe (Action msg)
539
+ , compact : Bool
540
+ , triggerIcon : Maybe (Html Never)
541
+ , attributes : List (Attribute msg)
542
+ }
543
+ -> Html msg
544
+ typed config =
545
+ let
546
+ optionOf choice =
547
+ { label = choice.label
548
+ , value = choice.value
549
+ , detail = Nothing
550
+ }
551
+
552
+ selectedValue =
553
+ choiceValue config.choices config.selected
554
+
555
+ onSelect value =
556
+ onSelectHelp config.choices config.fallback value config.onSelect
557
+ in
558
+ view
559
+ { options = List.map optionOf config.choices
560
+ , selected = selectedValue
561
+ , trigger = config.trigger
562
+ , open = config.open
563
+ , flip = config.flip
564
+ , id = config.id
565
+ , onToggle = config.onToggle
566
+ , onSelect = onSelect
567
+ , search = config.search
568
+ , action = config.action
569
+ , compact = config.compact
570
+ , triggerIcon = config.triggerIcon
571
+ , attributes = config.attributes
572
+ }
573
+
574
+
575
+ {-| The string value of a typed choice; "" when the item is absent.
576
+ -}
577
+ choiceValue : List (Choice a) -> a -> String
578
+ choiceValue choices item =
579
+ choices
580
+ |> List.filter (\c -> c.item == item)
581
+ |> List.map .value
582
+ |> List.head
583
+ |> Maybe.withDefault ""
584
+
585
+
586
+ {-| Unreachable fallback: every value comes from our own choice list.
587
+ -}
588
+ onSelectHelp :
589
+ List (Choice a)
590
+ -> a
591
+ -> String
592
+ -> (a -> msg)
593
+ -> msg
594
+ onSelectHelp choices fallback value onSelect =
595
+ choices
596
+ |> List.filter (\c -> c.value == value)
597
+ |> List.map .item
598
+ |> List.head
599
+ |> Maybe.withDefault fallback
600
+ |> onSelect
@@ -0,0 +1,41 @@
1
+ module Ui.Empty exposing (card, text)
2
+
3
+ {-| Empty and placeholder states. The plain `text` variant covers
4
+ loading, failed, disabled, and no-match messages (the same `p.empty`
5
+ every page leans on); the `card` variant is the call-to-action shown
6
+ when a list has nothing yet.
7
+ -}
8
+
9
+ import Html exposing (Html, button, div, h3, p, text)
10
+ import Html.Attributes
11
+ import Html.Events
12
+
13
+
14
+ {-| A plain quiet line: "Loading…", "No matching results."
15
+ -}
16
+ text : String -> Html msg
17
+ text message =
18
+ p [ Html.Attributes.class "empty" ] [ Html.text message ]
19
+
20
+
21
+ {-| The empty-list CTA: heading, one line of guidance, and a primary
22
+ button to start.
23
+ -}
24
+ card :
25
+ { title : String
26
+ , body : String
27
+ , ctaLabel : String
28
+ , onCta : msg
29
+ }
30
+ -> Html msg
31
+ card config =
32
+ div [ Html.Attributes.class "empty-card" ]
33
+ [ h3 [] [ text config.title ]
34
+ , p [] [ text config.body ]
35
+ , button
36
+ [ Html.Attributes.class "primary"
37
+ , Html.Attributes.type_ "button"
38
+ , Html.Events.onClick config.onCta
39
+ ]
40
+ [ text config.ctaLabel ]
41
+ ]
@@ -0,0 +1,34 @@
1
+ module Ui.ErrorBubble exposing (view)
2
+
3
+ {-| The dismissible error balloon from the auth screens: a cherry
4
+ bubble with a tail pointing at the field that failed. Click anywhere
5
+ on it to dismiss. Render it near the form top; the tail is part of the
6
+ glyph.
7
+ -}
8
+
9
+ import Html exposing (Html, div, text)
10
+ import Html.Attributes
11
+ import Html.Events
12
+ import Ui.Icon
13
+
14
+
15
+ {-| Render the bubble. `visible` drives the fade; keep it mounted
16
+ either way so the transition can play.
17
+ -}
18
+ view :
19
+ { message : String
20
+ , visible : Bool
21
+ , onDismiss : msg
22
+ }
23
+ -> Html msg
24
+ view config =
25
+ div
26
+ [ Html.Attributes.classList
27
+ [ ( "error-bubble", True )
28
+ , ( "visible", config.visible )
29
+ ]
30
+ , Html.Events.onClick config.onDismiss
31
+ ]
32
+ [ text config.message
33
+ , Ui.Icon.view Ui.Icon.ErrorTail
34
+ ]
@@ -0,0 +1,45 @@
1
+ module Ui.Field exposing (view)
2
+
3
+ {-| The stacked form field: a label, the control, and optional hint and
4
+ error copy. The settings-style stacked layout; the toolbar-style
5
+ create row is `Ui.InlineForm`.
6
+ -}
7
+
8
+ import Html exposing (Attribute, Html, div, label, text)
9
+ import Html.Attributes
10
+
11
+
12
+ {-| Render one field. `control` is any Ui control (`Ui.Input`,
13
+ `Ui.NumberBox`, a Dropdown); `hint` shows only when the field is
14
+ valid, `error` replaces it when present.
15
+ -}
16
+ view :
17
+ { label : String
18
+ , control : Html msg
19
+ , hint : Maybe String
20
+ , error : Maybe String
21
+ , attributes : List (Attribute msg)
22
+ }
23
+ -> Html msg
24
+ view config =
25
+ div ([ Html.Attributes.class "field" ] ++ config.attributes)
26
+ [ label []
27
+ [ text config.label
28
+ , config.control
29
+ ]
30
+ , case config.error of
31
+ Just error ->
32
+ Html.p
33
+ [ Html.Attributes.class "error"
34
+ , Html.Attributes.attribute "role" "alert"
35
+ ]
36
+ [ Html.text error ]
37
+
38
+ Nothing ->
39
+ case config.hint of
40
+ Just hint ->
41
+ Html.p [ Html.Attributes.class "hint" ] [ Html.text hint ]
42
+
43
+ Nothing ->
44
+ Html.text ""
45
+ ]