velvetkit 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/sidebar/menu_button.html.erb +10 -1
- data/registry/app/components/ui/sidebar/menu_button.rb +44 -6
- data/registry/app/components/ui/sidebar/menu_item.rb +4 -3
- data/registry/app/components/ui/sidebar/wrapper.html.erb +1 -1
- data/registry/app/components/ui/sidebar/wrapper.rb +45 -7
- data/registry/app/components/ui/sidebar.html.erb +10 -1
- data/registry/app/components/ui/sidebar.rb +60 -4
- data/registry/app/javascript/controllers/ui/sidebar_controller.ts +17 -0
- data/registry/app/javascript/controllers/ui/tooltip_controller.ts +3 -0
- data/registry/test/components/previews/ui/sidebar_preview/_top_bar.html.erb +19 -0
- data/registry/test/components/previews/ui/sidebar_preview/icon_rail.html.erb +81 -0
- data/registry/test/components/previews/ui/sidebar_preview/site_header.html.erb +52 -0
- data/registry/test/components/previews/ui/sidebar_preview.rb +23 -0
- data/registry/test/components/ui/sidebar/menu_button_test.rb +49 -0
- data/registry/test/components/ui/sidebar/wrapper_test.rb +30 -0
- data/registry/test/components/ui/sidebar_test.rb +50 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: daf46130dd01588b7563ec7950283f3fda2cd9d20f3429fe819b20ea46654d2b
|
|
4
|
+
data.tar.gz: 5c796994f8d99576842568b142d5b4277eade33cf5eda99dca896ac9d2a79702
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf57b163ca22ec31d9b6d875711a440a89e6998a80ff8681cd31249a9113158315c5fcfdc1b0afa72440173b73c2e2ff27307855577473413701f03ddffcd934
|
|
7
|
+
data.tar.gz: 75ba39a318fe15e179ac20f262014e1ecc7549a136c0d10fe95577089ca263deb6dc6f7f08cd29ba4e404469832efd53342f5baab5654ba4aac0249ba1df2e57
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.6.1 — 2026-11-30
|
|
6
|
+
|
|
7
|
+
Changes:
|
|
8
|
+
|
|
9
|
+
- `Sidebar`: two more layouts. A `header` on `Sidebar::Wrapper` stretches
|
|
10
|
+
across the top, on the sidebar's surface so the two frame the page, with
|
|
11
|
+
the sidebar and page below it; the sidebar sticks just under the header,
|
|
12
|
+
as tall as what's left, with no height to work out by hand
|
|
13
|
+
(`header_height:`, 3.5rem by default). And an icon rail with a panel of
|
|
14
|
+
pages beside it, both `nested:` sidebars inside the outer one, which
|
|
15
|
+
collapses to the rail and opens both as the phone's drawer. A rail button
|
|
16
|
+
with `section:` shows that section's panel straight away, with no page to
|
|
17
|
+
load, and opens the sidebar if it was collapsed. `MenuButton` has
|
|
18
|
+
`shape: :block`, a row whose current page is filled in as a rounded block
|
|
19
|
+
with no bar at the edge; `shape: :icon` for the rail, a square filled in
|
|
20
|
+
for the current section with its name as a tooltip; and `tooltip:` for any
|
|
21
|
+
shape. `Wrapper` takes `sidebar_width:` and keeps a `style:` of its own.
|
|
22
|
+
(#115)
|
|
23
|
+
- `Tooltip`: positioned `fixed`, so one inside a clipped box, such as a
|
|
24
|
+
sidebar, shows in full beside it. (#115)
|
|
25
|
+
|
|
5
26
|
## 0.6.0 — 2026-11-23
|
|
6
27
|
|
|
7
28
|
New components:
|
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.6.
|
|
7
|
+
VERSION = "0.6.1"
|
|
8
8
|
end
|
|
@@ -1 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
<% label = tooltip_text %>
|
|
2
|
+
<% button = capture do %><% if section? %><%= tag.button(**@system_args) do %><%= content %><% end %><% else %><%= link_to @path, **@system_args do %><%= content %><% end %><% end %><% end %>
|
|
3
|
+
<% if label %>
|
|
4
|
+
<%= render(UI::Tooltip.new(class: "flex")) do |tooltip| %>
|
|
5
|
+
<% tooltip.with_trigger(class: "flex w-full") { button } %>
|
|
6
|
+
<% tooltip.with_content(side: :right) { label } %>
|
|
7
|
+
<% end %>
|
|
8
|
+
<% else %>
|
|
9
|
+
<%= button %>
|
|
10
|
+
<% end %>
|
|
@@ -4,17 +4,37 @@
|
|
|
4
4
|
# readers too (aria-current="page").
|
|
5
5
|
#
|
|
6
6
|
# `shape:` is :default, a compact row with a bar at the sidebar's edge for the
|
|
7
|
-
# current page
|
|
8
|
-
#
|
|
7
|
+
# current page; :block, a taller row whose current page is filled in as a
|
|
8
|
+
# rounded block, with no bar; :pill, the same filled in edge to edge and
|
|
9
|
+
# rounded at both ends; or :icon, the icon alone in a square, filled in
|
|
10
|
+
# for the current page, for a rail of sections (`nested: :rail` on UI::Sidebar).
|
|
11
|
+
# An :icon button's text stays for screen readers, and shows as a tooltip.
|
|
12
|
+
#
|
|
13
|
+
# `section:` in place of a path makes it a button that shows that section's
|
|
14
|
+
# panel (`nested: :panel, section:` on UI::Sidebar) beside the rail, at once,
|
|
15
|
+
# with no page to load:
|
|
16
|
+
#
|
|
17
|
+
# <% item.with_menu_button(section: "projects", shape: :icon, active: true) do %>
|
|
18
|
+
# <%= render(UI::Icon.new(name: "folder-kanban")) %><span>Projects</span>
|
|
19
|
+
# <% end %>
|
|
20
|
+
#
|
|
21
|
+
# `tooltip:` gives any shape a tooltip; an :icon button takes it from its text
|
|
22
|
+
# when left out.
|
|
9
23
|
class UI::Sidebar::MenuButton < UI::Base
|
|
10
24
|
SHAPES = {
|
|
11
25
|
default: "h-8 rounded-md p-2 data-[active=true]:bg-sidebar-primary/10",
|
|
12
|
-
|
|
26
|
+
block: "h-9 gap-3 rounded-lg px-3 data-[active=true]:bg-sidebar-primary/15",
|
|
27
|
+
pill: "h-10 gap-3 rounded-full px-4 data-[active=true]:bg-sidebar-primary/15 group-data-[collapsible=icon]:rounded-full!",
|
|
28
|
+
icon: "size-8 shrink-0 justify-center rounded-md p-0 data-[active=true]:bg-sidebar-primary/15 [&>span]:sr-only"
|
|
13
29
|
}.freeze
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
# rubocop:disable Lint/UnusedMethodArgument
|
|
32
|
+
def initialize(path = nil, active: false, current: nil, shape: :default, section: nil, tooltip: nil, icon: nil, **system_args)
|
|
33
|
+
# rubocop:enable Lint/UnusedMethodArgument
|
|
16
34
|
@path = path
|
|
35
|
+
@section = section&.to_s
|
|
17
36
|
@is_active = active
|
|
37
|
+
@tooltip = tooltip
|
|
18
38
|
@shape = SHAPES.key?(shape.to_sym) ? shape.to_sym : :default
|
|
19
39
|
@system_args = system_args
|
|
20
40
|
|
|
@@ -24,9 +44,18 @@ class UI::Sidebar::MenuButton < UI::Base
|
|
|
24
44
|
@system_args[:data][:active] = @is_active.to_s
|
|
25
45
|
@system_args[:data][:shape] = @shape
|
|
26
46
|
|
|
27
|
-
|
|
47
|
+
if section?
|
|
48
|
+
# Opens its panel, and says which one and whether it's showing.
|
|
49
|
+
@system_args[:type] = "button"
|
|
50
|
+
@system_args[:data][:section] = @section
|
|
51
|
+
@system_args[:data][:action] = "ui--sidebar#showSection"
|
|
52
|
+
@system_args[:data][:"ui--sidebar-section-param"] = @section
|
|
53
|
+
@system_args[:aria] = (@system_args[:aria] || {}).merge(controls: UI::Sidebar.section_id(@section), expanded: @is_active.to_s)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# An explicit `current:` always wins; an active link falls back to "page"
|
|
28
57
|
# so assistive tech announces it without the caller repeating themselves.
|
|
29
|
-
aria_current = current || ("page" if @is_active)
|
|
58
|
+
aria_current = current || ("page" if @is_active && !section?)
|
|
30
59
|
if aria_current
|
|
31
60
|
@system_args[:aria] = (@system_args[:aria] || {}).merge(current: aria_current)
|
|
32
61
|
end
|
|
@@ -42,4 +71,13 @@ class UI::Sidebar::MenuButton < UI::Base
|
|
|
42
71
|
@system_args[:class]
|
|
43
72
|
)
|
|
44
73
|
end
|
|
74
|
+
|
|
75
|
+
def section? = @section.present?
|
|
76
|
+
|
|
77
|
+
# An :icon button's tooltip is its own text unless told otherwise.
|
|
78
|
+
def tooltip_text
|
|
79
|
+
return @tooltip if @tooltip.present?
|
|
80
|
+
|
|
81
|
+
Nokogiri::HTML5.fragment(content.to_s).text.squish.presence if @shape == :icon
|
|
82
|
+
end
|
|
45
83
|
end
|
|
@@ -20,11 +20,12 @@ class UI::Sidebar::MenuItem < UI::Base
|
|
|
20
20
|
@system_args[:class] = class_names(
|
|
21
21
|
"group/menu-item relative",
|
|
22
22
|
# Active indicator: a primary bar flush with the sidebar edge, for the
|
|
23
|
-
# default shape only; a pill is filled in instead.
|
|
23
|
+
# default shape only; a block, a pill or an icon is filled in instead. Not a direct
|
|
24
|
+
# child: a button with a tooltip sits inside the tooltip.
|
|
24
25
|
"before:absolute before:-start-2 before:top-4 before:h-6 before:w-1 " \
|
|
25
26
|
"before:-translate-y-1/2 before:rounded-e-full before:bg-sidebar-primary " \
|
|
26
27
|
"before:opacity-0 before:transition-opacity " \
|
|
27
|
-
"has-[
|
|
28
|
+
"has-[[data-active=true][data-shape=default]]:before:opacity-100",
|
|
28
29
|
@system_args[:class]
|
|
29
30
|
)
|
|
30
31
|
end
|
|
@@ -43,7 +44,7 @@ class UI::Sidebar::MenuItem < UI::Base
|
|
|
43
44
|
label: t("ui.sidebar.toggle_sub", name: sub_menu.name, default: "Show the links under %{name}") },
|
|
44
45
|
class: "absolute end-1 top-1 flex size-6 items-center justify-center rounded-md text-sidebar-foreground/70 outline-hidden " \
|
|
45
46
|
"ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus:ring-2 " \
|
|
46
|
-
"group-data-[collapsible=icon]:hidden group-has-[
|
|
47
|
+
"group-data-[collapsible=icon]:hidden group-has-[[data-shape=pill]]/menu-item:top-2 " \
|
|
47
48
|
"[&[aria-expanded=true]>svg]:rotate-90 [&>svg]:transition-transform motion-reduce:[&>svg]:transition-none" }
|
|
48
49
|
end
|
|
49
50
|
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%= tag.div(**@system_args) do %><%= content %><% end %>
|
|
1
|
+
<%= tag.div(**@system_args) do %><% if header? %><%= header %><div data-slot="sidebar-wrapper-body" class="flex min-h-0 w-full flex-1"><%= content %></div><% else %><%= content %><% end %><% end %>
|
|
@@ -1,9 +1,31 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Holds the sidebar and the page beside it, and the Stimulus controller that
|
|
4
|
+
# collapses and opens it.
|
|
5
|
+
#
|
|
6
|
+
# Two layouts:
|
|
7
|
+
#
|
|
8
|
+
# - Without a `header`, the sidebar runs the full height of the window and the
|
|
9
|
+
# page's own header goes at the top of `UI::Sidebar::Inset`.
|
|
10
|
+
# - With one, the header stretches across the top, sidebar and page below it:
|
|
11
|
+
#
|
|
12
|
+
# <%= render(UI::Sidebar::Wrapper.new(header_height: "3.5rem")) do |wrapper| %>
|
|
13
|
+
# <% wrapper.with_header(class: "gap-2 px-4") do %>…logo, search, avatar…<% end %>
|
|
14
|
+
# <%= render(UI::Sidebar.new(id: "app-sidebar")) do |sidebar| %>…<% end %>
|
|
15
|
+
# <%= render(UI::Sidebar::Inset.new) do %>…<% end %>
|
|
16
|
+
# <% end %>
|
|
17
|
+
#
|
|
18
|
+
# The header sticks to the top, and the sidebar sticks just under it, as tall
|
|
19
|
+
# as what's left of the window. `header_height:` is the one place that height
|
|
20
|
+
# is written; it's `--header-height` to anything inside.
|
|
21
|
+
#
|
|
22
|
+
# `sidebar_width:` widens the sidebar, say for an icon rail with a second
|
|
23
|
+
# sidebar beside it (see `nested:` on UI::Sidebar).
|
|
3
24
|
class UI::Sidebar::Wrapper < UI::Base
|
|
4
25
|
SIDEBAR_WIDTH = "16rem"
|
|
5
26
|
SIDEBAR_WIDTH_MOBILE = "18rem"
|
|
6
27
|
SIDEBAR_WIDTH_ICON = "3rem"
|
|
28
|
+
HEADER_HEIGHT = "3.5rem"
|
|
7
29
|
|
|
8
30
|
# Written out in full so Tailwind's source scanner can see each class literally;
|
|
9
31
|
# an interpolated "min-h-#{...}" is invisible to it and never gets generated.
|
|
@@ -16,23 +38,39 @@ class UI::Sidebar::Wrapper < UI::Base
|
|
|
16
38
|
none: nil
|
|
17
39
|
}.freeze
|
|
18
40
|
|
|
19
|
-
|
|
41
|
+
renders_one :header, lambda { |**system_args, &block|
|
|
42
|
+
system_args[:data] = (system_args[:data] || {}).merge(slot: "sidebar-wrapper-header")
|
|
43
|
+
# The sidebar's surface and border, so header and sidebar read as one
|
|
44
|
+
# frame around the page, in a dark theme as much as a light one.
|
|
45
|
+
system_args[:class] = cn(
|
|
46
|
+
"bg-sidebar text-sidebar-foreground border-sidebar-border sticky top-0 z-20 flex h-(--header-height) w-full shrink-0 items-center border-b",
|
|
47
|
+
system_args[:class]
|
|
48
|
+
)
|
|
49
|
+
content_tag(:header, **system_args, &block)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
def initialize(min_height: :svh, header_height: HEADER_HEIGHT, sidebar_width: SIDEBAR_WIDTH, **system_args)
|
|
20
53
|
unless MIN_HEIGHTS.key?(min_height)
|
|
21
54
|
raise ArgumentError, "min_height must be one of #{MIN_HEIGHTS.keys.join(', ')} (got #{min_height.inspect})"
|
|
22
55
|
end
|
|
23
56
|
|
|
24
57
|
@min_height = min_height
|
|
58
|
+
@header_height = header_height
|
|
59
|
+
@sidebar_width = sidebar_width
|
|
25
60
|
@system_args = system_args
|
|
61
|
+
end
|
|
26
62
|
|
|
27
|
-
|
|
28
|
-
@system_args[:data][:
|
|
29
|
-
@system_args[:data][:controller] = "ui--sidebar"
|
|
63
|
+
def before_render
|
|
64
|
+
@system_args[:data] = (@system_args[:data] || {}).merge(slot: "sidebar-wrapper", controller: "ui--sidebar")
|
|
30
65
|
|
|
31
|
-
|
|
32
|
-
|
|
66
|
+
# Without a header there's nothing above the sidebar, so its offset is 0.
|
|
67
|
+
vars = "--sidebar-width: #{@sidebar_width}; --sidebar-width-mobile: #{SIDEBAR_WIDTH_MOBILE}; " \
|
|
68
|
+
"--sidebar-width-icon: #{SIDEBAR_WIDTH_ICON}; --header-height: #{header? ? @header_height : '0px'}"
|
|
69
|
+
@system_args[:style] = [ vars, @system_args[:style] ].compact.join("; ")
|
|
33
70
|
|
|
34
|
-
@system_args[:class] =
|
|
71
|
+
@system_args[:class] = cn(
|
|
35
72
|
"group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex w-full",
|
|
73
|
+
("flex-col" if header?),
|
|
36
74
|
MIN_HEIGHTS[@min_height],
|
|
37
75
|
@system_args[:class]
|
|
38
76
|
)
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
<% if nested? %>
|
|
2
|
+
<%= tag.div(**@system_args) do %>
|
|
3
|
+
<%= sidebar_header if sidebar_header %>
|
|
4
|
+
<%= sidebar_content if sidebar_content %>
|
|
5
|
+
<%= sidebar_footer if sidebar_footer %>
|
|
6
|
+
<%= content %>
|
|
7
|
+
<% end %>
|
|
8
|
+
<% else %>
|
|
1
9
|
<%= tag.aside(**@system_args) do %>
|
|
2
10
|
<div data-slot="sidebar-backdrop" aria-hidden="true" class="<%= backdrop_classes %>" data-action="click->ui--sidebar#close"></div>
|
|
3
11
|
<div data-slot="sidebar-container" class="<%= container_classes %>" data-ui--sidebar-target="container" data-action="click->ui--sidebar#navigate">
|
|
4
|
-
<div data-sidebar="sidebar" data-slot="sidebar-inner" class="bg-sidebar flex h-full w-full flex-col overflow-hidden shadow-xl md:shadow-none group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border md:group-data-[variant=floating]:shadow-sm">
|
|
12
|
+
<div data-sidebar="sidebar" data-slot="sidebar-inner" class="bg-sidebar flex h-full w-full flex-col has-[>[data-nested]]:flex-row overflow-hidden shadow-xl md:shadow-none group-data-[variant=floating]:border-sidebar-border group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:border md:group-data-[variant=floating]:shadow-sm">
|
|
5
13
|
<%= sidebar_header if sidebar_header %>
|
|
6
14
|
<%= sidebar_content if sidebar_content %>
|
|
7
15
|
<%= sidebar_footer if sidebar_footer %>
|
|
@@ -9,3 +17,4 @@
|
|
|
9
17
|
</div>
|
|
10
18
|
</div>
|
|
11
19
|
<% end %>
|
|
20
|
+
<% end %>
|
|
@@ -31,17 +31,47 @@
|
|
|
31
31
|
# link closes it.
|
|
32
32
|
#
|
|
33
33
|
# The sidebar sticks to the top of the window and is as tall as it, or as the
|
|
34
|
-
# wrapper when that's shorter
|
|
35
|
-
#
|
|
34
|
+
# wrapper when that's shorter. Under a wrapper's `header` it sticks just below
|
|
35
|
+
# the header instead, as tall as what's left (see UI::Sidebar::Wrapper).
|
|
36
|
+
#
|
|
37
|
+
# An icon rail with a second sidebar beside it, the rail switching between
|
|
38
|
+
# sections and the second listing the pages of the current one, is two
|
|
39
|
+
# `nested:` sidebars inside an outer one:
|
|
40
|
+
#
|
|
41
|
+
# <%= render(UI::Sidebar::Wrapper.new(sidebar_width: "20rem")) do %>
|
|
42
|
+
# <%= render(UI::Sidebar.new(id: "app-sidebar", collapsible: :icon)) do %>
|
|
43
|
+
# <%= render(UI::Sidebar.new(nested: :rail)) do |rail| %>
|
|
44
|
+
# …menu buttons with `shape: :icon, section: "projects"`…
|
|
45
|
+
# <% end %>
|
|
46
|
+
# <%= render(UI::Sidebar.new(nested: :panel, section: "projects", active: true)) do |panel| %>…<% end %>
|
|
47
|
+
# <%= render(UI::Sidebar.new(nested: :panel, section: "inbox")) do |panel| %>…<% end %>
|
|
48
|
+
# <% end %>
|
|
49
|
+
# <%= render(UI::Sidebar::Inset.new) do %>…<% end %>
|
|
50
|
+
# <% end %>
|
|
51
|
+
#
|
|
52
|
+
# A panel for each section, the `active:` one showing; a rail button with
|
|
53
|
+
# `section:` shows its panel in the browser, no page to load, and opens the
|
|
54
|
+
# sidebar first if it was collapsed. One panel with no `section:` is the
|
|
55
|
+
# same, without the switching: its links are the pages of the section the
|
|
56
|
+
# server says you're in.
|
|
57
|
+
#
|
|
58
|
+
# The outer one is the drawer on a phone, and what collapses: to the rail with
|
|
59
|
+
# `collapsible: :icon`, the panel hidden. A nested sidebar is a plain column
|
|
60
|
+
# with the same header, content and footer slots.
|
|
36
61
|
class UI::Sidebar < UI::Base
|
|
37
62
|
COLLAPSIBLE = %i[icon offcanvas none].freeze
|
|
38
63
|
STATES = %i[expanded collapsed].freeze
|
|
64
|
+
NESTED = %i[rail panel].freeze
|
|
39
65
|
|
|
40
66
|
renders_one :sidebar_header, UI::Sidebar::Header
|
|
41
67
|
renders_one :sidebar_content, UI::Sidebar::Content
|
|
42
68
|
renders_one :sidebar_footer, UI::Sidebar::Footer
|
|
43
69
|
|
|
44
|
-
def initialize(collapsible: :icon, variant: :sidebar, side: :left, state: nil,
|
|
70
|
+
def initialize(collapsible: :icon, variant: :sidebar, side: :left, state: nil, nested: nil, section: nil, active: false,
|
|
71
|
+
**system_args)
|
|
72
|
+
@nested = NESTED.include?(nested&.to_sym) ? nested.to_sym : nil
|
|
73
|
+
@section = section&.to_s.presence
|
|
74
|
+
@active = active
|
|
45
75
|
@collapsible = COLLAPSIBLE.include?(collapsible.to_sym) ? collapsible.to_sym : :icon
|
|
46
76
|
@variant = variant
|
|
47
77
|
@side = side
|
|
@@ -52,7 +82,14 @@ class UI::Sidebar < UI::Base
|
|
|
52
82
|
# The cookie the controller writes the reader's choice to, one per sidebar.
|
|
53
83
|
def self.cookie_name(id) = "ui_sidebar_#{id.presence || 'state'}".tr("-", "_")
|
|
54
84
|
|
|
85
|
+
# The id of a section's panel, which its rail button points aria-controls at.
|
|
86
|
+
def self.section_id(section) = "sidebar-section-#{section}".parameterize
|
|
87
|
+
|
|
88
|
+
def nested? = !@nested.nil?
|
|
89
|
+
|
|
55
90
|
def before_render
|
|
91
|
+
return nested_before_render if nested?
|
|
92
|
+
|
|
56
93
|
@system_args[:data] = (@system_args[:data] || {}).merge(
|
|
57
94
|
slot: "sidebar", variant: @variant, side: @side, state: state,
|
|
58
95
|
# What the sidebar is doing now: "icon" or "offcanvas" while collapsed,
|
|
@@ -72,6 +109,23 @@ class UI::Sidebar < UI::Base
|
|
|
72
109
|
)
|
|
73
110
|
end
|
|
74
111
|
|
|
112
|
+
# A column inside the outer sidebar. The rail is as wide as the collapsed
|
|
113
|
+
# sidebar, so it's all that's left showing once that collapses; the panel
|
|
114
|
+
# takes the rest of the width and hides then, out of the tab order too.
|
|
115
|
+
def nested_before_render
|
|
116
|
+
@system_args[:data] = (@system_args[:data] || {}).merge(slot: "sidebar", nested: @nested)
|
|
117
|
+
if @section
|
|
118
|
+
@system_args[:id] ||= self.class.section_id(@section)
|
|
119
|
+
@system_args[:data][:section] = @section
|
|
120
|
+
@system_args[:hidden] = true unless @active
|
|
121
|
+
end
|
|
122
|
+
@system_args[:class] = cn(
|
|
123
|
+
"bg-sidebar text-sidebar-foreground flex h-full min-h-0 flex-col overflow-hidden",
|
|
124
|
+
(@nested == :rail ? "w-(--sidebar-width-icon) shrink-0 border-e border-sidebar-border" : "min-w-0 flex-1 md:group-data-[collapsible=icon]:hidden"),
|
|
125
|
+
@system_args[:class]
|
|
126
|
+
)
|
|
127
|
+
end
|
|
128
|
+
|
|
75
129
|
def state
|
|
76
130
|
return :collapsed if @collapsible != :none && @state == :collapsed
|
|
77
131
|
return :expanded if @state || @collapsible == :none
|
|
@@ -89,7 +143,9 @@ class UI::Sidebar < UI::Base
|
|
|
89
143
|
"-translate-x-full rtl:translate-x-full group-data-[side=right]:start-auto group-data-[side=right]:end-0",
|
|
90
144
|
"group-data-[side=right]:translate-x-full transition-[translate,visibility] duration-200 ease-out",
|
|
91
145
|
"group-data-[mobile=open]:visible group-data-[mobile=open]:translate-x-0 motion-reduce:transition-none",
|
|
92
|
-
|
|
146
|
+
# Below the wrapper's header, when there is one; --header-height is 0 otherwise.
|
|
147
|
+
"md:visible md:sticky md:top-(--header-height) md:z-10 md:h-[calc(100svh-var(--header-height))] md:max-h-full",
|
|
148
|
+
"md:w-(--sidebar-width) md:translate-x-0",
|
|
93
149
|
"md:transition-[width,translate] md:group-data-[collapsible=icon]:w-(--sidebar-width-icon)",
|
|
94
150
|
"md:group-data-[variant=floating]:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+1rem)]",
|
|
95
151
|
"md:group-data-[variant=inset]:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+1rem)]",
|
|
@@ -75,6 +75,23 @@ export default class extends Controller<HTMLElement> {
|
|
|
75
75
|
if (this.mobile && (event.target as Element).closest('a[href]')) this.close();
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
// A rail button with `section:` shows that section's panel and hides the
|
|
79
|
+
// others, at once, and opens the sidebar if it was collapsed to the rail.
|
|
80
|
+
showSection(event: Event & { params: { section?: string } }) {
|
|
81
|
+
const section = String(event.params.section ?? '');
|
|
82
|
+
if (!section) return;
|
|
83
|
+
|
|
84
|
+
this.element.querySelectorAll<HTMLElement>('[data-nested=panel][data-section]').forEach((panel) => {
|
|
85
|
+
panel.hidden = panel.dataset.section !== section;
|
|
86
|
+
});
|
|
87
|
+
this.element.querySelectorAll<HTMLElement>('button[data-sidebar=menu-button][data-section]').forEach((button) => {
|
|
88
|
+
const shown = button.dataset.section === section;
|
|
89
|
+
button.dataset.active = String(shown);
|
|
90
|
+
button.setAttribute('aria-expanded', String(shown));
|
|
91
|
+
});
|
|
92
|
+
if (!this.mobile && this.state === 'collapsed') this.setState('expanded');
|
|
93
|
+
}
|
|
94
|
+
|
|
78
95
|
// Opens or closes a group of links under a menu item.
|
|
79
96
|
toggleSub(event: Event) {
|
|
80
97
|
const button = event.currentTarget as HTMLElement;
|
|
@@ -48,8 +48,11 @@ export default class extends Controller<HTMLElement> {
|
|
|
48
48
|
// Offset = visible gap (8) + arrow protrusion (~6: 4px staticSide + ~2px
|
|
49
49
|
// diamond corner from rotate-45). Without this margin the arrow tip hugs
|
|
50
50
|
// the trigger edge and reads as "overlapped".
|
|
51
|
+
// Fixed, so a tooltip inside a clipped box (a sidebar, a scrolling list)
|
|
52
|
+
// still shows in full beside it.
|
|
51
53
|
const floating = useFloating(this.triggerTarget, this.contentTarget, {
|
|
52
54
|
placement,
|
|
55
|
+
strategy: 'fixed',
|
|
53
56
|
offset: 14,
|
|
54
57
|
flip: true,
|
|
55
58
|
shift: true,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<%# The bar across the top of the full-width-header previews: the app's logo,
|
|
2
|
+
a workspace switcher, then search and the account on the right. It's
|
|
3
|
+
what goes in UI::Sidebar::Wrapper's `header` slot; the wrapper draws the
|
|
4
|
+
<header> itself, sticky and --header-height tall. %>
|
|
5
|
+
<img src="/velvetkit/mark-light.svg" alt="VelvetKit" class="size-7 shrink-0 dark:hidden">
|
|
6
|
+
<img src="/velvetkit/mark-dark.svg" alt="VelvetKit" class="hidden size-7 shrink-0 dark:block">
|
|
7
|
+
<%= render(UI::Button.new(variant: :ghost, size: :sm, class: "gap-2")) do %>
|
|
8
|
+
<%= render(UI::Avatar.new(size: :sm, color: :purple)) { "A" } %>
|
|
9
|
+
<span class="font-medium">acme</span>
|
|
10
|
+
<%= render(UI::Icon.new(name: "chevrons-up-down", size: :sm, class: "text-muted-foreground")) %>
|
|
11
|
+
<% end %>
|
|
12
|
+
<div class="ms-auto flex items-center gap-2">
|
|
13
|
+
<%= render(UI::Button.new(variant: :outline, size: :sm, class: "w-56 justify-start gap-2 text-muted-foreground max-lg:hidden")) do %>
|
|
14
|
+
<%= render(UI::Icon.new(name: "search", size: :sm)) %>
|
|
15
|
+
<span>Search…</span>
|
|
16
|
+
<%= render(UI::Kbd.new("mod+k", size: :sm, class: "ms-auto")) %>
|
|
17
|
+
<% end %>
|
|
18
|
+
<%= render(UI::Avatar.new(size: :md, color: :purple)) { "A" } %>
|
|
19
|
+
</div>
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
<%# An icon rail of sections with a panel beside it listing the pages of
|
|
2
|
+
one section, under a full-width header. The outer sidebar holds the rail
|
|
3
|
+
and a panel per section, all `nested:`. A rail button with `section:`
|
|
4
|
+
shows its panel straight away, with no page to load, and opens the
|
|
5
|
+
sidebar if it's collapsed to the rail; the panels' links are pages.
|
|
6
|
+
On a phone, rail and panel open together as the drawer.
|
|
7
|
+
`sidebar_width:` makes room for the two side by side. %>
|
|
8
|
+
<% sections = UI::SidebarPreview::SECTIONS %>
|
|
9
|
+
<% current = "projects" %>
|
|
10
|
+
|
|
11
|
+
<%# Fills the preview pane, so the rail's footer is in sight. %>
|
|
12
|
+
<div class="relative h-[calc(100svh-3rem)] min-h-96 overflow-hidden rounded-lg border transform-gpu">
|
|
13
|
+
<%= render(UI::Sidebar::Wrapper.new(min_height: :none, sidebar_width: "19rem", class: "h-full")) do |wrapper| %>
|
|
14
|
+
<% wrapper.with_header(class: "gap-2 px-3") do %>
|
|
15
|
+
<%= render(UI::Sidebar::Trigger.new(sidebar_id: "preview-sidebar-rail", class: "md:hidden")) %>
|
|
16
|
+
<%= render "ui/sidebar_preview/top_bar" %>
|
|
17
|
+
<% end %>
|
|
18
|
+
|
|
19
|
+
<%= render(UI::Sidebar.new(id: "preview-sidebar-rail", collapsible: :icon)) do %>
|
|
20
|
+
<%= render(UI::Sidebar.new(nested: :rail)) do |rail| %>
|
|
21
|
+
<% rail.with_sidebar_content do |content| %>
|
|
22
|
+
<% content.with_sidebar_group(class: "py-4") do |group| %>
|
|
23
|
+
<% group.with_menu(class: "gap-2") do |menu| %>
|
|
24
|
+
<% sections.each do |key, nav| %>
|
|
25
|
+
<% menu.with_menu_item do |item| %>
|
|
26
|
+
<% item.with_menu_button(section: key, shape: :icon, active: key == current) do %>
|
|
27
|
+
<%= render(UI::Icon.new(name: nav[:icon], size: :sm)) %>
|
|
28
|
+
<span><%= nav[:text] %></span>
|
|
29
|
+
<% end %>
|
|
30
|
+
<% end %>
|
|
31
|
+
<% end %>
|
|
32
|
+
<% end %>
|
|
33
|
+
<% end %>
|
|
34
|
+
<% end %>
|
|
35
|
+
<% rail.with_sidebar_footer(class: "items-center max-md:hidden") do %>
|
|
36
|
+
<%= render(UI::Sidebar::Trigger.new(sidebar_id: "preview-sidebar-rail")) %>
|
|
37
|
+
<% end %>
|
|
38
|
+
<% end %>
|
|
39
|
+
|
|
40
|
+
<% sections.each do |key, nav| %>
|
|
41
|
+
<%= render(UI::Sidebar.new(nested: :panel, section: key, active: key == current)) do |panel| %>
|
|
42
|
+
<% panel.with_sidebar_header(class: "px-5 pt-5 pb-1") do %>
|
|
43
|
+
<span class="truncate text-xs font-medium tracking-wide text-sidebar-foreground/60 uppercase"><%= nav[:text] %></span>
|
|
44
|
+
<% end %>
|
|
45
|
+
<% panel.with_sidebar_content do |content| %>
|
|
46
|
+
<% content.with_sidebar_group(class: "px-3") do |group| %>
|
|
47
|
+
<% group.with_menu do |menu| %>
|
|
48
|
+
<% nav[:pages].each_with_index do |(icon, text), i| %>
|
|
49
|
+
<% menu.with_menu_item do |item| %>
|
|
50
|
+
<% item.with_menu_button("#", active: key == current && i.zero?, shape: :block) do %>
|
|
51
|
+
<%= render(UI::Icon.new(name: icon, size: :sm)) %>
|
|
52
|
+
<span><%= text %></span>
|
|
53
|
+
<% end %>
|
|
54
|
+
<% end %>
|
|
55
|
+
<% end %>
|
|
56
|
+
<% end %>
|
|
57
|
+
<% end %>
|
|
58
|
+
<% end %>
|
|
59
|
+
<% end %>
|
|
60
|
+
<% end %>
|
|
61
|
+
<% end %>
|
|
62
|
+
|
|
63
|
+
<%= render(UI::Sidebar::Inset.new(class: "@container overflow-y-auto")) do %>
|
|
64
|
+
<div class="mx-auto w-full max-w-4xl space-y-6 p-6 @xl:p-8">
|
|
65
|
+
<div class="space-y-1">
|
|
66
|
+
<p class="text-sm text-muted-foreground">Projects</p>
|
|
67
|
+
<h1 class="text-2xl font-semibold">All projects</h1>
|
|
68
|
+
</div>
|
|
69
|
+
<p class="text-sm text-muted-foreground">Pick a section in the rail: its pages show beside it straight away.</p>
|
|
70
|
+
<div class="grid gap-4 @xl:grid-cols-3">
|
|
71
|
+
<% [ [ "Open tasks", "24" ], [ "Due this week", "7" ], [ "Finished", "112" ] ].each do |label, value| %>
|
|
72
|
+
<div class="rounded-lg border p-4">
|
|
73
|
+
<p class="text-xs text-muted-foreground"><%= label %></p>
|
|
74
|
+
<p class="mt-1 text-xl"><%= value %></p>
|
|
75
|
+
</div>
|
|
76
|
+
<% end %>
|
|
77
|
+
</div>
|
|
78
|
+
</div>
|
|
79
|
+
<% end %>
|
|
80
|
+
<% end %>
|
|
81
|
+
</div>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<%# The header stretched across the top, the sidebar and page below it. The
|
|
2
|
+
wrapper's `header` slot is all it takes: the sidebar sticks just under
|
|
3
|
+
the header, as tall as what's left, with no height to work out by hand.
|
|
4
|
+
The phone's menu button goes in the header, since there's no sidebar
|
|
5
|
+
to put it in until it opens. The current page is filled in:
|
|
6
|
+
`shape: :block`. %>
|
|
7
|
+
<% sections = UI::SidebarPreview::SECTIONS %>
|
|
8
|
+
<% projects = ["Website redesign", "Spring campaign", "Mobile onboarding", "Pricing page", "Support handbook", "Q3 planning", "Partner portal", "Brand refresh"] %>
|
|
9
|
+
|
|
10
|
+
<%# Fills the preview pane, so the sidebar's footer is in sight. %>
|
|
11
|
+
<div class="relative h-[calc(100svh-3rem)] min-h-96 overflow-hidden rounded-lg border transform-gpu">
|
|
12
|
+
<%= render(UI::Sidebar::Wrapper.new(min_height: :none, class: "h-full")) do |wrapper| %>
|
|
13
|
+
<% wrapper.with_header(class: "gap-2 px-3") do %>
|
|
14
|
+
<%= render(UI::Sidebar::Trigger.new(sidebar_id: "preview-sidebar-site-header", class: "md:hidden")) %>
|
|
15
|
+
<%= render "ui/sidebar_preview/top_bar" %>
|
|
16
|
+
<% end %>
|
|
17
|
+
|
|
18
|
+
<%= render(UI::Sidebar.new(id: "preview-sidebar-site-header", collapsible: :icon)) do |sidebar| %>
|
|
19
|
+
<% sidebar.with_sidebar_content do |content| %>
|
|
20
|
+
<% content.with_sidebar_group(class: "px-3 py-4 group-data-[collapsible=icon]:px-2") do |group| %>
|
|
21
|
+
<% group.with_menu do |menu| %>
|
|
22
|
+
<% sections.each do |key, nav| %>
|
|
23
|
+
<% menu.with_menu_item do |item| %>
|
|
24
|
+
<% item.with_menu_button("#", active: key == "projects", shape: :block, tooltip: nav[:text]) do %>
|
|
25
|
+
<%= render(UI::Icon.new(name: nav[:icon], size: :sm)) %>
|
|
26
|
+
<span><%= nav[:text] %></span>
|
|
27
|
+
<% end %>
|
|
28
|
+
<% end %>
|
|
29
|
+
<% end %>
|
|
30
|
+
<% end %>
|
|
31
|
+
<% end %>
|
|
32
|
+
<% end %>
|
|
33
|
+
<% sidebar.with_sidebar_footer(class: "border-t border-sidebar-border px-3 group-data-[collapsible=icon]:px-2 max-md:hidden") do %>
|
|
34
|
+
<%= render(UI::Sidebar::Trigger.new(sidebar_id: "preview-sidebar-site-header")) %>
|
|
35
|
+
<% end %>
|
|
36
|
+
<% end %>
|
|
37
|
+
|
|
38
|
+
<%= render(UI::Sidebar::Inset.new(class: "@container overflow-y-auto")) do %>
|
|
39
|
+
<div class="mx-auto w-full max-w-4xl space-y-6 p-6 @xl:p-8">
|
|
40
|
+
<div class="space-y-1">
|
|
41
|
+
<h1 class="text-2xl font-semibold">Projects</h1>
|
|
42
|
+
<p class="text-sm text-muted-foreground">Scroll this page: the header and the sidebar stay put.</p>
|
|
43
|
+
</div>
|
|
44
|
+
<div class="space-y-3">
|
|
45
|
+
<% projects.each do |name| %>
|
|
46
|
+
<div class="rounded-lg border px-4 py-5 text-sm"><%= name %></div>
|
|
47
|
+
<% end %>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
<% end %>
|
|
51
|
+
<% end %>
|
|
52
|
+
</div>
|
|
@@ -15,4 +15,27 @@ class UI::SidebarPreview < ViewComponent::Preview
|
|
|
15
15
|
|
|
16
16
|
# @label Pill Links, Sub-menus and a Storage Meter
|
|
17
17
|
def pill_links; render_with_template; end
|
|
18
|
+
|
|
19
|
+
# The sections the full-width-header previews show, each with the pages
|
|
20
|
+
# listed beside the rail when it's open.
|
|
21
|
+
SECTIONS = {
|
|
22
|
+
"home" => { icon: "home", text: "Home",
|
|
23
|
+
pages: [ [ "layout-dashboard", "Dashboard" ], [ "list", "Activity" ], [ "calendar", "Calendar" ] ] },
|
|
24
|
+
"projects" => { icon: "folder-kanban", text: "Projects",
|
|
25
|
+
pages: [ [ "folder", "All projects" ], [ "star", "Starred" ], [ "package", "Archived" ] ] },
|
|
26
|
+
"inbox" => { icon: "inbox", text: "Inbox",
|
|
27
|
+
pages: [ [ "mail", "Unread" ], [ "message-circle", "Mentions" ], [ "check", "Done" ] ] },
|
|
28
|
+
"reports" => { icon: "bar-chart-3", text: "Reports",
|
|
29
|
+
pages: [ [ "chart-column", "Revenue" ], [ "globe", "Traffic" ], [ "download", "Exports" ] ] },
|
|
30
|
+
"team" => { icon: "users", text: "Team",
|
|
31
|
+
pages: [ [ "users", "Members" ], [ "user-plus", "Invites" ], [ "shield", "Roles" ] ] },
|
|
32
|
+
"settings" => { icon: "settings", text: "Settings",
|
|
33
|
+
pages: [ [ "settings", "General" ], [ "credit-card", "Billing" ], [ "lock", "Security" ] ] }
|
|
34
|
+
}.freeze
|
|
35
|
+
|
|
36
|
+
# @label Header Across the Top
|
|
37
|
+
def site_header; render_with_template; end
|
|
38
|
+
|
|
39
|
+
# @label Icon Rail and Nested Sidebar
|
|
40
|
+
def icon_rail; render_with_template; end
|
|
18
41
|
end
|
|
@@ -49,4 +49,53 @@ class UI::Sidebar::MenuButtonTest < ViewComponent::TestCase
|
|
|
49
49
|
link = page.find("a", text: "Dashboard")
|
|
50
50
|
assert_equal "step", link[:"aria-current"]
|
|
51
51
|
end
|
|
52
|
+
|
|
53
|
+
def test_icon_shape_fills_the_current_section_and_names_it_in_a_tooltip
|
|
54
|
+
render_inline(UI::Sidebar::MenuButton.new("/projects", shape: :icon, active: true)) do
|
|
55
|
+
'<svg></svg><span>Projects</span>'.html_safe
|
|
56
|
+
end
|
|
57
|
+
link = page.find("a[href='/projects']")
|
|
58
|
+
assert_equal "icon", link[:"data-shape"]
|
|
59
|
+
assert_includes link[:class], "size-8"
|
|
60
|
+
assert_includes link[:class], "data-[active=true]:bg-sidebar-primary/15"
|
|
61
|
+
# The text stays for screen readers.
|
|
62
|
+
assert_includes link[:class], "[&>span]:sr-only"
|
|
63
|
+
assert_selector "[data-controller=ui--tooltip] [role=tooltip]", text: "Projects", visible: :all
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_a_tooltip_of_its_own
|
|
67
|
+
render_inline(UI::Sidebar::MenuButton.new("#", tooltip: "Go home")) { "Home" }
|
|
68
|
+
assert_selector "[role=tooltip]", text: "Go home", visible: :all
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_no_tooltip_unless_asked_for
|
|
72
|
+
render_inline(UI::Sidebar::MenuButton.new("#")) { "Home" }
|
|
73
|
+
assert_no_selector "[data-controller=ui--tooltip]"
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_block_shape_fills_the_current_page_without_a_bar
|
|
77
|
+
render_inline(UI::Sidebar::MenuItem.new) do |item|
|
|
78
|
+
item.with_menu_button("#", active: true, shape: :block) { "Inbox" }
|
|
79
|
+
end
|
|
80
|
+
link = page.find("a", text: "Inbox")
|
|
81
|
+
assert_equal "block", link[:"data-shape"]
|
|
82
|
+
assert_includes link[:class], "rounded-lg"
|
|
83
|
+
assert_includes link[:class], "data-[active=true]:bg-sidebar-primary/15"
|
|
84
|
+
# The edge bar is for the default shape only.
|
|
85
|
+
assert_includes page.find("li")[:class], "has-[[data-active=true][data-shape=default]]:before:opacity-100"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_a_section_button_shows_its_panel_without_loading_a_page
|
|
89
|
+
render_inline(UI::Sidebar::MenuButton.new(section: "inbox", shape: :icon, active: true)) do
|
|
90
|
+
'<svg></svg><span>Inbox</span>'.html_safe
|
|
91
|
+
end
|
|
92
|
+
button = page.find("button[type=button][data-section=inbox]")
|
|
93
|
+
assert_equal "ui--sidebar#showSection", button[:"data-action"]
|
|
94
|
+
assert_equal "inbox", button[:"data-ui--sidebar-section-param"]
|
|
95
|
+
assert_equal UI::Sidebar.section_id("inbox"), button[:"aria-controls"]
|
|
96
|
+
assert_equal "true", button[:"aria-expanded"]
|
|
97
|
+
# It shows a panel rather than being the current page.
|
|
98
|
+
assert_nil button[:"aria-current"]
|
|
99
|
+
assert_no_selector "a"
|
|
100
|
+
end
|
|
52
101
|
end
|
|
@@ -12,4 +12,34 @@ class UI::Sidebar::WrapperTest < ViewComponent::TestCase
|
|
|
12
12
|
assert_includes wrapper[:class], "group/sidebar-wrapper"
|
|
13
13
|
assert_includes wrapper[:style], "--sidebar-width:"
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
def test_without_a_header_nothing_sits_above_the_sidebar
|
|
17
|
+
render_inline(UI::Sidebar::Wrapper.new) { "x" }
|
|
18
|
+
wrapper = page.find("[data-slot=sidebar-wrapper]")
|
|
19
|
+
assert_includes wrapper[:style], "--header-height: 0px"
|
|
20
|
+
assert_no_selector "header"
|
|
21
|
+
refute_includes wrapper[:class], "flex-col"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_a_header_stretches_across_above_the_sidebar
|
|
25
|
+
render_inline(UI::Sidebar::Wrapper.new(header_height: "4rem")) do |wrapper|
|
|
26
|
+
wrapper.with_header(class: "px-4") { "Logo" }
|
|
27
|
+
"Body"
|
|
28
|
+
end
|
|
29
|
+
wrapper = page.find("[data-slot=sidebar-wrapper]")
|
|
30
|
+
assert_includes wrapper[:style], "--header-height: 4rem"
|
|
31
|
+
assert_includes wrapper[:class], "flex-col"
|
|
32
|
+
header = page.find("header[data-slot=sidebar-wrapper-header]", text: "Logo")
|
|
33
|
+
assert_includes header[:class], "sticky"
|
|
34
|
+
assert_includes header[:class], "h-(--header-height)"
|
|
35
|
+
assert_includes header[:class], "px-4"
|
|
36
|
+
assert_selector "[data-slot=sidebar-wrapper-body]", text: "Body"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_sidebar_width_and_a_style_of_its_own
|
|
40
|
+
render_inline(UI::Sidebar::Wrapper.new(sidebar_width: "20rem", style: "color: red")) { "x" }
|
|
41
|
+
style = page.find("[data-slot=sidebar-wrapper]")[:style]
|
|
42
|
+
assert_includes style, "--sidebar-width: 20rem"
|
|
43
|
+
assert_includes style, "color: red"
|
|
44
|
+
end
|
|
15
45
|
end
|
|
@@ -118,4 +118,54 @@ class UI::SidebarTest < ViewComponent::TestCase
|
|
|
118
118
|
assert_includes page.find("[data-slot=sidebar-container]")[:class],
|
|
119
119
|
"md:group-data-[variant=inset]:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+1rem)]"
|
|
120
120
|
end
|
|
121
|
+
|
|
122
|
+
def test_sticks_below_the_wrappers_header
|
|
123
|
+
render_sidebar
|
|
124
|
+
container = page.find("[data-slot=sidebar-container]")
|
|
125
|
+
assert_includes container[:class], "md:top-(--header-height)"
|
|
126
|
+
assert_includes container[:class], "md:h-[calc(100svh-var(--header-height))]"
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_nested_sidebars_are_plain_columns
|
|
130
|
+
render_in_view_context do
|
|
131
|
+
render(UI::Sidebar.new(id: "outer")) do
|
|
132
|
+
rail = render(UI::Sidebar.new(nested: :rail)) { "Sections" }
|
|
133
|
+
panel = render(UI::Sidebar.new(nested: :panel)) { "Pages" }
|
|
134
|
+
rail + panel
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
# Only the outer one is the drawer the controller drives.
|
|
138
|
+
assert_selector "aside[data-ui--sidebar-target=sidebar]", count: 1, visible: :all
|
|
139
|
+
assert_selector "[data-slot=sidebar-container]", count: 1, visible: :all
|
|
140
|
+
inner = page.find("[data-slot=sidebar-inner]", visible: :all)
|
|
141
|
+
assert_includes inner[:class], "has-[>[data-nested]]:flex-row"
|
|
142
|
+
assert_selector "[data-slot=sidebar-inner] > [data-nested=rail]", text: "Sections", visible: :all
|
|
143
|
+
assert_selector "[data-slot=sidebar-inner] > [data-nested=panel]", text: "Pages", visible: :all
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_a_rail_keeps_to_the_icon_width
|
|
147
|
+
render_inline(UI::Sidebar.new(nested: :rail)) { |rail| rail.with_sidebar_header { "Sections" } }
|
|
148
|
+
rail = page.find("div[data-nested=rail]")
|
|
149
|
+
assert_includes rail[:class], "w-(--sidebar-width-icon)"
|
|
150
|
+
assert_no_selector "aside"
|
|
151
|
+
assert_no_selector "[data-ui--sidebar-target]"
|
|
152
|
+
assert_selector "[data-slot=sidebar-header]", text: "Sections"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def test_a_panel_hides_when_the_outer_sidebar_collapses_to_icons
|
|
156
|
+
render_inline(UI::Sidebar.new(nested: :panel)) { "Pages" }
|
|
157
|
+
panel = page.find("div[data-nested=panel]")
|
|
158
|
+
assert_includes panel[:class], "flex-1"
|
|
159
|
+
assert_includes panel[:class], "md:group-data-[collapsible=icon]:hidden"
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def test_a_section_panel_shows_only_when_active
|
|
163
|
+
render_inline(UI::Sidebar.new(nested: :panel, section: "inbox", active: true)) { "Unread" }
|
|
164
|
+
shown = page.find("div[data-nested=panel][data-section=inbox]")
|
|
165
|
+
assert_equal UI::Sidebar.section_id("inbox"), shown[:id]
|
|
166
|
+
assert_nil shown[:hidden]
|
|
167
|
+
|
|
168
|
+
render_inline(UI::Sidebar.new(nested: :panel, section: "team")) { "Members" }
|
|
169
|
+
assert_selector "div[data-section=team][hidden]", visible: :all
|
|
170
|
+
end
|
|
121
171
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: velvetkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rathan Kumar
|
|
@@ -911,9 +911,12 @@ files:
|
|
|
911
911
|
- registry/test/components/previews/ui/sidebar_preview.rb
|
|
912
912
|
- registry/test/components/previews/ui/sidebar_preview/_brand.html.erb
|
|
913
913
|
- registry/test/components/previews/ui/sidebar_preview/_shell.html.erb
|
|
914
|
+
- registry/test/components/previews/ui/sidebar_preview/_top_bar.html.erb
|
|
914
915
|
- registry/test/components/previews/ui/sidebar_preview/collapsible.html.erb
|
|
915
916
|
- registry/test/components/previews/ui/sidebar_preview/default.html.erb
|
|
917
|
+
- registry/test/components/previews/ui/sidebar_preview/icon_rail.html.erb
|
|
916
918
|
- registry/test/components/previews/ui/sidebar_preview/pill_links.html.erb
|
|
919
|
+
- registry/test/components/previews/ui/sidebar_preview/site_header.html.erb
|
|
917
920
|
- registry/test/components/previews/ui/sidebar_preview/with_dropdown_header.html.erb
|
|
918
921
|
- registry/test/components/previews/ui/sidebar_preview/with_groups.html.erb
|
|
919
922
|
- registry/test/components/previews/ui/skeleton_preview.rb
|