velvetkit 0.5.0 → 0.6.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 +63 -18
- 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 +9 -4
- data/registry/app/components/ui/carousel.rb +42 -1
- data/registry/app/components/ui/checkbox.rb +2 -2
- data/registry/app/components/ui/file_tree/file_item.html.erb +9 -0
- data/registry/app/components/ui/file_tree/file_item.rb +50 -0
- data/registry/app/components/ui/file_tree/folder.html.erb +9 -0
- data/registry/app/components/ui/file_tree/folder.rb +76 -0
- data/registry/app/components/ui/file_tree.html.erb +1 -0
- data/registry/app/components/ui/file_tree.rb +93 -0
- data/registry/app/components/ui/gallery.rb +4 -4
- 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.rb +1 -1
- data/registry/app/components/ui/rating.html.erb +16 -0
- data/registry/app/components/ui/rating.rb +200 -0
- data/registry/app/components/ui/sidebar/group_label.rb +1 -1
- data/registry/app/components/ui/sidebar/menu_button.rb +1 -1
- data/registry/app/components/ui/sidebar/menu_item.rb +1 -1
- data/registry/app/components/ui/sidebar/menu_sub.rb +1 -1
- data/registry/app/components/ui/switch.rb +2 -2
- data/registry/app/components/ui/tabs/trigger.rb +1 -1
- data/registry/app/javascript/controllers/ui/carousel_controller.ts +59 -1
- data/registry/app/javascript/controllers/ui/file_tree_controller.ts +189 -0
- data/registry/app/javascript/controllers/ui/rating_controller.ts +117 -0
- data/registry/components.yml +4 -0
- data/registry/config/locales/velvetkit.en.yml +13 -0
- data/registry/test/components/previews/ui/carousel_preview/with_indicators.html.erb +10 -0
- data/registry/test/components/previews/ui/carousel_preview.rb +7 -3
- data/registry/test/components/previews/ui/file_tree_preview/changes.html.erb +13 -0
- data/registry/test/components/previews/ui/file_tree_preview/from_data.html.erb +14 -0
- data/registry/test/components/previews/ui/file_tree_preview/picking_a_file.html.erb +25 -0
- data/registry/test/components/previews/ui/file_tree_preview/without_guides.html.erb +10 -0
- data/registry/test/components/previews/ui/file_tree_preview.rb +41 -0
- data/registry/test/components/previews/ui/image_preview/radii.html.erb +3 -3
- data/registry/test/components/previews/ui/image_preview/sizing.html.erb +9 -4
- data/registry/test/components/previews/ui/image_preview.rb +14 -1
- data/registry/test/components/previews/ui/rating_preview/in_form.html.erb +6 -0
- data/registry/test/components/previews/ui/rating_preview/model_errors.html.erb +20 -0
- data/registry/test/components/previews/ui/rating_preview/playground.html.erb +5 -0
- data/registry/test/components/previews/ui/rating_preview/scores.html.erb +18 -0
- data/registry/test/components/previews/ui/rating_preview/sizes.html.erb +6 -0
- data/registry/test/components/previews/ui/rating_preview.rb +28 -0
- data/registry/test/components/ui/base_test.rb +27 -0
- data/registry/test/components/ui/button_test.rb +2 -2
- data/registry/test/components/ui/carousel_test.rb +48 -0
- data/registry/test/components/ui/confirm_dialog_test.rb +3 -0
- data/registry/test/components/ui/file_tree_test.rb +187 -0
- data/registry/test/components/ui/gallery_test.rb +4 -4
- 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/rating_test.rb +271 -0
- data/registry/test/components/ui/switch_test.rb +4 -4
- metadata +25 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f58f1baf403abebd06bdf86d3b4d50105df8d9090008223e4149ac250665be7
|
|
4
|
+
data.tar.gz: 9b6082b7cf5bd4aba2d3b53d16b71eeb8fd5a50a26331898e1b071124bc815cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dc24ae54b89853b665c072a637b019fe386432510c1d993e2721c8fc816905ea3c376e1952253f4b848f4b39a1652433f37636aacff276e74f7297feb4aaf366
|
|
7
|
+
data.tar.gz: de55253d2436e91ff6662492b5e09931ae2ce30bcc3fc636f2590872d06d6f8fc464760499235638777ef70153816496688ce09b6cee2c4d3249924af695e8a8
|
data/CHANGELOG.md
CHANGED
|
@@ -2,22 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.6.0 — 2026-11-23
|
|
6
|
+
|
|
7
|
+
New components:
|
|
8
|
+
|
|
9
|
+
- `FileTree`: folders and files in a tree that opens and closes, with arrow
|
|
10
|
+
keys to move through it.
|
|
11
|
+
- `Rating`: a score in stars, shown to the half star with its count, or chosen
|
|
12
|
+
with a radio for each star. A star grows under the pointer and pops when
|
|
13
|
+
chosen with the arrow keys; `show_value: true` shows the chosen score
|
|
14
|
+
beside a field, as "4/5", and `thanks: true` swaps the field's error for
|
|
15
|
+
"Thank you for your rating" once a score is chosen.
|
|
16
|
+
|
|
17
|
+
Changes:
|
|
18
|
+
|
|
19
|
+
- `Carousel`: indicators, with `indicators: true`: a dot for each place the
|
|
20
|
+
strip stops, the lit one following the scroll as you swipe, and a tap on
|
|
21
|
+
one scrolling to its card. They're off by default. (#102)
|
|
22
|
+
- Docs: the Image page's Radii and Sizing examples draw a photo that fills
|
|
23
|
+
its frame, so each radius and each width reads differently, and Radii adds
|
|
24
|
+
`xs`. (#105)
|
|
25
|
+
- Docs site: runs on Ruby 3.4.13, with `net-ssh` and `puma` updated, to clear
|
|
26
|
+
security advisories. (#103)
|
|
27
|
+
|
|
28
|
+
## 0.5.1 — 2026-11-15
|
|
29
|
+
|
|
30
|
+
Changes:
|
|
31
|
+
|
|
32
|
+
- Fix: the focus ring shows on click again, as well as on Tab. 0.5.0 moved
|
|
33
|
+
it to `:focus-visible`, so a click on a button, link, tab, menu item,
|
|
34
|
+
checkbox, radio, switch, sidebar link or gallery button drew no ring. (#95)
|
|
35
|
+
- Docs: an Upgrading guide at /docs/upgrading takes an app from 0.4 to 0.5
|
|
36
|
+
in one place: one `velvetkit:add` for every changed component, and the
|
|
37
|
+
sidebar's `collapsible:` and `state:` with before and after code. (#98)
|
|
38
|
+
- Docs: every guide and chart page is also Markdown, at the same address
|
|
39
|
+
with `.md`, and llms.txt links them. The upgrading guide and the release
|
|
40
|
+
notes can be copied as Markdown or opened in Claude or ChatGPT, and
|
|
41
|
+
llms-full.txt ends with both. (#100)
|
|
42
|
+
|
|
43
|
+
Upgrading an app: re-run `velvetkit:add` for `base`, `button`, `link`,
|
|
44
|
+
`badge`, `tabs`, `accordion`, `menu`, `checkbox`, `radio_group`, `switch`,
|
|
45
|
+
`sidebar` and `gallery`.
|
|
46
|
+
|
|
47
|
+
## 0.5.0 — 2026-11-15
|
|
48
|
+
|
|
5
49
|
New components:
|
|
6
50
|
|
|
7
51
|
- `Carousel`: a row of cards that swipes and scrolls sideways, each stopping
|
|
8
52
|
at the edge, with previous and next buttons that show only while there's
|
|
9
53
|
more to see that way.
|
|
10
54
|
- `SelectionBar`: "3 selected", a button to clear them and the actions for
|
|
11
|
-
all of them at once, over a
|
|
55
|
+
all of them at once, over a table with `selection:` or any list whose
|
|
12
56
|
boxes it can count. It keeps "select all" in step, Shift-click chooses a
|
|
13
57
|
run, and Escape clears. An "all" box inside a `data-selection-group`
|
|
14
58
|
chooses just that group, such as a day's photos.
|
|
15
59
|
- `Scrubber`: a rail down the side of a long list for jumping through it by
|
|
16
60
|
date, with years marked, the date under the pointer, dragging like a
|
|
17
61
|
scrollbar, and one tab stop whose arrow keys move between the marks.
|
|
62
|
+
- `Fieldset`: a group of controls under one legend, with a hint and an error
|
|
63
|
+
message for the group.
|
|
18
64
|
|
|
19
65
|
Changes:
|
|
20
66
|
|
|
67
|
+
- `RadioGroup` and `ToggleGroup` take `legend:`, `hint:` and `error:`,
|
|
68
|
+
through the new `Fieldset`. (#87)
|
|
21
69
|
- `Sidebar` is a drawer on phones, opened by the same trigger, with a
|
|
22
70
|
backdrop, Escape, and focus moved in and back. It sticks to the top and
|
|
23
71
|
fits the wrapper's height, so a bar above the app no longer pushes its
|
|
@@ -42,39 +90,36 @@ Changes:
|
|
|
42
90
|
- Buttons, links, tabs, menu items, checkboxes, radios and switches show
|
|
43
91
|
their focus ring for the keyboard only (`:focus-visible`), not after a
|
|
44
92
|
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
93
|
- Docs: two more examples. Helio, a dashboard at /examples/dashboard, is the
|
|
61
94
|
admin side of a software company: customers to search, filter, sort,
|
|
62
95
|
choose and act on in bulk, a page for each with its invoices, activity
|
|
63
96
|
and notes, and an overview whose numbers change with the period. Pinhole,
|
|
64
97
|
a photo library at /examples/photos, has highlights, photos by day, a date
|
|
65
98
|
scrubber, albums, an archive and a bin, and a viewer with an info panel.
|
|
66
|
-
|
|
67
99
|
- Docs: an Examples page, linked from the header, shows apps built with
|
|
68
100
|
VelvetKit. The first, Daily Goods, is a shop you can use at
|
|
69
101
|
/examples/store: a front page with categories, reviews and a newsletter
|
|
70
102
|
signup, filters (price, rating, colour, features) and sorting, a cart, and
|
|
71
103
|
a page for each product with photos, details and reviews, all without a
|
|
72
104
|
page reload. A sign-in flow is on the way.
|
|
73
|
-
|
|
105
|
+
- Fix: a collapsed `inset` or `floating` sidebar is wide enough for its
|
|
106
|
+
icons; they were clipped by the panel's padding.
|
|
107
|
+
- Fix: a class given to `Sidebar::Inset` replaces the one it clashes with
|
|
108
|
+
(`bg-transparent` for its background, `shadow-none` for its shadow). Both
|
|
109
|
+
used to land on the element and the inset's own often won.
|
|
74
110
|
- Fix: `Select` puts `aria-label` and `aria-labelledby` on its visible button.
|
|
75
111
|
They went on the hidden native select, which left the dropdown with no name
|
|
76
112
|
for screen readers. (#80)
|
|
77
113
|
|
|
114
|
+
Upgrading an app: re-run `velvetkit:add` for `sidebar`, `table`, `gallery`,
|
|
115
|
+
`chart` and `checkbox`. A sidebar that passed `collapsible: :icon` to start
|
|
116
|
+
collapsed now passes `state: :collapsed`; `collapsible: :none` now means it
|
|
117
|
+
can't collapse. The choice is kept in a cookie, not `localStorage`. The
|
|
118
|
+
sidebar is no longer `position: fixed`, so a `transform` added to keep it
|
|
119
|
+
inside a box can go; give the wrapper a height instead
|
|
120
|
+
(`class: "h-[calc(100svh-3rem)]"`). Phones get the drawer, so a sheet that
|
|
121
|
+
stood in for it can go too.
|
|
122
|
+
|
|
78
123
|
Upgrading an app: `RadioGroup` and `ToggleGroup` now render through the new
|
|
79
124
|
`Fieldset`, so re-run `velvetkit:add radio_group toggle_group` to get it with
|
|
80
125
|
them. Without `legend:`, `hint:` or `error:` they render as before.
|
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.6.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
|
|
14
|
+
"focus:outline-none focus:ring-2 focus:ring-primary focus: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
|
|
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",
|
|
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
|
|
13
|
-
"focus
|
|
12
|
+
FOCUS_RING = "transition-all focus:outline-none focus:ring-2 focus:ring-primary " \
|
|
13
|
+
"focus: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
|
|
24
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus: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",
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
<%= tag.div(**root_attrs) do %>
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
<div class="relative">
|
|
3
|
+
<%= tag.ul id: track_id, class: track_classes, data: { "ui--carousel-target": "track", action: "scroll->ui--carousel#update" } do %>
|
|
4
|
+
<% items.each do |item| %><%= tag.li item, class: item_classes %><% end %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<%= render(UI::Button.new(**button_attrs(:previous))) do %><%= render(UI::Icon.new(name: "chevron-left", size: :sm, class: "rtl:rotate-180")) %><% end %>
|
|
7
|
+
<%= render(UI::Button.new(**button_attrs(:next))) do %><%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "rtl:rotate-180")) %><% end %>
|
|
8
|
+
</div>
|
|
9
|
+
<% if indicators? %>
|
|
10
|
+
<%= tag.div(**indicators_attrs) do %><% items.each_index do |index| %><%= tag.button(**indicator_attrs(index)) do %><span aria-hidden="true" class="<%= UI::Carousel::INDICATOR_FILL %>"></span><% end %><% end %><% end %>
|
|
4
11
|
<% 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
12
|
<% end %>
|
|
@@ -13,13 +13,22 @@
|
|
|
13
13
|
# and next buttons scroll a strip's width at a time, and each shows only while
|
|
14
14
|
# there's more to see that way. `item_class:` sizes the cards ("w-64",
|
|
15
15
|
# "basis-1/3"); they're as wide as their content otherwise.
|
|
16
|
+
#
|
|
17
|
+
# `indicators: true` adds a row of indicators under the strip, a dot for each
|
|
18
|
+
# place it can stop, with the one in view lit. Each indicator scrolls to its
|
|
19
|
+
# card. They're the way through on a phone, where the buttons don't show.
|
|
20
|
+
# Without JavaScript the row is left empty, as the indicators couldn't scroll.
|
|
21
|
+
# (`dots: true`, what 0.6.0 called it, still works.)
|
|
22
|
+
#
|
|
23
|
+
# <%= render(UI::Carousel.new(label: "Featured", item_class: "basis-full", indicators: true)) do |carousel| %>
|
|
16
24
|
class UI::Carousel < UI::Base
|
|
17
25
|
renders_many :items
|
|
18
26
|
|
|
19
|
-
def initialize(label:, item_class: nil, gap: 3, class: nil, **html_attrs)
|
|
27
|
+
def initialize(label:, item_class: nil, gap: 3, indicators: false, dots: nil, class: nil, **html_attrs)
|
|
20
28
|
@label = label
|
|
21
29
|
@item_class = item_class
|
|
22
30
|
@gap = gap
|
|
31
|
+
@indicators = dots.nil? ? indicators : dots
|
|
23
32
|
@user_class = binding.local_variable_get(:class)
|
|
24
33
|
@html_attrs = html_attrs
|
|
25
34
|
end
|
|
@@ -56,5 +65,37 @@ class UI::Carousel < UI::Base
|
|
|
56
65
|
data: { action: "ui--carousel##{direction}", "ui--carousel-target": direction } }
|
|
57
66
|
end
|
|
58
67
|
|
|
68
|
+
def indicators? = @indicators
|
|
69
|
+
|
|
70
|
+
# The row keeps its height while the indicators start hidden, so the page
|
|
71
|
+
# doesn't move when the controller shows them.
|
|
72
|
+
def indicators_attrs
|
|
73
|
+
{ role: "group", class: "mt-4 flex h-2 flex-wrap items-center justify-center gap-2",
|
|
74
|
+
aria: { label: t("ui.carousel.indicators", default: "Choose a slide") } }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# An indicator for each card; the controller hides those past the last place
|
|
78
|
+
# the strip can stop, as they'd all scroll to the end. The indicator is a
|
|
79
|
+
# small dot, so its ::after reaches across the gap and a finger's height to
|
|
80
|
+
# be easy to tap.
|
|
81
|
+
#
|
|
82
|
+
# How lit an indicator is follows the scroll, the way the dots under a
|
|
83
|
+
# phone's home screen do: the controller sets `--fill` from 0 to 1 as its
|
|
84
|
+
# card comes into place, and the dot widens into a pill as its colour fills
|
|
85
|
+
# in. So there's no transition on either, which would trail behind a finger.
|
|
86
|
+
#
|
|
87
|
+
# An indicator draws no focus ring: the lit one already shows which card is
|
|
88
|
+
# in view, and a ring round a dot this small swamps it.
|
|
89
|
+
def indicator_attrs(index)
|
|
90
|
+
{ type: "button", hidden: true,
|
|
91
|
+
class: cn("relative h-2 w-[calc(0.5rem+1rem*var(--fill,0))] shrink-0 outline-none",
|
|
92
|
+
"cursor-pointer rounded-full bg-foreground/20 hover:bg-foreground/40",
|
|
93
|
+
"after:absolute after:-inset-x-1 after:-inset-y-2"),
|
|
94
|
+
aria: { label: t("ui.carousel.indicator", number: index + 1, default: "Go to slide %{number}"), controls: track_id },
|
|
95
|
+
data: { action: "ui--carousel#go", "ui--carousel-target": "indicator", "ui--carousel-index-param": index } }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
INDICATOR_FILL = "absolute inset-0 rounded-full bg-primary opacity-[var(--fill,0)]"
|
|
99
|
+
|
|
59
100
|
def track_id = @track_id ||= "carousel-#{SecureRandom.hex(4)}"
|
|
60
101
|
end
|
|
@@ -7,7 +7,7 @@ class UI::Checkbox < UI::Base
|
|
|
7
7
|
base: "peer appearance-none shrink-0 border border-input bg-background " \
|
|
8
8
|
"transition-all " \
|
|
9
9
|
"checked:bg-primary checked:border-primary indeterminate:bg-primary indeterminate:border-primary " \
|
|
10
|
-
"focus:outline-none focus
|
|
10
|
+
"focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1 " \
|
|
11
11
|
"ring-offset-background",
|
|
12
12
|
variants: {
|
|
13
13
|
size: {
|
|
@@ -113,7 +113,7 @@ class UI::Checkbox < UI::Base
|
|
|
113
113
|
def classes
|
|
114
114
|
cn(
|
|
115
115
|
variant_classes(size: @size),
|
|
116
|
-
{ "border-destructive aria-invalid:focus
|
|
116
|
+
{ "border-destructive aria-invalid:focus:ring-destructive" => wrapper.error? },
|
|
117
117
|
@user_class
|
|
118
118
|
)
|
|
119
119
|
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%= tag.li(role: "none") do %>
|
|
2
|
+
<%= content_tag(tag_name, **row_attrs) do %>
|
|
3
|
+
<%# Where a folder has its chevron, so file and folder icons line up. %>
|
|
4
|
+
<%= tag.span class: "size-4 shrink-0", aria: { hidden: true } %>
|
|
5
|
+
<%= render(UI::Icon.new(name: icon, size: :sm, class: "shrink-0 text-muted-foreground group-aria-selected/row:text-primary", aria: { hidden: true })) %>
|
|
6
|
+
<%= tag.span name, class: "min-w-0 flex-1 truncate" %>
|
|
7
|
+
<% if content? %><%= tag.span content, class: "shrink-0 text-xs font-normal text-muted-foreground" %><% end %>
|
|
8
|
+
<% end %>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# A file in a UI::FileTree, added with `with_file`. With `href:` it's a link,
|
|
4
|
+
# and `active: true` marks it as the page being shown (aria-current="page").
|
|
5
|
+
# Without one it's a row to pick: the tree selects it and dispatches
|
|
6
|
+
# `ui--file-tree:select` with its `value:` (its name if not given) and name.
|
|
7
|
+
# `active: true` starts it selected.
|
|
8
|
+
#
|
|
9
|
+
# The block is shown at the end of the row, for a little more about the file
|
|
10
|
+
# (a size, a "M" for modified).
|
|
11
|
+
class UI::FileTree::FileItem < UI::Base
|
|
12
|
+
attr_reader :name, :icon
|
|
13
|
+
|
|
14
|
+
def initialize(name:, href: nil, active: false, value: nil, icon: "file", class: nil, **html_attrs)
|
|
15
|
+
@name = name
|
|
16
|
+
@href = href
|
|
17
|
+
@active = active
|
|
18
|
+
@value = value || name
|
|
19
|
+
@icon = icon
|
|
20
|
+
@user_class = binding.local_variable_get(:class)
|
|
21
|
+
@html_attrs = html_attrs
|
|
22
|
+
@level = 1
|
|
23
|
+
@guides = true
|
|
24
|
+
@tabbable = false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Set by the tree or folder holding this file, before it draws it.
|
|
28
|
+
def place(level:, guides:, tabbable: false)
|
|
29
|
+
@level = level
|
|
30
|
+
@guides = guides
|
|
31
|
+
@tabbable = tabbable
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def active? = @active
|
|
35
|
+
def link? = @href.present?
|
|
36
|
+
def tag_name = link? ? :a : :span
|
|
37
|
+
|
|
38
|
+
def row_attrs
|
|
39
|
+
attrs = @html_attrs.except(:data, :aria)
|
|
40
|
+
attrs[:href] = @href if link?
|
|
41
|
+
attrs[:role] = "treeitem"
|
|
42
|
+
attrs[:tabindex] = @tabbable ? 0 : -1
|
|
43
|
+
attrs[:class] = cn(UI::FileTree::ROW, @user_class)
|
|
44
|
+
attrs[:aria] = { selected: @active.to_s, level: @level, current: ("page" if @active && link?) }
|
|
45
|
+
.compact.merge(@html_attrs[:aria] || {})
|
|
46
|
+
attrs[:data] = { slot: "file-tree-file", name: @name, value: @value, "ui--file-tree-target": "item" }
|
|
47
|
+
.merge(@html_attrs[:data] || {})
|
|
48
|
+
attrs
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<% rows = capture do %><% items.each do |item| %><%= item %><% end %><% end %>
|
|
2
|
+
<%= tag.li(role: "none") do %>
|
|
3
|
+
<%= tag.span(**row_attrs) do %>
|
|
4
|
+
<%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "shrink-0 text-muted-foreground transition-transform duration-350 ease-[cubic-bezier(0.32,0.72,0,1)] group-aria-expanded/row:rotate-90 motion-reduce:transition-none", aria: { hidden: true })) %>
|
|
5
|
+
<%= render(UI::Icon.new(name: icon, size: :sm, class: "shrink-0 text-primary/80 dark:text-primary", aria: { hidden: true })) %>
|
|
6
|
+
<%= tag.span name, class: "min-w-0 flex-1 truncate" %>
|
|
7
|
+
<% end %>
|
|
8
|
+
<%= tag.ul(rows, id: group_id, role: "group", hidden: !open?, data: { slot: "file-tree-group", state: open? ? "open" : "closed" }, class: group_classes) %>
|
|
9
|
+
<% end %>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# A folder in a UI::FileTree: a row that opens and closes the folders and
|
|
4
|
+
# files added to it with `with_folder` and `with_file`, or listed in
|
|
5
|
+
# `children:` as hashes (see UI::FileTree).
|
|
6
|
+
#
|
|
7
|
+
# `open:` nil (the default) opens it when it holds the `active:` file, so the
|
|
8
|
+
# current file is in view; true or false decides. `icon:` swaps the folder
|
|
9
|
+
# icon for another.
|
|
10
|
+
class UI::FileTree::Folder < UI::Base
|
|
11
|
+
# The guide is a line of its own and not a border, so that while the folder
|
|
12
|
+
# has focus it can start lower down, past the ring, rather than run into it.
|
|
13
|
+
# It sits inside the padding, where the overflow the animation clips to
|
|
14
|
+
# can't cut it in half.
|
|
15
|
+
GUIDE = "relative ms-[calc(1rem-0.5px)] ps-[calc(0.375rem+0.5px)] " \
|
|
16
|
+
"before:absolute before:inset-y-0 before:start-0 before:w-px before:bg-border " \
|
|
17
|
+
"before:transition-[top] peer-focus/row:before:top-1.5"
|
|
18
|
+
|
|
19
|
+
renders_many :items, types: {
|
|
20
|
+
folder: { renders: UI::FileTree::Folder, as: :folder },
|
|
21
|
+
file: { renders: UI::FileTree::FileItem, as: :file }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
attr_reader :name, :icon
|
|
25
|
+
|
|
26
|
+
def initialize(name:, open: nil, icon: "folder", children: nil, class: nil, **html_attrs)
|
|
27
|
+
@name = name
|
|
28
|
+
@open = open
|
|
29
|
+
@icon = icon
|
|
30
|
+
@children = children
|
|
31
|
+
@user_class = binding.local_variable_get(:class)
|
|
32
|
+
@html_attrs = html_attrs
|
|
33
|
+
@level = 1
|
|
34
|
+
@guides = true
|
|
35
|
+
@tabbable = false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Set by the tree or folder holding this one, before it draws it.
|
|
39
|
+
def place(level:, guides:, tabbable: false)
|
|
40
|
+
@level = level
|
|
41
|
+
@guides = guides
|
|
42
|
+
@tabbable = tabbable
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def before_render
|
|
46
|
+
UI::FileTree.add_entries(self, @children)
|
|
47
|
+
items.each { |item| item.place(level: @level + 1, guides: @guides) }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Known once the items are drawn, since a folder inside finds out then.
|
|
51
|
+
def active? = items.any?(&:active?)
|
|
52
|
+
def open? = @open.nil? ? active? : @open
|
|
53
|
+
|
|
54
|
+
def group_id
|
|
55
|
+
@group_id ||= @html_attrs[:id] ? "#{@html_attrs[:id]}-group" : "ui-file-tree-group-#{SecureRandom.hex(4)}"
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def row_attrs
|
|
59
|
+
attrs = @html_attrs.except(:data, :aria, :id)
|
|
60
|
+
attrs[:role] = "treeitem"
|
|
61
|
+
attrs[:tabindex] = @tabbable ? 0 : -1
|
|
62
|
+
attrs[:class] = cn(UI::FileTree::ROW, "peer/row", @user_class)
|
|
63
|
+
attrs[:aria] = { expanded: open?.to_s, level: @level, owns: group_id }.merge(@html_attrs[:aria] || {})
|
|
64
|
+
attrs[:data] = { slot: "file-tree-folder", name: @name, "ui--file-tree-target": "item" }
|
|
65
|
+
.merge(@html_attrs[:data] || {})
|
|
66
|
+
attrs
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Indented so a folder's rows start under its icon, with the guide line
|
|
70
|
+
# running down from the middle of its chevron. The space above the first
|
|
71
|
+
# row is its margin, not the group's padding: padding would hold the group
|
|
72
|
+
# open at that height until the closing animation ended, then let it drop.
|
|
73
|
+
def group_classes
|
|
74
|
+
cn("flex flex-col [&>li:first-child]:mt-1.5", UI::FileTree::GAP, @guides ? GUIDE : "ps-5.5")
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= tag.ul(**root_attrs) do %><% items.each do |item| %><%= item %><% end %><% end %>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Folders and files as a tree: a repository's source, a project's documents,
|
|
4
|
+
# the pages of a site. Folders open and close, and a file is a link or, with
|
|
5
|
+
# no `href:`, a row to pick.
|
|
6
|
+
#
|
|
7
|
+
# <%= render(UI::FileTree.new(label: "Project files")) do |tree| %>
|
|
8
|
+
# <% tree.with_folder(name: "app") do |app| %>
|
|
9
|
+
# <% app.with_folder(name: "models") do |models| %>
|
|
10
|
+
# <% models.with_file(name: "user.rb", href: blob_path("app/models/user.rb"), active: true) %>
|
|
11
|
+
# <% end %>
|
|
12
|
+
# <% end %>
|
|
13
|
+
# <% tree.with_file(name: "README.md", href: blob_path("README.md")) %>
|
|
14
|
+
# <% end %>
|
|
15
|
+
#
|
|
16
|
+
# Or from data, where a hash with `children:` is a folder and any other a
|
|
17
|
+
# file, taking the same options as UI::FileTree::Folder and
|
|
18
|
+
# UI::FileTree::FileItem:
|
|
19
|
+
#
|
|
20
|
+
# <%= render(UI::FileTree.new(items: [
|
|
21
|
+
# { name: "app", children: [ { name: "user.rb", value: "app/user.rb" } ] },
|
|
22
|
+
# { name: "README.md", value: "README.md" }
|
|
23
|
+
# ])) %>
|
|
24
|
+
#
|
|
25
|
+
# A folder holding the `active:` file starts open; `open:` decides it
|
|
26
|
+
# otherwise. Rows follow the WAI-ARIA tree pattern: one is in the tab order,
|
|
27
|
+
# Up and Down move between them, Right opens a folder and Left closes it or
|
|
28
|
+
# goes to its parent, and typing a letter jumps to the next name starting with
|
|
29
|
+
# it. Picking a file with no `href:` selects it and dispatches
|
|
30
|
+
# `ui--file-tree:select` with `{ value, name }`.
|
|
31
|
+
#
|
|
32
|
+
# A folder slides open and shut on the easing iOS uses for its sheets, and
|
|
33
|
+
# reverses smoothly if clicked again part way; with reduced motion asked for,
|
|
34
|
+
# it opens at once.
|
|
35
|
+
#
|
|
36
|
+
# `guides: false` drops the line down the side of each open folder.
|
|
37
|
+
class UI::FileTree < UI::Base
|
|
38
|
+
# Every row, folder or file. A treeitem is the row itself, so the focus ring
|
|
39
|
+
# and the selection are drawn on the row and not round a whole folder.
|
|
40
|
+
# --primary is too dark to read as text on the dark surface, so in dark the
|
|
41
|
+
# selected row keeps its tint and icon but not its text colour.
|
|
42
|
+
ROW = "group/row flex h-7 w-full min-w-0 cursor-pointer select-none items-center gap-1.5 rounded-md px-2 " \
|
|
43
|
+
"text-sm text-foreground hover:bg-accent hover:text-accent-foreground " \
|
|
44
|
+
"aria-selected:bg-primary/10 aria-selected:font-medium aria-selected:text-primary " \
|
|
45
|
+
"aria-selected:hover:bg-primary/15 aria-selected:hover:text-primary " \
|
|
46
|
+
"dark:aria-selected:bg-primary/20 dark:aria-selected:text-foreground " \
|
|
47
|
+
"dark:aria-selected:hover:bg-primary/25 dark:aria-selected:hover:text-foreground " \
|
|
48
|
+
"#{UI::Base::FOCUS_RING}".freeze
|
|
49
|
+
|
|
50
|
+
# Between rows, and between a folder and its first row. The focus ring
|
|
51
|
+
# reaches 3px past its row (2px ring, 1px offset), so this leaves as much
|
|
52
|
+
# again before the next row's hover.
|
|
53
|
+
GAP = "gap-1.5"
|
|
54
|
+
|
|
55
|
+
renders_many :items, types: {
|
|
56
|
+
folder: { renders: UI::FileTree::Folder, as: :folder },
|
|
57
|
+
file: { renders: UI::FileTree::FileItem, as: :file }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# Adds a row to `branch` (the tree or a folder) for each hash in `entries`.
|
|
61
|
+
def self.add_entries(branch, entries)
|
|
62
|
+
Array(entries).each do |entry|
|
|
63
|
+
entry = entry.to_h.symbolize_keys
|
|
64
|
+
entry.key?(:children) ? branch.with_folder(**entry) : branch.with_file(**entry)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def initialize(items: nil, label: nil, guides: true, class: nil, **html_attrs)
|
|
69
|
+
@entries = items
|
|
70
|
+
@label = label
|
|
71
|
+
@guides = guides
|
|
72
|
+
@user_class = binding.local_variable_get(:class)
|
|
73
|
+
@html_attrs = html_attrs
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def before_render
|
|
77
|
+
UI::FileTree.add_entries(self, @entries)
|
|
78
|
+
items.each_with_index { |item, index| item.place(level: 1, guides: @guides, tabbable: index.zero?) }
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def root_attrs
|
|
82
|
+
attrs = @html_attrs.except(:data, :aria)
|
|
83
|
+
attrs[:role] = "tree"
|
|
84
|
+
attrs[:class] = cn("flex w-full flex-col #{GAP}", @user_class)
|
|
85
|
+
attrs[:aria] = { label: @label || t("ui.file_tree.label", default: "Files") }.merge(@html_attrs[:aria] || {})
|
|
86
|
+
attrs[:data] = {
|
|
87
|
+
slot: "file-tree",
|
|
88
|
+
controller: "ui--file-tree",
|
|
89
|
+
action: "click->ui--file-tree#click keydown->ui--file-tree#keydown"
|
|
90
|
+
}.merge(@html_attrs[:data] || {})
|
|
91
|
+
attrs
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -59,7 +59,7 @@ class UI::Gallery < UI::Base
|
|
|
59
59
|
# Always light on the dark backdrop, whatever the page's theme, ring included.
|
|
60
60
|
# The border keeps them in sight on a dark page, where the backdrop is black too.
|
|
61
61
|
OVERLAY_BUTTON = "rounded-full border border-white/25 bg-black/60 text-white hover:bg-black/80 hover:text-white " \
|
|
62
|
-
"focus
|
|
62
|
+
"focus:ring-white disabled:bg-black/60! disabled:text-white/50!"
|
|
63
63
|
|
|
64
64
|
renders_many :images, UI::Gallery::Image
|
|
65
65
|
|
|
@@ -85,8 +85,8 @@ class UI::Gallery < UI::Base
|
|
|
85
85
|
def trigger(index, class: nil, **html_attrs, &block)
|
|
86
86
|
image = images[index]
|
|
87
87
|
tag.button(type: "button", **html_attrs,
|
|
88
|
-
class: cn("group/trigger relative block cursor-zoom-in overflow-hidden focus:outline-none focus
|
|
89
|
-
"focus
|
|
88
|
+
class: cn("group/trigger relative block cursor-zoom-in overflow-hidden focus:outline-none focus:ring-2 " \
|
|
89
|
+
"focus:ring-primary focus:ring-offset-2 ring-offset-background",
|
|
90
90
|
binding.local_variable_get(:class)),
|
|
91
91
|
aria: { label: phrase(t("ui.gallery.open", default: "Open %{alt}"), alt: image&.alt), haspopup: "dialog" },
|
|
92
92
|
data: { action: "ui--gallery#open", "ui--gallery-index-param": index, "ui--gallery-target": "trigger" }) do
|
|
@@ -126,7 +126,7 @@ class UI::Gallery < UI::Base
|
|
|
126
126
|
# One tab stop for the strip: the image showing. The rest are out of sight.
|
|
127
127
|
{ type: "button", tabindex: index.zero? ? 0 : -1,
|
|
128
128
|
class: cn("group/slide relative block size-full rounded-lg transition-all focus:outline-none",
|
|
129
|
-
"focus
|
|
129
|
+
"focus:ring-2 focus:ring-inset focus:ring-primary", hover_zoom? ? "cursor-crosshair" : "cursor-zoom-in"),
|
|
130
130
|
aria: { label: phrase(t("ui.gallery.zoom", default: "Zoom image %{current}: %{alt}"), current: index + 1, alt: image.alt),
|
|
131
131
|
haspopup: "dialog" },
|
|
132
132
|
data: { action: slide_action, "ui--gallery-index-param": index } }
|
|
@@ -14,7 +14,7 @@ class UI::Link < UI::Base
|
|
|
14
14
|
variant: {
|
|
15
15
|
link: "text-primary underline-offset-4 hover:underline",
|
|
16
16
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
17
|
-
destructive: "bg-destructive text-white hover:bg-destructive/90 focus
|
|
17
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus:ring-destructive",
|
|
18
18
|
outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
|
|
19
19
|
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
20
20
|
ghost: "hover:bg-accent hover:text-accent-foreground"
|
|
@@ -5,7 +5,7 @@ class UI::Menu::Item < UI::Base
|
|
|
5
5
|
base:
|
|
6
6
|
"relative flex cursor-default select-none items-center gap-2 rounded w-full px-2 py-1 text-sm whitespace-nowrap border-0 bg-transparent outline-none transition-colors " \
|
|
7
7
|
"hover:bg-accent hover:text-accent-foreground " \
|
|
8
|
-
"focus:bg-accent focus:text-accent-foreground focus
|
|
8
|
+
"focus:bg-accent focus:text-accent-foreground focus:ring-2 focus:ring-ring focus:ring-offset-1 " \
|
|
9
9
|
"aria-checked:bg-accent aria-checked:text-accent-foreground aria-checked:font-medium " \
|
|
10
10
|
"data-[disabled]:pointer-events-none data-[disabled]:opacity-50 transition-all",
|
|
11
11
|
variants: {
|
|
@@ -5,7 +5,7 @@ class UI::RadioGroup::Item < UI::Base
|
|
|
5
5
|
base: "peer appearance-none shrink-0 rounded-full border border-input bg-background " \
|
|
6
6
|
"transition-all " \
|
|
7
7
|
"checked:bg-primary checked:border-primary " \
|
|
8
|
-
"focus:outline-none focus
|
|
8
|
+
"focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1 " \
|
|
9
9
|
"ring-offset-background",
|
|
10
10
|
variants: {
|
|
11
11
|
size: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<% if input? %><% row = capture do %><%= tag.div(**stars_attrs) do %><% 1.upto(max * 2) do |step| %><% value = option_value(step) %><%= tag.input(type: "radio", id: option_id(value), name: input_name, value: value, checked: chosen_steps == step, required: required?, disabled: disabled?, class: "sr-only", data: { action: "change->ui--rating#choose" }) %><%= tag.label(for: option_id(value), class: star_classes(step), data: { "ui--rating-target": "star", value: value, score: (score_text(Float(value)) if show_value?), action: "mouseenter->ui--rating#preview" }.compact) do %><span aria-hidden="true" class="pointer-events-none absolute inset-0 overflow-hidden"><span class="<%= star_icon_classes(step) %>"><%= render(UI::Icon.new(name: icon, class: "fill-current")) %></span></span><span class="sr-only"><%= option_label(value) %></span><% end %><% end %><% end %><% end %><% stars = capture do %><% if show_value? %><%= tag.div(class: "flex items-center gap-1.5") do %><%= row %><%= tag.output(score_label, id: score_id, aria: { hidden: true }, class: "text-sm font-medium tabular-nums") %><% end %><% else %><%= row %><% end %><% if thanks? %><%= tag.p(thanks_text, id: thanks_id, hidden: true, role: "status", class: "text-xs text-emerald-600 dark:text-emerald-400") %><% end %><% end %><% if fieldset.wrap? %><%= render(fieldset) { stars } %><% else %><%= stars %><% end %><% else %><%= tag.span(**display_attrs) do %>
|
|
2
|
+
<span role="img" aria-label="<%= image_label %>" class="<%= variant_classes(size: @size) %>">
|
|
3
|
+
<% fills.each do |fill| %>
|
|
4
|
+
<% if fill == :half %>
|
|
5
|
+
<span class="relative inline-flex <%= UI::Rating::OFF %>">
|
|
6
|
+
<%= render(UI::Icon.new(name: icon, class: "fill-current")) %>
|
|
7
|
+
<span class="absolute inset-y-0 start-0 flex w-1/2 overflow-hidden <%= UI::Rating::ON %>"><%= render(UI::Icon.new(name: icon, class: "fill-current")) %></span>
|
|
8
|
+
</span>
|
|
9
|
+
<% else %>
|
|
10
|
+
<%= render(UI::Icon.new(name: icon, class: class_names("fill-current", fill == :full ? UI::Rating::ON : UI::Rating::OFF))) %>
|
|
11
|
+
<% end %>
|
|
12
|
+
<% end %>
|
|
13
|
+
</span>
|
|
14
|
+
<% if show_value? %><span class="font-medium tabular-nums" aria-hidden="true"><%= formatted_score %></span><% end %>
|
|
15
|
+
<% if count? %><span class="text-muted-foreground"><span aria-hidden="true">(<%= formatted_count %>)</span><span class="sr-only"><%= count_label %></span></span><% end %>
|
|
16
|
+
<% end %><% end %>
|