velvetkit 0.4.2 → 0.5.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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +149 -2
  3. data/lib/velvetkit/version.rb +1 -1
  4. data/registry/app/components/ui/carousel.html.erb +7 -0
  5. data/registry/app/components/ui/carousel.rb +60 -0
  6. data/registry/app/components/ui/chart.html.erb +3 -3
  7. data/registry/app/components/ui/chart.rb +18 -10
  8. data/registry/app/components/ui/checkbox.html.erb +6 -0
  9. data/registry/app/components/ui/checkbox.rb +9 -2
  10. data/registry/app/components/ui/fieldset.html.erb +6 -0
  11. data/registry/app/components/ui/fieldset.rb +76 -0
  12. data/registry/app/components/ui/gallery/image.rb +14 -1
  13. data/registry/app/components/ui/gallery.html.erb +32 -3
  14. data/registry/app/components/ui/gallery.rb +44 -5
  15. data/registry/app/components/ui/radio_group/item.html.erb +1 -1
  16. data/registry/app/components/ui/radio_group/item.rb +4 -0
  17. data/registry/app/components/ui/radio_group.html.erb +1 -1
  18. data/registry/app/components/ui/radio_group.rb +42 -2
  19. data/registry/app/components/ui/scrubber.html.erb +18 -0
  20. data/registry/app/components/ui/scrubber.rb +62 -0
  21. data/registry/app/components/ui/select.html.erb +1 -1
  22. data/registry/app/components/ui/select.rb +16 -1
  23. data/registry/app/components/ui/selection_bar.html.erb +7 -0
  24. data/registry/app/components/ui/selection_bar.rb +75 -0
  25. data/registry/app/components/ui/sidebar/inset.rb +5 -2
  26. data/registry/app/components/ui/sidebar/menu_button.rb +24 -9
  27. data/registry/app/components/ui/sidebar/menu_item.html.erb +1 -1
  28. data/registry/app/components/ui/sidebar/menu_item.rb +31 -5
  29. data/registry/app/components/ui/sidebar/menu_sub.rb +59 -0
  30. data/registry/app/components/ui/sidebar.html.erb +3 -3
  31. data/registry/app/components/ui/sidebar.rb +91 -13
  32. data/registry/app/components/ui/table/column.html.erb +1 -1
  33. data/registry/app/components/ui/table/column.rb +26 -2
  34. data/registry/app/components/ui/table/head.html.erb +1 -1
  35. data/registry/app/components/ui/table/head.rb +15 -2
  36. data/registry/app/components/ui/table/row.html.erb +1 -1
  37. data/registry/app/components/ui/table/row.rb +19 -5
  38. data/registry/app/components/ui/table.html.erb +2 -2
  39. data/registry/app/components/ui/table.rb +29 -4
  40. data/registry/app/components/ui/toggle_group.html.erb +1 -1
  41. data/registry/app/components/ui/toggle_group.rb +26 -3
  42. data/registry/app/javascript/controllers/ui/carousel_controller.ts +63 -0
  43. data/registry/app/javascript/controllers/ui/file_field_controller.ts +1 -1
  44. data/registry/app/javascript/controllers/ui/gallery_controller.ts +52 -14
  45. data/registry/app/javascript/controllers/ui/scrubber_controller.ts +188 -0
  46. data/registry/app/javascript/controllers/ui/selection_bar_controller.ts +122 -0
  47. data/registry/app/javascript/controllers/ui/sidebar_controller.ts +102 -32
  48. data/registry/components.yml +11 -3
  49. data/registry/config/locales/velvetkit.en.yml +16 -0
  50. data/registry/icons/lucide/arrow-down.svg +16 -0
  51. data/registry/icons/lucide/arrow-up.svg +16 -0
  52. data/registry/icons/lucide/image.svg +17 -0
  53. data/registry/icons/lucide/star.svg +15 -0
  54. data/registry/icons/phosphor/arrow-down.svg +2 -0
  55. data/registry/icons/phosphor/arrow-up.svg +2 -0
  56. data/registry/icons/phosphor/image.svg +2 -0
  57. data/registry/icons/phosphor/star.svg +2 -0
  58. data/registry/icons/tabler/arrow-down.svg +18 -0
  59. data/registry/icons/tabler/arrow-up.svg +18 -0
  60. data/registry/icons/tabler/photo.svg +19 -0
  61. data/registry/icons/tabler/star.svg +16 -0
  62. data/registry/icons.yml +4 -0
  63. data/registry/test/components/previews/ui/carousel_preview/highlights.html.erb +17 -0
  64. data/registry/test/components/previews/ui/carousel_preview.rb +22 -0
  65. data/registry/test/components/previews/ui/chart_preview/whole_dollars.html.erb +19 -0
  66. data/registry/test/components/previews/ui/chart_preview.rb +7 -1
  67. data/registry/test/components/previews/ui/checkbox_preview/in_form.html.erb +2 -3
  68. data/registry/test/components/previews/ui/fieldset_preview/block_of_fields.html.erb +18 -0
  69. data/registry/test/components/previews/ui/fieldset_preview/groups.html.erb +14 -0
  70. data/registry/test/components/previews/ui/fieldset_preview/model_errors.html.erb +22 -0
  71. data/registry/test/components/previews/ui/fieldset_preview/playground.html.erb +5 -0
  72. data/registry/test/components/previews/ui/fieldset_preview.rb +24 -0
  73. data/registry/test/components/previews/ui/gallery_preview/grid.html.erb +25 -0
  74. data/registry/test/components/previews/ui/gallery_preview.rb +3 -0
  75. data/registry/test/components/previews/ui/scrubber_preview/default.html.erb +24 -0
  76. data/registry/test/components/previews/ui/scrubber_preview.rb +6 -0
  77. data/registry/test/components/previews/ui/selection_bar_preview/floating.html.erb +16 -0
  78. data/registry/test/components/previews/ui/selection_bar_preview/table.html.erb +26 -0
  79. data/registry/test/components/previews/ui/selection_bar_preview.rb +9 -0
  80. data/registry/test/components/previews/ui/sidebar_preview/_shell.html.erb +5 -4
  81. data/registry/test/components/previews/ui/sidebar_preview/pill_links.html.erb +52 -0
  82. data/registry/test/components/previews/ui/sidebar_preview.rb +3 -0
  83. data/registry/test/components/previews/ui/table_preview/selectable.html.erb +26 -0
  84. data/registry/test/components/previews/ui/table_preview/sortable.html.erb +20 -0
  85. data/registry/test/components/previews/ui/table_preview/sticky_header.html.erb +13 -0
  86. data/registry/test/components/previews/ui/table_preview.rb +9 -0
  87. data/registry/test/components/ui/base_test.rb +27 -0
  88. data/registry/test/components/ui/carousel_test.rb +38 -0
  89. data/registry/test/components/ui/chart_test.rb +20 -0
  90. data/registry/test/components/ui/checkbox_test.rb +11 -2
  91. data/registry/test/components/ui/confirm_dialog_test.rb +3 -0
  92. data/registry/test/components/ui/fieldset_test.rb +119 -0
  93. data/registry/test/components/ui/gallery_test.rb +36 -1
  94. data/registry/test/components/ui/radio_group_test.rb +106 -0
  95. data/registry/test/components/ui/scrubber_test.rb +43 -0
  96. data/registry/test/components/ui/select_test.rb +21 -0
  97. data/registry/test/components/ui/selection_bar_test.rb +46 -0
  98. data/registry/test/components/ui/sidebar/menu_button_test.rb +9 -0
  99. data/registry/test/components/ui/sidebar_test.rb +79 -1
  100. data/registry/test/components/ui/toggle_group_test.rb +45 -0
  101. metadata +47 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72694a7eeade1ead01f0db952b0945196c102cbdab7e500988ac98cf286fd4c8
