@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.
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 +13815 -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 +1268 -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 +957 -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 +560 -0
  40. package/src/core/Gem/Render.elm +510 -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,348 @@
1
+ module Ui.Menu exposing
2
+ ( Config
3
+ , Item
4
+ , ItemGroup(..)
5
+ , Model
6
+ , Msg(..)
7
+ , Placement(..)
8
+ , init
9
+ , subscriptions
10
+ , update
11
+ , view
12
+ , withAttributes
13
+ , withHead
14
+ , withPlacement
15
+ , withSections
16
+ , withTrigger
17
+ )
18
+
19
+ {-| The popover menu: a ghost trigger that opens a floating panel of
20
+ grouped items — the account control from the dashboard's rail. Unlike
21
+ the Dropdown (a select-shaped field), the Menu's trigger is a quiet
22
+ ghost button and the panel opens above it by default, phone-style.
23
+
24
+ The panel carries a head (identity block), grouped items with
25
+ dividers, and optional footer items pinned to the bottom. Outside
26
+ press closes it.
27
+
28
+ type Msg
29
+ = MenuMsg Ui.Menu.Msg
30
+
31
+ model =
32
+ { menu = Ui.Menu.init "account-menu" }
33
+
34
+ Ui.Menu.view
35
+ { trigger = { name = "sam", detail = Just "account@charm.land" }
36
+ , head = Just { name = "sam", detail = "account@charm.land" }
37
+ , sections =
38
+ [ Ui.Menu.Items
39
+ [ { label = "Settings", icon = Nothing, onSelect = Settings }
40
+ , { label = "Sign out", icon = Nothing, onSelect = SignOut }
41
+ ]
42
+ ]
43
+ , placement = Ui.Menu.Above
44
+ , attributes = []
45
+ }
46
+ model.menu
47
+
48
+ -}
49
+
50
+ import Browser.Events
51
+ import Html exposing (Attribute, Html, button, div, span, text, ul)
52
+ import Html.Attributes as Attr
53
+ import Html.Events
54
+ import Json.Decode as Decode
55
+ import Ui.Icon
56
+
57
+
58
+
59
+ -- MODEL
60
+
61
+
62
+ {-| Whether the menu panel is open.
63
+ -}
64
+ type alias Model =
65
+ { id : String
66
+ , open : Bool
67
+ }
68
+
69
+
70
+ {-| Create the model. The id must be unique per page instance — the
71
+ outside-press listener targets it.
72
+ -}
73
+ init : String -> Model
74
+ init id =
75
+ { id = id
76
+ , open = False
77
+ }
78
+
79
+
80
+
81
+ -- MSG
82
+
83
+
84
+ {-| Internal messages; the host maps them wholesale. `Select` carries
85
+ the item's message — the host acts there.
86
+ -}
87
+ type Msg
88
+ = Toggled
89
+ | Closed
90
+ | Selected
91
+
92
+
93
+
94
+ -- UPDATE
95
+
96
+
97
+ update : Msg -> Model -> ( Model, Cmd Msg )
98
+ update msg model =
99
+ case msg of
100
+ Toggled ->
101
+ ( { model | open = not model.open }, Cmd.none )
102
+
103
+ Closed ->
104
+ ( { model | open = False }, Cmd.none )
105
+
106
+ Selected ->
107
+ ( { model | open = False }, Cmd.none )
108
+
109
+
110
+
111
+ -- SUBSCRIPTIONS
112
+
113
+
114
+ {-| Dismiss the open menu on any pointer press outside it.
115
+ -}
116
+ subscriptions : Model -> Sub Msg
117
+ subscriptions model =
118
+ if model.open then
119
+ Browser.Events.onMouseDown (outsideDecoder model.id Closed)
120
+
121
+ else
122
+ Sub.none
123
+
124
+
125
+ outsideDecoder : String -> Msg -> Decode.Decoder Msg
126
+ outsideDecoder id onDismiss =
127
+ Decode.field "target" (isOutside id)
128
+ |> Decode.andThen
129
+ (\outside ->
130
+ if outside then
131
+ Decode.succeed onDismiss
132
+
133
+ else
134
+ Decode.fail "inside menu"
135
+ )
136
+
137
+
138
+ isOutside : String -> Decode.Decoder Bool
139
+ isOutside id =
140
+ Decode.oneOf
141
+ [ Decode.field "id" Decode.string
142
+ |> Decode.andThen
143
+ (\found ->
144
+ if found == id then
145
+ Decode.succeed False
146
+
147
+ else
148
+ Decode.fail "not this node"
149
+ )
150
+ , Decode.lazy (\_ -> Decode.field "parentNode" (isOutside id))
151
+ , Decode.succeed True
152
+ ]
153
+
154
+
155
+
156
+ -- CONFIG
157
+
158
+
159
+ {-| Where the panel opens relative to the trigger.
160
+ -}
161
+ type Placement
162
+ = Above
163
+ | Below
164
+
165
+
166
+ {-| One menu item: a label and the message it sends when clicked.
167
+ -}
168
+ type alias Item msg =
169
+ { label : String
170
+ , icon : Maybe (Html msg)
171
+ , onSelect : msg
172
+ }
173
+
174
+
175
+ {-| A group of items, rendered with a divider between groups.
176
+ -}
177
+ type ItemGroup msg
178
+ = Items (List (Item msg))
179
+ | Divider
180
+
181
+
182
+ {-| The trigger's identity block: a primary label and an optional
183
+ muted detail line.
184
+ -}
185
+ type alias Trigger =
186
+ { label : String
187
+ , detail : Maybe String
188
+ }
189
+
190
+
191
+ {-| The panel's head: an identity block shown above the items.
192
+ -}
193
+ type alias Head =
194
+ { name : String
195
+ , detail : String
196
+ }
197
+
198
+
199
+ {-| Menu configuration.
200
+ -}
201
+ type alias Config msg =
202
+ { trigger : Trigger
203
+ , head : Maybe Head
204
+ , sections : List (ItemGroup msg)
205
+ , placement : Placement
206
+ , toMsg : Msg -> msg
207
+ , attributes : List (Attribute msg)
208
+ }
209
+
210
+
211
+ {-| Set the trigger (the ghost button's copy).
212
+ -}
213
+ withTrigger : Trigger -> Config msg -> Config msg
214
+ withTrigger trigger config =
215
+ { config | trigger = trigger }
216
+
217
+
218
+ {-| Set the identity block shown at the top of the panel.
219
+ -}
220
+ withHead : Head -> Config msg -> Config msg
221
+ withHead head config =
222
+ { config | head = Just head }
223
+
224
+
225
+ {-| Set the grouped items.
226
+ -}
227
+ withSections : List (ItemGroup msg) -> Config msg -> Config msg
228
+ withSections sections config =
229
+ { config | sections = sections }
230
+
231
+
232
+ {-| Open the panel above (default) or below the trigger.
233
+ -}
234
+ withPlacement : Placement -> Config msg -> Config msg
235
+ withPlacement placement config =
236
+ { config | placement = placement }
237
+
238
+
239
+ {-| Add extra attributes (ids, test selectors, additional handlers).
240
+ -}
241
+ withAttributes : List (Attribute msg) -> Config msg -> Config msg
242
+ withAttributes attributes config =
243
+ { config | attributes = config.attributes ++ attributes }
244
+
245
+
246
+
247
+ -- VIEW
248
+
249
+
250
+ {-| Render the menu: a ghost trigger button and, when open, the
251
+ floating panel.
252
+ -}
253
+ view : Config msg -> Model -> Html msg
254
+ view config model =
255
+ let
256
+ placementClass =
257
+ case config.placement of
258
+ Above ->
259
+ ( "menu-above", True )
260
+
261
+ Below ->
262
+ ( "menu-below", True )
263
+ in
264
+ div
265
+ ([ Attr.id model.id
266
+ , Attr.classList
267
+ [ ( "menu", True )
268
+ , ( "open", model.open )
269
+ , placementClass
270
+ ]
271
+ ]
272
+ ++ config.attributes
273
+ )
274
+ [ button
275
+ [ Attr.type_ "button"
276
+ , Attr.class "menu-trigger"
277
+ , Attr.attribute "aria-haspopup" "menu"
278
+ , Attr.attribute "aria-expanded"
279
+ (if model.open then
280
+ "true"
281
+
282
+ else
283
+ "false"
284
+ )
285
+ , Html.Events.onClick (config.toMsg Toggled)
286
+ ]
287
+ [ span [ Attr.class "label" ]
288
+ [ span [ Attr.class "name" ] [ text config.trigger.label ]
289
+ , case config.trigger.detail of
290
+ Just detail ->
291
+ span [ Attr.class "detail" ] [ text detail ]
292
+
293
+ Nothing ->
294
+ Html.text ""
295
+ ]
296
+ , span [ Attr.class "chevron" ]
297
+ [ Ui.Icon.view Ui.Icon.Chevron ]
298
+ ]
299
+ , if model.open then
300
+ div [ Attr.class "menu-panel", Attr.attribute "role" "menu" ]
301
+ ([ case config.head of
302
+ Just head ->
303
+ div [ Attr.class "menu-head" ]
304
+ [ div [ Attr.class "name" ] [ Html.text head.name ]
305
+ , div [ Attr.class "detail" ] [ Html.text head.detail ]
306
+ ]
307
+
308
+ Nothing ->
309
+ Html.text ""
310
+ ]
311
+ ++ List.map groupNode config.sections
312
+ )
313
+
314
+ else
315
+ Html.text ""
316
+ ]
317
+
318
+
319
+ groupNode : ItemGroup msg -> Html msg
320
+ groupNode group =
321
+ case group of
322
+ Items items ->
323
+ Html.ul []
324
+ (List.map
325
+ (\item ->
326
+ Html.li []
327
+ [ button
328
+ [ Attr.type_ "button"
329
+ , Attr.class "menu-item"
330
+ , Attr.attribute "role" "menuitem"
331
+ , Html.Events.onClick item.onSelect
332
+ ]
333
+ (case item.icon of
334
+ Just icon ->
335
+ [ span [ Attr.class "icon" ] [ icon ]
336
+ , span [ Attr.class "menu-label" ] [ Html.text item.label ]
337
+ ]
338
+
339
+ Nothing ->
340
+ [ span [ Attr.class "menu-label" ] [ Html.text item.label ] ]
341
+ )
342
+ ]
343
+ )
344
+ items
345
+ )
346
+
347
+ Divider ->
348
+ Html.li [ Attr.class "menu-divider" ] []
@@ -0,0 +1,132 @@
1
+ module Ui.Meter exposing (view)
2
+
3
+ {-| The credit meter: a rounded SVG progress bar with a charple-to-dolly
4
+ gradient, an accessible `role="meter"`, and an animated reveal clip.
5
+ The overview page's usage meters. Colors are fixed swatches (Elm
6
+ cannot read the SCSS theme tokens), chosen per theme via the classes
7
+ the stylesheet restyles on `data-theme="light"`.
8
+ -}
9
+
10
+ import Html exposing (Attribute, Html, div, p, text)
11
+ import Html.Attributes as Attr
12
+ import Svg exposing (clipPath, defs, g, linearGradient, rect, stop, svg)
13
+ import Svg.Attributes as SA
14
+
15
+
16
+ {-| Meter configuration. `value` of `Nothing` renders the "Unknown"
17
+ state: full track, no fill, "Unknown" in place of a percentage.
18
+ `returnText` is the caption under the bar ("" at 100% full).
19
+ -}
20
+ view :
21
+ { key : String
22
+ , label : String
23
+ , heading : String
24
+ , value : Maybe Float
25
+ , maximum : Float
26
+ , returnText : String
27
+ , attributes : List (Attribute msg)
28
+ }
29
+ -> Html msg
30
+ view config =
31
+ let
32
+ fraction =
33
+ if config.maximum > 0 then
34
+ clamp 0 1 (Maybe.withDefault 0 config.value / config.maximum)
35
+
36
+ else
37
+ 0
38
+
39
+ clipId =
40
+ "ui-meter-clip-" ++ config.key
41
+
42
+ gradientId =
43
+ "ui-meter-gradient-" ++ config.key
44
+
45
+ ariaValue value =
46
+ String.fromFloat (toFloat (round (value * 10)) / 10)
47
+
48
+ formatted value =
49
+ String.fromInt (round value)
50
+ in
51
+ div ([ Attr.class "credit-meter" ] ++ config.attributes)
52
+ [ p [ Attr.class "meter-heading" ]
53
+ [ text config.heading
54
+ , Html.span [ Attr.class "meter-max" ]
55
+ [ text (" " ++ formatted config.maximum) ]
56
+ ]
57
+ , svg
58
+ (case config.value of
59
+ Just value ->
60
+ [ Attr.attribute "role" "meter"
61
+ , Attr.attribute "aria-label" config.label
62
+ , Attr.attribute "aria-valuemin" "0"
63
+ , Attr.attribute "aria-valuemax" (ariaValue config.maximum)
64
+ , Attr.attribute "aria-valuenow" (ariaValue (clamp 0 config.maximum value))
65
+ ]
66
+
67
+ Nothing ->
68
+ [ Attr.attribute "role" "img"
69
+ , Attr.attribute "aria-label" (config.label ++ ": Unknown")
70
+ ]
71
+ )
72
+ [ defs []
73
+ [ clipPath [ SA.id clipId ]
74
+ [ rect
75
+ [ SA.class "reveal"
76
+ , SA.x "0.21875rem"
77
+ , SA.y "0.1875rem"
78
+ , SA.width
79
+ ("calc("
80
+ ++ String.fromFloat (100 * fraction)
81
+ ++ "% - "
82
+ ++ String.fromFloat (0.4375 * fraction)
83
+ ++ "rem)"
84
+ )
85
+ , SA.height "0.75rem"
86
+ ]
87
+ []
88
+ ]
89
+ , linearGradient
90
+ [ SA.id gradientId
91
+ , SA.gradientUnits "userSpaceOnUse"
92
+ , SA.x1 "0"
93
+ , SA.x2 "100%"
94
+ , SA.y1 "0"
95
+ , SA.y2 "0"
96
+ ]
97
+ [ stop [ SA.offset "0%", SA.class "hazy" ] []
98
+ , stop [ SA.offset "100%", SA.class "charple" ] []
99
+ ]
100
+ ]
101
+ , rect [ SA.class "track", SA.width "100%", SA.height "100%" ] []
102
+ , g [ SA.clipPath ("url(#" ++ clipId ++ ")") ]
103
+ [ rect
104
+ [ SA.class "gradient"
105
+ , SA.x "0.21875rem"
106
+ , SA.y "0.1875rem"
107
+ , SA.height "0.75rem"
108
+ , SA.fill ("url(#" ++ gradientId ++ ")")
109
+ ]
110
+ []
111
+ ]
112
+ ]
113
+ , Html.span [ Attr.class "percentage" ]
114
+ [ text
115
+ (case config.value of
116
+ Just _ ->
117
+ String.fromInt (round (fraction * 100)) ++ "%"
118
+
119
+ Nothing ->
120
+ "Unknown"
121
+ )
122
+ ]
123
+ , p [ Attr.class "meter-return" ]
124
+ [ text
125
+ (if fraction >= 1 then
126
+ ""
127
+
128
+ else
129
+ config.returnText
130
+ )
131
+ ]
132
+ ]