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,11 @@
|
|
|
1
|
+
<%= tag.div(class: classes,
|
|
2
|
+
role: role,
|
|
3
|
+
aria: { live: live }.merge(@html_attrs[:aria] || {}),
|
|
4
|
+
data: {
|
|
5
|
+
controller: "ui--toast",
|
|
6
|
+
"ui--toast-duration-value": @duration_ms,
|
|
7
|
+
action: "mouseenter->ui--toast#pause mouseleave->ui--toast#resume",
|
|
8
|
+
state: "open",
|
|
9
|
+
slot: "toast"
|
|
10
|
+
}.merge(@html_attrs[:data] || {}),
|
|
11
|
+
**@html_attrs.except(:data, :aria)) do %><% if icon? %><%= render(UI::Icon.new(name: @icon_name, size: :sm, aria: { hidden: true })) %><% end %><div class="flex-1 min-w-0 space-y-1"><% if title? %><p class="text-sm font-semibold leading-none" data-ui--toast-target="title"><%= @title %></p><% end %><% if description? %><p class="text-sm opacity-90" data-ui--toast-target="description"><%= @description %></p><% end %><% if action? %><%= action %><% end %></div><% if dismissible? %><%= render(UI::Button.new(variant: :ghost, size: :icon_sm, class: "shrink-0 -m-1 text-current/70 hover:text-current hover:bg-current/10", aria: { label: t("ui.toast.close_label", default: "Dismiss") }, data: { action: "click->ui--toast#dismiss" })) do |btn| %><% btn.with_leading_icon(name: "x", size: :sm) %><% end %><% end %><% end %>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# UI::Toast — a single dismissible, auto-expiring message.
|
|
4
|
+
#
|
|
5
|
+
# A toast has nowhere to appear on its own: render a UI::Toast::Viewport once
|
|
6
|
+
# per page (e.g. in the layout), then push toasts into it either from the
|
|
7
|
+
# server, by appending one in a Turbo Stream response —
|
|
8
|
+
#
|
|
9
|
+
# turbo_stream.append(UI::Toast::Viewport::ID, render(UI::Toast.new(variant: :success, title: "Saved")))
|
|
10
|
+
#
|
|
11
|
+
# — or from the client, with the `toast()` helper exported by the
|
|
12
|
+
# toast-viewport controller.
|
|
13
|
+
class UI::Toast < UI::Base
|
|
14
|
+
DEFAULT_ICONS = {
|
|
15
|
+
default: "info",
|
|
16
|
+
success: "circle-check",
|
|
17
|
+
destructive: "circle-alert",
|
|
18
|
+
warning: "circle-alert",
|
|
19
|
+
info: "info"
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
# The same motion in reverse for in/out, and explicitly longer than the
|
|
23
|
+
# plugin's 150ms default: fine for an 8px tooltip nudge, too snappy for a
|
|
24
|
+
# whole card to travel, which read as an unsmoothed flicker rather than a
|
|
25
|
+
# dismissal. The ui--toast controller's own EXIT_DURATION constant waits
|
|
26
|
+
# this same 300ms before removing a dismissed toast from the DOM — keep
|
|
27
|
+
# them in sync if this changes.
|
|
28
|
+
#
|
|
29
|
+
# A neutral bg-popover surface, same as Dialog/Sheet/Popover/Menu — the
|
|
30
|
+
# other floating, elevated surfaces in the kit. Variant color is carried by
|
|
31
|
+
# the icon alone, nothing else on the card changes: Alert is the one place
|
|
32
|
+
# that tints its whole surface, because it sits inline in the page rather
|
|
33
|
+
# than floating above it.
|
|
34
|
+
# fill-mode-forwards matters here specifically: tw-animate-css's
|
|
35
|
+
# animate-in/animate-out default to animation-fill-mode: none, so without
|
|
36
|
+
# it the element snaps back to its unanimated state (fully visible, no
|
|
37
|
+
# transform) the instant the exit animation ends — a flicker right before
|
|
38
|
+
# the timeout below removes it. Dialog/Sheet never hit this because they
|
|
39
|
+
# never remove the element after animating; Toast is the first thing here
|
|
40
|
+
# that does.
|
|
41
|
+
variants(
|
|
42
|
+
base: "relative flex w-full items-start gap-3 rounded-lg border bg-popover p-4 " \
|
|
43
|
+
"text-popover-foreground shadow-lg pointer-events-auto duration-300 fill-mode-forwards " \
|
|
44
|
+
"data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:slide-in-from-bottom-2 " \
|
|
45
|
+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-bottom-2 " \
|
|
46
|
+
"[&>i]:translate-y-0.5 [&>i]:shrink-0",
|
|
47
|
+
variants: {
|
|
48
|
+
variant: {
|
|
49
|
+
default: "[&>i]:text-muted-foreground",
|
|
50
|
+
success: "[&>i]:text-emerald-600 dark:[&>i]:text-emerald-400",
|
|
51
|
+
destructive: "[&>i]:text-destructive",
|
|
52
|
+
warning: "[&>i]:text-amber-600 dark:[&>i]:text-amber-400",
|
|
53
|
+
info: "[&>i]:text-sky-600 dark:[&>i]:text-sky-400"
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
defaults: { variant: :default }
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
renders_one :action, ->(**opts, &block) { tag.div(class: "mt-2", **opts, &block) }
|
|
60
|
+
|
|
61
|
+
# duration is seconds before the toast dismisses itself; 0 (or nil) leaves
|
|
62
|
+
# it on screen until the visitor dismisses it. Takes a plain number of
|
|
63
|
+
# seconds or an ActiveSupport::Duration (duration: 10.seconds).
|
|
64
|
+
def initialize(variant: :default, title: nil, description: nil, duration: 5,
|
|
65
|
+
dismissible: true, icon: true, class: nil, **html_attrs)
|
|
66
|
+
@variant = variant
|
|
67
|
+
@title = title
|
|
68
|
+
@description = description
|
|
69
|
+
@duration_ms = duration.to_i * 1000
|
|
70
|
+
@dismissible = dismissible
|
|
71
|
+
@icon_name = icon == true ? DEFAULT_ICONS.fetch(variant, "info") : icon
|
|
72
|
+
@user_class = binding.local_variable_get(:class)
|
|
73
|
+
@html_attrs = html_attrs
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def classes
|
|
77
|
+
cn(variant_classes(variant: @variant), @user_class)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def title?; @title.present?; end
|
|
81
|
+
def description?; @description.present?; end
|
|
82
|
+
def icon?; @icon_name.present?; end
|
|
83
|
+
def dismissible?; @dismissible; end
|
|
84
|
+
|
|
85
|
+
# A destructive toast interrupts (assertive); anything else just announces
|
|
86
|
+
# once it's there (polite), same split Alert makes for role/aria-live.
|
|
87
|
+
def role; @variant == :destructive ? "alert" : "status"; end
|
|
88
|
+
def live; @variant == :destructive ? "assertive" : "polite"; end
|
|
89
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* UI::FileField controller — drag-and-drop over a native <input type="file">.
|
|
5
|
+
*
|
|
6
|
+
* The <label> wrapping the input already opens the native picker on click,
|
|
7
|
+
* no JS needed for that. This only adds what a label can't: highlighting the
|
|
8
|
+
* dropzone while dragging, assigning dropped files to the input, and
|
|
9
|
+
* listing the chosen file names.
|
|
10
|
+
*/
|
|
11
|
+
export default class extends Controller<HTMLElement> {
|
|
12
|
+
static targets = ['dropzone', 'input', 'filenames'];
|
|
13
|
+
|
|
14
|
+
declare readonly dropzoneTarget: HTMLElement;
|
|
15
|
+
declare readonly inputTarget: HTMLInputElement;
|
|
16
|
+
declare readonly hasFilenamesTarget: boolean;
|
|
17
|
+
declare readonly filenamesTarget: HTMLElement;
|
|
18
|
+
|
|
19
|
+
connect() {
|
|
20
|
+
this.updateNames();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
dragOver(event: DragEvent) {
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
if (this.inputTarget.disabled) return;
|
|
26
|
+
this.dropzoneTarget.dataset.drag = 'true';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
dragLeave() {
|
|
30
|
+
delete this.dropzoneTarget.dataset.drag;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
drop(event: DragEvent) {
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
delete this.dropzoneTarget.dataset.drag;
|
|
36
|
+
|
|
37
|
+
const files = event.dataTransfer?.files;
|
|
38
|
+
if (!files || !files.length || this.inputTarget.disabled) return;
|
|
39
|
+
|
|
40
|
+
this.inputTarget.files = files;
|
|
41
|
+
this.inputTarget.dispatchEvent(new Event('change', { bubbles: true }));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
updateNames() {
|
|
45
|
+
if (!this.hasFilenamesTarget) return;
|
|
46
|
+
const names = Array.from(this.inputTarget.files ?? []).map((file) => file.name);
|
|
47
|
+
this.filenamesTarget.textContent = names.join(', ');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -38,6 +38,9 @@ export default class extends Controller<HTMLElement> {
|
|
|
38
38
|
offset: 4,
|
|
39
39
|
flip: true,
|
|
40
40
|
shift: true,
|
|
41
|
+
// Escape scrolling or clipped ancestors (a scrolling tab bar, a table
|
|
42
|
+
// cell, a drawer), as UI::Select does.
|
|
43
|
+
strategy: 'fixed',
|
|
41
44
|
});
|
|
42
45
|
this.floatingCleanup = floating.destroy;
|
|
43
46
|
|