velvetkit 0.1.0.beta → 0.2.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/README.md +143 -75
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/checkbox.html.erb +2 -0
- data/registry/app/components/ui/checkbox.rb +11 -5
- data/registry/app/components/ui/collapsible.html.erb +7 -0
- data/registry/app/components/ui/collapsible.rb +67 -0
- data/registry/app/components/ui/date_picker.html.erb +4 -1
- data/registry/app/components/ui/date_picker.rb +10 -2
- data/registry/app/components/ui/file_field.html.erb +4 -0
- data/registry/app/components/ui/file_field.rb +73 -0
- data/registry/app/components/ui/form_field/messages.html.erb +6 -0
- data/registry/app/components/ui/form_field/messages.rb +11 -0
- data/registry/app/components/ui/form_field.html.erb +9 -0
- data/registry/app/components/ui/form_field.rb +105 -0
- data/registry/app/components/ui/input.html.erb +1 -8
- data/registry/app/components/ui/input.rb +12 -36
- data/registry/app/components/ui/input_group/addon.rb +4 -1
- data/registry/app/components/ui/input_group/field.rb +4 -1
- data/registry/app/components/ui/input_group.rb +12 -10
- data/registry/app/components/ui/native_select.html.erb +2 -9
- data/registry/app/components/ui/native_select.rb +17 -31
- data/registry/app/components/ui/password_input.html.erb +1 -8
- data/registry/app/components/ui/password_input.rb +9 -27
- data/registry/app/components/ui/select.html.erb +4 -0
- data/registry/app/components/ui/select.rb +12 -29
- data/registry/app/components/ui/session_tabs/add.html.erb +1 -0
- data/registry/app/components/ui/session_tabs/add.rb +52 -0
- data/registry/app/components/ui/session_tabs/tab.html.erb +37 -0
- data/registry/app/components/ui/session_tabs/tab.rb +243 -0
- data/registry/app/components/ui/session_tabs.html.erb +15 -0
- data/registry/app/components/ui/session_tabs.rb +101 -0
- data/registry/app/components/ui/skeleton.html.erb +1 -0
- data/registry/app/components/ui/skeleton.rb +30 -0
- data/registry/app/components/ui/table_of_contents/item.html.erb +8 -0
- data/registry/app/components/ui/table_of_contents/item.rb +41 -0
- data/registry/app/components/ui/table_of_contents.html.erb +13 -0
- data/registry/app/components/ui/table_of_contents.rb +58 -0
- data/registry/app/components/ui/textarea.html.erb +2 -0
- data/registry/app/components/ui/textarea.rb +101 -0
- data/registry/app/components/ui/toast/viewport.html.erb +4 -0
- data/registry/app/components/ui/toast/viewport.rb +41 -0
- data/registry/app/components/ui/toast.html.erb +11 -0
- data/registry/app/components/ui/toast.rb +89 -0
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +49 -0
- data/registry/app/javascript/controllers/ui/menu_controller.ts +3 -0
- data/registry/app/javascript/controllers/ui/session_tabs_controller.ts +732 -0
- data/registry/app/javascript/controllers/ui/table_of_contents_controller.ts +179 -0
- data/registry/app/javascript/controllers/ui/toast_controller.ts +62 -0
- data/registry/app/javascript/controllers/ui/toast_viewport_controller.ts +82 -0
- data/registry/app/javascript/velvetkit_icons.ts +21 -9
- data/registry/components.yml +17 -1
- data/registry/config/locales/velvetkit.en.yml +21 -0
- data/registry/test/components/previews/ui/collapsible_preview/default.html.erb +18 -0
- data/registry/test/components/previews/ui/collapsible_preview/show_more.html.erb +7 -0
- data/registry/test/components/previews/ui/collapsible_preview.rb +19 -0
- data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +3 -0
- data/registry/test/components/previews/ui/file_field_preview/with_error.html.erb +3 -0
- data/registry/test/components/previews/ui/file_field_preview.rb +18 -0
- data/registry/test/components/previews/ui/form_field_preview/custom_control.html.erb +6 -0
- data/registry/test/components/previews/ui/form_field_preview/default.html.erb +7 -0
- data/registry/test/components/previews/ui/form_field_preview/model_errors.html.erb +11 -0
- data/registry/test/components/previews/ui/form_field_preview.rb +12 -0
- data/registry/test/components/previews/ui/input_preview/hint_and_error.html.erb +4 -0
- data/registry/test/components/previews/ui/input_preview.rb +3 -0
- data/registry/test/components/previews/ui/session_tabs_preview/handling_events.html.erb +46 -0
- data/registry/test/components/previews/ui/session_tabs_preview/saved_views.html.erb +16 -0
- data/registry/test/components/previews/ui/session_tabs_preview/touch_with_confirmation.html.erb +20 -0
- data/registry/test/components/previews/ui/session_tabs_preview.rb +35 -0
- data/registry/test/components/previews/ui/sidebar_preview/_brand.html.erb +4 -4
- data/registry/test/components/previews/ui/sidebar_preview/with_dropdown_header.html.erb +1 -1
- data/registry/test/components/previews/ui/skeleton_preview/card_placeholder.html.erb +10 -0
- data/registry/test/components/previews/ui/skeleton_preview/shapes.html.erb +9 -0
- data/registry/test/components/previews/ui/skeleton_preview.rb +15 -0
- data/registry/test/components/previews/ui/table_of_contents_preview/default.html.erb +41 -0
- data/registry/test/components/previews/ui/table_of_contents_preview/flat.html.erb +17 -0
- data/registry/test/components/previews/ui/table_of_contents_preview.rb +9 -0
- data/registry/test/components/previews/ui/textarea_preview/autogrow.html.erb +4 -0
- data/registry/test/components/previews/ui/textarea_preview/default.html.erb +3 -0
- data/registry/test/components/previews/ui/textarea_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/textarea_preview/states.html.erb +7 -0
- data/registry/test/components/previews/ui/textarea_preview.rb +33 -0
- data/registry/test/components/previews/ui/toast_preview/live_viewport.html.erb +21 -0
- data/registry/test/components/previews/ui/toast_preview/variants.html.erb +7 -0
- data/registry/test/components/previews/ui/toast_preview/with_action.html.erb +7 -0
- data/registry/test/components/previews/ui/toast_preview.rb +29 -0
- data/registry/test/components/ui/checkbox_test.rb +24 -0
- data/registry/test/components/ui/collapsible_test.rb +71 -0
- data/registry/test/components/ui/date_picker_test.rb +14 -0
- data/registry/test/components/ui/file_field_test.rb +101 -0
- data/registry/test/components/ui/form_field/messages_test.rb +19 -0
- data/registry/test/components/ui/form_field_test.rb +122 -0
- data/registry/test/components/ui/input_group_test.rb +30 -2
- data/registry/test/components/ui/input_test.rb +37 -0
- data/registry/test/components/ui/native_select_test.rb +25 -0
- data/registry/test/components/ui/password_input_test.rb +9 -0
- data/registry/test/components/ui/select_test.rb +14 -0
- data/registry/test/components/ui/session_tabs/add_test.rb +52 -0
- data/registry/test/components/ui/session_tabs_test.rb +281 -0
- data/registry/test/components/ui/skeleton_test.rb +65 -0
- data/registry/test/components/ui/table_of_contents/item_test.rb +38 -0
- data/registry/test/components/ui/table_of_contents_test.rb +120 -0
- data/registry/test/components/ui/textarea_test.rb +178 -0
- data/registry/test/components/ui/toast/viewport_test.rb +72 -0
- data/registry/test/components/ui/toast_test.rb +183 -0
- metadata +77 -4
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<%# A "Default" view the user can't close or rename, plus views they made. %>
|
|
2
|
+
<div class="max-w-2xl">
|
|
3
|
+
<%= render(UI::SessionTabs.new(label: "Saved views")) do |tabs| %>
|
|
4
|
+
<% tabs.with_tab(value: "default", active: true, duplicate: true) do |tab| %>
|
|
5
|
+
<% tab.with_meta { "128" } %>Default
|
|
6
|
+
<% end %>
|
|
7
|
+
<% tabs.with_tab(value: "unpaid", rename: true, duplicate: true, move: true, close: true) do |tab| %>
|
|
8
|
+
<% tab.with_meta { "12" } %>Unpaid
|
|
9
|
+
<% end %>
|
|
10
|
+
<% tabs.with_tab(value: "this-week", rename: true, duplicate: true, move: true, close: true) do |tab| %>
|
|
11
|
+
<% tab.with_meta { "41" } %>This week
|
|
12
|
+
<% end %>
|
|
13
|
+
<% tabs.with_add %>
|
|
14
|
+
<% end %>
|
|
15
|
+
<div class="rounded-b-md border border-t-0 p-4 text-sm text-muted-foreground">The table for the selected view goes here.</div>
|
|
16
|
+
</div>
|
data/registry/test/components/previews/ui/session_tabs_preview/touch_with_confirmation.html.erb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%# Touch size: 44px tabs; long-press a tab to open its menu. Tabs with
|
|
2
|
+
unsaved work ask before closing; empty ones close straight away. %>
|
|
3
|
+
<div class="max-w-2xl space-y-3">
|
|
4
|
+
<%= render(UI::SessionTabs.new(size: :touch, return_focus: "#session-tabs-demo-input")) do |tabs| %>
|
|
5
|
+
<% tabs.with_tab(value: "1", active: true, rename: true, move: true, close: true,
|
|
6
|
+
close_confirm: "This tab has 3 unsaved items. They will be lost.") do |tab| %>
|
|
7
|
+
<% tab.with_meta { "3 items" } %>Tab 1
|
|
8
|
+
<% end %>
|
|
9
|
+
<% tabs.with_tab(value: "2", rename: true, move: true, close: true,
|
|
10
|
+
close_confirm: "This tab has 1 unsaved item. It will be lost.") do |tab| %>
|
|
11
|
+
<% tab.with_meta { "1 item" } %>Tab 2
|
|
12
|
+
<% end %>
|
|
13
|
+
<% tabs.with_tab(value: "3", rename: true, move: true, close: true) do |tab| %>
|
|
14
|
+
<% tab.with_meta { "Empty" } %>Tab 3
|
|
15
|
+
<% end %>
|
|
16
|
+
<% tabs.with_add %>
|
|
17
|
+
<% end %>
|
|
18
|
+
<input id="session-tabs-demo-input" class="h-11 w-full rounded-md border border-input bg-background px-3 text-sm"
|
|
19
|
+
placeholder="Focus comes back here after each tab action (return_focus:)">
|
|
20
|
+
</div>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Tabs the user manages: rename, duplicate, reorder, close, add.
|
|
4
|
+
#
|
|
5
|
+
# Each action is opt-in per tab and takes either a URL (submitted as a Turbo
|
|
6
|
+
# form — rename PATCH, duplicate POST, move PATCH with a 1-based `position`,
|
|
7
|
+
# close DELETE) or `true` (only the cancelable `ui--session-tabs:<action>`
|
|
8
|
+
# event fires). These previews use events only, so nothing is saved.
|
|
9
|
+
class UI::SessionTabsPreview < ViewComponent::Preview
|
|
10
|
+
# @label Playground
|
|
11
|
+
# @param size select { choices: [default, touch] }
|
|
12
|
+
# @param min_tabs number
|
|
13
|
+
# @param rename toggle
|
|
14
|
+
# @param duplicate toggle
|
|
15
|
+
# @param move toggle
|
|
16
|
+
# @param close toggle
|
|
17
|
+
def playground(size: :default, min_tabs: 1, rename: true, duplicate: true, move: true, close: true)
|
|
18
|
+
render(UI::SessionTabs.new(size: size.to_sym, min_tabs: min_tabs.to_i)) do |tabs|
|
|
19
|
+
%w[Default Drafts Archive].each_with_index do |name, i|
|
|
20
|
+
tabs.with_tab(value: name.downcase, active: i.zero?,
|
|
21
|
+
rename: rename, duplicate: duplicate, move: move, close: close) { name }
|
|
22
|
+
end
|
|
23
|
+
tabs.with_add
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @label Saved views
|
|
28
|
+
def saved_views; render_with_template; end
|
|
29
|
+
|
|
30
|
+
# @label Touch, with close confirmation
|
|
31
|
+
def touch_with_confirmation; render_with_template; end
|
|
32
|
+
|
|
33
|
+
# @label Handling the events
|
|
34
|
+
def handling_events; render_with_template; end
|
|
35
|
+
end
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
the icons. The images are velvetkit.com's; in an app, put its own logo here. %>
|
|
5
5
|
<div class="flex h-9 min-w-0 items-center px-2 group-data-[collapsible=icon]:px-0">
|
|
6
6
|
<span class="group-data-[collapsible=icon]:hidden">
|
|
7
|
-
<img src="/velvetkit/logo-light.
|
|
8
|
-
<img src="/velvetkit/logo-dark.
|
|
7
|
+
<img src="/velvetkit/logo-light.svg" alt="VelvetKit" class="h-8 w-auto max-w-none dark:hidden">
|
|
8
|
+
<img src="/velvetkit/logo-dark.svg" alt="VelvetKit" class="hidden h-8 w-auto max-w-none dark:block">
|
|
9
9
|
</span>
|
|
10
10
|
<span class="hidden size-8 shrink-0 items-center justify-center group-data-[collapsible=icon]:flex">
|
|
11
|
-
<img src="/velvetkit/mark-light.
|
|
12
|
-
<img src="/velvetkit/mark-dark.
|
|
11
|
+
<img src="/velvetkit/mark-light.svg" alt="VelvetKit" class="size-7 max-w-none shrink-0 object-contain dark:hidden">
|
|
12
|
+
<img src="/velvetkit/mark-dark.svg" alt="VelvetKit" class="hidden size-7 max-w-none shrink-0 object-contain dark:block">
|
|
13
13
|
</span>
|
|
14
14
|
</div>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<% brand = capture do %>
|
|
2
2
|
<%= render(UI::Menu.new) do |menu| %>
|
|
3
3
|
<% menu.with_trigger(variant: :ghost, class: "w-full justify-start px-2 h-auto py-1.5 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:p-0") do %>
|
|
4
|
-
<img src="/velvetkit/mark-light.
|
|
4
|
+
<img src="/velvetkit/mark-light.svg" alt="" class="size-8 max-w-none shrink-0 object-contain dark:hidden"><img src="/velvetkit/mark-dark.svg" alt="" class="hidden size-8 max-w-none shrink-0 object-contain dark:block">
|
|
5
5
|
<div class="grid flex-1 text-left text-sm leading-tight group-data-[collapsible=icon]:hidden">
|
|
6
6
|
<span class="truncate font-medium">VelvetKit</span>
|
|
7
7
|
<span class="truncate text-xs text-muted-foreground">Workspace</span>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<%= render(UI::Card.new(class: "w-80 p-6")) do %>
|
|
2
|
+
<div class="flex items-center gap-4">
|
|
3
|
+
<%= render(UI::Skeleton.new(shape: :circle)) %>
|
|
4
|
+
<div class="flex-1 space-y-2">
|
|
5
|
+
<%= render(UI::Skeleton.new(shape: :text, class: "w-3/4")) %>
|
|
6
|
+
<%= render(UI::Skeleton.new(shape: :text, class: "w-1/2")) %>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
<%= render(UI::Skeleton.new(shape: :rectangle, class: "mt-4")) %>
|
|
10
|
+
<% end %>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<div class="flex flex-col gap-6">
|
|
2
|
+
<div class="space-y-2">
|
|
3
|
+
<%= render(UI::Skeleton.new(shape: :text, class: "w-64")) %>
|
|
4
|
+
<%= render(UI::Skeleton.new(shape: :text, class: "w-48")) %>
|
|
5
|
+
<%= render(UI::Skeleton.new(shape: :text, class: "w-56")) %>
|
|
6
|
+
</div>
|
|
7
|
+
<%= render(UI::Skeleton.new(shape: :circle)) %>
|
|
8
|
+
<%= render(UI::Skeleton.new(shape: :rectangle, class: "w-64")) %>
|
|
9
|
+
</div>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::SkeletonPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param shape select { choices: [text, circle, rectangle] }
|
|
6
|
+
def playground(shape: :text)
|
|
7
|
+
render(UI::Skeleton.new(shape: shape.to_sym, class: shape.to_sym == :circle ? nil : "w-64"))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# @label Shapes
|
|
11
|
+
def shapes; render_with_template; end
|
|
12
|
+
|
|
13
|
+
# @label Card Placeholder
|
|
14
|
+
def card_placeholder; render_with_template; end
|
|
15
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<%# The article scrolls in its own box here; on a real page leave out `container:`. %>
|
|
2
|
+
<div class="grid grid-cols-[1fr_14rem] gap-8 max-w-3xl">
|
|
3
|
+
<div id="toc-default-article" class="h-96 overflow-y-auto rounded-md border p-6 space-y-6">
|
|
4
|
+
<section class="space-y-2">
|
|
5
|
+
<h2 id="toc-default-process" class="text-lg font-semibold">Contribution process</h2>
|
|
6
|
+
<p class="text-sm text-muted-foreground">Every change goes through the same four steps.</p>
|
|
7
|
+
</section>
|
|
8
|
+
<% [
|
|
9
|
+
["toc-default-issue", "1. Create an issue or open a merge request"],
|
|
10
|
+
["toc-default-classify", "2. Classify as core or extended"],
|
|
11
|
+
["toc-default-support", "3. Define level of support"],
|
|
12
|
+
["toc-default-merge", "4. Merge your changes"]
|
|
13
|
+
].each do |id, heading| %>
|
|
14
|
+
<section class="space-y-2">
|
|
15
|
+
<h3 id="<%= id %>" class="font-medium"><%= heading %></h3>
|
|
16
|
+
<p class="text-sm text-muted-foreground">Describe the change and why it matters. Link related issues, add screenshots for visual changes, and note anything reviewers should try by hand.</p>
|
|
17
|
+
<p class="text-sm text-muted-foreground">Keep each change focused on one thing, so it is quick to review and easy to revert.</p>
|
|
18
|
+
</section>
|
|
19
|
+
<% end %>
|
|
20
|
+
<section class="space-y-2">
|
|
21
|
+
<h2 id="toc-default-resources" class="text-lg font-semibold">Resources</h2>
|
|
22
|
+
<p class="text-sm text-muted-foreground">Guides, design files and the component checklist.</p>
|
|
23
|
+
<p class="text-sm text-muted-foreground">Ask in the discussion board when something is unclear.</p>
|
|
24
|
+
</section>
|
|
25
|
+
<section class="min-h-80 space-y-2">
|
|
26
|
+
<h2 id="toc-default-conduct" class="text-lg font-semibold">Code of conduct</h2>
|
|
27
|
+
<p class="text-sm text-muted-foreground">Be kind, assume good intent, and keep feedback about the work.</p>
|
|
28
|
+
</section>
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<%= render(UI::TableOfContents.new(title: "On this page", container: "#toc-default-article", offset: 24)) do |toc| %>
|
|
32
|
+
<% toc.with_item(href: "#toc-default-process", text: "Contribution process") do |item| %>
|
|
33
|
+
<% item.with_item(href: "#toc-default-issue", text: "1. Create an issue or open a merge request") %>
|
|
34
|
+
<% item.with_item(href: "#toc-default-classify", text: "2. Classify as core or extended") %>
|
|
35
|
+
<% item.with_item(href: "#toc-default-support", text: "3. Define level of support") %>
|
|
36
|
+
<% item.with_item(href: "#toc-default-merge", text: "4. Merge your changes") %>
|
|
37
|
+
<% end %>
|
|
38
|
+
<% toc.with_item(href: "#toc-default-resources", text: "Resources") %>
|
|
39
|
+
<% toc.with_item(href: "#toc-default-conduct", text: "Code of conduct") %>
|
|
40
|
+
<% end %>
|
|
41
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<div class="grid grid-cols-[1fr_12rem] gap-8 max-w-2xl">
|
|
2
|
+
<div id="toc-flat-article" class="h-72 overflow-y-auto rounded-md border p-6 space-y-6 [&>section:last-child]:min-h-60">
|
|
3
|
+
<% %w[Install Configure Theme Deploy].each do |heading| %>
|
|
4
|
+
<section class="space-y-2">
|
|
5
|
+
<h2 id="toc-flat-<%= heading.downcase %>" class="font-semibold"><%= heading %></h2>
|
|
6
|
+
<p class="text-sm text-muted-foreground">Each section starts with what you need and ends with how to check it worked.</p>
|
|
7
|
+
<p class="text-sm text-muted-foreground">Commands run from the root of your Rails app.</p>
|
|
8
|
+
</section>
|
|
9
|
+
<% end %>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<%= render(UI::TableOfContents.new(container: "#toc-flat-article", offset: 24)) do |toc| %>
|
|
13
|
+
<% %w[Install Configure Theme Deploy].each do |heading| %>
|
|
14
|
+
<% toc.with_item(href: "#toc-flat-#{heading.downcase}", text: heading) %>
|
|
15
|
+
<% end %>
|
|
16
|
+
<% end %>
|
|
17
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<div class="flex flex-col gap-4 max-w-md">
|
|
2
|
+
<%= render(UI::Textarea.new(label: "Bio", value: "Rails developer who likes accessible UI.")) %>
|
|
3
|
+
<%= render(UI::Textarea.new(label: "Reason", required: true, placeholder: "Required")) %>
|
|
4
|
+
<%= render(UI::Textarea.new(label: "Summary", error: true, value: "Too short")) %>
|
|
5
|
+
<%= render(UI::Textarea.new(label: "Notes", disabled: true, value: "Locked after review")) %>
|
|
6
|
+
<%= render(UI::Textarea.new(label: "Fixed size", resize: :none, placeholder: "Can't be resized")) %>
|
|
7
|
+
</div>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::TextareaPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param size select { choices: [sm, default, lg] }
|
|
6
|
+
# @param resize select { choices: [vertical, none, both] }
|
|
7
|
+
# @param rows number
|
|
8
|
+
# @param autogrow toggle
|
|
9
|
+
# @param label text
|
|
10
|
+
# @param required toggle
|
|
11
|
+
# @param error toggle
|
|
12
|
+
# @param disabled toggle
|
|
13
|
+
# @param placeholder text
|
|
14
|
+
def playground(size: :default, resize: :vertical, rows: 3, autogrow: false,
|
|
15
|
+
label: "Message", required: false, error: false, disabled: false,
|
|
16
|
+
placeholder: "Write a message…")
|
|
17
|
+
render(UI::Textarea.new(size: size.to_sym, resize: resize.to_sym, rows: rows.to_i, autogrow: autogrow,
|
|
18
|
+
label: label, required: required, error: error, disabled: disabled,
|
|
19
|
+
placeholder: placeholder))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @label Default
|
|
23
|
+
def default; render_with_template; end
|
|
24
|
+
|
|
25
|
+
# @label Grows with its text
|
|
26
|
+
def autogrow; render_with_template; end
|
|
27
|
+
|
|
28
|
+
# @label States
|
|
29
|
+
def states; render_with_template; end
|
|
30
|
+
|
|
31
|
+
# @label All Sizes
|
|
32
|
+
def sizes; render_with_template; end
|
|
33
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<div class="flex flex-wrap gap-2">
|
|
2
|
+
<%
|
|
3
|
+
demos = {
|
|
4
|
+
default: ["Notification", "Heads up, something happened."],
|
|
5
|
+
success: ["Saved", "Your changes have been saved."],
|
|
6
|
+
destructive: ["Something broke", "There was a problem with your request."],
|
|
7
|
+
warning: ["Careful", "This action cannot be undone."],
|
|
8
|
+
info: ["FYI", "Here's some helpful information."]
|
|
9
|
+
}
|
|
10
|
+
%>
|
|
11
|
+
<% demos.each do |variant, (title, description)| %>
|
|
12
|
+
<% payload = { title: title, description: description, variant: variant }.to_json %>
|
|
13
|
+
<%= render(UI::Button.new(variant: :outline, size: :sm,
|
|
14
|
+
onclick: "window.dispatchEvent(new CustomEvent('toast:show', { detail: #{payload} }))")) { title } %>
|
|
15
|
+
<% end %>
|
|
16
|
+
<% persistent = { title: "Stays until dismissed", description: "duration: 0 skips the auto-dismiss timer.", variant: :default, duration: 0 }.to_json %>
|
|
17
|
+
<%= render(UI::Button.new(variant: :outline, size: :sm,
|
|
18
|
+
onclick: "window.dispatchEvent(new CustomEvent('toast:show', { detail: #{persistent} }))")) { "Persistent" } %>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<%= render(UI::Toast::Viewport.new) %>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<div class="flex flex-col gap-4 max-w-sm">
|
|
2
|
+
<%= render(UI::Toast.new(variant: :default, title: "Default", description: "Heads up, something happened.")) %>
|
|
3
|
+
<%= render(UI::Toast.new(variant: :success, title: "Success", description: "Your changes have been saved.")) %>
|
|
4
|
+
<%= render(UI::Toast.new(variant: :destructive, title: "Destructive", description: "There was a problem with your request.")) %>
|
|
5
|
+
<%= render(UI::Toast.new(variant: :warning, title: "Warning", description: "This action cannot be undone.")) %>
|
|
6
|
+
<%= render(UI::Toast.new(variant: :info, title: "Info", description: "Here's some helpful information.")) %>
|
|
7
|
+
</div>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::ToastPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param variant select { choices: [default, success, destructive, warning, info] }
|
|
6
|
+
# @param title text
|
|
7
|
+
# @param description text
|
|
8
|
+
# @param duration number Seconds before it auto-dismisses; 0 stays until dismissed.
|
|
9
|
+
# @param dismissible toggle
|
|
10
|
+
def playground(variant: :success, title: "Saved", description: "Your changes have been saved.",
|
|
11
|
+
duration: 5, dismissible: true)
|
|
12
|
+
render(UI::Toast.new(variant: variant.to_sym, title: title, description: description,
|
|
13
|
+
duration: duration, dismissible: dismissible))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @label All Variants
|
|
17
|
+
def variants; render_with_template; end
|
|
18
|
+
|
|
19
|
+
# @label With Action
|
|
20
|
+
def with_action; render_with_template; end
|
|
21
|
+
|
|
22
|
+
# @label Live Viewport
|
|
23
|
+
#
|
|
24
|
+
# Each button fires the same `toast:show` event the `toast()` helper
|
|
25
|
+
# dispatches, so this is exactly what a client-triggered toast looks like:
|
|
26
|
+
# stacking, auto-dismiss and pause-on-hover all come from the real
|
|
27
|
+
# UI::Toast::Viewport and ui--toast controllers, not a preview-only stand-in.
|
|
28
|
+
def live_viewport; render_with_template; end
|
|
29
|
+
end
|
|
@@ -233,4 +233,28 @@ class UI::CheckboxTest < ViewComponent::TestCase
|
|
|
233
233
|
render_inline(UI::Checkbox.new(form: form_builder_for(User.new), field: :remember_me, label: false))
|
|
234
234
|
assert_no_selector "label"
|
|
235
235
|
end
|
|
236
|
+
|
|
237
|
+
def test_error_message_shows_under_the_box_and_describes_it
|
|
238
|
+
render_inline(UI::Checkbox.new(name: "terms", label: "I accept the terms", id: "terms", error: "You must accept the terms"))
|
|
239
|
+
box = page.find("input#terms[aria-invalid='true']")
|
|
240
|
+
assert_equal "terms-error", box["aria-describedby"]
|
|
241
|
+
assert_selector "div > label + p#terms-error.text-destructive", text: "You must accept the terms"
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def test_model_errors_show_under_a_bound_checkbox
|
|
245
|
+
record = Struct.new(:terms) do
|
|
246
|
+
include ActiveModel::Validations
|
|
247
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Signup")
|
|
248
|
+
validates :terms, acceptance: { accept: "1" }
|
|
249
|
+
end.new("0").tap(&:validate)
|
|
250
|
+
form = ActionView::Helpers::FormBuilder.new(:signup, record, vc_test_controller.view_context, {})
|
|
251
|
+
render_inline(UI::Checkbox.new(form: form, field: :terms))
|
|
252
|
+
assert_selector "input[type='checkbox'][aria-invalid='true']"
|
|
253
|
+
assert_selector "p.text-destructive", text: "Terms must be accepted"
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def test_no_messages_no_wrapper
|
|
257
|
+
render_inline(UI::Checkbox.new(name: "terms", label: "Terms"))
|
|
258
|
+
refute_selector "div"
|
|
259
|
+
end
|
|
236
260
|
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::CollapsibleTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_collapsible(**opts)
|
|
10
|
+
render_inline(UI::Collapsible.new(**opts)) do |c|
|
|
11
|
+
c.with_trigger { "Forms" }
|
|
12
|
+
"<a href='/input'>Input</a>".html_safe
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def test_renders_details_with_summary_trigger
|
|
17
|
+
render_collapsible
|
|
18
|
+
assert_selector "details > summary", text: "Forms"
|
|
19
|
+
assert_selector "details > summary + div > a[href='/input']", visible: :all
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_closed_by_default
|
|
23
|
+
render_collapsible
|
|
24
|
+
assert_selector "details:not([open])", visible: :all
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_open
|
|
28
|
+
render_collapsible(open: true)
|
|
29
|
+
assert_selector "details[open]"
|
|
30
|
+
assert_selector "a[href='/input']", text: "Input"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_chevron_is_decorative_and_turns_when_open
|
|
34
|
+
render_collapsible
|
|
35
|
+
icon = page.find("summary [aria-hidden='true']", visible: :all)
|
|
36
|
+
assert_includes icon[:class].split, "group-open/collapsible:rotate-90"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_hides_the_native_marker
|
|
40
|
+
render_collapsible
|
|
41
|
+
classes = page.find("summary")[:class].split
|
|
42
|
+
assert_includes classes, "list-none"
|
|
43
|
+
assert_includes classes, "[&::-webkit-details-marker]:hidden"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_sizes
|
|
47
|
+
render_collapsible(size: :sm)
|
|
48
|
+
assert_includes page.find("summary")[:class].split, "text-xs"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_trigger_and_content_classes
|
|
52
|
+
render_collapsible(trigger_class: "font-semibold", content_class: "ml-3 border-l")
|
|
53
|
+
assert_includes page.find("summary")[:class].split, "font-semibold"
|
|
54
|
+
assert_includes page.find("details > div", visible: :all)[:class].split, "border-l"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_html_attrs_and_class_on_details
|
|
58
|
+
render_collapsible(id: "forms-tree", class: "mt-2", data: { test_id: "tree" })
|
|
59
|
+
details = page.find("details#forms-tree[data-test-id='tree']", visible: :all)
|
|
60
|
+
assert_includes details[:class].split, "mt-2"
|
|
61
|
+
assert_includes details[:class].split, "group/collapsible"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_nests
|
|
65
|
+
render_inline(UI::Collapsible.new(open: true)) do |outer|
|
|
66
|
+
outer.with_trigger { "Components" }
|
|
67
|
+
vc_test_controller.view_context.render(UI::Collapsible.new) { |inner| inner.with_trigger { "Forms" } }
|
|
68
|
+
end
|
|
69
|
+
assert_selector "details[open] > div > details > summary", text: "Forms"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -165,4 +165,18 @@ class UI::DatePickerTest < ViewComponent::TestCase
|
|
|
165
165
|
assert_includes arrow.text(:all), I18n.t(key)
|
|
166
166
|
end
|
|
167
167
|
end
|
|
168
|
+
|
|
169
|
+
def test_error_message_shows_under_the_hint_and_describes_the_input
|
|
170
|
+
render_inline(UI::DatePicker.new(name: "starts_on", label: "Start date", error: "Pick a date in the future"))
|
|
171
|
+
input = page.find("input[type='text'][aria-invalid='true']")
|
|
172
|
+
assert_equal "#{input[:id]}-hint #{input[:id]}-error", input["aria-describedby"]
|
|
173
|
+
assert_selector "p##{input[:id]}-error.text-destructive", text: "Pick a date in the future"
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
def test_no_error_only_the_hint_describes
|
|
177
|
+
render_inline(UI::DatePicker.new(name: "starts_on"))
|
|
178
|
+
input = page.find("input[type='text']")
|
|
179
|
+
assert_equal "#{input[:id]}-hint", input["aria-describedby"]
|
|
180
|
+
refute input["aria-invalid"]
|
|
181
|
+
end
|
|
168
182
|
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::FileFieldTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def test_renders_a_file_input
|
|
10
|
+
render_inline(UI::FileField.new)
|
|
11
|
+
assert_selector "input[type='file']"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_input_is_screen_reader_only_not_hidden
|
|
15
|
+
render_inline(UI::FileField.new)
|
|
16
|
+
input = page.find("input", visible: :all)
|
|
17
|
+
assert_includes input[:class].split, "sr-only"
|
|
18
|
+
refute input[:hidden]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_dropzone_is_a_label_pointing_at_the_input
|
|
22
|
+
render_inline(UI::FileField.new)
|
|
23
|
+
label = page.find("label")
|
|
24
|
+
input = page.find("input", visible: :all)
|
|
25
|
+
assert_equal input[:id], label[:for]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_dropzone_wired_to_controller
|
|
29
|
+
render_inline(UI::FileField.new)
|
|
30
|
+
label = page.find("label")
|
|
31
|
+
assert_equal "ui--file-field", label["data-controller"]
|
|
32
|
+
assert_includes label["data-action"], "dragover->ui--file-field#dragOver"
|
|
33
|
+
assert_includes label["data-action"], "dragleave->ui--file-field#dragLeave"
|
|
34
|
+
assert_includes label["data-action"], "drop->ui--file-field#drop"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_input_wired_to_update_names_on_change
|
|
38
|
+
render_inline(UI::FileField.new)
|
|
39
|
+
input = page.find("input", visible: :all)
|
|
40
|
+
assert_includes input["data-action"], "change->ui--file-field#updateNames"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_not_multiple_by_default
|
|
44
|
+
render_inline(UI::FileField.new)
|
|
45
|
+
refute page.find("input", visible: :all)[:multiple]
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_multiple
|
|
49
|
+
render_inline(UI::FileField.new(multiple: true))
|
|
50
|
+
assert page.find("input", visible: :all)[:multiple]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def test_accept
|
|
54
|
+
render_inline(UI::FileField.new(accept: "image/*"))
|
|
55
|
+
assert_equal "image/*", page.find("input", visible: :all)[:accept]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_disabled
|
|
59
|
+
render_inline(UI::FileField.new(disabled: true))
|
|
60
|
+
assert page.find("input", visible: :all)[:disabled]
|
|
61
|
+
assert_includes page.find("label")[:class], "opacity-50"
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_error_true_marks_the_input_invalid
|
|
65
|
+
render_inline(UI::FileField.new(error: true))
|
|
66
|
+
input = page.find("input", visible: :all)
|
|
67
|
+
assert_equal "true", input["aria-invalid"]
|
|
68
|
+
assert_includes page.find("label")[:class], "border-destructive"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# --- form-builder binding (Rails convention) ---
|
|
72
|
+
|
|
73
|
+
class User
|
|
74
|
+
include ActiveModel::Model
|
|
75
|
+
attr_accessor :avatar
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def form_builder_for(record)
|
|
79
|
+
ActionView::Helpers::FormBuilder.new(:user, record, vc_test_controller.view_context, {})
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_form_binding_scopes_the_field_name
|
|
83
|
+
render_inline(UI::FileField.new(form: form_builder_for(User.new), field: :avatar))
|
|
84
|
+
assert_selector "input[type='file'][name='user[avatar]']"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_label_is_derived_from_the_attribute_name
|
|
88
|
+
render_inline(UI::FileField.new(form: form_builder_for(User.new), field: :avatar))
|
|
89
|
+
assert_selector "label", text: "Avatar"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_hint_renders
|
|
93
|
+
render_inline(UI::FileField.new(hint: "PNG or JPG, up to 5MB"))
|
|
94
|
+
assert_text "PNG or JPG, up to 5MB"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def test_html_attrs_passthrough
|
|
98
|
+
render_inline(UI::FileField.new(id: "my-id", data: { test_id: "f" }))
|
|
99
|
+
assert_selector "input#my-id[data-test-id='f']", visible: :all
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::FormField::MessagesTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def test_renders_hint_and_error_with_ids
|
|
10
|
+
render_inline(UI::FormField::Messages.new(UI::FormField.new(hint: "Hint", error: "Error", for: "f")))
|
|
11
|
+
assert_selector "p#f-hint", text: "Hint"
|
|
12
|
+
assert_selector "p#f-error", text: "Error"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_renders_nothing_without_messages
|
|
16
|
+
render_inline(UI::FormField::Messages.new(UI::FormField.new(error: true, for: "f")))
|
|
17
|
+
refute_selector "p"
|
|
18
|
+
end
|
|
19
|
+
end
|