velvetkit 0.4.2 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +127 -2
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/accordion/trigger.rb +1 -1
- data/registry/app/components/ui/badge.rb +1 -1
- data/registry/app/components/ui/base.rb +2 -2
- data/registry/app/components/ui/button.rb +1 -1
- data/registry/app/components/ui/carousel.html.erb +7 -0
- data/registry/app/components/ui/carousel.rb +60 -0
- data/registry/app/components/ui/chart.html.erb +3 -3
- data/registry/app/components/ui/chart.rb +18 -10
- data/registry/app/components/ui/checkbox.html.erb +6 -0
- data/registry/app/components/ui/checkbox.rb +11 -4
- data/registry/app/components/ui/fieldset.html.erb +6 -0
- data/registry/app/components/ui/fieldset.rb +76 -0
- data/registry/app/components/ui/gallery/image.rb +14 -1
- data/registry/app/components/ui/gallery.html.erb +32 -3
- data/registry/app/components/ui/gallery.rb +46 -7
- data/registry/app/components/ui/link.rb +1 -1
- data/registry/app/components/ui/menu/item.rb +1 -1
- data/registry/app/components/ui/radio_group/item.html.erb +1 -1
- data/registry/app/components/ui/radio_group/item.rb +5 -1
- data/registry/app/components/ui/radio_group.html.erb +1 -1
- data/registry/app/components/ui/radio_group.rb +42 -2
- data/registry/app/components/ui/scrubber.html.erb +18 -0
- data/registry/app/components/ui/scrubber.rb +62 -0
- data/registry/app/components/ui/select.html.erb +1 -1
- data/registry/app/components/ui/select.rb +16 -1
- data/registry/app/components/ui/selection_bar.html.erb +7 -0
- data/registry/app/components/ui/selection_bar.rb +75 -0
- data/registry/app/components/ui/sidebar/group_label.rb +1 -1
- data/registry/app/components/ui/sidebar/inset.rb +5 -2
- data/registry/app/components/ui/sidebar/menu_button.rb +24 -9
- data/registry/app/components/ui/sidebar/menu_item.html.erb +1 -1
- data/registry/app/components/ui/sidebar/menu_item.rb +31 -5
- data/registry/app/components/ui/sidebar/menu_sub.rb +59 -0
- data/registry/app/components/ui/sidebar.html.erb +3 -3
- data/registry/app/components/ui/sidebar.rb +91 -13
- data/registry/app/components/ui/switch.rb +2 -2
- data/registry/app/components/ui/table/column.html.erb +1 -1
- data/registry/app/components/ui/table/column.rb +26 -2
- data/registry/app/components/ui/table/head.html.erb +1 -1
- data/registry/app/components/ui/table/head.rb +15 -2
- data/registry/app/components/ui/table/row.html.erb +1 -1
- data/registry/app/components/ui/table/row.rb +19 -5
- data/registry/app/components/ui/table.html.erb +2 -2
- data/registry/app/components/ui/table.rb +29 -4
- data/registry/app/components/ui/tabs/trigger.rb +1 -1
- data/registry/app/components/ui/toggle_group.html.erb +1 -1
- data/registry/app/components/ui/toggle_group.rb +26 -3
- data/registry/app/javascript/controllers/ui/carousel_controller.ts +63 -0
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +1 -1
- data/registry/app/javascript/controllers/ui/gallery_controller.ts +52 -14
- data/registry/app/javascript/controllers/ui/scrubber_controller.ts +188 -0
- data/registry/app/javascript/controllers/ui/selection_bar_controller.ts +122 -0
- data/registry/app/javascript/controllers/ui/sidebar_controller.ts +102 -32
- data/registry/components.yml +11 -3
- data/registry/config/locales/velvetkit.en.yml +16 -0
- data/registry/icons/lucide/arrow-down.svg +16 -0
- data/registry/icons/lucide/arrow-up.svg +16 -0
- data/registry/icons/lucide/image.svg +17 -0
- data/registry/icons/lucide/star.svg +15 -0
- data/registry/icons/phosphor/arrow-down.svg +2 -0
- data/registry/icons/phosphor/arrow-up.svg +2 -0
- data/registry/icons/phosphor/image.svg +2 -0
- data/registry/icons/phosphor/star.svg +2 -0
- data/registry/icons/tabler/arrow-down.svg +18 -0
- data/registry/icons/tabler/arrow-up.svg +18 -0
- data/registry/icons/tabler/photo.svg +19 -0
- data/registry/icons/tabler/star.svg +16 -0
- data/registry/icons.yml +4 -0
- data/registry/test/components/previews/ui/carousel_preview/highlights.html.erb +17 -0
- data/registry/test/components/previews/ui/carousel_preview.rb +22 -0
- data/registry/test/components/previews/ui/chart_preview/whole_dollars.html.erb +19 -0
- data/registry/test/components/previews/ui/chart_preview.rb +7 -1
- data/registry/test/components/previews/ui/checkbox_preview/in_form.html.erb +2 -3
- data/registry/test/components/previews/ui/fieldset_preview/block_of_fields.html.erb +18 -0
- data/registry/test/components/previews/ui/fieldset_preview/groups.html.erb +14 -0
- data/registry/test/components/previews/ui/fieldset_preview/model_errors.html.erb +22 -0
- data/registry/test/components/previews/ui/fieldset_preview/playground.html.erb +5 -0
- data/registry/test/components/previews/ui/fieldset_preview.rb +24 -0
- data/registry/test/components/previews/ui/gallery_preview/grid.html.erb +25 -0
- data/registry/test/components/previews/ui/gallery_preview.rb +3 -0
- data/registry/test/components/previews/ui/scrubber_preview/default.html.erb +24 -0
- data/registry/test/components/previews/ui/scrubber_preview.rb +6 -0
- data/registry/test/components/previews/ui/selection_bar_preview/floating.html.erb +16 -0
- data/registry/test/components/previews/ui/selection_bar_preview/table.html.erb +26 -0
- data/registry/test/components/previews/ui/selection_bar_preview.rb +9 -0
- data/registry/test/components/previews/ui/sidebar_preview/_shell.html.erb +5 -4
- data/registry/test/components/previews/ui/sidebar_preview/pill_links.html.erb +52 -0
- data/registry/test/components/previews/ui/sidebar_preview.rb +3 -0
- data/registry/test/components/previews/ui/table_preview/selectable.html.erb +26 -0
- data/registry/test/components/previews/ui/table_preview/sortable.html.erb +20 -0
- data/registry/test/components/previews/ui/table_preview/sticky_header.html.erb +13 -0
- data/registry/test/components/previews/ui/table_preview.rb +9 -0
- data/registry/test/components/ui/button_test.rb +2 -2
- data/registry/test/components/ui/carousel_test.rb +38 -0
- data/registry/test/components/ui/chart_test.rb +20 -0
- data/registry/test/components/ui/checkbox_test.rb +11 -2
- data/registry/test/components/ui/fieldset_test.rb +119 -0
- data/registry/test/components/ui/gallery_test.rb +40 -5
- data/registry/test/components/ui/link_test.rb +1 -1
- data/registry/test/components/ui/number_input_test.rb +1 -1
- data/registry/test/components/ui/radio_group_test.rb +106 -0
- data/registry/test/components/ui/scrubber_test.rb +43 -0
- data/registry/test/components/ui/select_test.rb +21 -0
- data/registry/test/components/ui/selection_bar_test.rb +46 -0
- data/registry/test/components/ui/sidebar/menu_button_test.rb +9 -0
- data/registry/test/components/ui/sidebar_test.rb +79 -1
- data/registry/test/components/ui/switch_test.rb +4 -4
- data/registry/test/components/ui/toggle_group_test.rb +45 -0
- metadata +47 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0c2f8866e70934ca1e0f3ed6bb6d2d4925d7b84c11a5b8aaab89f5f3d48a69e7
|
|
4
|
+
data.tar.gz: 26320e37c7048700ebedcbbb2188cd739a3574b58fb1a624008ad5ee36d432ee
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1ac2dc774e3a3cf2593bec85d15c703b54e83d36216e24cc00cea5300a714db01ef08ee52abf8a6a4b63b97c4601b024c12abaa29a202e8252bd10a23204c381
|
|
7
|
+
data.tar.gz: 1b7c9127670e0382ddc16ef189905b8c18e7d3af126026dc8638d1b152eaea073c27d67e2844620802e70d29d60cab08fa099ae4f7943cc9f99347281639a9f4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,84 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
New components:
|
|
6
|
+
|
|
7
|
+
- `Carousel`: a row of cards that swipes and scrolls sideways, each stopping
|
|
8
|
+
at the edge, with previous and next buttons that show only while there's
|
|
9
|
+
more to see that way.
|
|
10
|
+
- `SelectionBar`: "3 selected", a button to clear them and the actions for
|
|
11
|
+
all of them at once, over a `Table` with `selection:` or any list whose
|
|
12
|
+
boxes it can count. It keeps "select all" in step, Shift-click chooses a
|
|
13
|
+
run, and Escape clears. An "all" box inside a `data-selection-group`
|
|
14
|
+
chooses just that group, such as a day's photos.
|
|
15
|
+
- `Scrubber`: a rail down the side of a long list for jumping through it by
|
|
16
|
+
date, with years marked, the date under the pointer, dragging like a
|
|
17
|
+
scrollbar, and one tab stop whose arrow keys move between the marks.
|
|
18
|
+
|
|
19
|
+
Changes:
|
|
20
|
+
|
|
21
|
+
- `Sidebar` is a drawer on phones, opened by the same trigger, with a
|
|
22
|
+
backdrop, Escape, and focus moved in and back. It sticks to the top and
|
|
23
|
+
fits the wrapper's height, so a bar above the app no longer pushes its
|
|
24
|
+
footer out of sight. Menu items take a sub-menu (`with_sub_menu`), opened
|
|
25
|
+
from an arrow beside the link and open when one of its links is the
|
|
26
|
+
current page, and `with_menu_button` takes `shape: :pill`. `collapsible:`
|
|
27
|
+
now says what the trigger does (:icon, :offcanvas or :none) and `state:`
|
|
28
|
+
whether it starts collapsed; left out, it's what the reader last chose,
|
|
29
|
+
kept in a cookie so the page is drawn that way from the start.
|
|
30
|
+
- `Table`: headers sort with `sort_href:` and `sorted:` (and say so to
|
|
31
|
+
screen readers), `selection:` adds a checkbox to each row and one for
|
|
32
|
+
all, and `sticky_header: true` with `max_height:` keeps the header in sight.
|
|
33
|
+
- `Gallery`: `strip: false` leaves the page to show the images its own
|
|
34
|
+
way, such as a grid of photos, and `gallery.trigger(index)` opens any of
|
|
35
|
+
them in the overlay. In the overlay, `image.with_info` shows in a panel
|
|
36
|
+
beside the image and `image.with_action` adds a button to the top bar.
|
|
37
|
+
- `Chart`: `precision:` sets the decimals (0 for whole dollars), and
|
|
38
|
+
`show_data: false` leaves the table of numbers to screen readers. A pie
|
|
39
|
+
or donut sits beside its legend by its own width, not the window's, so it
|
|
40
|
+
fits a narrow card.
|
|
41
|
+
- `Checkbox` shows a dash when it's partly checked (`indeterminate`).
|
|
42
|
+
- Buttons, links, tabs, menu items, checkboxes, radios and switches show
|
|
43
|
+
their focus ring for the keyboard only (`:focus-visible`), not after a
|
|
44
|
+
mouse click. Text fields keep theirs on click.
|
|
45
|
+
- Fix: a collapsed `inset` or `floating` sidebar is wide enough for its
|
|
46
|
+
icons; they were clipped by the panel's padding.
|
|
47
|
+
- Fix: a class given to `Sidebar::Inset` replaces the one it clashes with
|
|
48
|
+
(`bg-transparent` for its background, `shadow-none` for its shadow). Both
|
|
49
|
+
used to land on the element and the inset's own often won.
|
|
50
|
+
|
|
51
|
+
Upgrading an app: re-run `velvetkit:add` for `sidebar`, `table`, `gallery`,
|
|
52
|
+
`chart` and `checkbox`. A sidebar that passed `collapsible: :icon` to start
|
|
53
|
+
collapsed now passes `state: :collapsed`; `collapsible: :none` now means it
|
|
54
|
+
can't collapse. The choice is kept in a cookie, not `localStorage`. The
|
|
55
|
+
sidebar is no longer `position: fixed`, so a `transform` added to keep it
|
|
56
|
+
inside a box can go; give the wrapper a height instead
|
|
57
|
+
(`class: "h-[calc(100svh-3rem)]"`). Phones get the drawer, so a sheet that
|
|
58
|
+
stood in for it can go too.
|
|
59
|
+
|
|
60
|
+
- Docs: two more examples. Helio, a dashboard at /examples/dashboard, is the
|
|
61
|
+
admin side of a software company: customers to search, filter, sort,
|
|
62
|
+
choose and act on in bulk, a page for each with its invoices, activity
|
|
63
|
+
and notes, and an overview whose numbers change with the period. Pinhole,
|
|
64
|
+
a photo library at /examples/photos, has highlights, photos by day, a date
|
|
65
|
+
scrubber, albums, an archive and a bin, and a viewer with an info panel.
|
|
66
|
+
|
|
67
|
+
- Docs: an Examples page, linked from the header, shows apps built with
|
|
68
|
+
VelvetKit. The first, Daily Goods, is a shop you can use at
|
|
69
|
+
/examples/store: a front page with categories, reviews and a newsletter
|
|
70
|
+
signup, filters (price, rating, colour, features) and sorting, a cart, and
|
|
71
|
+
a page for each product with photos, details and reviews, all without a
|
|
72
|
+
page reload. A sign-in flow is on the way.
|
|
73
|
+
|
|
74
|
+
- Fix: `Select` puts `aria-label` and `aria-labelledby` on its visible button.
|
|
75
|
+
They went on the hidden native select, which left the dropdown with no name
|
|
76
|
+
for screen readers. (#80)
|
|
77
|
+
|
|
78
|
+
Upgrading an app: `RadioGroup` and `ToggleGroup` now render through the new
|
|
79
|
+
`Fieldset`, so re-run `velvetkit:add radio_group toggle_group` to get it with
|
|
80
|
+
them. Without `legend:`, `hint:` or `error:` they render as before.
|
|
81
|
+
|
|
3
82
|
## 0.4.2 — 2026-11-09
|
|
4
83
|
|
|
5
84
|
Changes:
|
|
@@ -94,6 +173,8 @@ it as it is. `progress` needs the `velvetkit-progress` keyframes from the new
|
|
|
94
173
|
|
|
95
174
|
## 0.3.0 — 2026-11-03
|
|
96
175
|
|
|
176
|
+
New components:
|
|
177
|
+
|
|
97
178
|
- `Stepper`: the steps of a multi-step form, done, current or to come, with
|
|
98
179
|
dots, centred labels, panels moved between in the browser, and links back
|
|
99
180
|
to done steps.
|
|
@@ -103,33 +184,77 @@ it as it is. `progress` needs the `velvetkit-progress` keyframes from the new
|
|
|
103
184
|
radios or checkboxes.
|
|
104
185
|
- `EmptyState`: an icon, title, text and actions for a page with nothing to
|
|
105
186
|
list.
|
|
187
|
+
|
|
188
|
+
Changes:
|
|
189
|
+
|
|
106
190
|
- Icons come from Lucide, Tabler or Phosphor, chosen with
|
|
107
191
|
`velvetkit:install --icons=`, and are drawn as inline SVG.
|
|
108
192
|
|
|
109
193
|
## 0.2.2 — 2026-11-02
|
|
110
194
|
|
|
195
|
+
Changes:
|
|
196
|
+
|
|
111
197
|
- Fix: the `plus`, `search`, `ellipsis-vertical` and `grip-vertical` icons were
|
|
112
198
|
missing from installs.
|
|
113
199
|
|
|
114
200
|
## 0.2.1 — 2026-11-01
|
|
115
201
|
|
|
202
|
+
New components:
|
|
203
|
+
|
|
116
204
|
- `NavigationMenu`: site navigation with links and panels of rich links that
|
|
117
205
|
open on hover or click.
|
|
118
206
|
|
|
119
207
|
## 0.2.0 — 2026-11-01
|
|
120
208
|
|
|
209
|
+
New components:
|
|
210
|
+
|
|
121
211
|
- `Toast`: stacked messages that dismiss themselves.
|
|
122
212
|
- `SessionTabs`: tabs for open sessions, with a button to add one.
|
|
123
|
-
- `Skeleton
|
|
213
|
+
- `Skeleton`: a pulsing placeholder in a piece of content's shape while it
|
|
214
|
+
loads.
|
|
215
|
+
- `FileField`: a drag-and-drop file picker with a label, hint and error
|
|
216
|
+
message, standalone or with a form builder.
|
|
217
|
+
|
|
218
|
+
Changes:
|
|
219
|
+
|
|
124
220
|
- Fix: `Menu` content positions itself with the fixed strategy, so it isn't
|
|
125
221
|
clipped by a scrolling container.
|
|
126
222
|
- Fix: dependencies updated for security advisories in `addressable` and `rack`.
|
|
127
223
|
|
|
224
|
+
## 0.1.0 — 2026-10-29
|
|
225
|
+
|
|
226
|
+
New components:
|
|
227
|
+
|
|
228
|
+
- `FormField`: a label, a control, a hint and an error message in one. The
|
|
229
|
+
form controls take `hint:` and `error:` and wrap themselves in it.
|
|
230
|
+
- `Textarea`: a multi-line field that can grow with its text.
|
|
231
|
+
- `Collapsible`: a section that opens under its trigger.
|
|
232
|
+
- `TableOfContents`: an "On this page" list that highlights the section
|
|
233
|
+
being read.
|
|
234
|
+
|
|
235
|
+
Changes:
|
|
236
|
+
|
|
237
|
+
- The docs site has a Building forms guide.
|
|
238
|
+
- Fix: `NativeSelect` keeps the model's value when the form is rendered again.
|
|
239
|
+
- Fix: `InputGroup` shows its error border, and draws one focus ring at a time.
|
|
240
|
+
- Fix: `TableOfContents` doesn't animate its first highlight on page load.
|
|
241
|
+
|
|
128
242
|
## 0.1.0.beta — 2026-10-26
|
|
129
243
|
|
|
244
|
+
New components:
|
|
245
|
+
|
|
246
|
+
- 38 components, with their Stimulus controllers, tests and Lookbook
|
|
247
|
+
previews: `Accordion`, `Alert`, `Avatar`, `AvatarGroup`, `Badge`, `Banner`,
|
|
248
|
+
`Breadcrumb`, `Button`, `ButtonTo`, `Card`, `Checkbox`, `DataGrid`,
|
|
249
|
+
`DatePicker`, `Dialog`, `Divider`, `Icon`, `Image`, `Input`, `InputGroup`,
|
|
250
|
+
`Label`, `Link`, `Menu`, `NativeSelect`, `Pagination`, `PasswordInput`,
|
|
251
|
+
`Popover`, `RadioGroup`, `Select`, `Sheet`, `Sidebar`, `Spinner`, `Switch`,
|
|
252
|
+
`Table`, `Tabs`, `Text`, `ThemeToggle`, `Tooltip` and `Typography`.
|
|
253
|
+
|
|
254
|
+
Changes:
|
|
255
|
+
|
|
130
256
|
- First release of the component library.
|
|
131
257
|
- `velvetkit:install` and `velvetkit:add` generators, with a configurable namespace.
|
|
132
|
-
- 39 components, their Stimulus controllers, tests and Lookbook previews.
|
|
133
258
|
- `Select` is a styled dropdown (listbox, keyboard, type-ahead), with
|
|
134
259
|
`searchable:` and `multiple:`; it posts through a hidden native select, so
|
|
135
260
|
forms work unchanged. The browser's own control is now `NativeSelect`.
|
data/lib/velvetkit/version.rb
CHANGED
|
@@ -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.
|
|
7
|
+
VERSION = "0.5.0"
|
|
8
8
|
end
|
|
@@ -11,7 +11,7 @@ class UI::Accordion::Trigger < UI::Base
|
|
|
11
11
|
def classes
|
|
12
12
|
cn(
|
|
13
13
|
"group flex w-full items-center gap-3 py-2 text-sm font-medium transition-all hover:underline text-left text-primary",
|
|
14
|
-
"focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1 rounded",
|
|
14
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1 rounded",
|
|
15
15
|
"disabled:pointer-events-none disabled:opacity-50",
|
|
16
16
|
UI::Base::FOCUS_RING,
|
|
17
17
|
@user_class
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
class UI::Badge < UI::Base
|
|
4
4
|
variants(
|
|
5
|
-
base: "inline-flex items-center justify-center gap-1 rounded-full font-medium whitespace-nowrap border border-transparent transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1",
|
|
5
|
+
base: "inline-flex items-center justify-center gap-1 rounded-full font-medium whitespace-nowrap border border-transparent transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1",
|
|
6
6
|
variants: {
|
|
7
7
|
variant: {
|
|
8
8
|
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
@@ -9,8 +9,8 @@ class UI::Base < ViewComponent::Base
|
|
|
9
9
|
# includes it in its variant `base:` string. It shows on click as well as on
|
|
10
10
|
# Tab, and animates in. (The docs site keeps it on the clicked link across
|
|
11
11
|
# page visits, so a visit doesn't cut the animation off.)
|
|
12
|
-
FOCUS_RING = "transition-all focus:outline-none focus:ring-2 focus:ring-primary " \
|
|
13
|
-
"focus:ring-offset-1 ring-offset-background"
|
|
12
|
+
FOCUS_RING = "transition-all focus:outline-none focus-visible:ring-2 focus-visible:ring-primary " \
|
|
13
|
+
"focus-visible:ring-offset-1 ring-offset-background"
|
|
14
14
|
|
|
15
15
|
class_attribute :variant_config,
|
|
16
16
|
instance_writer: false,
|
|
@@ -21,7 +21,7 @@ class UI::Button < UI::Base
|
|
|
21
21
|
variants: {
|
|
22
22
|
variant: {
|
|
23
23
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
24
|
-
destructive: "bg-destructive text-white hover:bg-destructive/90 focus:ring-destructive",
|
|
24
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive",
|
|
25
25
|
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground " \
|
|
26
26
|
"disabled:border-input!",
|
|
27
27
|
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
@@ -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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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:` ("₹"). `
|
|
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,
|
|
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
|
|
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
|
|
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", { "
|
|
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:
|
|
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,8 +6,8 @@ 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 " \
|
|
10
|
-
"focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1 " \
|
|
9
|
+
"checked:bg-primary checked:border-primary indeterminate:bg-primary indeterminate:border-primary " \
|
|
10
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1 " \
|
|
11
11
|
"ring-offset-background",
|
|
12
12
|
variants: {
|
|
13
13
|
size: {
|
|
@@ -113,14 +113,21 @@ class UI::Checkbox < UI::Base
|
|
|
113
113
|
def classes
|
|
114
114
|
cn(
|
|
115
115
|
variant_classes(size: @size),
|
|
116
|
-
{ "border-destructive aria-invalid:focus:ring-destructive" => wrapper.error? },
|
|
116
|
+
{ "border-destructive aria-invalid:focus-visible:ring-destructive" => wrapper.error? },
|
|
117
117
|
@user_class
|
|
118
118
|
)
|
|
119
119
|
end
|
|
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
|
-
|
|
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
|
-
<%=
|
|
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 %>
|