velvetkit 0.4.0 → 0.4.2
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 +47 -2
- data/lib/velvetkit/version.rb +1 -1
- data/registry/app/components/ui/card/action.html.erb +1 -0
- data/registry/app/components/ui/card/action.rb +14 -0
- data/registry/app/components/ui/card/content.html.erb +1 -1
- data/registry/app/components/ui/card/content.rb +4 -2
- data/registry/app/components/ui/card/description.html.erb +1 -1
- data/registry/app/components/ui/card/description.rb +4 -2
- data/registry/app/components/ui/card/footer.html.erb +1 -1
- data/registry/app/components/ui/card/footer.rb +4 -2
- data/registry/app/components/ui/card/header.html.erb +1 -1
- data/registry/app/components/ui/card/header.rb +9 -2
- data/registry/app/components/ui/card/title.html.erb +1 -1
- data/registry/app/components/ui/card/title.rb +4 -2
- data/registry/app/components/ui/card.html.erb +1 -1
- data/registry/app/components/ui/card.rb +49 -3
- data/registry/app/components/ui/money_input.html.erb +8 -0
- data/registry/app/components/ui/money_input.rb +153 -0
- data/registry/app/components/ui/scan_input.html.erb +6 -0
- data/registry/app/components/ui/scan_input.rb +94 -0
- data/registry/app/components/ui/slider.html.erb +23 -0
- data/registry/app/components/ui/slider.rb +254 -0
- data/registry/app/javascript/controllers/ui/money_input_controller.ts +228 -0
- data/registry/app/javascript/controllers/ui/scan_input_controller.ts +143 -0
- data/registry/app/javascript/controllers/ui/slider_controller.ts +216 -0
- data/registry/components.yml +7 -1
- data/registry/config/locales/velvetkit.en.yml +6 -0
- data/registry/icons/lucide/scan-barcode.svg +21 -0
- data/registry/icons/lucide/volume-2.svg +17 -0
- data/registry/icons/lucide/volume-x.svg +17 -0
- data/registry/icons/phosphor/barcode.svg +2 -0
- data/registry/icons/phosphor/speaker-high.svg +2 -0
- data/registry/icons/phosphor/speaker-x.svg +2 -0
- data/registry/icons/tabler/barcode.svg +23 -0
- data/registry/icons/tabler/volume-3.svg +17 -0
- data/registry/icons/tabler/volume.svg +18 -0
- data/registry/icons.yml +3 -0
- data/registry/test/components/previews/ui/card_preview/edge_to_edge.html.erb +19 -0
- data/registry/test/components/previews/ui/card_preview/image.html.erb +12 -0
- data/registry/test/components/previews/ui/card_preview/just_content.html.erb +10 -0
- data/registry/test/components/previews/ui/card_preview/open_bill.html.erb +18 -0
- data/registry/test/components/previews/ui/card_preview/playground.html.erb +17 -0
- data/registry/test/components/previews/ui/card_preview/settings_form.html.erb +15 -24
- data/registry/test/components/previews/ui/card_preview/sign_in.html.erb +23 -0
- data/registry/test/components/previews/ui/card_preview/small.html.erb +17 -0
- data/registry/test/components/previews/ui/card_preview/spacing.html.erb +13 -0
- data/registry/test/components/previews/ui/card_preview/stats.html.erb +11 -0
- data/registry/test/components/previews/ui/card_preview/team.html.erb +21 -0
- data/registry/test/components/previews/ui/card_preview.rb +42 -28
- data/registry/test/components/previews/ui/money_input_preview/cash_tendered.html.erb +24 -0
- data/registry/test/components/previews/ui/money_input_preview/currencies.html.erb +7 -0
- data/registry/test/components/previews/ui/money_input_preview/invoice.html.erb +24 -0
- data/registry/test/components/previews/ui/money_input_preview/sizes_and_states.html.erb +9 -0
- data/registry/test/components/previews/ui/money_input_preview.rb +34 -0
- data/registry/test/components/previews/ui/scan_input_preview/_simulate.html.erb +20 -0
- data/registry/test/components/previews/ui/scan_input_preview/library_checkout.html.erb +30 -0
- data/registry/test/components/previews/ui/scan_input_preview/playground.html.erb +13 -0
- data/registry/test/components/previews/ui/scan_input_preview/stock_count.html.erb +24 -0
- data/registry/test/components/previews/ui/scan_input_preview/ticket_check_in.html.erb +34 -0
- data/registry/test/components/previews/ui/scan_input_preview/till.html.erb +9 -0
- data/registry/test/components/previews/ui/scan_input_preview.rb +33 -0
- data/registry/test/components/previews/ui/slider_preview/named_steps.html.erb +7 -0
- data/registry/test/components/previews/ui/slider_preview/opening_hours.html.erb +5 -0
- data/registry/test/components/previews/ui/slider_preview/price_range.html.erb +6 -0
- data/registry/test/components/previews/ui/slider_preview/sizes_and_states.html.erb +9 -0
- data/registry/test/components/previews/ui/slider_preview/text_size.html.erb +16 -0
- data/registry/test/components/previews/ui/slider_preview/tip.html.erb +22 -0
- data/registry/test/components/previews/ui/slider_preview/volume.html.erb +5 -0
- data/registry/test/components/previews/ui/slider_preview.rb +45 -0
- data/registry/test/components/ui/card/action_test.rb +19 -0
- data/registry/test/components/ui/card/content_test.rb +1 -11
- data/registry/test/components/ui/card/footer_test.rb +3 -2
- data/registry/test/components/ui/card/header_test.rb +3 -4
- data/registry/test/components/ui/card/title_test.rb +3 -4
- data/registry/test/components/ui/card_test.rb +63 -2
- data/registry/test/components/ui/money_input_test.rb +149 -0
- data/registry/test/components/ui/scan_input_test.rb +110 -0
- data/registry/test/components/ui/slider_test.rb +190 -0
- metadata +55 -5
- data/registry/test/components/previews/ui/card_preview/complete.html.erb +0 -31
- data/registry/test/components/previews/ui/card_preview/default.html.erb +0 -7
- data/registry/test/components/previews/ui/card_preview/with_footer.html.erb +0 -13
- data/registry/test/components/previews/ui/card_preview/with_header.html.erb +0 -11
|
@@ -1,44 +1,58 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class UI::CardPreview < ViewComponent::Preview
|
|
4
|
+
# Drawn here so the previews need no image files.
|
|
5
|
+
def self.photo(from, to)
|
|
6
|
+
svg = "<svg xmlns='http://www.w3.org/2000/svg' width='800' height='450'>" \
|
|
7
|
+
"<defs><linearGradient id='g' x2='1' y2='1'><stop stop-color='#{from}'/><stop offset='1' stop-color='#{to}'/>" \
|
|
8
|
+
"</linearGradient></defs><rect width='800' height='450' fill='url(#g)'/>" \
|
|
9
|
+
"<circle cx='620' cy='120' r='70' fill='#fff' fill-opacity='.35'/>" \
|
|
10
|
+
"<path d='M0 450 240 210l150 140 110-90 300 190z' fill='#000' fill-opacity='.18'/></svg>"
|
|
11
|
+
"data:image/svg+xml,#{ERB::Util.url_encode(svg)}"
|
|
12
|
+
end
|
|
13
|
+
|
|
4
14
|
# @label Playground
|
|
5
15
|
# @param title text
|
|
6
16
|
# @param description text
|
|
17
|
+
# @param size select { choices: [default, sm] }
|
|
18
|
+
# @param spacing select { choices: ["", 3, 4, 5, 6, 8] } "Blank follows the size"
|
|
19
|
+
# @param show_action toggle
|
|
20
|
+
# @param show_image toggle
|
|
7
21
|
# @param show_footer toggle
|
|
8
|
-
def playground(title: "Create project", description: "Deploy your new project in one click.",
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
card.with_content do
|
|
15
|
-
tag.p(class: "text-sm text-muted-foreground") { "Card body content goes here." }
|
|
16
|
-
end
|
|
17
|
-
if show_footer
|
|
18
|
-
card.with_footer do
|
|
19
|
-
tag.div(class: "flex gap-2") do
|
|
20
|
-
safe_join([
|
|
21
|
-
render(UI::Button.new(variant: :primary, size: :sm)) { "Deploy" },
|
|
22
|
-
render(UI::Button.new(variant: :outline, size: :sm)) { "Cancel" }
|
|
23
|
-
])
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
22
|
+
def playground(title: "Create project", description: "Deploy your new project in one click.", size: :default,
|
|
23
|
+
spacing: "", show_action: true, show_image: false, show_footer: true)
|
|
24
|
+
render_with_template(locals: { title: title, description: description, size: size.to_sym,
|
|
25
|
+
spacing: spacing.presence&.to_i, show_action: show_action,
|
|
26
|
+
show_image: show_image, show_footer: show_footer })
|
|
28
27
|
end
|
|
29
28
|
|
|
30
|
-
# @label
|
|
31
|
-
def
|
|
29
|
+
# @label Sign In
|
|
30
|
+
def sign_in; render_with_template; end
|
|
32
31
|
|
|
33
|
-
# @label
|
|
34
|
-
def
|
|
32
|
+
# @label Small
|
|
33
|
+
def small; render_with_template; end
|
|
35
34
|
|
|
36
|
-
# @label With
|
|
37
|
-
def
|
|
35
|
+
# @label With an Image
|
|
36
|
+
def image; render_with_template; end
|
|
38
37
|
|
|
39
|
-
# @label
|
|
40
|
-
def
|
|
38
|
+
# @label Stats, with a Badge as the Action
|
|
39
|
+
def stats; render_with_template; end
|
|
40
|
+
|
|
41
|
+
# @label Team, with a Button as the Action
|
|
42
|
+
def team; render_with_template; end
|
|
41
43
|
|
|
42
44
|
# @label Settings Form
|
|
43
45
|
def settings_form; render_with_template; end
|
|
46
|
+
|
|
47
|
+
# @label Spacing
|
|
48
|
+
def spacing; render_with_template; end
|
|
49
|
+
|
|
50
|
+
# @label Content to the Edges
|
|
51
|
+
def edge_to_edge; render_with_template; end
|
|
52
|
+
|
|
53
|
+
# @label Just Content
|
|
54
|
+
def just_content; render_with_template; end
|
|
55
|
+
|
|
56
|
+
# @label Open Bill at a Till
|
|
57
|
+
def open_bill; render_with_template; end
|
|
44
58
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<div id="money-cash-demo" class="max-w-xs space-y-4 rounded-lg border p-5">
|
|
2
|
+
<div class="flex items-baseline justify-between">
|
|
3
|
+
<span class="text-sm text-muted-foreground">To pay</span>
|
|
4
|
+
<span class="text-2xl font-semibold tabular-nums">₹1,847.00</span>
|
|
5
|
+
</div>
|
|
6
|
+
<%= render(UI::MoneyInput.new(name: "tendered", unit: "₹", size: :lg, label: "Cash received", autofocus: true)) %>
|
|
7
|
+
<div class="flex items-baseline justify-between text-sm">
|
|
8
|
+
<span class="text-muted-foreground">Change</span>
|
|
9
|
+
<span class="font-medium tabular-nums" data-demo="change" role="status">—</span>
|
|
10
|
+
</div>
|
|
11
|
+
</div>
|
|
12
|
+
<script>
|
|
13
|
+
(() => {
|
|
14
|
+
const root = document.getElementById("money-cash-demo");
|
|
15
|
+
const due = 1847;
|
|
16
|
+
root.addEventListener("input", () => {
|
|
17
|
+
const given = Number(root.querySelector('input[type=hidden][name="tendered"]').value || 0);
|
|
18
|
+
const out = root.querySelector('[data-demo="change"]');
|
|
19
|
+
if (!given) out.textContent = "—";
|
|
20
|
+
else if (given < due) out.textContent = "₹" + (due - given).toLocaleString("en-IN", { minimumFractionDigits: 2 }) + " short";
|
|
21
|
+
else out.textContent = "₹" + (given - due).toLocaleString("en-IN", { minimumFractionDigits: 2 });
|
|
22
|
+
});
|
|
23
|
+
})();
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<div class="grid max-w-xs gap-4">
|
|
2
|
+
<%= render(UI::MoneyInput.new(name: "inr", unit: "₹", value: 12345678.9, label: "Rupees, grouped in lakhs and crores")) %>
|
|
3
|
+
<%= render(UI::MoneyInput.new(name: "usd", unit: "$", value: 12345678.9, label: "Dollars, grouped in thousands")) %>
|
|
4
|
+
<%= render(UI::MoneyInput.new(name: "eur", unit: "€", value: 1234.5, separator: ",", delimiter: ".", label: "Euros, with a decimal comma")) %>
|
|
5
|
+
<%= render(UI::MoneyInput.new(name: "jpy", unit: "¥", value: 15800, precision: 0, label: "Yen, no decimals")) %>
|
|
6
|
+
<p class="text-sm text-muted-foreground">Each posts the plain number, like <code>12345678.90</code>. The sign, separators and decimals default to the app's locale.</p>
|
|
7
|
+
</div>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%# Reads the hidden fields, which hold plain numbers, so there's no comma or full stop to strip. %>
|
|
2
|
+
<div id="money-invoice-demo" class="grid max-w-sm gap-4">
|
|
3
|
+
<%= render(UI::MoneyInput.new(name: "fee", unit: "€", separator: ",", delimiter: ".", value: 8500, label: "Design work")) %>
|
|
4
|
+
<%= render(UI::MoneyInput.new(name: "expenses", unit: "€", separator: ",", delimiter: ".", value: 1245.75, label: "Expenses",
|
|
5
|
+
hint: "Travel and printing, at cost.")) %>
|
|
6
|
+
<dl class="grid grid-cols-2 gap-y-1 border-t pt-3 text-sm">
|
|
7
|
+
<dt class="text-muted-foreground">VAT at 20% on the work</dt><dd class="text-end tabular-nums" data-demo="vat"></dd>
|
|
8
|
+
<dt class="font-medium">Total</dt><dd class="text-end font-medium tabular-nums" data-demo="total"></dd>
|
|
9
|
+
</dl>
|
|
10
|
+
</div>
|
|
11
|
+
<script>
|
|
12
|
+
(() => {
|
|
13
|
+
const root = document.getElementById("money-invoice-demo");
|
|
14
|
+
const money = (n) => "€" + n.toLocaleString("de-DE", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
|
15
|
+
const amount = (name) => Number(root.querySelector(`input[type=hidden][name="${name}"]`).value || 0);
|
|
16
|
+
const total = () => {
|
|
17
|
+
const vat = amount("fee") * 0.2;
|
|
18
|
+
root.querySelector('[data-demo="vat"]').textContent = money(vat);
|
|
19
|
+
root.querySelector('[data-demo="total"]').textContent = money(amount("fee") + amount("expenses") + vat);
|
|
20
|
+
};
|
|
21
|
+
root.addEventListener("input", total);
|
|
22
|
+
total();
|
|
23
|
+
})();
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<div class="grid max-w-xs gap-4">
|
|
2
|
+
<%= render(UI::MoneyInput.new(name: "small", unit: "$", value: 499, size: :sm, label: "Small")) %>
|
|
3
|
+
<%= render(UI::MoneyInput.new(name: "default", unit: "$", value: 4999, label: "Default")) %>
|
|
4
|
+
<%= render(UI::MoneyInput.new(name: "large", unit: "$", value: 49999, size: :lg, label: "Large, for touch screens")) %>
|
|
5
|
+
<%= render(UI::MoneyInput.new(name: "empty", unit: "$", label: "Empty, required", required: true, hint: "Cents are filled in when you leave the field.")) %>
|
|
6
|
+
<%= render(UI::MoneyInput.new(name: "refund", unit: "$", value: -1200, negative: true, label: "A refund, below zero allowed")) %>
|
|
7
|
+
<%= render(UI::MoneyInput.new(name: "disabled", unit: "$", value: 2500, label: "Disabled", disabled: true)) %>
|
|
8
|
+
<%= render(UI::MoneyInput.new(name: "invalid", unit: "$", value: 0, label: "With an error", error: "Must be more than $0")) %>
|
|
9
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::MoneyInputPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param unit text
|
|
6
|
+
# @param value text
|
|
7
|
+
# @param precision number "Decimals: 2 for paise or cents, 0 for whole amounts"
|
|
8
|
+
# @param grouping select { choices: ["", thousands, indian] } "Blank: Indian for ₹, thousands otherwise. Try ₹ as the unit"
|
|
9
|
+
# @param negative toggle
|
|
10
|
+
# @param size select { choices: [sm, default, lg] }
|
|
11
|
+
# @param label text
|
|
12
|
+
# @param hint text
|
|
13
|
+
# @param disabled toggle
|
|
14
|
+
# @param error text
|
|
15
|
+
def playground(unit: "$", value: "123456.5", precision: 2, grouping: "", negative: false, size: :default,
|
|
16
|
+
label: "Amount", hint: "", disabled: false, error: "")
|
|
17
|
+
render(UI::MoneyInput.new(name: "amount", unit: unit, value: value.presence, precision: precision,
|
|
18
|
+
grouping: grouping.presence, negative: negative, size: size.to_sym,
|
|
19
|
+
label: label.presence, hint: hint.presence, disabled: disabled,
|
|
20
|
+
error: error.presence, class: "max-w-xs"))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @label Currencies
|
|
24
|
+
def currencies; render_with_template; end
|
|
25
|
+
|
|
26
|
+
# @label Sizes and States
|
|
27
|
+
def sizes_and_states; render_with_template; end
|
|
28
|
+
|
|
29
|
+
# @label Invoice Total, Following Live
|
|
30
|
+
def invoice; render_with_template; end
|
|
31
|
+
|
|
32
|
+
# @label Cash and Change at a Till
|
|
33
|
+
def cash_tendered; render_with_template; end
|
|
34
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%# What a scanner does: types the code fast, then presses the suffix key. For trying the demos without one. %>
|
|
2
|
+
<div class="flex flex-wrap items-center gap-2 text-sm">
|
|
3
|
+
<span class="text-muted-foreground">Simulate a scan:</span>
|
|
4
|
+
<% codes.each do |code, label| %>
|
|
5
|
+
<%= render(UI::Button.new(variant: :outline, size: :sm, data: { simulate: code, key: local_assigns.fetch(:key, "Enter") })) { label } %>
|
|
6
|
+
<% end %>
|
|
7
|
+
</div>
|
|
8
|
+
<script>
|
|
9
|
+
(() => {
|
|
10
|
+
const root = document.currentScript.previousElementSibling;
|
|
11
|
+
root.addEventListener("click", (event) => {
|
|
12
|
+
const button = event.target.closest("[data-simulate]");
|
|
13
|
+
if (!button) return;
|
|
14
|
+
const field = root.closest("[data-demo]").querySelector("[data-ui--scan-input-target=field]");
|
|
15
|
+
field.focus();
|
|
16
|
+
field.value = button.dataset.simulate;
|
|
17
|
+
field.dispatchEvent(new KeyboardEvent("keydown", { key: button.dataset.key, bubbles: true, cancelable: true }));
|
|
18
|
+
});
|
|
19
|
+
})();
|
|
20
|
+
</script>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<%# Handled in the page: the scan event is cancelled, so nothing is submitted. %>
|
|
2
|
+
<div class="grid max-w-md gap-4" data-demo>
|
|
3
|
+
<%= render(UI::ScanInput.new(name: "isbn", label: "Scan each book's barcode", placeholder: "ISBN")) %>
|
|
4
|
+
<%= render "ui/scan_input_preview/simulate", codes: { "9780141439518" => "Pride and Prejudice", "9780262033848" => "Introduction to Algorithms", "9780000000000" => "Unknown" } %>
|
|
5
|
+
<p class="text-sm" role="status" data-out></p>
|
|
6
|
+
<ol class="divide-y rounded-md border text-sm" data-list></ol>
|
|
7
|
+
<p class="text-sm text-muted-foreground"><span data-count>0</span> books, due back in 14 days.</p>
|
|
8
|
+
</div>
|
|
9
|
+
<script>
|
|
10
|
+
(() => {
|
|
11
|
+
const root = document.currentScript.previousElementSibling;
|
|
12
|
+
const books = { "9780141439518": "Pride and Prejudice", "9780262033848": "Introduction to Algorithms", "9780316769488": "The Catcher in the Rye" };
|
|
13
|
+
const list = root.querySelector("[data-list]");
|
|
14
|
+
const say = (text) => (root.querySelector("[data-out]").textContent = text);
|
|
15
|
+
root.addEventListener("ui--scan-input:scan", (event) => {
|
|
16
|
+
event.preventDefault();
|
|
17
|
+
const { code } = event.detail;
|
|
18
|
+
const title = books[code];
|
|
19
|
+
if (!title) return say(`No book with the ISBN ${code}.`);
|
|
20
|
+
if (list.querySelector(`[data-isbn="${code}"]`)) return say(`${title} is already on this loan.`);
|
|
21
|
+
const item = document.createElement("li");
|
|
22
|
+
item.className = "px-3 py-2";
|
|
23
|
+
item.dataset.isbn = code;
|
|
24
|
+
item.textContent = title;
|
|
25
|
+
list.append(item);
|
|
26
|
+
root.querySelector("[data-count]").textContent = list.children.length;
|
|
27
|
+
say(`Added ${title}.`);
|
|
28
|
+
});
|
|
29
|
+
})();
|
|
30
|
+
</script>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div class="grid max-w-sm gap-4" data-demo>
|
|
2
|
+
<%= render(UI::ScanInput.new(name: "code", submit: false, **options)) %>
|
|
3
|
+
<%= render "ui/scan_input_preview/simulate", codes: { "4006381333931" => "EAN-13", "TICKET-7F3K-0192" => "QR ticket" }, key: options[:suffix] == :tab ? "Tab" : "Enter" %>
|
|
4
|
+
<p class="text-sm text-muted-foreground" role="status" data-demo-out>Nothing scanned yet.</p>
|
|
5
|
+
</div>
|
|
6
|
+
<script>
|
|
7
|
+
(() => {
|
|
8
|
+
const root = document.currentScript.previousElementSibling;
|
|
9
|
+
root.addEventListener("ui--scan-input:scan", (event) => {
|
|
10
|
+
root.querySelector("[data-demo-out]").textContent = `Scanned ${event.detail.code}`;
|
|
11
|
+
});
|
|
12
|
+
})();
|
|
13
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%# capture: true sends keys typed with no field focused into this one, so a scan lands even after clicking elsewhere. %>
|
|
2
|
+
<div class="grid max-w-md gap-4" data-demo>
|
|
3
|
+
<%= render(UI::ScanInput.new(name: "sku", label: "Count shelf B-12", capture: true,
|
|
4
|
+
hint: "Click anywhere on the page, then scan: the code still lands here.")) %>
|
|
5
|
+
<%= render "ui/scan_input_preview/simulate", codes: { "SKU-1042" => "Cable ties", "SKU-2210" => "Hex bolts", "SKU-3307" => "Wall plugs" } %>
|
|
6
|
+
<table class="text-sm">
|
|
7
|
+
<thead><tr class="text-start text-muted-foreground"><th class="py-1 text-start font-normal">Item</th><th class="py-1 text-end font-normal">Counted</th><th class="py-1 text-end font-normal">Expected</th></tr></thead>
|
|
8
|
+
<tbody data-rows>
|
|
9
|
+
<tr data-sku="SKU-1042"><td class="py-1">Cable ties</td><td class="py-1 text-end tabular-nums" data-n>0</td><td class="py-1 text-end tabular-nums">3</td></tr>
|
|
10
|
+
<tr data-sku="SKU-2210"><td class="py-1">Hex bolts</td><td class="py-1 text-end tabular-nums" data-n>0</td><td class="py-1 text-end tabular-nums">2</td></tr>
|
|
11
|
+
<tr data-sku="SKU-3307"><td class="py-1">Wall plugs</td><td class="py-1 text-end tabular-nums" data-n>0</td><td class="py-1 text-end tabular-nums">4</td></tr>
|
|
12
|
+
</tbody>
|
|
13
|
+
</table>
|
|
14
|
+
</div>
|
|
15
|
+
<script>
|
|
16
|
+
(() => {
|
|
17
|
+
const root = document.currentScript.previousElementSibling;
|
|
18
|
+
root.addEventListener("ui--scan-input:scan", (event) => {
|
|
19
|
+
event.preventDefault();
|
|
20
|
+
const cell = root.querySelector(`tr[data-sku="${event.detail.code}"] [data-n]`);
|
|
21
|
+
if (cell) cell.textContent = Number(cell.textContent) + 1;
|
|
22
|
+
});
|
|
23
|
+
})();
|
|
24
|
+
</script>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<%# keyboard: false keeps a handheld's on-screen keyboard down; its trigger button does the typing. %>
|
|
2
|
+
<div class="grid max-w-sm gap-4" data-demo>
|
|
3
|
+
<%= render(UI::ScanInput.new(name: "ticket", label: "Check in", placeholder: "Scan a ticket's QR code", size: :lg, keyboard: false)) %>
|
|
4
|
+
<%= render "ui/scan_input_preview/simulate", codes: { "TKT-A-0192" => "Valid", "TKT-A-0007" => "Already used", "TKT-Z-9999" => "Not for today" } %>
|
|
5
|
+
<div class="rounded-md border p-4 text-center" role="status" data-out>
|
|
6
|
+
<p class="text-sm text-muted-foreground">Waiting for a ticket</p>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
<script>
|
|
10
|
+
(() => {
|
|
11
|
+
const root = document.currentScript.previousElementSibling;
|
|
12
|
+
const used = new Set(["TKT-A-0007"]);
|
|
13
|
+
const out = root.querySelector("[data-out]");
|
|
14
|
+
const show = (title, line, tone) => {
|
|
15
|
+
out.className = `rounded-md border p-4 text-center ${tone}`;
|
|
16
|
+
out.innerHTML = "";
|
|
17
|
+
const strong = document.createElement("p");
|
|
18
|
+
strong.className = "text-lg font-semibold";
|
|
19
|
+
strong.textContent = title;
|
|
20
|
+
const small = document.createElement("p");
|
|
21
|
+
small.className = "text-sm";
|
|
22
|
+
small.textContent = line;
|
|
23
|
+
out.append(strong, small);
|
|
24
|
+
};
|
|
25
|
+
root.addEventListener("ui--scan-input:scan", (event) => {
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
const { code } = event.detail;
|
|
28
|
+
if (!code.startsWith("TKT-A-")) return show("Not for today", `${code} is for another day.`, "border-amber-500/50 bg-amber-500/10");
|
|
29
|
+
if (used.has(code)) return show("Already checked in", `${code} was used at 18:42.`, "border-destructive/50 bg-destructive/10");
|
|
30
|
+
used.add(code);
|
|
31
|
+
show("Welcome", `${code}, general admission.`, "border-emerald-500/50 bg-emerald-500/10");
|
|
32
|
+
});
|
|
33
|
+
})();
|
|
34
|
+
</script>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<%# A real form: each code is posted, and the server answers with a Turbo Stream adding the line. The demo server answers slowly, so quick scans queue. %>
|
|
2
|
+
<div class="grid max-w-md gap-4" data-demo>
|
|
3
|
+
<%= form_with url: "/demo/scans", class: "contents", data: { demo_live: true } do %>
|
|
4
|
+
<%= render(UI::ScanInput.new(name: "code", label: "Scan items", size: :lg)) %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<%= render "ui/scan_input_preview/simulate", codes: { "8901030865278" => "Rice", "8901058851298" => "Noodles", "8901719110016" => "Dal", "1111" => "Unknown" } %>
|
|
7
|
+
<p class="text-sm text-destructive" id="scan-demo-status" role="status"></p>
|
|
8
|
+
<ul id="scan-demo-lines" class="divide-y rounded-md border px-3 text-sm"></ul>
|
|
9
|
+
</div>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::ScanInputPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param label text
|
|
6
|
+
# @param placeholder text
|
|
7
|
+
# @param size select { choices: [sm, default, lg] }
|
|
8
|
+
# @param suffix select { choices: [enter, tab] } "The key the scanner ends a code with"
|
|
9
|
+
# @param keyboard toggle "Off keeps a phone's on-screen keyboard down"
|
|
10
|
+
# @param capture toggle "Keys typed anywhere on the page go into the field"
|
|
11
|
+
# @param disabled toggle
|
|
12
|
+
# @param hint text
|
|
13
|
+
# @param error text
|
|
14
|
+
def playground(label: "Scan an item", placeholder: "", size: :default, suffix: :enter, keyboard: true,
|
|
15
|
+
capture: false, disabled: false, hint: "", error: "")
|
|
16
|
+
render_with_template(locals: { options: {
|
|
17
|
+
label: label.presence, placeholder: placeholder.presence, size: size.to_sym, suffix: suffix.to_sym,
|
|
18
|
+
keyboard: keyboard, capture: capture, disabled: disabled, hint: hint.presence, error: error.presence
|
|
19
|
+
} })
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @label Library Checkout
|
|
23
|
+
def library_checkout; render_with_template; end
|
|
24
|
+
|
|
25
|
+
# @label Stock Count, Scanning Anywhere on the Page
|
|
26
|
+
def stock_count; render_with_template; end
|
|
27
|
+
|
|
28
|
+
# @label Ticket Check-in on a Handheld
|
|
29
|
+
def ticket_check_in; render_with_template; end
|
|
30
|
+
|
|
31
|
+
# @label Till, Sent to the Server
|
|
32
|
+
def till; render_with_template; end
|
|
33
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<div class="grid max-w-sm gap-8">
|
|
2
|
+
<%= render(UI::Slider.new(name: "digest", min: 0, max: 3, value: 1, label: "Email me about comments", show_value: true,
|
|
3
|
+
marks: { 0 => "Never", 1 => "Weekly", 2 => "Daily", 3 => "Right away" })) %>
|
|
4
|
+
<%= render(UI::Slider.new(name: "quality", min: 1, max: 3, value: 2, label: "Video quality", show_value: true,
|
|
5
|
+
marks: { 1 => "Low", 2 => "Medium", 3 => "High" },
|
|
6
|
+
hint: "Higher uses more data.")) %>
|
|
7
|
+
</div>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<div class="max-w-md">
|
|
2
|
+
<%= render(UI::Slider.new(range: true, label: "Open", min: 0, max: 24, from: 9, to: 17, from_name: "opens_at",
|
|
3
|
+
to_name: "closes_at", value_text: "%{value}:00", show_value: true,
|
|
4
|
+
marks: { 0 => "Midnight", 6 => "6:00", 12 => "Noon", 18 => "18:00", 24 => "Midnight" })) %>
|
|
5
|
+
</div>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<%# A filter form submits on change, which fires once a handle is let go, not on every step of a drag. %>
|
|
2
|
+
<form class="max-w-sm space-y-3" onsubmit="event.preventDefault()">
|
|
3
|
+
<%= render(UI::Slider.new(range: true, label: "Price", min: 0, max: 500, step: 10, from: 40, to: 260,
|
|
4
|
+
from_name: "min_price", to_name: "max_price", value_text: "$%{value}", show_value: true)) %>
|
|
5
|
+
<p class="text-sm text-muted-foreground">Handles meet but don't pass each other. Press the track to grab the nearest.</p>
|
|
6
|
+
</form>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<div class="grid max-w-sm gap-6">
|
|
2
|
+
<%= render(UI::Slider.new(name: "small", value: 30, size: :sm, label: "Small", show_value: true)) %>
|
|
3
|
+
<%= render(UI::Slider.new(name: "default", value: 50, label: "Default", show_value: true)) %>
|
|
4
|
+
<%= render(UI::Slider.new(name: "large", value: 70, size: :lg, label: "Large, for touch screens", show_value: true)) %>
|
|
5
|
+
<%= render(UI::Slider.new(name: "disabled", value: 40, label: "Disabled", disabled: true, show_value: true)) %>
|
|
6
|
+
<%= render(UI::Slider.new(name: "alert_at", value: 30, min: 50, max: 100, step: 5, label: "Warn me when storage reaches",
|
|
7
|
+
value_text: "%{value}%", show_value: true, hint: "We'll email you once a day until there's room.",
|
|
8
|
+
error: "Must be at least 50%")) %>
|
|
9
|
+
</div>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<div id="slider-text-size-demo" class="grid max-w-md gap-4">
|
|
2
|
+
<%= render(UI::Slider.new(name: "text_size", min: 12, max: 24, value: 16, label: "Text size", value_text: "%{value}px",
|
|
3
|
+
show_value: true, marks: [ 12, 16, 20, 24 ])) %>
|
|
4
|
+
<p class="rounded-md border p-4" data-demo="sample" style="font-size: 16px">
|
|
5
|
+
The quick brown fox jumps over the lazy dog.
|
|
6
|
+
</p>
|
|
7
|
+
</div>
|
|
8
|
+
<script>
|
|
9
|
+
(() => {
|
|
10
|
+
const root = document.getElementById("slider-text-size-demo");
|
|
11
|
+
const sample = root.querySelector('[data-demo="sample"]');
|
|
12
|
+
root.addEventListener("input", (event) => {
|
|
13
|
+
if (event.target.name === "text_size") sample.style.fontSize = `${event.target.value}px`;
|
|
14
|
+
});
|
|
15
|
+
})();
|
|
16
|
+
</script>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<div id="slider-tip-demo" class="max-w-xs space-y-5 rounded-lg border p-5">
|
|
2
|
+
<div class="text-center">
|
|
3
|
+
<p class="text-sm text-muted-foreground">Add a tip</p>
|
|
4
|
+
<p class="text-3xl font-semibold tabular-nums" data-demo="total">$48.30</p>
|
|
5
|
+
<p class="text-sm text-muted-foreground" data-demo="breakdown">$42.00 + $6.30 tip</p>
|
|
6
|
+
</div>
|
|
7
|
+
<%= render(UI::Slider.new(name: "tip_percent", min: 0, max: 25, step: 5, value: 15, size: :lg, label: false,
|
|
8
|
+
aria: { label: "Tip" }, value_text: "%{value}%",
|
|
9
|
+
marks: { 0 => "None", 10 => "10%", 15 => "15%", 20 => "20%", 25 => "25%" })) %>
|
|
10
|
+
</div>
|
|
11
|
+
<script>
|
|
12
|
+
(() => {
|
|
13
|
+
const root = document.getElementById("slider-tip-demo");
|
|
14
|
+
const bill = 42;
|
|
15
|
+
const money = (n) => `$${n.toFixed(2)}`;
|
|
16
|
+
root.addEventListener("input", (event) => {
|
|
17
|
+
const tip = bill * Number(event.target.value) / 100;
|
|
18
|
+
root.querySelector('[data-demo="total"]').textContent = money(bill + tip);
|
|
19
|
+
root.querySelector('[data-demo="breakdown"]').textContent = tip ? `${money(bill)} + ${money(tip)} tip` : "No tip";
|
|
20
|
+
});
|
|
21
|
+
})();
|
|
22
|
+
</script>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<div class="flex max-w-xs items-center gap-3">
|
|
2
|
+
<%= render(UI::Icon.new(name: "volume-x", size: :sm, class: "shrink-0 text-muted-foreground")) %>
|
|
3
|
+
<%= render(UI::Slider.new(name: "volume", value: 65, label: false, aria: { label: "Volume" }, value_text: "%{value}%")) %>
|
|
4
|
+
<%= render(UI::Icon.new(name: "volume-2", size: :sm, class: "shrink-0 text-muted-foreground")) %>
|
|
5
|
+
</div>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::SliderPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param range toggle "Two handles, a low and a high"
|
|
6
|
+
# @param value number
|
|
7
|
+
# @param min number
|
|
8
|
+
# @param max number
|
|
9
|
+
# @param step number
|
|
10
|
+
# @param label text
|
|
11
|
+
# @param show_value toggle
|
|
12
|
+
# @param value_text text "Can use %{value}"
|
|
13
|
+
# @param size select { choices: [sm, default, lg] }
|
|
14
|
+
# @param disabled toggle
|
|
15
|
+
# @param hint text
|
|
16
|
+
# @param error text
|
|
17
|
+
def playground(range: false, value: 40, min: 0, max: 100, step: 1, label: "Volume", show_value: true,
|
|
18
|
+
value_text: "%{value}%", size: :default, disabled: false, hint: "", error: "")
|
|
19
|
+
render(UI::Slider.new(name: "volume", range: range, value: value, from: value, to: max, min: min, max: max,
|
|
20
|
+
step: step, label: label.presence, show_value: show_value, value_text: value_text.presence,
|
|
21
|
+
size: size.to_sym, disabled: disabled, hint: hint.presence, error: error.presence,
|
|
22
|
+
class: "max-w-sm"))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @label Sizes and States
|
|
26
|
+
def sizes_and_states; render_with_template; end
|
|
27
|
+
|
|
28
|
+
# @label Volume, with Icons
|
|
29
|
+
def volume; render_with_template; end
|
|
30
|
+
|
|
31
|
+
# @label Price Range Filter
|
|
32
|
+
def price_range; render_with_template; end
|
|
33
|
+
|
|
34
|
+
# @label Opening Hours, with Marks
|
|
35
|
+
def opening_hours; render_with_template; end
|
|
36
|
+
|
|
37
|
+
# @label Named Steps
|
|
38
|
+
def named_steps; render_with_template; end
|
|
39
|
+
|
|
40
|
+
# @label Text Size, Following Live
|
|
41
|
+
def text_size; render_with_template; end
|
|
42
|
+
|
|
43
|
+
# @label Tip on a Card Reader
|
|
44
|
+
def tip; render_with_template; end
|
|
45
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::Card::ActionTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def test_sits_in_the_headers_second_column
|
|
10
|
+
render_inline(UI::Card::Action.new) { "Invite" }
|
|
11
|
+
action = page.find("[data-slot='card-action']", text: "Invite")
|
|
12
|
+
%w[col-start-2 row-span-2 row-start-1 justify-self-end].each { |c| assert_includes action[:class].split, c }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_passes_class_and_attributes
|
|
16
|
+
render_inline(UI::Card::Action.new(class: "self-center", id: "a", data: { testid: "t" })) { "x" }
|
|
17
|
+
assert_selector "#a.self-center[data-testid='t'][data-slot='card-action']"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -14,8 +14,7 @@ class UI::Card::ContentTest < ViewComponent::TestCase
|
|
|
14
14
|
def test_default_classes
|
|
15
15
|
render_inline(UI::Card::Content.new) { "x" }
|
|
16
16
|
classes = page.find("div")[:class].split
|
|
17
|
-
assert_includes classes, "
|
|
18
|
-
assert_includes classes, "pt-0"
|
|
17
|
+
assert_includes classes, "px-(--card-spacing)"
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
def test_user_class_override
|
|
@@ -29,13 +28,4 @@ class UI::Card::ContentTest < ViewComponent::TestCase
|
|
|
29
28
|
render_inline(UI::Card::Content.new(id: "my-content", data: { test_id: "c" })) { "x" }
|
|
30
29
|
assert_selector "div#my-content[data-test-id='c']"
|
|
31
30
|
end
|
|
32
|
-
|
|
33
|
-
# Content sits flush under a header, but needs its own top padding when it
|
|
34
|
-
# is the first thing in the card.
|
|
35
|
-
def test_content_first_in_a_card_gets_top_padding
|
|
36
|
-
render_inline(UI::Card::Content.new) { "Body" }
|
|
37
|
-
classes = page.find("div")[:class].split
|
|
38
|
-
assert_includes classes, "pt-0"
|
|
39
|
-
assert_includes classes, "first:pt-6"
|
|
40
|
-
end
|
|
41
31
|
end
|
|
@@ -16,8 +16,9 @@ class UI::Card::FooterTest < ViewComponent::TestCase
|
|
|
16
16
|
classes = page.find("div")[:class].split
|
|
17
17
|
assert_includes classes, "flex"
|
|
18
18
|
assert_includes classes, "items-center"
|
|
19
|
-
assert_includes classes, "p-
|
|
20
|
-
assert_includes classes, "
|
|
19
|
+
assert_includes classes, "p-(--card-spacing)"
|
|
20
|
+
assert_includes classes, "border-t"
|
|
21
|
+
assert_includes classes, "bg-muted/50"
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
def test_user_class_override
|
|
@@ -14,10 +14,9 @@ class UI::Card::HeaderTest < ViewComponent::TestCase
|
|
|
14
14
|
def test_default_classes
|
|
15
15
|
render_inline(UI::Card::Header.new) { "x" }
|
|
16
16
|
classes = page.find("div")[:class].split
|
|
17
|
-
assert_includes classes, "
|
|
18
|
-
assert_includes classes, "
|
|
19
|
-
assert_includes classes, "
|
|
20
|
-
assert_includes classes, "p-6"
|
|
17
|
+
assert_includes classes, "grid"
|
|
18
|
+
assert_includes classes, "gap-1"
|
|
19
|
+
assert_includes classes, "px-(--card-spacing)"
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
def test_renders_with_title_slot
|
|
@@ -14,10 +14,9 @@ class UI::Card::TitleTest < ViewComponent::TestCase
|
|
|
14
14
|
def test_default_classes
|
|
15
15
|
render_inline(UI::Card::Title.new) { "x" }
|
|
16
16
|
classes = page.find("h3")[:class].split
|
|
17
|
-
assert_includes classes, "text-
|
|
18
|
-
assert_includes classes, "font-
|
|
19
|
-
assert_includes classes, "leading-
|
|
20
|
-
assert_includes classes, "tracking-tight"
|
|
17
|
+
assert_includes classes, "text-base"
|
|
18
|
+
assert_includes classes, "font-medium"
|
|
19
|
+
assert_includes classes, "leading-snug"
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
def test_user_class_override
|