velvetkit 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/velvetkit/version.rb +1 -1
  4. data/registry/app/components/ui/file_field.html.erb +4 -0
  5. data/registry/app/components/ui/file_field.rb +73 -0
  6. data/registry/app/components/ui/navigation_menu/item.html.erb +16 -0
  7. data/registry/app/components/ui/navigation_menu/item.rb +102 -0
  8. data/registry/app/components/ui/navigation_menu/link.html.erb +9 -0
  9. data/registry/app/components/ui/navigation_menu/link.rb +41 -0
  10. data/registry/app/components/ui/navigation_menu.html.erb +3 -0
  11. data/registry/app/components/ui/navigation_menu.rb +64 -0
  12. data/registry/app/components/ui/session_tabs/add.html.erb +1 -0
  13. data/registry/app/components/ui/session_tabs/add.rb +52 -0
  14. data/registry/app/components/ui/session_tabs/tab.html.erb +37 -0
  15. data/registry/app/components/ui/session_tabs/tab.rb +243 -0
  16. data/registry/app/components/ui/session_tabs.html.erb +15 -0
  17. data/registry/app/components/ui/session_tabs.rb +101 -0
  18. data/registry/app/components/ui/skeleton.html.erb +1 -0
  19. data/registry/app/components/ui/skeleton.rb +30 -0
  20. data/registry/app/components/ui/toast/viewport.html.erb +4 -0
  21. data/registry/app/components/ui/toast/viewport.rb +41 -0
  22. data/registry/app/components/ui/toast.html.erb +11 -0
  23. data/registry/app/components/ui/toast.rb +89 -0
  24. data/registry/app/javascript/controllers/ui/file_field_controller.ts +49 -0
  25. data/registry/app/javascript/controllers/ui/menu_controller.ts +3 -0
  26. data/registry/app/javascript/controllers/ui/navigation_menu_controller.ts +265 -0
  27. data/registry/app/javascript/controllers/ui/session_tabs_controller.ts +732 -0
  28. data/registry/app/javascript/controllers/ui/toast_controller.ts +62 -0
  29. data/registry/app/javascript/controllers/ui/toast_viewport_controller.ts +82 -0
  30. data/registry/app/javascript/velvetkit_icons.ts +21 -9
  31. data/registry/components.yml +10 -0
  32. data/registry/config/locales/velvetkit.en.yml +21 -0
  33. data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +3 -0
  34. data/registry/test/components/previews/ui/file_field_preview/with_error.html.erb +3 -0
  35. data/registry/test/components/previews/ui/file_field_preview.rb +18 -0
  36. data/registry/test/components/previews/ui/navigation_menu_preview/custom_panel.html.erb +20 -0
  37. data/registry/test/components/previews/ui/navigation_menu_preview/playground.html.erb +73 -0
  38. data/registry/test/components/previews/ui/navigation_menu_preview/simple.html.erb +23 -0
  39. data/registry/test/components/previews/ui/navigation_menu_preview.rb +23 -0
  40. data/registry/test/components/previews/ui/session_tabs_preview/handling_events.html.erb +46 -0
  41. data/registry/test/components/previews/ui/session_tabs_preview/saved_views.html.erb +16 -0
  42. data/registry/test/components/previews/ui/session_tabs_preview/touch_with_confirmation.html.erb +20 -0
  43. data/registry/test/components/previews/ui/session_tabs_preview.rb +35 -0
  44. data/registry/test/components/previews/ui/skeleton_preview/card_placeholder.html.erb +10 -0
  45. data/registry/test/components/previews/ui/skeleton_preview/shapes.html.erb +9 -0
  46. data/registry/test/components/previews/ui/skeleton_preview.rb +15 -0
  47. data/registry/test/components/previews/ui/toast_preview/live_viewport.html.erb +21 -0
  48. data/registry/test/components/previews/ui/toast_preview/variants.html.erb +7 -0
  49. data/registry/test/components/previews/ui/toast_preview/with_action.html.erb +7 -0
  50. data/registry/test/components/previews/ui/toast_preview.rb +29 -0
  51. data/registry/test/components/ui/file_field_test.rb +101 -0
  52. data/registry/test/components/ui/navigation_menu_test.rb +130 -0
  53. data/registry/test/components/ui/session_tabs/add_test.rb +52 -0
  54. data/registry/test/components/ui/session_tabs_test.rb +281 -0
  55. data/registry/test/components/ui/skeleton_test.rb +65 -0
  56. data/registry/test/components/ui/toast/viewport_test.rb +72 -0
  57. data/registry/test/components/ui/toast_test.rb +183 -0
  58. metadata +51 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 783fb129530172b7add0378661a6542b52014dfb663b558b625aa5fef0489bdd