4
- data.tar.gz: aab42bfc198a73982c20b53754596ff1cf905b9f211479656ab9ecc5cde5d1c3
3
+ metadata.gz: 9a598255d821f68fb0ab11f28b32e1f60aaf51ee752ac22f39aca95fc7e2e2fb
4
+ data.tar.gz: 12c189b8e5e1f6f76b240ad79e8c63e4644668eb8881ca311f7fb35d0a349627
5
5
  SHA512:
6
- metadata.gz: 0401f8a0d91f4186852e0f5431efa7ba15ba6578124ba1ab31de40f79df4fb4cf0019b5665d2ad8844f5051a0220b03775a4c3f7a2f9cec49ac6a7af497b7bdd
7
- data.tar.gz: c0be11bcf1a941922e3b50b8cb813858bf8daf04c8246e44f1d73cc0472b8401808e95f5ea5b0662b626debd85121762e549802f42069d7ee441af142bc04d9b
6
+ metadata.gz: 9eb743aa4315865dfaa72f1727e826522c74ff7025c3370ba5e5514b06d0d179787454a85ac9bd1de1539527ef1947ab9ab186cea36a5bc58953ad87a315ee89
7
+ data.tar.gz: be5fdad891a582556befbe4e5593f6a30cd2a847e984ad7b8b54d48075e7b6b4e4764bf40ec1567236eb37c7c1ebbfc4bfbfed3e861db197ae4248f73881fbdb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,106 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.5.1 — 2026-11-15
6
+
7
+ Changes:
8
+
9
+ - Fix: the focus ring shows on click again, as well as on Tab. 0.5.0 moved
10
+ it to `:focus-visible`, so a click on a button, link, tab, menu item,
11
+ checkbox, radio, switch, sidebar link or gallery button drew no ring. (#95)
12
+ - Docs: an Upgrading guide at /docs/upgrading takes an app from 0.4 to 0.5
13
+ in one place: one `velvetkit:add` for every changed component, and the
14
+ sidebar's `collapsible:` and `state:` with before and after code. (#98)
15
+ - Docs: every guide and chart page is also Markdown, at the same address
16
+ with `.md`, and llms.txt links them. The upgrading guide and the release
17
+ notes can be copied as Markdown or opened in Claude or ChatGPT, and
18
+ llms-full.txt ends with both. (#100)
19
+
20
+ Upgrading an app: re-run `velvetkit:add` for `base`, `button`, `link`,
21
+ `badge`, `tabs`, `accordion`, `menu`, `checkbox`, `radio_group`, `switch`,
22
+ `sidebar` and `gallery`.
23
+
24
+ ## 0.5.0 — 2026-11-15
25
+
26
+ New components:
27
+
28
+ - `Carousel`: a row of cards that swipes and scrolls sideways, each stopping
29
+ at the edge, with previous and next buttons that show only while there's
30
+ more to see that way.
31
+ - `SelectionBar`: "3 selected", a button to clear them and the actions for
32
+ all of them at once, over a table with `selection:` or any list whose
33
+ boxes it can count. It keeps "select all" in step, Shift-click chooses a
34
+ run, and Escape clears. An "all" box inside a `data-selection-group`
35
+ chooses just that group, such as a day's photos.
36
+ - `Scrubber`: a rail down the side of a long list for jumping through it by
37
+ date, with years marked, the date under the pointer, dragging like a
38
+ scrollbar, and one tab stop whose arrow keys move between the marks.
39
+ - `Fieldset`: a group of controls under one legend, with a hint and an error
40
+ message for the group.
41
+
42
+ Changes:
43
+
44
+ - `RadioGroup` and `ToggleGroup` take `legend:`, `hint:` and `error:`,
45
+ through the new `Fieldset`. (#87)
46
+ - `Sidebar` is a drawer on phones, opened by the same trigger, with a
47
+ backdrop, Escape, and focus moved in and back. It sticks to the top and
48
+ fits the wrapper's height, so a bar above the app no longer pushes its
49
+ footer out of sight. Menu items take a sub-menu (`with_sub_menu`), opened
50
+ from an arrow beside the link and open when one of its links is the
51
+ current page, and `with_menu_button` takes `shape: :pill`. `collapsible:`
52
+ now says what the trigger does (:icon, :offcanvas or :none) and `state:`
53
+ whether it starts collapsed; left out, it's what the reader last chose,
54
+ kept in a cookie so the page is drawn that way from the start.
55
+ - `Table`: headers sort with `sort_href:` and `sorted:` (and say so to
56
+ screen readers), `selection:` adds a checkbox to each row and one for
57
+ all, and `sticky_header: true` with `max_height:` keeps the header in sight.
58
+ - `Gallery`: `strip: false` leaves the page to show the images its own
59
+ way, such as a grid of photos, and `gallery.trigger(index)` opens any of
60
+ them in the overlay. In the overlay, `image.with_info` shows in a panel
61
+ beside the image and `image.with_action` adds a button to the top bar.
62
+ - `Chart`: `precision:` sets the decimals (0 for whole dollars), and
63
+ `show_data: false` leaves the table of numbers to screen readers. A pie
64
+ or donut sits beside its legend by its own width, not the window's, so it
65
+ fits a narrow card.
66
+ - `Checkbox` shows a dash when it's partly checked (`indeterminate`).
67
+ - Buttons, links, tabs, menu items, checkboxes, radios and switches show
68
+ their focus ring for the keyboard only (`:focus-visible`), not after a
69
+ mouse click. Text fields keep theirs on click.
70
+ - Docs: two more examples. Helio, a dashboard at /examples/dashboard, is the
71
+ admin side of a software company: customers to search, filter, sort,
72
+ choose and act on in bulk, a page for each with its invoices, activity
73
+ and notes, and an overview whose numbers change with the period. Pinhole,
74
+ a photo library at /examples/photos, has highlights, photos by day, a date
75
+ scrubber, albums, an archive and a bin, and a viewer with an info panel.
76
+ - Docs: an Examples page, linked from the header, shows apps built with
77
+ VelvetKit. The first, Daily Goods, is a shop you can use at
78
+ /examples/store: a front page with categories, reviews and a newsletter
79
+ signup, filters (price, rating, colour, features) and sorting, a cart, and
80
+ a page for each product with photos, details and reviews, all without a
81
+ page reload. A sign-in flow is on the way.
82
+ - Fix: a collapsed `inset` or `floating` sidebar is wide enough for its
83
+ icons; they were clipped by the panel's padding.
84
+ - Fix: a class given to `Sidebar::Inset` replaces the one it clashes with
85
+ (`bg-transparent` for its background, `shadow-none` for its shadow). Both
86
+ used to land on the element and the inset's own often won.
87
+ - Fix: `Select` puts `aria-label` and `aria-labelledby` on its visible button.
88
+ They went on the hidden native select, which left the dropdown with no name
89
+ for screen readers. (#80)
90
+
91
+ Upgrading an app: re-run `velvetkit:add` for `sidebar`, `table`, `gallery`,
92
+ `chart` and `checkbox`. A sidebar that passed `collapsible: :icon` to start
93
+ collapsed now passes `state: :collapsed`; `collapsible: :none` now means it
94
+ can't collapse. The choice is kept in a cookie, not `localStorage`. The
95
+ sidebar is no longer `position: fixed`, so a `transform` added to keep it
96
+ inside a box can go; give the wrapper a height instead
97
+ (`class: "h-[calc(100svh-3rem)]"`). Phones get the drawer, so a sheet that
98
+ stood in for it can go too.
99
+
100
+ Upgrading an app: `RadioGroup` and `ToggleGroup` now render through the new
101
+ `Fieldset`, so re-run `velvetkit:add radio_group toggle_group` to get it with
102
+ them. Without `legend:`, `hint:` or `error:` they render as before.
103
+
3
104
  ## 0.4.2 — 2026-11-09
4
105
 
5
106
  Changes:
@@ -94,6 +195,8 @@ it as it is. `progress` needs the `velvetkit-progress` keyframes from the new
94
195
 
95
196
  ## 0.3.0 — 2026-11-03
96
197
 
198
+ New components:
199
+
97
200
  - `Stepper`: the steps of a multi-step form, done, current or to come, with
98
201
  dots, centred labels, panels moved between in the browser, and links back
99
202
  to done steps.
@@ -103,33 +206,77 @@ it as it is. `progress` needs the `velvetkit-progress` keyframes from the new
103
206
  radios or checkboxes.
104
207
  - `EmptyState`: an icon, title, text and actions for a page with nothing to
105
208
  list.
209
+
210
+ Changes:
211
+
106
212
  - Icons come from Lucide, Tabler or Phosphor, chosen with
107
213
  `velvetkit:install --icons=`, and are drawn as inline SVG.
108
214
 
109
215
  ## 0.2.2 — 2026-11-02
110
216
 
217
+ Changes:
218
+
111
219
  - Fix: the `plus`, `search`, `ellipsis-vertical` and `grip-vertical` icons were
112
220
  missing from installs.
113
221
 
114
222
  ## 0.2.1 — 2026-11-01
115
223
 
224
+ New components:
225
+
116
226
  - `NavigationMenu`: site navigation with links and panels of rich links that
117
227
  open on hover or click.
118
228
 
119
229
  ## 0.2.0 — 2026-11-01
120
230
 
231
+ New components:
232
+
121
233
  - `Toast`: stacked messages that dismiss themselves.
122
234
  - `SessionTabs`: tabs for open sessions, with a button to add one.
123
- - `Skeleton` and `FileField`.
235
+ - `Skeleton`: a pulsing placeholder in a piece of content's shape while it
236
+ loads.
237
+ - `FileField`: a drag-and-drop file picker with a label, hint and error
238
+ message, standalone or with a form builder.
239
+
240
+ Changes:
241
+
124
242
  - Fix: `Menu` content positions itself with the fixed strategy, so it isn't
125
243
  clipped by a scrolling container.
126
244
  - Fix: dependencies updated for security advisories in `addressable` and `rack`.
127
245
 
246
+ ## 0.1.0 — 2026-10-29
247
+
248
+ New components:
249
+
250
+ - `FormField`: a label, a control, a hint and an error message in one. The
251
+ form controls take `hint:` and `error:` and wrap themselves in it.
252
+ - `Textarea`: a multi-line field that can grow with its text.
253
+ - `Collapsible`: a section that opens under its trigger.
254
+ - `TableOfContents`: an "On this page" list that highlights the section
255
+ being read.
256
+
257
+ Changes:
258
+
259
+ - The docs site has a Building forms guide.
260
+ - Fix: `NativeSelect` keeps the model's value when the form is rendered again.
261
+ - Fix: `InputGroup` shows its error border, and draws one focus ring at a time.
262
+ - Fix: `TableOfContents` doesn't animate its first highlight on page load.
263
+
128
264
  ## 0.1.0.beta — 2026-10-26
129
265
 
266
+ New components:
267
+
268
+ - 38 components, with their Stimulus controllers, tests and Lookbook
269
+ previews: `Accordion`, `Alert`, `Avatar`, `AvatarGroup`, `Badge`, `Banner`,
270
+ `Breadcrumb`, `Button`, `ButtonTo`, `Card`, `Checkbox`, `DataGrid`,
271
+ `DatePicker`, `Dialog`, `Divider`, `Icon`, `Image`, `Input`, `InputGroup`,
272
+ `Label`, `Link`, `Menu`, `NativeSelect`, `Pagination`, `PasswordInput`,
273
+ `Popover`, `RadioGroup`, `Select`, `Sheet`, `Sidebar`, `Spinner`, `Switch`,
274
+ `Table`, `Tabs`, `Text`, `ThemeToggle`, `Tooltip` and `Typography`.
275
+
276
+ Changes:
277
+
130
278
  - First release of the component library.
131
279
  - `velvetkit:install` and `velvetkit:add` generators, with a configurable namespace.
132
- - 39 components, their Stimulus controllers, tests and Lookbook previews.
133
280
  - `Select` is a styled dropdown (listbox, keyboard, type-ahead), with
134
281
  `searchable:` and `multiple:`; it posts through a hidden native select, so
135
282
  forms work unchanged. The browser's own control is now `NativeSelect`.
@@ -4,5 +4,5 @@ module Velvetkit
4
4
  # Not the released version: the release workflow takes that from the tag
5
5
  # (v0.3.0 publishes 0.3.0) and writes it here on the runner only, so this
6
6
  # file can stay behind. See .github/workflows/release.yml.
7
- VERSION = "0.4.2"
7
+ VERSION = "0.5.1"
8
8
  end
@@ -0,0 +1,7 @@
1
+ <%= tag.div(**root_attrs) do %>
2
+ <%= tag.ul id: track_id, class: track_classes, data: { "ui--carousel-target": "track", action: "scroll->ui--carousel#update" } do %>
3
+ <% items.each do |item| %><%= tag.li item, class: item_classes %><% end %>
4
+ <% end %>
5
+ <%= render(UI::Button.new(**button_attrs(:previous))) do %><%= render(UI::Icon.new(name: "chevron-left", size: :sm, class: "rtl:rotate-180")) %><% end %>
6
+ <%= render(UI::Button.new(**button_attrs(:next))) do %><%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "rtl:rotate-180")) %><% end %>
7
+ <% end %>
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # A row of cards that scrolls sideways: highlights, albums, related products.
4
+ #
5
+ # <%= render(UI::Carousel.new(label: "Highlights", item_class: "w-64")) do |carousel| %>
6
+ # <% @highlights.each do |highlight| %>
7
+ # <% carousel.with_item { render(highlight) } %>
8
+ # <% end %>
9
+ # <% end %>
10
+ #
11
+ # It's a scroll-snap strip, so it swipes on a touch screen and scrolls with a
12
+ # trackpad with no script involved, and each card stops at the edge. Previous
13
+ # and next buttons scroll a strip's width at a time, and each shows only while
14
+ # there's more to see that way. `item_class:` sizes the cards ("w-64",
15
+ # "basis-1/3"); they're as wide as their content otherwise.
16
+ class UI::Carousel < UI::Base
17
+ renders_many :items
18
+
19
+ def initialize(label:, item_class: nil, gap: 3, class: nil, **html_attrs)
20
+ @label = label
21
+ @item_class = item_class
22
+ @gap = gap
23
+ @user_class = binding.local_variable_get(:class)
24
+ @html_attrs = html_attrs
25
+ end
26
+
27
+ # Written out in full so Tailwind finds them.
28
+ GAPS = { 2 => "gap-2", 3 => "gap-3", 4 => "gap-4", 6 => "gap-6" }.freeze
29
+
30
+ def root_attrs
31
+ attrs = @html_attrs.except(:data, :aria)
32
+ attrs[:role] = "region"
33
+ attrs[:class] = cn("group/carousel relative min-w-0", @user_class)
34
+ attrs[:aria] = { label: @label, roledescription: t("ui.carousel.roledescription", default: "carousel") }
35
+ .merge(@html_attrs[:aria] || {})
36
+ attrs[:data] = { slot: "carousel", controller: "ui--carousel",
37
+ action: "resize@window->ui--carousel#update" }.merge(@html_attrs[:data] || {})
38
+ attrs
39
+ end
40
+
41
+ # The padding gives the cards' focus rings room, and the margin takes it back.
42
+ def track_classes
43
+ cn("-m-1 flex snap-x snap-mandatory scroll-px-1 overflow-x-auto scroll-smooth p-1 motion-reduce:scroll-auto",
44
+ "[scrollbar-width:none] [&::-webkit-scrollbar]:hidden", GAPS.fetch(@gap, GAPS[3]))
45
+ end
46
+
47
+ def item_classes = cn("shrink-0 snap-start", @item_class)
48
+
49
+ def button_attrs(direction)
50
+ edge = direction == :previous ? "start-0 -translate-x-1/2 rtl:translate-x-1/2" : "end-0 translate-x-1/2 rtl:-translate-x-1/2"
51
+ { variant: :outline, size: :icon,
52
+ class: cn("absolute top-1/2 z-10 hidden -translate-y-1/2 rounded-full bg-background shadow-md sm:inline-flex [&[hidden]]:hidden!", edge),
53
+ hidden: true,
54
+ aria: { label: t("ui.carousel.#{direction}", default: direction == :previous ? "Previous" : "Next"),
55
+ controls: track_id },
56
+ data: { action: "ui--carousel##{direction}", "ui--carousel-target": direction } }
57
+ end
58
+
59
+ def track_id = @track_id ||= "carousel-#{SecureRandom.hex(4)}"
60
+ end
@@ -20,8 +20,8 @@
20
20
  class: "pointer-events-none invisible absolute left-0 top-0 z-10 min-w-32 rounded-md border bg-popover px-3 py-2 text-xs text-popover-foreground opacity-0 shadow-md transition-[opacity,transform,visibility] duration-150 ease-out data-[shown]:visible data-[shown]:opacity-100 motion-reduce:transition-none" %>
21
21
  <% end %>
22
22
  <% end %>
23
- <details class="group/data text-sm">
24
- <%= tag.summary t("ui.chart.show_data", default: "Show the data"), class: "w-fit cursor-pointer rounded-sm text-muted-foreground hover:text-foreground #{UI::Base::FOCUS_RING}" %>
23
+ <%= tag.send(show_data? ? :details : :div, class: show_data? ? "group/data text-sm" : "sr-only") do %>
24
+ <% if show_data? %><%= tag.summary t("ui.chart.show_data", default: "Show the data"), class: "w-fit cursor-pointer rounded-sm text-muted-foreground hover:text-foreground #{UI::Base::FOCUS_RING}" %><% end %>
25
25
  <div class="mt-2 overflow-x-auto">
26
26
  <table class="w-full text-sm tabular-nums">
27
27
  <%= tag.caption label, class: "sr-only" %>
@@ -43,5 +43,5 @@
43
43
  </tbody>
44
44
  </table>
45
45
  </div>
46
- </details>
46
+ <% end %>
47
47
  <% end %>
@@ -15,7 +15,8 @@
15
15
  # Its legend gives each part's value and share, and a donut shows the total in
16
16
  # its middle. `format:` is :number, :currency or :percent (values from 0 to
17
17
  # 100), and the values are written in the app's locale: currency uses Rails'
18
- # own format for it, or `unit:` ("₹"). `nil` leaves a gap.
18
+ # own format for it, or `unit:` ("₹"). `precision:` sets the decimals (0 for
19
+ # whole dollars). `nil` leaves a gap.
19
20
  #
20
21
  # Each series takes the next of five colours, `--chart-1` to `--chart-5`, which
21
22
  # change with the theme. A series keeps its colour by its place in the list, so
@@ -26,6 +27,10 @@
26
27
  # Two or more series get a legend, and a line ends with its last value. Hover,
27
28
  # or focus the chart and use the arrow keys, for the values at each point; the
28
29
  # numbers are also in a table under "Show the data", for screen readers too.
30
+ # `show_data: false` leaves the table to screen readers alone.
31
+ #
32
+ # A pie sits beside its legend when the chart is wide enough, measured by its
33
+ # own width rather than the window's, so it fits a narrow card.
29
34
  # Chart.js loads when the first chart on a page appears, and each chart draws
30
35
  # when it scrolls into view: bars grow from the baseline and a line draws
31
36
  # itself from left to right, unless the system asks for reduced motion.
@@ -40,14 +45,16 @@ class UI::Chart < UI::Base
40
45
 
41
46
  Series = Struct.new(:name, :data, :color, keyword_init: true)
42
47
 
43
- def initialize(labels:, series:, type: :line, label: nil, stacked: false, format: :number, unit: nil, height: 288,
44
- class: nil, **html_attrs)
48
+ def initialize(labels:, series:, type: :line, label: nil, stacked: false, format: :number, unit: nil, precision: nil,
49
+ show_data: true, height: 288, class: nil, **html_attrs)
45
50
  @labels = labels.map(&:to_s)
46
51
  @type = TYPES.include?(type.to_sym) ? type.to_sym : :line
47
52
  @label = label
48
53
  @stacked = stacked && @type == :bar
49
54
  @format = FORMATS.include?(format.to_sym) ? format.to_sym : :number
50
55
  @unit = unit
56
+ @precision = precision
57
+ @show_data = show_data
51
58
  @height = height
52
59
  @user_class = binding.local_variable_get(:class)
53
60
  @html_attrs = html_attrs
@@ -58,6 +65,7 @@ class UI::Chart < UI::Base
58
65
  attr_reader :labels, :series
59
66
 
60
67
  def legend? = circular? || @series.size > 1
68
+ def show_data? = @show_data
61
69
  def line? = @type == :line
62
70
  def circular? = CIRCULAR.include?(@type)
63
71
  def swatch_classes(entry) = cn(SWATCHES[entry.color], line? ? "h-0.5 w-3.5 rounded-full" : "size-2.5 rounded-sm")
@@ -76,7 +84,7 @@ class UI::Chart < UI::Base
76
84
 
77
85
  def legend_classes
78
86
  if circular?
79
- "flex flex-col gap-2 text-sm sm:w-64 sm:shrink-0"
87
+ "flex flex-col gap-2 text-sm @md:w-64 @md:shrink-0"
80
88
  else
81
89
  "flex flex-wrap gap-x-4 gap-y-1 text-sm text-muted-foreground"
82
90
  end
@@ -84,12 +92,12 @@ class UI::Chart < UI::Base
84
92
 
85
93
  # A pie sits beside its legend once there's room; the others keep it above.
86
94
  def body_classes
87
- circular? ? "flex flex-col-reverse gap-4 sm:flex-row sm:items-center sm:gap-8" : "contents"
95
+ circular? ? "flex flex-col-reverse gap-4 @md:flex-row @md:items-center @md:gap-8" : "contents"
88
96
  end
89
97
 
90
98
  def root_attrs
91
99
  attrs = @html_attrs.except(:data)
92
- attrs[:class] = cn("flex w-full min-w-0 flex-col gap-3", @user_class)
100
+ attrs[:class] = cn("@container flex w-full min-w-0 flex-col gap-3", @user_class)
93
101
  attrs[:data] = { slot: "chart", type: @type, controller: "ui--chart",
94
102
  "ui--chart-config-value": config.to_json,
95
103
  # Propshaft digests the filename, so the URL has to come from Ruby.
@@ -106,7 +114,7 @@ class UI::Chart < UI::Base
106
114
  end
107
115
 
108
116
  def frame_style = "height: #{@height.to_i}px"
109
- def frame_classes = cn("relative w-full", { "sm:flex-1" => circular? })
117
+ def frame_classes = cn("relative w-full", { "@md:flex-1" => circular? })
110
118
 
111
119
  def label = @label || t("ui.chart.label", default: "Chart")
112
120
 
@@ -114,9 +122,9 @@ class UI::Chart < UI::Base
114
122
  return t("ui.chart.missing", default: "—") if value.nil?
115
123
 
116
124
  case @format
117
- when :currency then ActiveSupport::NumberHelper.number_to_currency(value, **{ unit: @unit }.compact)
118
- when :percent then ActiveSupport::NumberHelper.number_to_percentage(value, precision: 1, strip_insignificant_zeros: true)
119
- else ActiveSupport::NumberHelper.number_to_delimited(value)
125
+ when :currency then ActiveSupport::NumberHelper.number_to_currency(value, **{ unit: @unit, precision: @precision }.compact)
126
+ when :percent then ActiveSupport::NumberHelper.number_to_percentage(value, precision: @precision || 1, strip_insignificant_zeros: @precision.nil?)
127
+ else ActiveSupport::NumberHelper.number_to_delimited(@precision ? value.to_f.round(@precision) : value)
120
128
  end
121
129
  end
122
130
 
@@ -6,6 +6,9 @@
6
6
  <%= tag.span class: overlay_classes do %>
7
7
  <%= render(UI::Icon.new(name: "check", size: icon_size, class: "stroke-[3]", aria: { hidden: true })) %>
8
8
  <% end %>
9
+ <%= tag.span class: mixed_overlay_classes do %>
10
+ <%= render(UI::Icon.new(name: "minus", size: icon_size, class: "stroke-[3]", aria: { hidden: true })) %>
11
+ <% end %>
9
12
  <% end %>
10
13
  <%= tag.span class: label_text_classes do %><%= label %><% if required? %><%= tag.span(" *", class: "text-destructive ml-0.5") %><% end %><% end %>
11
14
  <% end %>
@@ -15,6 +18,9 @@
15
18
  <%= tag.span class: overlay_classes do %>
16
19
  <%= render(UI::Icon.new(name: "check", size: icon_size, class: "stroke-[3]", aria: { hidden: true })) %>
17
20
  <% end %>
21
+ <%= tag.span class: mixed_overlay_classes do %>
22
+ <%= render(UI::Icon.new(name: "minus", size: icon_size, class: "stroke-[3]", aria: { hidden: true })) %>
23
+ <% end %>
18
24
  <% end %>
19
25
  <% end %>
20
26
  <% end %>
@@ -6,7 +6,7 @@ class UI::Checkbox < UI::Base
6
6
  variants(
7
7
  base: "peer appearance-none shrink-0 border border-input bg-background " \
8
8
  "transition-all " \
9
- "checked:bg-primary checked:border-primary " \
9
+ "checked:bg-primary checked:border-primary indeterminate:bg-primary indeterminate:border-primary " \
10
10
  "focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1 " \
11
11
  "ring-offset-background",
12
12
  variants: {
@@ -120,7 +120,14 @@ class UI::Checkbox < UI::Base
120
120
 
121
121
  def overlay_classes
122
122
  "pointer-events-none absolute inset-0 flex items-center justify-center " \
123
- "text-primary-foreground opacity-0 peer-checked:opacity-100 transition-opacity"
123
+ "text-primary-foreground opacity-0 peer-checked:opacity-100 peer-indeterminate:opacity-0 transition-opacity"
124
+ end
125
+
126
+ # A dash for a box that's partly checked, such as "select all" with some of
127
+ # the rows chosen. Only script sets that state, as `indeterminate`.
128
+ def mixed_overlay_classes
129
+ "pointer-events-none absolute inset-0 flex items-center justify-center " \
130
+ "text-primary-foreground opacity-0 peer-indeterminate:opacity-100 transition-opacity"
124
131
  end
125
132
 
126
133
  def wrapper_classes
@@ -0,0 +1,6 @@
1
+ <%= tag.fieldset(**fieldset_attrs) do %>
2
+ <% if legend? %><%= tag.legend(id: legend_id, class: legend_classes) do %><%= legend_text %><% if @required %><%= tag.span(" *", class: "text-destructive ml-0.5") %><% end %><% end %><% end %>
3
+ <% if hint.present? %><%= tag.p(hint, id: hint_id, class: "text-xs text-muted-foreground") %><% end %>
4
+ <%= content %>
5
+ <% if error_message.present? %><%= tag.p(error_message, id: error_id, class: "text-xs text-destructive") %><% end %>
6
+ <% end %>
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ # Controls that belong together under one caption: a <fieldset> whose
6
+ # <legend> names the group, a hint under it and an error message for the
7
+ # group as a whole. Use it for a set of checkboxes, a block of settings or an
8
+ # address. RadioGroup and ToggleGroup render through it themselves when given
9
+ # `legend:`, `hint:` or `error:`.
10
+ #
11
+ # <%= render(UI::Fieldset.new(legend: "Notifications", hint: "Where we tell you about replies.")) do %>
12
+ # <%= render(UI::Checkbox.new(name: "notify[]", value: "email", label: "Email")) %>
13
+ # <%= render(UI::Checkbox.new(name: "notify[]", value: "push", label: "Push")) %>
14
+ # <% end %>
15
+ #
16
+ # `disabled: true` disables every control inside, natively, and the browser
17
+ # then leaves them out of the form's submission. `required: true` marks the
18
+ # legend only; set `required` on the controls that need it. `error:` takes a
19
+ # message, or `true` to mark the group invalid without one. Bound to a form
20
+ # (`form:` + `field:`), the model's errors on that attribute are the message
21
+ # and its human name is the legend (`legend:` overrides it, `legend: false`
22
+ # opts out), the way UI::FormField does it for one control.
23
+ class UI::Fieldset < UI::Base
24
+ def initialize(legend: nil, hint: nil, error: nil, required: false, disabled: false,
25
+ form: nil, field: nil, class: nil, **html_attrs)
26
+ @required = required
27
+ @disabled = disabled
28
+ @user_class = binding.local_variable_get(:class)
29
+ @html_attrs = html_attrs
30
+ # FormField already works out a label, hint and error, from a form or not;
31
+ # the legend is that label.
32
+ @details = UI::FormField.new(label: legend, hint: hint, error: error, form: form, field: field,
33
+ for: html_attrs[:id] || "ui-fieldset-#{SecureRandom.hex(4)}")
34
+ end
35
+
36
+ def id = @details.control_id
37
+ def legend_id = "#{id}-legend"
38
+ def hint_id = @details.hint_id
39
+ def error_id = @details.error_id
40
+
41
+ # Never an empty legend: it would name the group "".
42
+ def legend? = @details.render_label? && legend_text.present?
43
+ def legend_text = @details.label_text
44
+ def hint = @details.hint
45
+ def error_message = @details.error_message
46
+
47
+ # Whether there's anything to show around the controls. RadioGroup and
48
+ # ToggleGroup render bare without it.
49
+ def wrap? = legend? || hint.present? || error_message.present?
50
+
51
+ def fieldset_attrs
52
+ # A radiogroup takes aria-required and aria-invalid; a plain fieldset is a
53
+ # group, which takes neither.
54
+ radiogroup = @html_attrs[:role].to_s == "radiogroup"
55
+ user_aria = (@html_attrs[:aria] || {}).symbolize_keys
56
+ aria = {
57
+ labelledby: (legend_id if legend?),
58
+ required: ("true" if radiogroup && @required),
59
+ invalid: ("true" if radiogroup && @details.error?)
60
+ }.compact.merge(user_aria)
61
+ # Your own aria-describedby adds to the hint's and error's ids.
62
+ aria[:describedby] = [ @details.describedby, user_aria[:describedby] ].compact_blank.join(" ").presence
63
+ @html_attrs.except(:aria).merge(id: id, class: classes, disabled: @disabled, aria: aria.compact)
64
+ end
65
+
66
+ def classes
67
+ cn("flex min-w-0 flex-col gap-3", @user_class)
68
+ end
69
+
70
+ # The legend sits outside the fieldset's flex layout, so its own margin
71
+ # spaces it: close to a hint, further from the controls.
72
+ def legend_classes
73
+ cn("text-sm font-medium leading-snug", hint.present? ? "mb-1.5" : "mb-3",
74
+ { "text-muted-foreground" => @disabled })
75
+ end
76
+ end
@@ -3,9 +3,17 @@
3
3
  # One image in a UI::Gallery. Holds what the gallery needs to draw it in three
4
4
  # places (the main view, its thumbnail and the zoomed view); it draws nothing
5
5
  # itself.
6
+ #
7
+ # In the zoomed view, `with_info` is shown in a panel beside the image, opened
8
+ # with the Info button (when it was taken, where, the camera), and each
9
+ # `with_action` is a button in the top bar (favourite, download, delete), for
10
+ # this image alone.
6
11
  class UI::Gallery::Image < UI::Base
7
12
  attr_reader :src, :alt
8
13
 
14
+ renders_one :info
15
+ renders_many :actions
16
+
9
17
  def initialize(src:, alt:, zoom_src: nil, thumbnail_src: nil)
10
18
  @src = src
11
19
  @alt = alt
@@ -16,5 +24,10 @@ class UI::Gallery::Image < UI::Base
16
24
  def zoom_src = @zoom_src || @src
17
25
  def thumbnail_src = @thumbnail_src || @src
18
26
 
19
- def call = nil
27
+ # Runs the block given to `with_image`, which fills in the info and actions.
28
+ # The gallery draws them where they go.
29
+ def call
30
+ content
31
+ nil
32
+ end
20
33
  end
@@ -1,4 +1,6 @@
1
1
  <%= tag.div(**root_attrs) do %>
2
+ <% images.each(&:to_s) %>
3
+ <% if strip? %>
2
4
  <%= tag.div class: "relative min-w-0" do %>
3
5
  <%= tag.ul class: track_classes, data: { "ui--gallery-target": "track", action: "scroll->ui--gallery#scrolled pointerdown->ui--gallery#released" } do %>
4
6
  <% images.each_with_index do |image, index| %>
@@ -19,8 +21,15 @@
19
21
  <%= render(UI::Button.new(**nav_button_attrs(:next))) do %><%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "rtl:rotate-180")) %><% end %>
20
22
  <% end %>
21
23
  <% end %>
24
+ <% else %>
25
+ <%# What the overlay needs to know of each image; the page shows them its own way. %>
26
+ <%= tag.ul hidden: true do %>
27
+ <% images.each do |image| %><%= tag.li data: { "ui--gallery-target": "slide", zoom_src: asset_path(image.zoom_src), alt: image.alt } %><% end %>
28
+ <% end %>
29
+ <%= content %>
30
+ <% end %>
22
31
  <%= tag.p position_text, class: "sr-only", aria: { live: "polite" }, data: { "ui--gallery-target": "status" } %>
23
- <% if multiple? %>
32
+ <% if multiple? && strip? %>
24
33
  <%= tag.ul class: thumbnail_strip_classes do %>
25
34
  <% images.each_with_index do |image, index| %>
26
35
  <li class="shrink-0"><%= tag.button(**thumbnail_attrs(index)) do %><%= render(UI::Image.new(src: image.thumbnail_src, alt: "", rounded: :none, class: "size-full object-cover", draggable: "false")) %><% end %></li>
@@ -30,7 +39,7 @@
30
39
  <%= tag.dialog class: dialog_classes, tabindex: -1,
31
40
  aria: { label: t("ui.gallery.dialog", default: "Zoomed image") },
32
41
  data: { "ui--gallery-target": "dialog", action: "close->ui--gallery#closed cancel->ui--gallery#cancel" } do %>
33
- <%= tag.div class: viewport_classes,
42
+ <%= tag.div class: cn(viewport_classes, "sm:group-data-[info]/dialog:end-80"),
34
43
  data: { "ui--gallery-target": "viewport",
35
44
  action: "click->ui--gallery#viewportClick pointerdown->ui--gallery#panStart pointermove->ui--gallery#panMove " \
36
45
  "pointerup->ui--gallery#panEnd pointercancel->ui--gallery#panEnd wheel->ui--gallery#wheel" } do %>
@@ -43,7 +52,27 @@
43
52
  <%= render(UI::Button.new(**zoom_button_attrs(:out, "Zoom out"))) do %><%= render(UI::Icon.new(name: "zoom-out", size: :sm)) %><% end %>
44
53
  <%= render(UI::Button.new(**zoom_button_attrs(:in, "Zoom in"))) do %><%= render(UI::Icon.new(name: "zoom-in", size: :sm)) %><% end %>
45
54
  <% end %>
46
- <%= render(UI::Button.new(variant: :ghost, size: :icon, class: cn(UI::Gallery::OVERLAY_BUTTON, "absolute end-4 top-4 z-10"), aria: { label: t("ui.gallery.close", default: "Close") }, data: { action: "ui--gallery#close" })) do %><%= render(UI::Icon.new(name: "x", size: :sm)) %><% end %>
55
+ <%= tag.div class: "absolute end-4 top-4 z-40 flex items-center gap-2" do %>
56
+ <% images.each_with_index do |image, index| %>
57
+ <% if image.actions? %>
58
+ <%= tag.div class: "flex items-center gap-2", hidden: !index.zero?, data: { "ui--gallery-target": "perImage", index: index } do %><% image.actions.each do |action| %><%= action %><% end %><% end %>
59
+ <% end %>
60
+ <% end %>
61
+ <% if info? %>
62
+ <%= render(UI::Button.new(**info_toggle_attrs)) do %><%= render(UI::Icon.new(name: "info", size: :sm)) %><% end %>
63
+ <% end %>
64
+ <%= render(UI::Button.new(variant: :ghost, size: :icon, class: UI::Gallery::OVERLAY_BUTTON, aria: { label: t("ui.gallery.close", default: "Close") }, data: { action: "ui--gallery#close" })) do %><%= render(UI::Icon.new(name: "x", size: :sm)) %><% end %>
65
+ <% end %>
66
+ <% if info? %>
67
+ <%= tag.aside id: info_id, hidden: true, aria: { label: t("ui.gallery.info", default: "Info") },
68
+ class: "absolute inset-x-0 bottom-0 z-30 max-h-[55%] overflow-y-auto rounded-t-xl bg-background p-5 text-foreground shadow-xl " \
69
+ "sm:inset-x-auto sm:inset-y-0 sm:end-0 sm:max-h-none sm:w-80 sm:rounded-none sm:pt-20",
70
+ data: { "ui--gallery-target": "infoPanel" } do %>
71
+ <% images.each_with_index do |image, index| %>
72
+ <%= tag.div image.info, hidden: !index.zero?, data: { "ui--gallery-target": "perImage", index: index } %>
73
+ <% end %>
74
+ <% end %>
75
+ <% end %>
47
76
  <% if multiple? %>
48
77
  <%= render(UI::Button.new(**overlay_nav_attrs(:previous))) do %><%= render(UI::Icon.new(name: "chevron-left", size: :sm, class: "rtl:rotate-180")) %><% end %>
49
78
  <%= render(UI::Button.new(**overlay_nav_attrs(:next))) do %><%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "rtl:rotate-180")) %><% end %>