velvetkit 0.5.1 → 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 +44 -0
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/carousel.html.erb +9 -4
- data/registry/app/components/ui/carousel.rb +42 -1
- data/registry/app/components/ui/file_tree/file_item.html.erb +9 -0
- data/registry/app/components/ui/file_tree/file_item.rb +50 -0
- data/registry/app/components/ui/file_tree/folder.html.erb +9 -0
- data/registry/app/components/ui/file_tree/folder.rb +76 -0
- data/registry/app/components/ui/file_tree.html.erb +1 -0
- data/registry/app/components/ui/file_tree.rb +93 -0
- data/registry/app/components/ui/rating.html.erb +16 -0
- data/registry/app/components/ui/rating.rb +200 -0
- 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/carousel_controller.ts +59 -1
- data/registry/app/javascript/controllers/ui/file_tree_controller.ts +189 -0
- data/registry/app/javascript/controllers/ui/rating_controller.ts +117 -0
- data/registry/app/javascript/controllers/ui/sidebar_controller.ts +17 -0
- data/registry/app/javascript/controllers/ui/tooltip_controller.ts +3 -0
- data/registry/components.yml +4 -0
- data/registry/config/locales/velvetkit.en.yml +13 -0
- data/registry/test/components/previews/ui/carousel_preview/with_indicators.html.erb +10 -0
- data/registry/test/components/previews/ui/carousel_preview.rb +7 -3
- data/registry/test/components/previews/ui/file_tree_preview/changes.html.erb +13 -0
- data/registry/test/components/previews/ui/file_tree_preview/from_data.html.erb +14 -0
- data/registry/test/components/previews/ui/file_tree_preview/picking_a_file.html.erb +25 -0
- data/registry/test/components/previews/ui/file_tree_preview/without_guides.html.erb +10 -0
- data/registry/test/components/previews/ui/file_tree_preview.rb +41 -0
- data/registry/test/components/previews/ui/image_preview/radii.html.erb +3 -3
- data/registry/test/components/previews/ui/image_preview/sizing.html.erb +9 -4
- data/registry/test/components/previews/ui/image_preview.rb +14 -1
- data/registry/test/components/previews/ui/rating_preview/in_form.html.erb +6 -0
- data/registry/test/components/previews/ui/rating_preview/model_errors.html.erb +20 -0
- data/registry/test/components/previews/ui/rating_preview/playground.html.erb +5 -0
- data/registry/test/components/previews/ui/rating_preview/scores.html.erb +18 -0
- data/registry/test/components/previews/ui/rating_preview/sizes.html.erb +6 -0
- data/registry/test/components/previews/ui/rating_preview.rb +28 -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/carousel_test.rb +48 -0
- data/registry/test/components/ui/file_tree_test.rb +187 -0
- data/registry/test/components/ui/rating_test.rb +271 -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 +28 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
|
2
|
+
|
|
3
|
+
// Connects to data-controller="ui--rating"
|
|
4
|
+
//
|
|
5
|
+
// Each half-star is the label of a radio, and CSS fills the stars up to the
|
|
6
|
+
// checked one. Over a half-star, this lights that half and the ones before it,
|
|
7
|
+
// and grows the star it's in; leaving the stars, or choosing one, hands them
|
|
8
|
+
// back. It also gives the choice some feedback: a chosen star settles back to
|
|
9
|
+
// size, or pops when chosen from the keyboard. Choosing also clears the field's error, if it has one, and
|
|
10
|
+
// shows its thanks, if it has those, and writes the score beside the stars, if
|
|
11
|
+
// it's shown; resetting the form brings them back as they were (the score is an
|
|
12
|
+
// <output>, which the form resets itself).
|
|
13
|
+
export default class extends Controller<HTMLElement> {
|
|
14
|
+
static targets = ['star'];
|
|
15
|
+
static values = { error: String, thanks: String, score: String };
|
|
16
|
+
|
|
17
|
+
declare readonly starTargets: HTMLLabelElement[];
|
|
18
|
+
declare readonly errorValue: string;
|
|
19
|
+
declare readonly thanksValue: string;
|
|
20
|
+
declare readonly scoreValue: string;
|
|
21
|
+
|
|
22
|
+
// The star just chosen under the pointer, kept at its size until the
|
|
23
|
+
// pointer moves to another.
|
|
24
|
+
private settled: number | null = null;
|
|
25
|
+
|
|
26
|
+
preview(event: MouseEvent) {
|
|
27
|
+
const star = event.currentTarget as HTMLLabelElement;
|
|
28
|
+
if ((star.control as HTMLInputElement | null)?.disabled) return;
|
|
29
|
+
|
|
30
|
+
const value = Number(star.dataset.value);
|
|
31
|
+
this.starTargets.forEach((each) => {
|
|
32
|
+
each.dataset.lit = String(Number(each.dataset.value) <= value);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const whole = Math.ceil(value);
|
|
36
|
+
if (whole !== this.settled) this.settled = null;
|
|
37
|
+
this.hover(this.settled === null ? this.halvesOf(whole) : []);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
reset() {
|
|
41
|
+
for (const star of this.starTargets) delete star.dataset.lit;
|
|
42
|
+
this.hover([]);
|
|
43
|
+
this.settled = null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
choose(event: Event) {
|
|
47
|
+
const input = event.target as HTMLInputElement;
|
|
48
|
+
const whole = Math.ceil(Number(input.value));
|
|
49
|
+
const halves = this.halvesOf(whole);
|
|
50
|
+
|
|
51
|
+
for (const star of this.starTargets) delete star.dataset.lit;
|
|
52
|
+
|
|
53
|
+
if (halves.some((half) => half.dataset.hovered)) {
|
|
54
|
+
this.hover([]);
|
|
55
|
+
this.settled = whole;
|
|
56
|
+
} else {
|
|
57
|
+
this.pop(halves);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.showAnswered(true);
|
|
61
|
+
|
|
62
|
+
// The chosen star carries its score, "4.5/5". Its value, not its text,
|
|
63
|
+
// which is what the form's reset goes back to.
|
|
64
|
+
const score = this.scoreValue && (document.getElementById(this.scoreValue) as HTMLOutputElement | null);
|
|
65
|
+
if (score) score.value = input.labels?.[0]?.dataset.score ?? '';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// The form's reset puts the radios back; this puts back the rest.
|
|
69
|
+
formReset(event: Event) {
|
|
70
|
+
if (!(event.target as Node).contains(this.element)) return;
|
|
71
|
+
|
|
72
|
+
this.reset();
|
|
73
|
+
this.showAnswered(false);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Answered, the error's hidden and gone from what the group says about
|
|
77
|
+
// itself, and the thanks, which are a status, are read out as they show.
|
|
78
|
+
private showAnswered(answered: boolean) {
|
|
79
|
+
const error = this.errorValue && document.getElementById(this.errorValue);
|
|
80
|
+
if (error) {
|
|
81
|
+
error.hidden = answered;
|
|
82
|
+
const group = this.element.closest('[role="radiogroup"]');
|
|
83
|
+
const others = (group?.getAttribute('aria-describedby') ?? '').split(' ').filter((id) => id && id !== this.errorValue);
|
|
84
|
+
const describedby = answered ? others : [...others, this.errorValue];
|
|
85
|
+
if (answered) group?.removeAttribute('aria-invalid');
|
|
86
|
+
else group?.setAttribute('aria-invalid', 'true');
|
|
87
|
+
if (describedby.length) group?.setAttribute('aria-describedby', describedby.join(' '));
|
|
88
|
+
else group?.removeAttribute('aria-describedby');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const thanks = this.thanksValue && document.getElementById(this.thanksValue);
|
|
92
|
+
if (thanks) thanks.hidden = !answered;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Both half-star labels of a whole star.
|
|
96
|
+
private halvesOf(whole: number) {
|
|
97
|
+
return this.starTargets.filter((each) => Math.ceil(Number(each.dataset.value)) === whole);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private hover(halves: HTMLLabelElement[]) {
|
|
101
|
+
for (const star of this.starTargets) {
|
|
102
|
+
if (halves.includes(star)) star.dataset.hovered = 'true';
|
|
103
|
+
else delete star.dataset.hovered;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private pop(halves: HTMLLabelElement[]) {
|
|
108
|
+
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
109
|
+
|
|
110
|
+
for (const half of halves) {
|
|
111
|
+
half.animate([1, 1.25, 1].map((scale) => ({ transform: `scale(${scale})` })), {
|
|
112
|
+
duration: 250,
|
|
113
|
+
easing: 'ease-out',
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -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,
|
data/registry/components.yml
CHANGED
|
@@ -68,6 +68,8 @@ components:
|
|
|
68
68
|
description: A group of controls under one legend, with a hint and an error message for the group.
|
|
69
69
|
file_field:
|
|
70
70
|
description: A drag-and-drop file picker with previews, and direct upload to storage, standalone or with a form builder.
|
|
71
|
+
file_tree:
|
|
72
|
+
description: Folders and files in a tree that opens and closes, with arrow keys to move through it.
|
|
71
73
|
form_field:
|
|
72
74
|
description: A label, hint and error message wired to any form control.
|
|
73
75
|
gallery:
|
|
@@ -105,6 +107,8 @@ components:
|
|
|
105
107
|
description: A bar showing how far along a task is, or that it's still going.
|
|
106
108
|
radio_group:
|
|
107
109
|
description: A set of radio buttons.
|
|
110
|
+
rating:
|
|
111
|
+
description: A score in stars, shown to the half star with its count, or chosen with a radio for each star.
|
|
108
112
|
native_select:
|
|
109
113
|
description: The browser's own select, styled closed; best for phones' system pickers.
|
|
110
114
|
scan_input:
|
|
@@ -33,6 +33,8 @@ en:
|
|
|
33
33
|
roledescription: 'carousel'
|
|
34
34
|
previous: 'Previous'
|
|
35
35
|
next: 'Next'
|
|
36
|
+
indicators: 'Choose a slide'
|
|
37
|
+
indicator: 'Go to slide %{number}'
|
|
36
38
|
chart:
|
|
37
39
|
label: 'Chart'
|
|
38
40
|
keyboard: 'Use the arrow keys to read each value.'
|
|
@@ -80,6 +82,15 @@ en:
|
|
|
80
82
|
progress:
|
|
81
83
|
label: 'Progress'
|
|
82
84
|
value_text: '%{percent}%'
|
|
85
|
+
rating:
|
|
86
|
+
name: 'Rating'
|
|
87
|
+
label: 'Rated %{value} out of %{max}'
|
|
88
|
+
option: '%{count} out of %{max}'
|
|
89
|
+
thanks: 'Thank you for your rating'
|
|
90
|
+
score: '%{value}/%{max}'
|
|
91
|
+
count:
|
|
92
|
+
one: '%{count} rating'
|
|
93
|
+
other: '%{count} ratings'
|
|
83
94
|
slider:
|
|
84
95
|
from: 'Minimum'
|
|
85
96
|
to: 'Maximum'
|
|
@@ -170,6 +181,8 @@ en:
|
|
|
170
181
|
position: 'Image %{current} of %{total}'
|
|
171
182
|
open: 'Open %{alt}'
|
|
172
183
|
info: 'Info'
|
|
184
|
+
file_tree:
|
|
185
|
+
label: 'Files'
|
|
173
186
|
file_field:
|
|
174
187
|
browse: 'Click to upload'
|
|
175
188
|
drop: 'or drag and drop'
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<%# One photo at a time, with an indicator for each. The indicators are the way
|
|
2
|
+
through on a phone, where the buttons don't show; turn them on with
|
|
3
|
+
`indicators: true`. %>
|
|
4
|
+
<%= render(UI::Carousel.new(label: "Featured", item_class: "basis-full", indicators: true, class: "max-w-2xl")) do |carousel| %>
|
|
5
|
+
<% UI::GalleryPreview.photos.each do |title, src| %>
|
|
6
|
+
<% carousel.with_item do %>
|
|
7
|
+
<%= image_tag src, alt: title, class: "aspect-[16/9] w-full rounded-xl object-cover" %>
|
|
8
|
+
<% end %>
|
|
9
|
+
<% end %>
|
|
10
|
+
<% end %>
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
class UI::CarouselPreview < ViewComponent::Preview
|
|
4
4
|
# @label Playground
|
|
5
5
|
# @param count number { min: 1, max: 12 }
|
|
6
|
-
# @param item_class select { choices: [w-48, w-64, basis-1/2, basis-1/3] }
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
# @param item_class select { choices: [w-48, w-64, basis-1/2, basis-1/3, basis-full] }
|
|
7
|
+
# @param indicators toggle
|
|
8
|
+
def playground(count: 8, item_class: "w-48", indicators: false)
|
|
9
|
+
render(UI::Carousel.new(label: "Albums", item_class: item_class, indicators: indicators, class: "max-w-2xl")) do |carousel|
|
|
9
10
|
UI::GalleryPreview.photos.cycle.first(count.to_i).each_with_index do |(title, src), index|
|
|
10
11
|
carousel.with_item do
|
|
11
12
|
tag.a(href: "#", class: "group block space-y-2 rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary") do
|
|
@@ -19,4 +20,7 @@ class UI::CarouselPreview < ViewComponent::Preview
|
|
|
19
20
|
|
|
20
21
|
# @label Highlights
|
|
21
22
|
def highlights; render_with_template; end
|
|
23
|
+
|
|
24
|
+
# @label With indicators
|
|
25
|
+
def with_indicators; render_with_template; end
|
|
22
26
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%# The block shows at the end of a file's row. %>
|
|
2
|
+
<%= render(UI::FileTree.new(label: "Changed files", class: "max-w-xs")) do |tree| %>
|
|
3
|
+
<% tree.with_folder(name: "app", open: true) do |app| %>
|
|
4
|
+
<% app.with_folder(name: "controllers", open: true) do |controllers| %>
|
|
5
|
+
<% controllers.with_file(name: "orders_controller.rb", value: "app/controllers/orders_controller.rb") do %><span class="text-amber-600 dark:text-amber-400">M</span><% end %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% app.with_folder(name: "models", open: true) do |models| %>
|
|
8
|
+
<% models.with_file(name: "order.rb", value: "app/models/order.rb") do %><span class="text-amber-600 dark:text-amber-400">M</span><% end %>
|
|
9
|
+
<% models.with_file(name: "refund.rb", value: "app/models/refund.rb", active: true) do %><span class="text-emerald-600 dark:text-emerald-400">A</span><% end %>
|
|
10
|
+
<% end %>
|
|
11
|
+
<% end %>
|
|
12
|
+
<% tree.with_file(name: "legacy_export.rb", value: "legacy_export.rb") do %><span class="text-destructive">D</span><% end %>
|
|
13
|
+
<% end %>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<%# A hash with `children:` is a folder; any other is a file. %>
|
|
2
|
+
<%= render(UI::FileTree.new(label: "Documents", class: "max-w-xs", items: [
|
|
3
|
+
{ name: "Contracts", children: [
|
|
4
|
+
{ name: "2025", children: [
|
|
5
|
+
{ name: "Acme MSA.pdf", value: "contracts/2025/acme-msa.pdf" },
|
|
6
|
+
{ name: "Globex NDA.pdf", value: "contracts/2025/globex-nda.pdf" }
|
|
7
|
+
] },
|
|
8
|
+
{ name: "2026", children: [
|
|
9
|
+
{ name: "Initech SOW.pdf", value: "contracts/2026/initech-sow.pdf", active: true }
|
|
10
|
+
] }
|
|
11
|
+
] },
|
|
12
|
+
{ name: "Invoices", children: [] },
|
|
13
|
+
{ name: "Brand guide.pdf", value: "brand-guide.pdf", icon: "file-text" }
|
|
14
|
+
])) %>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<div id="file-tree-picking-demo" class="grid max-w-2xl gap-4 sm:grid-cols-[14rem_1fr]">
|
|
2
|
+
<%= render(UI::FileTree.new(label: "Source")) do |tree| %>
|
|
3
|
+
<% tree.with_folder(name: "src") do |src| %>
|
|
4
|
+
<% src.with_folder(name: "lib") do |lib| %>
|
|
5
|
+
<% lib.with_file(name: "format.ts", value: "src/lib/format.ts") %>
|
|
6
|
+
<% lib.with_file(name: "money.ts", value: "src/lib/money.ts") %>
|
|
7
|
+
<% end %>
|
|
8
|
+
<% src.with_file(name: "index.ts", value: "src/index.ts", active: true) %>
|
|
9
|
+
<% end %>
|
|
10
|
+
<% tree.with_file(name: "package.json", value: "package.json") %>
|
|
11
|
+
<% tree.with_file(name: "tsconfig.json", value: "tsconfig.json") %>
|
|
12
|
+
<% end %>
|
|
13
|
+
<div class="rounded-lg border bg-muted/40 p-4 font-mono text-sm">
|
|
14
|
+
<p class="text-muted-foreground">Selected</p>
|
|
15
|
+
<p data-demo="path" class="mt-1 text-foreground">src/index.ts</p>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
<script>
|
|
19
|
+
(() => {
|
|
20
|
+
const root = document.getElementById("file-tree-picking-demo");
|
|
21
|
+
root.addEventListener("ui--file-tree:select", (event) => {
|
|
22
|
+
root.querySelector('[data-demo="path"]').textContent = event.detail.value;
|
|
23
|
+
});
|
|
24
|
+
})();
|
|
25
|
+
</script>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<%= render(UI::FileTree.new(label: "Project files", guides: false, class: "max-w-xs")) do |tree| %>
|
|
2
|
+
<% tree.with_folder(name: "app", open: true) do |app| %>
|
|
3
|
+
<% app.with_folder(name: "views", open: true) do |views| %>
|
|
4
|
+
<% views.with_file(name: "index.html.erb", value: "app/views/index.html.erb") %>
|
|
5
|
+
<% views.with_file(name: "show.html.erb", value: "app/views/show.html.erb", active: true) %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% app.with_file(name: "application.rb", value: "app/application.rb") %>
|
|
8
|
+
<% end %>
|
|
9
|
+
<% tree.with_file(name: "Gemfile", value: "Gemfile") %>
|
|
10
|
+
<% end %>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::FileTreePreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param guides toggle
|
|
6
|
+
# @param open toggle "Open every folder, whatever the active file"
|
|
7
|
+
# @param links toggle "Files are links, not rows to pick"
|
|
8
|
+
def playground(guides: true, open: false, links: true)
|
|
9
|
+
href = ->(path) { "#/blob/#{path}" if links }
|
|
10
|
+
open = open || nil
|
|
11
|
+
render(UI::FileTree.new(label: "Project files", guides: guides, class: "max-w-xs")) do |tree|
|
|
12
|
+
tree.with_folder(name: "app", open: open) do |app|
|
|
13
|
+
app.with_folder(name: "components", open: open) do |components|
|
|
14
|
+
components.with_file(name: "button.rb", href: href.("app/components/button.rb"), active: true)
|
|
15
|
+
components.with_file(name: "button.html.erb", href: href.("app/components/button.html.erb"))
|
|
16
|
+
components.with_file(name: "card.rb", href: href.("app/components/card.rb"))
|
|
17
|
+
end
|
|
18
|
+
app.with_folder(name: "models", open: open) do |models|
|
|
19
|
+
models.with_file(name: "user.rb", href: href.("app/models/user.rb"))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
tree.with_folder(name: "config", open: open) do |config|
|
|
23
|
+
config.with_file(name: "routes.rb", href: href.("config/routes.rb"))
|
|
24
|
+
end
|
|
25
|
+
tree.with_file(name: "Gemfile", href: href.("Gemfile"))
|
|
26
|
+
tree.with_file(name: "README.md", href: href.("README.md"), icon: "file-text")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# @label From Data
|
|
31
|
+
def from_data; render_with_template; end
|
|
32
|
+
|
|
33
|
+
# @label Picking a File
|
|
34
|
+
def picking_a_file; render_with_template; end
|
|
35
|
+
|
|
36
|
+
# @label Changes, with Badges
|
|
37
|
+
def changes; render_with_template; end
|
|
38
|
+
|
|
39
|
+
# @label Without Guides
|
|
40
|
+
def without_guides; render_with_template; end
|
|
41
|
+
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<div class="flex flex-wrap
|
|
2
|
-
<% %i[none sm md lg xl full].each do |r| %>
|
|
1
|
+
<div class="flex flex-wrap gap-6">
|
|
2
|
+
<% %i[none xs sm md lg xl full].each do |r| %>
|
|
3
3
|
<div class="flex flex-col items-center gap-2">
|
|
4
|
-
<%= render(UI::Image.new(src:
|
|
4
|
+
<%= render(UI::Image.new(src: UI::ImagePreview.photo, alt: "Mountains at sunset", rounded: r, width: "96px", height: "96px")) %>
|
|
5
5
|
<span class="text-xs text-muted-foreground"><%= r %></span>
|
|
6
6
|
</div>
|
|
7
7
|
<% end %>
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
<%# Dimensions land on the <img> itself, not on a wrapper. %>
|
|
2
|
-
<div class="flex flex-wrap items-end gap-
|
|
1
|
+
<%# Dimensions land on the <img> itself, not on a wrapper; the height follows the image's own ratio. %>
|
|
2
|
+
<div class="flex flex-wrap items-end gap-8">
|
|
3
3
|
<% ["48px", "96px", "160px"].each do |w| %>
|
|
4
4
|
<div class="flex flex-col items-center gap-2">
|
|
5
|
-
<%= render(UI::Image.new(src:
|
|
6
|
-
<
|
|
5
|
+
<%= render(UI::Image.new(src: UI::ImagePreview.photo, alt: "Mountains at sunset", rounded: :md, width: w)) %>
|
|
6
|
+
<div class="flex items-center text-muted-foreground" style="width: <%= w %>" aria-hidden="true">
|
|
7
|
+
<span class="h-2 border-l border-current"></span>
|
|
8
|
+
<span class="flex-1 border-t border-current"></span>
|
|
9
|
+
<span class="h-2 border-r border-current"></span>
|
|
10
|
+
</div>
|
|
11
|
+
<span class="text-xs text-muted-foreground"><%= w %></span>
|
|
7
12
|
</div>
|
|
8
13
|
<% end %>
|
|
9
14
|
</div>
|
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class UI::ImagePreview < ViewComponent::Preview
|
|
4
|
+
# Drawn here so the previews need no image files. It fills its frame edge to
|
|
5
|
+
# edge (`slice`), so the corners show the radius and the size reads at a glance.
|
|
6
|
+
def self.photo
|
|
7
|
+
svg = "<svg xmlns='http://www.w3.org/2000/svg' width='400' height='300' viewBox='0 0 400 300' " \
|
|
8
|
+
"preserveAspectRatio='xMidYMid slice'>" \
|
|
9
|
+
"<defs><linearGradient id='sky' x2='0' y2='1'><stop stop-color='#c4b5fd'/><stop offset='1' stop-color='#fde68a'/>" \
|
|
10
|
+
"</linearGradient></defs><rect width='400' height='300' fill='url(#sky)'/>" \
|
|
11
|
+
"<circle cx='290' cy='110' r='42' fill='#f59e0b'/>" \
|
|
12
|
+
"<path d='M0 300V190l90-80 70 60 80-90 90 100 70-50v170z' fill='#7c3aed'/>" \
|
|
13
|
+
"<path d='M0 300V240l110-60 90 50 100-40 100 60v50z' fill='#4c1d95'/></svg>"
|
|
14
|
+
"data:image/svg+xml,#{ERB::Util.url_encode(svg)}"
|
|
15
|
+
end
|
|
16
|
+
|
|
4
17
|
# @label Playground
|
|
5
18
|
# @param rounded select { choices: [none, xs, sm, md, lg, xl, full] }
|
|
6
19
|
# @param width text
|
|
7
20
|
def playground(rounded: :sm, width: "160px")
|
|
8
|
-
render(UI::Image.new(src:
|
|
21
|
+
render(UI::Image.new(src: self.class.photo, alt: "Mountains at sunset", rounded: rounded.to_sym, width: width))
|
|
9
22
|
end
|
|
10
23
|
|
|
11
24
|
# @label Radii
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<%# A radio for each star: it posts with the form and needs no JavaScript. Arrow keys move between the stars. %>
|
|
2
|
+
<form class="flex max-w-sm flex-col gap-6" action="#" onsubmit="event.preventDefault()">
|
|
3
|
+
<%= render(UI::Rating.new(name: "review[rating]", legend: "Your rating", hint: "How did the kettle work for you?", required: true, size: :lg)) %>
|
|
4
|
+
<%= render(UI::Textarea.new(name: "review[body]", label: "Review", rows: 3)) %>
|
|
5
|
+
<%= render(UI::Button.new(type: :submit, class: "self-start")) { "Post review" } %>
|
|
6
|
+
</form>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%# In an app, @review comes back from a failed save. Bound, the field shows its errors on its own,
|
|
2
|
+
and choosing a score clears them; `thanks: true` then says thank you. Resetting the form brings
|
|
3
|
+
the errors back: the reset button is only here to try it again. The messages are kept from
|
|
4
|
+
widening the field, so the button stays beside the stars. %>
|
|
5
|
+
<% review = Struct.new(:rating, :delivery) do
|
|
6
|
+
include ActiveModel::Validations
|
|
7
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Review")
|
|
8
|
+
validates :rating, presence: true
|
|
9
|
+
end.new(nil, 4).tap(&:validate) %>
|
|
10
|
+
<%= form_with(model: review, url: "#", class: "flex max-w-sm flex-col gap-6") do |f| %>
|
|
11
|
+
<div class="flex items-center gap-2 [&_fieldset>p]:w-0 [&_fieldset>p]:whitespace-nowrap">
|
|
12
|
+
<%= render(UI::Rating.new(form: f, field: :rating, legend: true, required: true, thanks: true, show_value: true)) %>
|
|
13
|
+
<button type="reset" title="Start again" aria-label="Start again"
|
|
14
|
+
class="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-primary">
|
|
15
|
+
<%# Not one of the kit's controls, so only the icon: a ring only from the keyboard. %>
|
|
16
|
+
<%= render(UI::Icon.new(name: "rotate-cw", size: :sm)) %>
|
|
17
|
+
</button>
|
|
18
|
+
</div>
|
|
19
|
+
<%= render(UI::Rating.new(form: f, field: :delivery, legend: "Delivery", hint: "Was it on time and well packed?")) %>
|
|
20
|
+
<% end %>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<% if field %>
|
|
2
|
+
<%= render(UI::Rating.new(name: "rating", value: value, max: max, size: size, disabled: disabled, show_value: show_value, legend: "Your rating")) %>
|
|
3
|
+
<% else %>
|
|
4
|
+
<%= render(UI::Rating.new(value: value, max: max, size: size, show_value: show_value, count: count)) %>
|
|
5
|
+
<% end %>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<%# Shown to the nearest half star. A screen reader hears one image, "Rated 4.5 out of 5", and the count.
|
|
2
|
+
The last is a field to choose one: `show_value: true` keeps the score beside it to the one chosen, and
|
|
3
|
+
it resets with the form. The reset button is only here to try it again. %>
|
|
4
|
+
<div class="flex flex-col gap-3">
|
|
5
|
+
<%= render(UI::Rating.new(value: 5, show_value: true, count: 2_481)) %>
|
|
6
|
+
<%= render(UI::Rating.new(value: 4.5, show_value: true, count: 312)) %>
|
|
7
|
+
<%= render(UI::Rating.new(value: 3.7, show_value: true, count: 46)) %>
|
|
8
|
+
<%= render(UI::Rating.new(value: 2, show_value: true, count: 1)) %>
|
|
9
|
+
<%= render(UI::Rating.new(value: nil, show_value: true, count: 0)) %>
|
|
10
|
+
<form action="#" onsubmit="event.preventDefault()" class="flex items-center gap-2">
|
|
11
|
+
<%= render(UI::Rating.new(name: "rating", show_value: true)) %>
|
|
12
|
+
<button type="reset" title="Start again" aria-label="Start again"
|
|
13
|
+
class="rounded-sm text-muted-foreground transition-colors hover:text-foreground focus:outline-none focus-visible:ring-2 focus-visible:ring-primary">
|
|
14
|
+
<%# Not one of the kit's controls, so only the icon: a ring only from the keyboard. %>
|
|
15
|
+
<%= render(UI::Icon.new(name: "rotate-cw", size: :sm)) %>
|
|
16
|
+
</button>
|
|
17
|
+
</form>
|
|
18
|
+
</div>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<div class="flex flex-col gap-4">
|
|
2
|
+
<%= render(UI::Rating.new(value: 4.5, size: :sm, show_value: true, count: 89)) %>
|
|
3
|
+
<%= render(UI::Rating.new(value: 4.5, show_value: true, count: 89)) %>
|
|
4
|
+
<%= render(UI::Rating.new(value: 4.5, size: :lg, class: "text-base", show_value: true, count: 89)) %>
|
|
5
|
+
<%= render(UI::Rating.new(name: "size_lg", value: 4, size: :lg, label: "Large rating")) %>
|
|
6
|
+
</div>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::RatingPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param field toggle
|
|
6
|
+
# @param value number
|
|
7
|
+
# @param max number
|
|
8
|
+
# @param size select { choices: [sm, default, lg] }
|
|
9
|
+
# @param show_value toggle
|
|
10
|
+
# @param count number
|
|
11
|
+
# @param disabled toggle
|
|
12
|
+
def playground(field: false, value: 3.5, max: 5, size: :default, show_value: true, count: 128, disabled: false)
|
|
13
|
+
render_with_template(locals: { field: field, value: value, max: max.to_i.clamp(1, 10), size: size.to_sym,
|
|
14
|
+
show_value: show_value, count: count.presence, disabled: disabled })
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @label Scores
|
|
18
|
+
def scores; render_with_template; end
|
|
19
|
+
|
|
20
|
+
# @label Sizes
|
|
21
|
+
def sizes; render_with_template; end
|
|
22
|
+
|
|
23
|
+
# @label In a Form
|
|
24
|
+
def in_form; render_with_template; end
|
|
25
|
+
|
|
26
|
+
# @label Errors from the Model
|
|
27
|
+
def model_errors; render_with_template; end
|
|
28
|
+
end
|
|
@@ -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>
|