4
- data.tar.gz: 9cb5e73f8e4ae8a94b3be1cb7ddbed5e8dbfd9ff36d9fbdddbfed317ba576769
3
+ metadata.gz: 11bfe45c2cfd5776e7525424166343744e1c51e26d62a29322bdd15aeff9dc13
4
+ data.tar.gz: 7c840a04c6e0a4cc45c6285b766e320f4ca9ff2218ca1574c8354b37ddce8c7b
5
5
  SHA512:
6
- metadata.gz: 3b399bf5d193fa63a3b92f7e686622761c56b453e14137bb6b8783ee95d703103ab6ca455dcade1f5695e868c44a8f6faa54eb652e0c4a141d0a6b4895553ed8
7
- data.tar.gz: 4a7b4fb856f8645f7ed4ece0f8eeb5de9228d71ced91ae9ecd908814b51a59c8f1b9744bc40f99ca3af2443fb894014bdc548e7cc23074ec59b3ecb652fee1b5
6
+ metadata.gz: 1702b2c951054c63690231808cf94577f2a03d36eee3e08287c9d5f4c0a7a6bfb5bd8facacdd1cc19eb7ceb870e4dc37e956a4782a07478b7211dd26d39940e5
7
+ data.tar.gz: 4270d831f5952b00790957e5ece167864e972d46e5dc75b4d34b78455cc560e97b179c49013ec727df887a970dde8b8aee2f210d55964dd777f708a73436118d
data/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  copied into your app one at a time, under your namespace.</p>
8
8
 
9
9
  <p>
10
- <a href="https://rubygems.org/gems/velvetkit"><img alt="Gem version" src="https://img.shields.io/gem/v/velvetkit?include_prereleases&color=4D1A7F"></a>
10
+ <a href="https://rubygems.org/gems/velvetkit"><img alt="Gem version" src="https://img.shields.io/gem/v/velvetkit?color=4D1A7F"></a>
11
11
  <a href="https://github.com/kitforge-tech/velvetkit/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/kitforge-tech/velvetkit/actions/workflows/ci.yml/badge.svg"></a>
12
12
  <img alt="Rails 7.1+" src="https://img.shields.io/badge/Rails-7.1%2B-CC0000?logo=rubyonrails&logoColor=white">
