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
|
@@ -31,6 +31,20 @@
|
|
|
31
31
|
# `aspect:` is :square, :landscape or :portrait, and `fit:` is :contain (the whole
|
|
32
32
|
# photo) or :cover (fills the frame, cropping). A single image gets no thumbnails
|
|
33
33
|
# or arrows.
|
|
34
|
+
#
|
|
35
|
+
# `strip: false` leaves out the large image and thumbnails, for a page that
|
|
36
|
+
# shows the images its own way, such as a grid of photos. Anything made with
|
|
37
|
+
# `gallery.trigger(index)` opens that image in the overlay, and previous and
|
|
38
|
+
# next go through all of them:
|
|
39
|
+
#
|
|
40
|
+
# <%= render(UI::Gallery.new(strip: false, label: "Photos")) do |gallery| %>
|
|
41
|
+
# <% @photos.each { |photo| gallery.with_image(src: photo.url, alt: photo.alt) } %>
|
|
42
|
+
# <div class="grid grid-cols-4 gap-1">
|
|
43
|
+
# <% @photos.each_with_index do |photo, index| %>
|
|
44
|
+
# <%= gallery.trigger(index, class: "aspect-square") { image_tag(photo.thumb_url, alt: "") } %>
|
|
45
|
+
# <% end %>
|
|
46
|
+
# </div>
|
|
47
|
+
# <% end %>
|
|
34
48
|
class UI::Gallery < UI::Base
|
|
35
49
|
ASPECTS = { square: "aspect-square", landscape: "aspect-video", portrait: "aspect-[4/5]" }.freeze
|
|
36
50
|
FITS = { contain: "object-contain", cover: "object-cover" }.freeze
|
|
@@ -45,12 +59,13 @@ class UI::Gallery < UI::Base
|
|
|
45
59
|
# Always light on the dark backdrop, whatever the page's theme, ring included.
|
|
46
60
|
# The border keeps them in sight on a dark page, where the backdrop is black too.
|
|
47
61
|
OVERLAY_BUTTON = "rounded-full border border-white/25 bg-black/60 text-white hover:bg-black/80 hover:text-white " \
|
|
48
|
-
"focus:ring-white disabled:bg-black/60! disabled:text-white/50!"
|
|
62
|
+
"focus-visible:ring-white disabled:bg-black/60! disabled:text-white/50!"
|
|
49
63
|
|
|
50
64
|
renders_many :images, UI::Gallery::Image
|
|
51
65
|
|
|
52
|
-
def initialize(label: nil, aspect: :square, fit: :contain, zoom: :overlay, zoom_scale: 2.5, class: nil, **html_attrs)
|
|
66
|
+
def initialize(label: nil, aspect: :square, fit: :contain, zoom: :overlay, zoom_scale: 2.5, strip: true, class: nil, **html_attrs)
|
|
53
67
|
@label = label
|
|
68
|
+
@strip = strip
|
|
54
69
|
@aspect = ASPECTS.key?(aspect.to_sym) ? aspect.to_sym : :square
|
|
55
70
|
@fit = FITS.key?(fit.to_sym) ? fit.to_sym : :contain
|
|
56
71
|
@zoom = ZOOMS.include?(zoom.to_sym) ? zoom.to_sym : :overlay
|
|
@@ -61,12 +76,36 @@ class UI::Gallery < UI::Base
|
|
|
61
76
|
|
|
62
77
|
def render? = images.any?
|
|
63
78
|
def multiple? = images.size > 1
|
|
64
|
-
def
|
|
79
|
+
def strip? = @strip
|
|
80
|
+
def hover_zoom? = @zoom == :hover && strip?
|
|
81
|
+
def info? = images.any?(&:info?)
|
|
82
|
+
|
|
83
|
+
# A button that opens image `index` in the overlay. Its own image, if it has
|
|
84
|
+
# one, is where the overlay grows from and shrinks back to.
|
|
85
|
+
def trigger(index, class: nil, **html_attrs, &block)
|
|
86
|
+
image = images[index]
|
|
87
|
+
tag.button(type: "button", **html_attrs,
|
|
88
|
+
class: cn("group/trigger relative block cursor-zoom-in overflow-hidden focus:outline-none focus-visible:ring-2 " \
|
|
89
|
+
"focus-visible:ring-primary focus-visible:ring-offset-2 ring-offset-background",
|
|
90
|
+
binding.local_variable_get(:class)),
|
|
91
|
+
aria: { label: phrase(t("ui.gallery.open", default: "Open %{alt}"), alt: image&.alt), haspopup: "dialog" },
|
|
92
|
+
data: { action: "ui--gallery#open", "ui--gallery-index-param": index, "ui--gallery-target": "trigger" }) do
|
|
93
|
+
capture(&block) if block
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def info_toggle_attrs
|
|
98
|
+
{ variant: :ghost, size: :icon, class: cn(OVERLAY_BUTTON, "aria-expanded:bg-white aria-expanded:text-black aria-expanded:hover:bg-white/90"),
|
|
99
|
+
aria: { label: t("ui.gallery.info", default: "Info"), expanded: "false", controls: info_id },
|
|
100
|
+
data: { action: "ui--gallery#toggleInfo", "ui--gallery-target": "infoToggle" } }
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def info_id = @info_id ||= "gallery-info-#{SecureRandom.hex(4)}"
|
|
65
104
|
|
|
66
105
|
def root_attrs
|
|
67
106
|
attrs = @html_attrs.except(:data, :aria)
|
|
68
107
|
attrs[:role] = "group"
|
|
69
|
-
attrs[:class] = cn("flex w-full min-w-0 flex-col gap-3", @user_class)
|
|
108
|
+
attrs[:class] = cn(strip? ? "flex w-full min-w-0 flex-col gap-3" : "block min-w-0", @user_class)
|
|
70
109
|
attrs[:aria] = { label: label, roledescription: t("ui.gallery.roledescription", default: "gallery") }
|
|
71
110
|
.merge(@html_attrs[:aria] || {})
|
|
72
111
|
attrs[:data] = { slot: "gallery", controller: "ui--gallery", zoom: @zoom,
|
|
@@ -87,7 +126,7 @@ class UI::Gallery < UI::Base
|
|
|
87
126
|
# One tab stop for the strip: the image showing. The rest are out of sight.
|
|
88
127
|
{ type: "button", tabindex: index.zero? ? 0 : -1,
|
|
89
128
|
class: cn("group/slide relative block size-full rounded-lg transition-all focus:outline-none",
|
|
90
|
-
"focus:ring-2 focus:ring-inset focus:ring-primary", hover_zoom? ? "cursor-crosshair" : "cursor-zoom-in"),
|
|
129
|
+
"focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary", hover_zoom? ? "cursor-crosshair" : "cursor-zoom-in"),
|
|
91
130
|
aria: { label: phrase(t("ui.gallery.zoom", default: "Zoom image %{current}: %{alt}"), current: index + 1, alt: image.alt),
|
|
92
131
|
haspopup: "dialog" },
|
|
93
132
|
data: { action: slide_action, "ui--gallery-index-param": index } }
|
|
@@ -96,7 +135,7 @@ class UI::Gallery < UI::Base
|
|
|
96
135
|
# Covers the window with nothing of its own: only the image and its buttons sit
|
|
97
136
|
# on the backdrop.
|
|
98
137
|
def dialog_classes
|
|
99
|
-
"m-0 size-full max-h-none max-w-none overflow-hidden bg-transparent p-0 outline-none backdrop:bg-black/80"
|
|
138
|
+
"group/dialog m-0 size-full max-h-none max-w-none overflow-hidden bg-transparent p-0 outline-none backdrop:bg-black/80"
|
|
100
139
|
end
|
|
101
140
|
|
|
102
141
|
def viewport_classes
|
|
@@ -129,7 +168,7 @@ class UI::Gallery < UI::Base
|
|
|
129
168
|
end
|
|
130
169
|
|
|
131
170
|
def overlay_nav_attrs(direction)
|
|
132
|
-
edge = direction == :previous ? "start-4" : "end-4"
|
|
171
|
+
edge = direction == :previous ? "start-4" : "end-4 sm:group-data-[info]/dialog:end-84"
|
|
133
172
|
{ variant: :ghost, size: :icon,
|
|
134
173
|
class: cn(OVERLAY_BUTTON, "absolute top-1/2 z-10 -translate-y-1/2", edge),
|
|
135
174
|
aria: { label: nav_label(direction) }, data: { action: "ui--gallery##{direction}" } }
|
|
@@ -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:ring-destructive",
|
|
17
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible: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:ring-2 focus:ring-ring focus:ring-offset-1 " \
|
|
8
|
+
"focus:bg-accent focus:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible: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: {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<%= tag.span class: dot_size_class + " rounded-full bg-primary-foreground" %>
|
|
7
7
|
<% end %>
|
|
8
8
|
<% end %>
|
|
9
|
-
<%= tag.span class: label_text_classes do %><%= label %><% if
|
|
9
|
+
<%= tag.span class: label_text_classes do %><%= label %><% if required_mark? %><%= tag.span(" *", class: "text-destructive ml-0.5") %><% end %><% end %>
|
|
10
10
|
<% end %>
|
|
11
11
|
<% else %>
|
|
12
12
|
<%= tag.span class: "relative inline-flex" do %>
|
|
@@ -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:ring-2 focus:ring-primary focus:ring-offset-1 " \
|
|
8
|
+
"focus:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1 " \
|
|
9
9
|
"ring-offset-background",
|
|
10
10
|
variants: {
|
|
11
11
|
size: {
|
|
@@ -38,6 +38,9 @@ class UI::RadioGroup::Item < UI::Base
|
|
|
38
38
|
def disabled?; @disabled; end
|
|
39
39
|
def required?; @group_required; end
|
|
40
40
|
|
|
41
|
+
# A legend marks the whole group required, so its items don't repeat it.
|
|
42
|
+
def required_mark?; @group_required && !@group_legend; end
|
|
43
|
+
|
|
41
44
|
def input_options
|
|
42
45
|
opts = @html_attrs.dup
|
|
43
46
|
opts[:type] = :radio
|
|
@@ -87,6 +90,7 @@ class UI::RadioGroup::Item < UI::Base
|
|
|
87
90
|
@group_name = group.name
|
|
88
91
|
@group_value = group.value
|
|
89
92
|
@group_required = group.required?
|
|
93
|
+
@group_legend = group.fieldset.legend?
|
|
90
94
|
@group_disabled = group.disabled?
|
|
91
95
|
@size ||= group.size
|
|
92
96
|
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
<% group = capture do %><%= tag.div(**group_attrs) do %><% items.each do |item| %><%= render item %><% end %><% end %><% end %><% if fieldset.wrap? %><%= render(fieldset) { group } %><% else %><%= group %><% end %>
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# A set of radio buttons. Give it a `legend:` (and a `hint:` or `error:`) and
|
|
4
|
+
# it renders through UI::Fieldset: a <fieldset role="radiogroup"> named by its
|
|
5
|
+
# legend, around the radios. Bind it to a form builder with `form:` and
|
|
6
|
+
# `field:`, and the model's errors on that attribute show on their own;
|
|
7
|
+
# `legend: true` then uses the attribute's name.
|
|
3
8
|
class UI::RadioGroup < UI::Base
|
|
4
9
|
renders_many :items, ->(value:, **opts) {
|
|
5
10
|
item = UI::RadioGroup::Item.new(value: value, **opts)
|
|
@@ -9,12 +14,19 @@ class UI::RadioGroup < UI::Base
|
|
|
9
14
|
|
|
10
15
|
def initialize(name: nil, value: nil, size: :default,
|
|
11
16
|
required: false, disabled: false,
|
|
17
|
+
legend: nil, hint: nil, error: nil,
|
|
18
|
+
form: nil, field: nil,
|
|
12
19
|
class: nil, **html_attrs)
|
|
13
20
|
@name = name
|
|
14
21
|
@value = value
|
|
15
22
|
@size = size
|
|
16
23
|
@required = required
|
|
17
24
|
@disabled = disabled
|
|
25
|
+
@legend = legend
|
|
26
|
+
@hint = hint
|
|
27
|
+
@error = error
|
|
28
|
+
@form = form
|
|
29
|
+
@field = field
|
|
18
30
|
@user_class = binding.local_variable_get(:class)
|
|
19
31
|
@html_attrs = html_attrs
|
|
20
32
|
end
|
|
@@ -27,9 +39,37 @@ class UI::RadioGroup < UI::Base
|
|
|
27
39
|
@html_attrs[:id] || "ui-rg-#{SecureRandom.hex(4)}"
|
|
28
40
|
end
|
|
29
41
|
|
|
42
|
+
# The legend shows only when given: a bound group that's never been named
|
|
43
|
+
# doesn't grow one when it has an error.
|
|
44
|
+
def fieldset
|
|
45
|
+
@fieldset ||= UI::Fieldset.new(legend: @legend.presence || false, hint: @hint, error: @error,
|
|
46
|
+
form: @form, field: @field,
|
|
47
|
+
required: @required, disabled: @disabled,
|
|
48
|
+
role: "radiogroup", aria: @html_attrs[:aria])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Inside a fieldset, the fieldset has the role and the aria attributes that
|
|
52
|
+
# name and describe the group; the radios' container keeps the rest.
|
|
53
|
+
def group_attrs
|
|
54
|
+
wrapped = fieldset.wrap?
|
|
55
|
+
attrs = wrapped ? @html_attrs.except(:id, :aria) : @html_attrs.except(:id)
|
|
56
|
+
{ role: ("radiogroup" unless wrapped), id: group_id, class: classes, **attrs }
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def form_field? = @form.present? && @field.present?
|
|
60
|
+
|
|
30
61
|
def required?; @required; end
|
|
31
62
|
def disabled?; @disabled; end
|
|
32
|
-
def name; @name; end
|
|
33
|
-
def value; @value; end
|
|
34
63
|
def size; @size; end
|
|
64
|
+
|
|
65
|
+
def name
|
|
66
|
+
form_field? ? "#{@form.object_name}[#{@field}]" : @name
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# As a string, since each item compares it with its own value as one.
|
|
70
|
+
def value
|
|
71
|
+
value = @value
|
|
72
|
+
value = @form.object.public_send(@field) if value.nil? && form_field? && @form.object.respond_to?(@field)
|
|
73
|
+
value&.to_s
|
|
74
|
+
end
|
|
35
75
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<%= tag.nav(**root_attrs) do %>
|
|
2
|
+
<%= tag.div class: "absolute inset-y-3 inset-x-0 cursor-ns-resize",
|
|
3
|
+
data: { "ui--scrubber-target": "rail",
|
|
4
|
+
action: "pointerdown->ui--scrubber#grab pointermove->ui--scrubber#point pointerup->ui--scrubber#release " \
|
|
5
|
+
"pointercancel->ui--scrubber#release pointerleave->ui--scrubber#leave" } do %>
|
|
6
|
+
<ol>
|
|
7
|
+
<% marks.each_with_index do |mark, index| %>
|
|
8
|
+
<li><%= tag.a(**mark_attrs(mark, index)) do %><% if mark.major %><%= mark.major %><% else %><span class="size-1 rounded-full bg-muted-foreground/40"></span><% end %><% end %></li>
|
|
9
|
+
<% end %>
|
|
10
|
+
</ol>
|
|
11
|
+
<%= tag.div aria: { hidden: true }, data: { "ui--scrubber-target": "thumb" },
|
|
12
|
+
class: "pointer-events-none absolute end-0 top-0 h-0.5 w-7 -translate-y-1/2 rounded-full bg-primary invisible group-data-[ready]/scrubber:visible" %>
|
|
13
|
+
<%= tag.div aria: { hidden: true }, data: { "ui--scrubber-target": "tip" },
|
|
14
|
+
class: "pointer-events-none absolute end-full top-0 me-1 -translate-y-1/2 whitespace-nowrap rounded-md border bg-popover px-2 py-1 " \
|
|
15
|
+
"text-xs font-medium text-popover-foreground shadow-md invisible opacity-0 transition-opacity duration-100 " \
|
|
16
|
+
"data-[shown]:visible data-[shown]:opacity-100 motion-reduce:transition-none" %>
|
|
17
|
+
<% end %>
|
|
18
|
+
<% end %>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# A rail down the side of a long list for jumping through it by date: the
|
|
4
|
+
# years marked on it, a dot for each month, and the date under the pointer.
|
|
5
|
+
#
|
|
6
|
+
# <%= render(UI::Scrubber.new(label: "Jump to a date", for: "library", class: "fixed inset-y-16 end-0")) do |scrubber| %>
|
|
7
|
+
# <% @months.each do |month| %>
|
|
8
|
+
# <% scrubber.with_mark(href: "##{month.id}", label: month.name, major: (month.year if month.january?)) %>
|
|
9
|
+
# <% end %>
|
|
10
|
+
# <% end %>
|
|
11
|
+
#
|
|
12
|
+
# Each mark is a link to a heading in the list (`href: "#march-2026"`), placed
|
|
13
|
+
# on the rail as far down as that heading is in the list, so a busy month takes
|
|
14
|
+
# more of the rail. `major:` is the text shown beside the mark, such as the
|
|
15
|
+
# year; the others are dots. A line follows how far down the list is.
|
|
16
|
+
#
|
|
17
|
+
# Dragging along the rail scrolls the list with it, the way a scrollbar does,
|
|
18
|
+
# with the date under the pointer beside it. From the keyboard it's one stop:
|
|
19
|
+
# ↑ and ↓ move between the marks, Home and End to the ends, and Enter goes
|
|
20
|
+
# there. `for:` is the id of the element that scrolls, or the window when
|
|
21
|
+
# it's left out.
|
|
22
|
+
class UI::Scrubber < UI::Base
|
|
23
|
+
Mark = Struct.new(:href, :label, :major, keyword_init: true)
|
|
24
|
+
|
|
25
|
+
def initialize(label:, for: nil, class: nil, **html_attrs)
|
|
26
|
+
@label = label
|
|
27
|
+
@for = binding.local_variable_get(:for)
|
|
28
|
+
@user_class = binding.local_variable_get(:class)
|
|
29
|
+
@html_attrs = html_attrs
|
|
30
|
+
@marks = []
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
attr_reader :marks
|
|
34
|
+
|
|
35
|
+
def with_mark(href:, label:, major: nil)
|
|
36
|
+
@marks << Mark.new(href: href, label: label, major: major)
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def before_render = content
|
|
41
|
+
|
|
42
|
+
def render? = true
|
|
43
|
+
|
|
44
|
+
def root_attrs
|
|
45
|
+
attrs = @html_attrs.except(:data, :aria)
|
|
46
|
+
attrs[:class] = cn("group/scrubber relative w-14 touch-none select-none", @user_class)
|
|
47
|
+
attrs[:aria] = { label: @label }.merge(@html_attrs[:aria] || {})
|
|
48
|
+
attrs[:data] = { slot: "scrubber", controller: "ui--scrubber", "ui--scrubber-for-value": @for,
|
|
49
|
+
action: "keydown->ui--scrubber#keydown resize@window->ui--scrubber#layout" }
|
|
50
|
+
.merge(@html_attrs[:data] || {})
|
|
51
|
+
attrs
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def mark_attrs(mark, index)
|
|
55
|
+
{ href: mark.href, tabindex: index.zero? ? 0 : -1,
|
|
56
|
+
class: cn("absolute end-0 top-0 flex h-4 -translate-y-1/2 items-center justify-end rounded-sm pe-2 outline-none " \
|
|
57
|
+
"invisible group-data-[ready]/scrubber:visible focus-visible:ring-2 focus-visible:ring-primary",
|
|
58
|
+
mark.major ? "min-w-8 text-[11px] font-medium text-muted-foreground" : "w-4"),
|
|
59
|
+
aria: { label: mark.label },
|
|
60
|
+
data: { "ui--scrubber-target": "mark", label: mark.label, major: mark.major.present? } }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
<% end %>
|
|
32
32
|
|
|
33
33
|
<%= tag.div(id: listbox_id, role: "listbox", tabindex: -1,
|
|
34
|
-
aria: { labelledby: (
|
|
34
|
+
aria: { labelledby: (named? ? trigger_id : nil), multiselectable: (multiple? ? "true" : nil) },
|
|
35
35
|
data: { "ui--select-target": "listbox", action: "mousedown->ui--select#keepFocus" },
|
|
36
36
|
class: "max-h-64 overflow-y-auto p-1") do %>
|
|
37
37
|
<% listbox_options.each_with_index do |(label, value), index| %>
|
|
@@ -81,6 +81,7 @@ class UI::Select < UI::Base
|
|
|
81
81
|
@form = form
|
|
82
82
|
@field = field
|
|
83
83
|
@user_class = binding.local_variable_get(:class)
|
|
84
|
+
@name_attrs = take_accessible_name(html_attrs)
|
|
84
85
|
@html_attrs = html_attrs
|
|
85
86
|
@uid = SecureRandom.hex(4)
|
|
86
87
|
@wrapper = UI::FormField.new(label: label, hint: hint, error: error,
|
|
@@ -115,7 +116,7 @@ class UI::Select < UI::Base
|
|
|
115
116
|
class: trigger_classes,
|
|
116
117
|
role: "combobox",
|
|
117
118
|
disabled: @disabled,
|
|
118
|
-
aria: { haspopup: "listbox", expanded: "false", controls: listbox_id,
|
|
119
|
+
aria: { haspopup: "listbox", expanded: "false", controls: listbox_id, **@name_attrs,
|
|
119
120
|
invalid: ("true" if wrapper.error?), describedby: wrapper.describedby },
|
|
120
121
|
data: { "ui--select-target": "trigger",
|
|
121
122
|
action: "click->ui--select#toggle keydown->ui--select#keydown" }
|
|
@@ -197,7 +198,21 @@ class UI::Select < UI::Base
|
|
|
197
198
|
attrs
|
|
198
199
|
end
|
|
199
200
|
|
|
201
|
+
# Whether the button has a name for the list to borrow.
|
|
202
|
+
def named? = render_label? || @name_attrs.any?
|
|
203
|
+
|
|
200
204
|
def native_choices
|
|
201
205
|
listbox_options.map { |label, value| [ label, value ] }
|
|
202
206
|
end
|
|
207
|
+
|
|
208
|
+
private
|
|
209
|
+
|
|
210
|
+
# `aria-label` or `aria-labelledby` names what people reach, the visible
|
|
211
|
+
# button. Left in html_attrs it would go on the native select, which is
|
|
212
|
+
# hidden from screen readers, and the button would have no name at all.
|
|
213
|
+
def take_accessible_name(attrs)
|
|
214
|
+
aria = attrs[:aria] = (attrs[:aria] || {}).dup
|
|
215
|
+
{ label: attrs.delete(:"aria-label") || aria.delete(:label),
|
|
216
|
+
labelledby: attrs.delete(:"aria-labelledby") || aria.delete(:labelledby) }.compact
|
|
217
|
+
end
|
|
203
218
|
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<%= tag.div(**root_attrs) do %>
|
|
2
|
+
<%= render(UI::Button.new(**clear_attrs)) do %><%= render(UI::Icon.new(name: "x", size: :sm)) %><% end %>
|
|
3
|
+
<%= tag.p class: "min-w-0 flex-1 truncate text-sm font-medium tabular-nums", aria: { live: "polite" }, data: { "ui--selection-bar-target": "count" } %>
|
|
4
|
+
<% if actions? %>
|
|
5
|
+
<div class="flex shrink-0 items-center gap-1"><% actions.each do |action| %><%= action %><% end %></div>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% end %>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# What to do with the things chosen on a page: "3 selected", a button to clear
|
|
4
|
+
# them, and the actions that work on all of them at once.
|
|
5
|
+
#
|
|
6
|
+
# <%= render(UI::SelectionBar.new(for: "customers")) do |bar| %>
|
|
7
|
+
# <% bar.with_action do %>
|
|
8
|
+
# <%= render(UI::Button.new(variant: :ghost, type: :submit, form: "bulk", formaction: export_customers_path)) { "Export" } %>
|
|
9
|
+
# <% end %>
|
|
10
|
+
# <% end %>
|
|
11
|
+
#
|
|
12
|
+
# `for:` is the id of what holds the checkboxes: a `UI::Table` with
|
|
13
|
+
# `selection:`, or any list whose boxes carry `data-selection="item"` (and one
|
|
14
|
+
# with `data-selection="all"` to choose them all). The bar shows once one is
|
|
15
|
+
# checked and hides when none are, keeps "select all" checked, unchecked or
|
|
16
|
+
# partly checked to match, and lets Shift-click check a run of them. Escape
|
|
17
|
+
# or the clear button unchecks them all.
|
|
18
|
+
#
|
|
19
|
+
# An "all" box inside an element with `data-selection-group` chooses only the
|
|
20
|
+
# items in it: a day's photos under that day's heading.
|
|
21
|
+
#
|
|
22
|
+
# The boxes post like any checkbox, so an action is a submit button for the
|
|
23
|
+
# form they belong to (`form:` and `formaction:` on the button, `form:` on the
|
|
24
|
+
# table). A `selection-bar:change` event carries the count and the values, for
|
|
25
|
+
# a page that does more.
|
|
26
|
+
#
|
|
27
|
+
# `placement:` is :top, a bar that sticks to the top of its scrolling area, or
|
|
28
|
+
# :floating, a rounded bar near the bottom of the window.
|
|
29
|
+
class UI::SelectionBar < UI::Base
|
|
30
|
+
PLACEMENTS = {
|
|
31
|
+
top: "sticky top-0 z-30 flex h-14 w-full items-center gap-2 border-b bg-background/95 px-2 backdrop-blur " \
|
|
32
|
+
"supports-[backdrop-filter]:bg-background/80 sm:px-4",
|
|
33
|
+
floating: "fixed inset-x-4 bottom-4 z-40 mx-auto flex w-auto max-w-xl items-center gap-2 rounded-full border " \
|
|
34
|
+
"bg-popover py-1.5 ps-1.5 pe-2 text-popover-foreground shadow-lg sm:inset-x-0 sm:w-fit"
|
|
35
|
+
}.freeze
|
|
36
|
+
|
|
37
|
+
renders_many :actions
|
|
38
|
+
|
|
39
|
+
def initialize(for:, placement: :top, label: nil, class: nil, **html_attrs)
|
|
40
|
+
@for = binding.local_variable_get(:for)
|
|
41
|
+
@placement = PLACEMENTS.key?(placement.to_sym) ? placement.to_sym : :top
|
|
42
|
+
@label = label
|
|
43
|
+
@user_class = binding.local_variable_get(:class)
|
|
44
|
+
@html_attrs = html_attrs
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def root_attrs
|
|
48
|
+
attrs = @html_attrs.except(:data, :aria)
|
|
49
|
+
attrs[:role] = "region"
|
|
50
|
+
attrs[:hidden] = true
|
|
51
|
+
attrs[:class] = cn(PLACEMENTS[@placement], "[&[hidden]]:hidden", @user_class)
|
|
52
|
+
attrs[:aria] = { label: @label || t("ui.selection_bar.label", default: "Selection") }.merge(@html_attrs[:aria] || {})
|
|
53
|
+
attrs[:data] = { slot: "selection-bar", placement: @placement, controller: "ui--selection-bar",
|
|
54
|
+
"ui--selection-bar-for-value": @for,
|
|
55
|
+
"ui--selection-bar-one-value": t("ui.selection_bar.count.one", default: "%{count} selected"),
|
|
56
|
+
"ui--selection-bar-other-value": t("ui.selection_bar.count.other", default: "%{count} selected") }
|
|
57
|
+
.merge(@html_attrs[:data] || {})
|
|
58
|
+
attrs
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# A checkbox the bar counts: `:item` for each thing to choose, `:all` for
|
|
62
|
+
# one that chooses them all. `form:` is the id of the form it posts with;
|
|
63
|
+
# `class:` restyles it, such as a round box over a photo.
|
|
64
|
+
def self.checkbox(kind, label:, name: nil, value: nil, form: nil, checked: false, **options)
|
|
65
|
+
attrs = { "aria-label": label, data: { selection: kind }, checked: checked, **options }
|
|
66
|
+
attrs["form"] = form if form # the HTML attribute; `form:` is a form builder to Checkbox
|
|
67
|
+
UI::Checkbox.new(name: name, value: value, unchecked_value: nil, **attrs)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def clear_attrs
|
|
71
|
+
{ variant: :ghost, size: :icon, class: "shrink-0 rounded-full",
|
|
72
|
+
aria: { label: t("ui.selection_bar.clear", default: "Clear selection") },
|
|
73
|
+
data: { action: "ui--selection-bar#clear" } }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -10,7 +10,7 @@ class UI::Sidebar::GroupLabel < ViewComponent::Base
|
|
|
10
10
|
@system_args[:data][:sidebar] = "group-label"
|
|
11
11
|
|
|
12
12
|
@system_args[:class] = class_names(
|
|
13
|
-
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
|
13
|
+
"text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 text-xs font-medium outline-hidden transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
|
|
14
14
|
"group-data-[collapsible=icon]:-mt-8 group-data-[collapsible=icon]:opacity-0",
|
|
15
15
|
@system_args[:class]
|
|
16
16
|
)
|
|
@@ -7,9 +7,12 @@ class UI::Sidebar::Inset < UI::Base
|
|
|
7
7
|
@system_args[:data][:slot] = "sidebar-inset"
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
# cn, not class_names: a class passed in replaces the one it clashes with
|
|
11
|
+
# (bg-transparent for bg-background, shadow-none for shadow-sm), rather than
|
|
12
|
+
# both landing on the element and CSS order picking one.
|
|
10
13
|
def before_render
|
|
11
|
-
@system_args[:class] =
|
|
12
|
-
"bg-background relative flex w-full flex-1 flex-col",
|
|
14
|
+
@system_args[:class] = cn(
|
|
15
|
+
"bg-background relative flex w-full min-w-0 flex-1 flex-col",
|
|
13
16
|
"md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow-sm md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
|
|
14
17
|
@system_args[:class]
|
|
15
18
|
)
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# A link in the sidebar. `active: true` marks the page being shown, for screen
|
|
4
|
+
# readers too (aria-current="page").
|
|
5
|
+
#
|
|
6
|
+
# `shape:` is :default, a compact row with a bar at the sidebar's edge for the
|
|
7
|
+
# current page, or :pill, a taller row whose current page is filled in edge to
|
|
8
|
+
# edge, rounded at both ends.
|
|
9
|
+
class UI::Sidebar::MenuButton < UI::Base
|
|
10
|
+
SHAPES = {
|
|
11
|
+
default: "h-8 rounded-md p-2 data-[active=true]:bg-sidebar-primary/10",
|
|
12
|
+
pill: "h-10 gap-3 rounded-full px-4 data-[active=true]:bg-sidebar-primary/15 group-data-[collapsible=icon]:rounded-full!"
|
|
13
|
+
}.freeze
|
|
14
|
+
|
|
15
|
+
def initialize(path, active: false, current: nil, shape: :default, icon: nil, **system_args) # rubocop:disable Lint/UnusedMethodArgument
|
|
5
16
|
@path = path
|
|
6
17
|
@is_active = active
|
|
7
|
-
|
|
18
|
+
@shape = SHAPES.key?(shape.to_sym) ? shape.to_sym : :default
|
|
8
19
|
@system_args = system_args
|
|
9
20
|
|
|
10
21
|
@system_args[:data] ||= {}
|
|
11
22
|
@system_args[:data][:slot] = "sidebar-menu-button"
|
|
12
23
|
@system_args[:data][:sidebar] = "menu-button"
|
|
13
24
|
@system_args[:data][:active] = @is_active.to_s
|
|
25
|
+
@system_args[:data][:shape] = @shape
|
|
14
26
|
|
|
15
27
|
# An explicit `current:` always wins; an active button falls back to "page"
|
|
16
28
|
# so assistive tech announces it without the caller repeating themselves.
|
|
@@ -19,12 +31,15 @@ class UI::Sidebar::MenuButton < ViewComponent::Base
|
|
|
19
31
|
@system_args[:aria] = (@system_args[:aria] || {}).merge(current: aria_current)
|
|
20
32
|
end
|
|
21
33
|
|
|
22
|
-
@system_args[:class] =
|
|
23
|
-
"peer/menu-button flex w-full items-center gap-2 overflow-hidden
|
|
24
|
-
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
"
|
|
34
|
+
@system_args[:class] = cn(
|
|
35
|
+
"peer/menu-button flex w-full items-center gap-2 overflow-hidden text-left text-sm outline-hidden ring-sidebar-ring " \
|
|
36
|
+
"transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 " \
|
|
37
|
+
"active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 " \
|
|
38
|
+
"group-has-data-[sidebar=menu-action]/menu-item:pe-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 " \
|
|
39
|
+
"data-[active=true]:font-semibold data-[active=true]:text-sidebar-primary data-[active=true]:[&>svg]:stroke-current " \
|
|
40
|
+
"group-data-[collapsible=icon]:size-8! group-data-[collapsible=icon]:p-2! [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0",
|
|
41
|
+
SHAPES[@shape],
|
|
42
|
+
@system_args[:class]
|
|
28
43
|
)
|
|
29
44
|
end
|
|
30
45
|
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%= tag.li(**@system_args) do %><%= content %><%= menu_button if menu_button %><% end %>
|
|
1
|
+
<%= tag.li(**@system_args) do %><%= content %><%= menu_button if menu_button %><% if sub_menu? %><% links = sub_menu_html %><%= tag.button(**toggle_attrs) do %><%= render(UI::Icon.new(name: "chevron-right", size: :sm, class: "rtl:rotate-180")) %><% end %><%= links %><% end %><% end %>
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# One entry in a sidebar menu: a `menu_button`, and optionally a `sub_menu` of
|
|
4
|
+
# links under it, such as a list of albums. The sub-menu has a button of its
|
|
5
|
+
# own to open and close it, beside the link, so the link still goes to its
|
|
6
|
+
# page. It starts open when `open:` says so, or when one of its links is the
|
|
7
|
+
# current page.
|
|
3
8
|
class UI::Sidebar::MenuItem < UI::Base
|
|
4
9
|
renders_one :menu_button, UI::Sidebar::MenuButton
|
|
10
|
+
renders_one :sub_menu, UI::Sidebar::MenuSub
|
|
5
11
|
|
|
6
|
-
def initialize(**system_args)
|
|
12
|
+
def initialize(open: nil, **system_args)
|
|
13
|
+
@open = open
|
|
7
14
|
@system_args = system_args
|
|
8
15
|
|
|
9
16
|
@system_args[:data] ||= {}
|
|
@@ -12,12 +19,31 @@ class UI::Sidebar::MenuItem < UI::Base
|
|
|
12
19
|
|
|
13
20
|
@system_args[:class] = class_names(
|
|
14
21
|
"group/menu-item relative",
|
|
15
|
-
# Active indicator: a primary bar flush with the sidebar edge
|
|
16
|
-
|
|
17
|
-
"before:-
|
|
22
|
+
# Active indicator: a primary bar flush with the sidebar edge, for the
|
|
23
|
+
# default shape only; a pill is filled in instead.
|
|
24
|
+
"before:absolute before:-start-2 before:top-4 before:h-6 before:w-1 " \
|
|
25
|
+
"before:-translate-y-1/2 before:rounded-e-full before:bg-sidebar-primary " \
|
|
18
26
|
"before:opacity-0 before:transition-opacity " \
|
|
19
|
-
"has-[[data-active=true]]:before:opacity-100",
|
|
27
|
+
"has-[>[data-active=true][data-shape=default]]:before:opacity-100",
|
|
20
28
|
@system_args[:class]
|
|
21
29
|
)
|
|
22
30
|
end
|
|
31
|
+
|
|
32
|
+
def sub_menu_id = @sub_menu_id ||= "sidebar-sub-#{SecureRandom.hex(4)}"
|
|
33
|
+
|
|
34
|
+
# Drawn first, so it knows whether one of its links is the current page.
|
|
35
|
+
def sub_menu_html
|
|
36
|
+
sub_menu.configure(id: sub_menu_id, open: @open)
|
|
37
|
+
sub_menu.to_s
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def toggle_attrs
|
|
41
|
+
{ type: "button", data: { sidebar: "menu-action", action: "ui--sidebar#toggleSub" },
|
|
42
|
+
aria: { expanded: sub_menu.open?.to_s, controls: sub_menu_id,
|
|
43
|
+
label: t("ui.sidebar.toggle_sub", name: sub_menu.name, default: "Show the links under %{name}") },
|
|
44
|
+
class: "absolute end-1 top-1 flex size-6 items-center justify-center rounded-md text-sidebar-foreground/70 outline-hidden " \
|
|
45
|
+
"ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 " \
|
|
46
|
+
"group-data-[collapsible=icon]:hidden group-has-[>[data-shape=pill]]/menu-item:top-2 " \
|
|
47
|
+
"[&[aria-expanded=true]>svg]:rotate-90 [&>svg]:transition-transform motion-reduce:[&>svg]:transition-none" }
|
|
48
|
+
end
|
|
23
49
|
end
|