13
13
  <img alt="Tailwind CSS 4" src="https://img.shields.io/badge/Tailwind_CSS-4-38BDF8?logo=tailwindcss&logoColor=white">
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Velvetkit
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -0,0 +1,4 @@
1
+ <%= render(wrapper) do %><%= tag.label for: @input_id, class: dropzone_classes,
2
+ data: { controller: "ui--file-field",
3
+ "ui--file-field-target": "dropzone",
4
+ action: "dragover->ui--file-field#dragOver dragleave->ui--file-field#dragLeave drop->ui--file-field#drop" } do %><%= render(UI::Icon.new(name: "upload", size: :lg, class: "text-muted-foreground", aria: { hidden: true })) %><p class="text-sm text-muted-foreground"><span class="font-medium text-primary"><%= t("ui.file_field.browse", default: "Click to upload") %></span> <%= t("ui.file_field.drop", default: "or drag and drop") %></p><p class="text-xs text-muted-foreground empty:hidden" data-ui--file-field-target="filenames"></p><% if form_field? %><%= @form.file_field(@field, **form_field_options) %><% else %><%= tag.input(**html_options) %><% end %><% end %><% end %>
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ # UI::FileField — a drag-and-drop dropzone over a native file input.
6
+ #
7
+ # The input itself is sr-only, not hidden: it stays in the accessibility
8
+ # tree and keyboard/native-picker behavior (Tab, Enter/Space, the OS file
9
+ # dialog) comes from the real <input type="file">, same as every other
10
+ # styled-native-control component here. The dropzone is a <label> around it,
11
+ # so clicking anywhere in it opens the picker without any JS, and the
12
+ # ui--file-field controller only adds what a label can't: drag-over
13
+ # highlighting and listing the chosen file names.
14
+ class UI::FileField < UI::Base
15
+ def initialize(multiple: false, accept: nil,
16
+ label: nil, label_size: :default, label_weight: :medium,
17
+ hint: nil, required: false, error: nil, disabled: false,
18
+ form: nil, field: nil,
19
+ class: nil, **html_attrs)
20
+ @form = form
21
+ @field = field
22
+ @multiple = multiple
23
+ @accept = accept
24
+ @required = required
25
+ @disabled = disabled
26
+ @user_class = binding.local_variable_get(:class)
27
+ @html_attrs = html_attrs
28
+ @wrapper = UI::FormField.new(label: label, hint: hint, error: error,
29
+ required: required, disabled: disabled,
30
+ label_size: label_size, label_weight: label_weight,
31
+ form: form, field: field)
32
+ @input_id = @html_attrs[:id] || "ui-file-field-#{SecureRandom.hex(4)}"
33
+ @html_attrs[:id] = @input_id
34
+ @wrapper.for = @input_id
35
+ end
36
+
37
+ attr_reader :wrapper
38
+
39
+ def form_field?
40
+ @form.present? && @field.present?
41
+ end
42
+
43
+ def dropzone_classes
44
+ cn(
45
+ "relative flex cursor-pointer flex-col items-center gap-2 rounded-lg border-2 border-dashed p-6 text-center transition-colors",
46
+ "border-input hover:bg-accent/50",
47
+ "data-[drag=true]:border-primary data-[drag=true]:bg-primary/5",
48
+ { "border-destructive" => wrapper.error?,
49
+ "pointer-events-none opacity-50" => @disabled },
50
+ @user_class
51
+ )
52
+ end
53
+
54
+ def html_options
55
+ opts = @html_attrs.dup
56
+ opts[:type] = "file"
57
+ opts[:class] = "sr-only"
58
+ opts[:multiple] = true if @multiple
59
+ opts[:accept] = @accept if @accept
60
+ opts[:disabled] = true if @disabled
61
+ opts[:required] = true if @required
62
+ opts[:"data-ui--file-field-target"] = "input"
63
+ opts[:"data-action"] = "change->ui--file-field#updateNames"
64
+ opts[:"aria-invalid"] = "true" if wrapper.error?
65
+ opts[:"aria-describedby"] = wrapper.describedby if wrapper.describedby
66
+ opts
67
+ end
68
+
69
+ # The builder derives the name itself, so drop any explicit one.
70
+ def form_field_options
71
+ html_options.except(:name, :type)
72
+ end
73
+ end
@@ -0,0 +1,16 @@
1
+ <%# Run the block first, so with_link calls and any custom panel markup exist
2
+ before deciding whether this item is a trigger or a plain link. %>
3
+ <% body = content %>
4
+ <%= tag.li(**li_options) do %>
5
+ <% if links? || body.present? %>
6
+ <%= tag.button(**trigger_options) do %><%= label %><%= render(UI::Icon.new(name: "chevron-down", size: :xs, class: "transition-transform duration-200 group-aria-expanded/nav-item:rotate-180 motion-reduce:transition-none")) %><% end %>
7
+ <%= tag.div(**panel_options) do %>
8
+ <% if links? %>
9
+ <ul class="<%= list_classes %>"><% links.each do |link| %><li><%= link %></li><% end %></ul>
10
+ <% end %>
11
+ <%= body %>
12
+ <% end %>
13
+ <% else %>
14
+ <%= tag.a(**link_options) do %><%= label %><% end %>
15
+ <% end %>
16
+ <% end %>
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ # UI::NavigationMenu::Item — one entry in the top row.
4
+ #
5
+ # With `with_link`s (or any block content) it is a trigger that opens a
6
+ # panel; without, give it `href:` and it is a plain link.
7
+ #
8
+ # label: the text in the top row
9
+ # href: makes it a plain link (ignored when it has a panel)
10
+ # active: marks the current section: aria-current="page" on a plain
11
+ # link, a highlight on a trigger
12
+ # columns: 1 or 2 columns of links in the panel
13
+ # panel_class: extra classes for the panel, e.g. a width
14
+ class UI::NavigationMenu::Item < UI::Base
15
+ TOP_ITEM = "group/nav-item inline-flex h-9 items-center justify-center gap-1 rounded-md px-3 " \
16
+ "text-sm font-medium whitespace-nowrap text-foreground transition-colors " \
17
+ "hover:bg-accent hover:text-accent-foreground " \
18
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-1 " \
19
+ "aria-expanded:bg-accent aria-expanded:text-accent-foreground " \
20
+ "data-[active]:bg-accent/60 aria-[current=page]:bg-accent/60"
21
+
22
+ renders_many :links, ->(title:, href:, **opts) { UI::NavigationMenu::Link.new(title: title, href: href, **opts) }
23
+
24
+ def initialize(label:, href: nil, active: false, columns: 1, panel_class: nil, class: nil, **html_attrs)
25
+ @label = label
26
+ @href = href
27
+ @active = active
28
+ @columns = columns == 2 ? 2 : 1
29
+ @panel_class = panel_class
30
+ @user_class = binding.local_variable_get(:class)
31
+ @html_attrs = html_attrs
32
+ end
33
+
34
+ attr_reader :label
35
+
36
+ def set_navigation_context(nav, index:)
37
+ @nav = nav
38
+ @index = index
39
+ end
40
+
41
+ def trigger_id; "#{@nav.id}-trigger-#{@index}"; end
42
+ def panel_id; "#{@nav.id}-panel-#{@index}"; end
43
+
44
+ def li_options
45
+ { class: cn("relative", @user_class), **@html_attrs }
46
+ end
47
+
48
+ def link_options
49
+ {
50
+ href: @href,
51
+ class: TOP_ITEM,
52
+ "aria-current": (@active ? "page" : nil),
53
+ data: { "ui--navigation-menu-target": "top", action: "keydown->ui--navigation-menu#topKeydown" }
54
+ }
55
+ end
56
+
57
+ def trigger_options
58
+ {
59
+ type: "button",
60
+ id: trigger_id,
61
+ class: TOP_ITEM,
62
+ "aria-expanded": "false",
63
+ "aria-controls": panel_id,
64
+ data: {
65
+ "ui--navigation-menu-target": "top trigger",
66
+ active: (@active ? "" : nil),
67
+ action: [
68
+ "click->ui--navigation-menu#toggle",
69
+ "pointerenter->ui--navigation-menu#hoverOpen",
70
+ "pointerleave->ui--navigation-menu#hoverClose",
71
+ "keydown->ui--navigation-menu#topKeydown"
72
+ ].join(" ")
73
+ }
74
+ }
75
+ end
76
+
77
+ def panel_options
78
+ {
79
+ id: panel_id,
80
+ hidden: true,
81
+ class: cn(
82
+ "z-50 max-w-[calc(100vw-1rem)] rounded-lg border bg-popover p-2 text-popover-foreground shadow-md",
83
+ "animate-in fade-in-0 zoom-in-95",
84
+ @columns == 2 ? "w-[36rem]" : "w-96",
85
+ @panel_class
86
+ ),
87
+ data: {
88
+ "ui--navigation-menu-target": "panel",
89
+ state: "closed",
90
+ action: [
91
+ "pointerenter->ui--navigation-menu#cancelClose",
92
+ "pointerleave->ui--navigation-menu#hoverClose",
93
+ "keydown->ui--navigation-menu#panelKeydown"
94
+ ].join(" ")
95
+ }
96
+ }
97
+ end
98
+
99
+ def list_classes
100
+ cn("grid gap-1", { "sm:grid-cols-2" => @columns == 2 })
101
+ end
102
+ end
@@ -0,0 +1,9 @@
1
+ <%= tag.a(**link_options) do %>
2
+ <% if icon %>
3
+ <span class="flex size-9 shrink-0 items-center justify-center rounded-md border bg-background text-muted-foreground"><%= render(UI::Icon.new(name: icon, size: :sm)) %></span>
4
+ <% end %>
5
+ <span class="min-w-0">
6
+ <span class="block font-medium leading-snug"><%= title %></span>
7
+ <% if description %><span class="mt-1 line-clamp-2 block leading-snug text-muted-foreground"><%= description %></span><% end %>
8
+ </span>
9
+ <% end %>
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ # UI::NavigationMenu::Link — a rich link in a panel: a title, an optional
4
+ # one- or two-line description and an optional leading icon.
5
+ #
6
+ # title: the link text
7
+ # href: where it goes
8
+ # description: muted text under the title
9
+ # icon: a Lucide icon name, shown in a tile on the left
10
+ # active: the current page (aria-current="page")
11
+ class UI::NavigationMenu::Link < UI::Base
12
+ def initialize(title:, href:, description: nil, icon: nil, active: false, class: nil, **html_attrs)
13
+ @title = title
14
+ @href = href
15
+ @description = description
16
+ @icon = icon
17
+ @active = active
18
+ @user_class = binding.local_variable_get(:class)
19
+ @html_attrs = html_attrs
20
+ end
21
+
22
+ attr_reader :title, :description, :icon
23
+
24
+ def link_options
25
+ user_data = @html_attrs[:data] || {}
26
+ @html_attrs.except(:data).merge(
27
+ href: @href,
28
+ class: cn(
29
+ "flex gap-3 rounded-md p-3 text-sm outline-none transition-colors",
30
+ # A title alone sits level with its icon; with a description, both
31
+ # start at the top.
32
+ @description ? "items-start" : "items-center",
33
+ "hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground",
34
+ "focus-visible:ring-2 focus-visible:ring-primary aria-[current=page]:bg-accent/60",
35
+ @user_class
36
+ ),
37
+ "aria-current": (@active ? "page" : nil),
38
+ data: user_data.merge("ui--navigation-menu-target": "link")
39
+ )
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ <%= tag.nav(id: id, "aria-label": nav_label, class: root_classes, data: root_data, **@html_attrs.except(:data)) do %>
2
+ <ul class="flex flex-wrap items-center gap-1"><% items.each do |item| %><%= item %><% end %></ul>
3
+ <% end %>
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ # UI::NavigationMenu — a site's main navigation: plain links, and triggers
4
+ # that open a panel of rich links (title, description, optional icon).
5
+ #
6
+ # Follows the WAI-ARIA disclosure navigation pattern (buttons with
7
+ # aria-expanded controlling a panel of ordinary links), not role="menu",
8
+ # which is for application menus.
9
+ #
10
+ # <%= render(UI::NavigationMenu.new) do |nav| %>
11
+ # <% nav.with_item(label: "Getting started") do |item| %>
12
+ # <% item.with_link(title: "Introduction", href: "/docs",
13
+ # description: "Re-usable components built with Tailwind CSS.") %>
14
+ # <% end %>
15
+ # <% nav.with_item(label: "Docs", href: "/docs") %>
16
+ # <% end %>
17
+ #
18
+ # A panel opens on hover (mouse, after `open_delay` ms; instantly when
19
+ # another panel is already open), on click, or with Enter/Space/ArrowDown.
20
+ # Escape, a click outside or tabbing away closes it.
21
+ #
22
+ # Compound:
23
+ # UI::NavigationMenu — the <nav> and its list
24
+ # UI::NavigationMenu::Item — a plain link, or a trigger plus its panel
25
+ # UI::NavigationMenu::Link — a rich link inside a panel
26
+ class UI::NavigationMenu < UI::Base
27
+ renders_many :items, ->(label:, **opts) {
28
+ @item_count = (@item_count || 0) + 1
29
+ UI::NavigationMenu::Item.new(label: label, **opts).tap { |i| i.set_navigation_context(self, index: @item_count) }
30
+ }
31
+
32
+ # label: accessible name of the <nav> (several navs on a page need
33
+ # different names)
34
+ # open_delay: ms of hovering before a panel opens
35
+ # close_delay: ms after the pointer leaves before it closes, so it can
36
+ # cross the gap between trigger and panel
37
+ def initialize(label: nil, open_delay: 150, close_delay: 200, class: nil, **html_attrs)
38
+ @label = label
39
+ @open_delay = open_delay
40
+ @close_delay = close_delay
41
+ @user_class = binding.local_variable_get(:class)
42
+ @html_attrs = html_attrs
43
+ @id = @html_attrs.delete(:id) || "ui-navigation-menu-#{SecureRandom.hex(4)}"
44
+ end
45
+
46
+ attr_reader :id
47
+
48
+ def nav_label
49
+ @label || t("ui.navigation_menu.label", default: "Main")
50
+ end
51
+
52
+ def root_classes
53
+ cn("relative", @user_class)
54
+ end
55
+
56
+ def root_data
57
+ {
58
+ controller: "ui--navigation-menu",
59
+ "ui--navigation-menu-open-delay-value": @open_delay,
60
+ "ui--navigation-menu-close-delay-value": @close_delay,
61
+ action: "focusin->ui--navigation-menu#focusIn focusout->ui--navigation-menu#focusOut"
62
+ }.merge(@html_attrs[:data] || {})
63
+ end
64
+ end
@@ -0,0 +1 @@
1
+ <% if url? %><%= render(UI::ButtonTo.new(url, method: :post, form_class: "contents", **button_options)) do |b| %><% b.with_leading_icon(name: "plus", size: icon_size) %><% end %><% else %><%= render(UI::Button.new(**button_options)) do |b| %><% b.with_leading_icon(name: "plus", size: icon_size) %><% end %><% end %>
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ # UI::SessionTabs::Add — the "+" button after the tabs.
4
+ #
5
+ # url: POSTs a real form there (works without JS; Turbo disables the button
6
+ # while the request is in flight, so a double click opens one tab).
7
+ # Omit it to only dispatch `ui--session-tabs:add`.
8
+ # label: accessible name; defaults to the "New tab" translation.
9
+ class UI::SessionTabs::Add < UI::Base
10
+ def initialize(url: nil, label: nil, class: nil, **html_attrs)
11
+ @url = url
12
+ @label = label
13
+ @user_class = binding.local_variable_get(:class)
14
+ @html_attrs = html_attrs
15
+ end
16
+
17
+ def set_session_tabs_context(tabs)
18
+ @tabs = tabs
19
+ end
20
+
21
+ def url?
22
+ @url.present?
23
+ end
24
+
25
+ attr_reader :url
26
+
27
+ def label
28
+ @label || t("ui.session_tabs.add", default: "New tab")
29
+ end
30
+
31
+ def touch?
32
+ @tabs.size == :touch
33
+ end
34
+
35
+ def icon_size
36
+ touch? ? :sm : :xs
37
+ end
38
+
39
+ def button_options
40
+ user_data = @html_attrs[:data] || {}
41
+ @html_attrs.except(:data).merge(
42
+ variant: :ghost,
43
+ size: :icon_sm,
44
+ class: cn("mb-1 shrink-0", touch? ? "size-8" : "size-7", @user_class),
45
+ "aria-label": label,
46
+ title: label,
47
+ data: user_data.merge(
48
+ action: [ user_data[:action], "click->ui--session-tabs#add" ].compact.join(" ")
49
+ )
50
+ )
51
+ end
52
+ end
@@ -0,0 +1,37 @@
1
+ <% label_html = content %>
2
+ <%= tag.div(**wrapper_options) do %>
3
+ <% if movable? %><%= tag.span(**handle_options) do %><%= render(UI::Icon.new(name: "grip-vertical", size: menu_icon_size, class: handle_icon_classes)) %><% end %><% end %>
4
+ <%= tag.public_send(link? ? :a : :button, **trigger_options) do %>
5
+ <%= tag.span(label_html, id: label_id, class: "truncate max-w-[20ch]", data: { "ui--session-tabs-target": "label" }) %>
6
+ <% if meta? %><span class="shrink-0 text-xs font-normal tabular-nums text-muted-foreground"><%= meta %></span><% end %>
7
+ <% end %>
8
+ <% if any_menu? %>
9
+ <%= render(UI::Menu.new(class: "flex shrink-0")) do |menu| %>
10
+ <% menu.with_trigger(**menu_trigger_options) do %><%= render(UI::Icon.new(name: "ellipsis-vertical", size: menu_icon_size, class: menu_icon_classes)) %><% end %>
11
+ <% menu.with_content(align: :end) do |c| %>
12
+ <% if enabled?(:rename) %>
13
+ <% c.with_item(t("ui.session_tabs.rename", default: "Rename"), **action_item_options(:rename)) %>
14
+ <% end %>
15
+ <% if enabled?(:duplicate) %>
16
+ <% c.with_item(t("ui.session_tabs.duplicate", default: "Duplicate"), **action_item_options(:duplicate)) %>
17
+ <% end %>
18
+ <% if enabled?(:move) %>
19
+ <% c.with_item(t("ui.session_tabs.move_left", default: "Move left"),
20
+ **action_item_options(:moveLeft, move: "left"), **hidden_item_options(!can_move_left?)) %>
21
+ <% c.with_item(t("ui.session_tabs.move_right", default: "Move right"),
22
+ **action_item_options(:moveRight, move: "right"), **hidden_item_options(!can_move_right?)) %>
23
+ <% end %>
24
+ <% menu_items.each do |label, opts, block| %>
25
+ <% c.with_item(label, **opts, &block) %>
26
+ <% end %>
27
+ <% if enabled?(:close) %>
28
+ <% if enabled?(:rename) || enabled?(:duplicate) || enabled?(:move) || menu_items.any? %>
29
+ <% c.with_divider(hidden: !close_available?, data: { "close-part": true }) %>
30
+ <% end %>
31
+ <% c.with_item(t("ui.session_tabs.close", default: "Close"), variant: :destructive,
32
+ **action_item_options(:close, "close-part": true), **hidden_item_options(!close_available?)) %>
33
+ <% end %>
34
+ <% end %>
35
+ <% end %>
36
+ <% end %>
37
+ <% end %>