velvetkit 0.3.0 → 0.4.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 +109 -0
- data/README.md +5 -1
- data/lib/generators/velvetkit/add/add_generator.rb +58 -0
- data/lib/velvetkit/version.rb +4 -1
- data/lib/velvetkit.rb +7 -0
- data/registry/app/assets/tailwind/velvetkit.css +90 -155
- data/registry/app/components/ui/chart.html.erb +47 -0
- data/registry/app/components/ui/chart.rb +177 -0
- data/registry/app/components/ui/command/group.rb +27 -0
- data/registry/app/components/ui/command/item.rb +64 -0
- data/registry/app/components/ui/command.html.erb +41 -0
- data/registry/app/components/ui/command.rb +122 -0
- data/registry/app/components/ui/date_picker.html.erb +58 -64
- data/registry/app/components/ui/date_picker.rb +199 -75
- data/registry/app/components/ui/file_field.html.erb +14 -4
- data/registry/app/components/ui/file_field.rb +179 -28
- data/registry/app/components/ui/gallery/image.rb +20 -0
- data/registry/app/components/ui/gallery.html.erb +52 -0
- data/registry/app/components/ui/gallery.rb +164 -0
- data/registry/app/components/ui/kbd.html.erb +27 -0
- data/registry/app/components/ui/kbd.rb +134 -0
- 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/number_input.html.erb +11 -0
- data/registry/app/components/ui/number_input.rb +103 -0
- data/registry/app/components/ui/progress/segment.rb +25 -0
- data/registry/app/components/ui/progress.html.erb +25 -0
- data/registry/app/components/ui/progress.rb +182 -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/select.html.erb +24 -5
- data/registry/app/components/ui/select.rb +44 -5
- data/registry/app/components/ui/slider.html.erb +23 -0
- data/registry/app/components/ui/slider.rb +254 -0
- data/registry/app/components/ui/timeline/item.html.erb +21 -0
- data/registry/app/components/ui/timeline/item.rb +145 -0
- data/registry/app/components/ui/timeline.html.erb +1 -0
- data/registry/app/components/ui/timeline.rb +42 -0
- data/registry/app/javascript/chart_js.ts +37 -0
- data/registry/app/javascript/controllers/ui/_internal/date_format.ts +74 -0
- data/registry/app/javascript/controllers/ui/_internal/shortcut.ts +80 -0
- data/registry/app/javascript/controllers/ui/chart_controller.ts +585 -0
- data/registry/app/javascript/controllers/ui/command_controller.ts +454 -0
- data/registry/app/javascript/controllers/ui/date_picker_controller.ts +247 -82
- data/registry/app/javascript/controllers/ui/file_field_controller.ts +288 -16
- data/registry/app/javascript/controllers/ui/gallery_controller.ts +568 -0
- data/registry/app/javascript/controllers/ui/kbd_controller.ts +60 -0
- data/registry/app/javascript/controllers/ui/money_input_controller.ts +228 -0
- data/registry/app/javascript/controllers/ui/number_input_controller.ts +111 -0
- data/registry/app/javascript/controllers/ui/progress_controller.ts +87 -0
- data/registry/app/javascript/controllers/ui/scan_input_controller.ts +143 -0
- data/registry/app/javascript/controllers/ui/select_controller.ts +198 -8
- data/registry/app/javascript/controllers/ui/slider_controller.ts +216 -0
- data/registry/app/javascript/vanilla_calendar.ts +15 -0
- data/registry/components.yml +25 -3
- data/registry/config/locales/velvetkit.en.yml +79 -0
- data/registry/icons/lucide/download.svg +17 -0
- data/registry/icons/lucide/file-plus.svg +18 -0
- data/registry/icons/lucide/file.svg +16 -0
- data/registry/icons/lucide/folder.svg +15 -0
- data/registry/icons/lucide/keyboard.svg +23 -0
- data/registry/icons/lucide/minus.svg +15 -0
- data/registry/icons/lucide/package.svg +18 -0
- data/registry/icons/lucide/pause.svg +16 -0
- data/registry/icons/lucide/percent.svg +17 -0
- data/registry/icons/lucide/printer.svg +17 -0
- data/registry/icons/lucide/receipt.svg +17 -0
- data/registry/icons/lucide/scan-barcode.svg +21 -0
- data/registry/icons/lucide/sun-moon.svg +19 -0
- data/registry/icons/lucide/truck.svg +19 -0
- data/registry/icons/lucide/user-plus.svg +18 -0
- data/registry/icons/lucide/volume-2.svg +17 -0
- data/registry/icons/lucide/volume-x.svg +17 -0
- data/registry/icons/lucide/zoom-in.svg +18 -0
- data/registry/icons/lucide/zoom-out.svg +17 -0
- data/registry/icons/phosphor/barcode.svg +2 -0
- data/registry/icons/phosphor/circle-half.svg +2 -0
- data/registry/icons/phosphor/download-simple.svg +2 -0
- data/registry/icons/phosphor/file-plus.svg +2 -0
- data/registry/icons/phosphor/file.svg +2 -0
- data/registry/icons/phosphor/folder.svg +2 -0
- data/registry/icons/phosphor/keyboard.svg +2 -0
- data/registry/icons/phosphor/magnifying-glass-minus.svg +2 -0
- data/registry/icons/phosphor/magnifying-glass-plus.svg +2 -0
- data/registry/icons/phosphor/minus.svg +2 -0
- data/registry/icons/phosphor/package.svg +2 -0
- data/registry/icons/phosphor/pause.svg +2 -0
- data/registry/icons/phosphor/percent.svg +2 -0
- data/registry/icons/phosphor/printer.svg +2 -0
- data/registry/icons/phosphor/receipt.svg +2 -0
- data/registry/icons/phosphor/speaker-high.svg +2 -0
- data/registry/icons/phosphor/speaker-x.svg +2 -0
- data/registry/icons/phosphor/truck.svg +2 -0
- data/registry/icons/phosphor/user-plus.svg +2 -0
- data/registry/icons/tabler/barcode.svg +23 -0
- data/registry/icons/tabler/download.svg +18 -0
- data/registry/icons/tabler/file-plus.svg +19 -0
- data/registry/icons/tabler/file.svg +17 -0
- data/registry/icons/tabler/folder.svg +16 -0
- data/registry/icons/tabler/keyboard.svg +23 -0
- data/registry/icons/tabler/minus.svg +16 -0
- data/registry/icons/tabler/package.svg +20 -0
- data/registry/icons/tabler/percentage.svg +18 -0
- data/registry/icons/tabler/player-pause.svg +17 -0
- data/registry/icons/tabler/printer.svg +18 -0
- data/registry/icons/tabler/receipt.svg +16 -0
- data/registry/icons/tabler/sun-moon.svg +21 -0
- data/registry/icons/tabler/truck.svg +18 -0
- data/registry/icons/tabler/user-plus.svg +19 -0
- data/registry/icons/tabler/volume-3.svg +17 -0
- data/registry/icons/tabler/volume.svg +18 -0
- data/registry/icons/tabler/zoom-in.svg +19 -0
- data/registry/icons/tabler/zoom-out.svg +18 -0
- data/registry/icons.yml +19 -0
- data/registry/test/components/previews/ui/chart_preview/cash_flow.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/donut.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/margin.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/pie.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/sales.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/stock.html.erb +6 -0
- data/registry/test/components/previews/ui/chart_preview/takings.html.erb +8 -0
- data/registry/test/components/previews/ui/chart_preview.rb +46 -0
- data/registry/test/components/previews/ui/command_preview/_picked.html.erb +14 -0
- data/registry/test/components/previews/ui/command_preview/dialog.html.erb +24 -0
- data/registry/test/components/previews/ui/command_preview/inline.html.erb +16 -0
- data/registry/test/components/previews/ui/command_preview/playground.html.erb +15 -0
- data/registry/test/components/previews/ui/command_preview/server_search.html.erb +24 -0
- data/registry/test/components/previews/ui/command_preview/shortcuts.html.erb +12 -0
- data/registry/test/components/previews/ui/command_preview/till.html.erb +17 -0
- data/registry/test/components/previews/ui/command_preview.rb +25 -0
- data/registry/test/components/previews/ui/date_picker_preview/custom_presets.html.erb +6 -0
- data/registry/test/components/previews/ui/date_picker_preview/in_form.html.erb +11 -0
- data/registry/test/components/previews/ui/date_picker_preview/range.html.erb +5 -0
- data/registry/test/components/previews/ui/date_picker_preview/states.html.erb +4 -3
- data/registry/test/components/previews/ui/date_picker_preview.rb +26 -6
- data/registry/test/components/previews/ui/file_field_preview/multiple_files.html.erb +1 -1
- data/registry/test/components/previews/ui/file_field_preview/product_photos.html.erb +12 -0
- data/registry/test/components/previews/ui/file_field_preview/single_image.html.erb +4 -0
- data/registry/test/components/previews/ui/file_field_preview.rb +32 -5
- data/registry/test/components/previews/ui/gallery_preview/hover_zoom.html.erb +13 -0
- data/registry/test/components/previews/ui/gallery_preview/landscape.html.erb +5 -0
- data/registry/test/components/previews/ui/gallery_preview/product_page.html.erb +13 -0
- data/registry/test/components/previews/ui/gallery_preview/single.html.erb +3 -0
- data/registry/test/components/previews/ui/gallery_preview.rb +45 -0
- data/registry/test/components/previews/ui/kbd_preview/bound.html.erb +20 -0
- data/registry/test/components/previews/ui/kbd_preview/keys.html.erb +13 -0
- data/registry/test/components/previews/ui/kbd_preview/menu.html.erb +13 -0
- data/registry/test/components/previews/ui/kbd_preview/search_field.html.erb +8 -0
- data/registry/test/components/previews/ui/kbd_preview/shortcuts_list.html.erb +17 -0
- data/registry/test/components/previews/ui/kbd_preview/till.html.erb +23 -0
- data/registry/test/components/previews/ui/kbd_preview/tooltip_and_buttons.html.erb +14 -0
- data/registry/test/components/previews/ui/kbd_preview.rb +32 -0
- 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/number_input_preview/cart.html.erb +11 -0
- data/registry/test/components/previews/ui/number_input_preview/decimals.html.erb +4 -0
- data/registry/test/components/previews/ui/number_input_preview/sizes.html.erb +5 -0
- data/registry/test/components/previews/ui/number_input_preview/states.html.erb +7 -0
- data/registry/test/components/previews/ui/number_input_preview/stock_adjustment.html.erb +3 -0
- data/registry/test/components/previews/ui/number_input_preview.rb +36 -0
- data/registry/test/components/previews/ui/progress_preview/file_upload.html.erb +36 -0
- data/registry/test/components/previews/ui/progress_preview/free_shipping.html.erb +4 -0
- data/registry/test/components/previews/ui/progress_preview/indeterminate.html.erb +4 -0
- data/registry/test/components/previews/ui/progress_preview/sizes_and_tones.html.erb +8 -0
- data/registry/test/components/previews/ui/progress_preview/steps.html.erb +9 -0
- data/registry/test/components/previews/ui/progress_preview/storage.html.erb +8 -0
- data/registry/test/components/previews/ui/progress_preview/storage_by_category.html.erb +7 -0
- data/registry/test/components/previews/ui/progress_preview/tasks_by_status.html.erb +14 -0
- data/registry/test/components/previews/ui/progress_preview/traffic_by_source.html.erb +15 -0
- data/registry/test/components/previews/ui/progress_preview.rb +46 -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/select_preview/server_search.html.erb +22 -0
- data/registry/test/components/previews/ui/select_preview.rb +5 -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/previews/ui/timeline_preview/activity_log.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/colored.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/colored_by_meaning.html.erb +7 -0
- data/registry/test/components/previews/ui/timeline_preview/failed_delivery.html.erb +6 -0
- data/registry/test/components/previews/ui/timeline_preview/order_status.html.erb +9 -0
- data/registry/test/components/previews/ui/timeline_preview/real_dates.html.erb +5 -0
- data/registry/test/components/previews/ui/timeline_preview/stock_history.html.erb +6 -0
- data/registry/test/components/previews/ui/timeline_preview.rb +40 -0
- data/registry/test/components/ui/chart_test.rb +187 -0
- data/registry/test/components/ui/command/group_test.rb +19 -0
- data/registry/test/components/ui/command/item_test.rb +47 -0
- data/registry/test/components/ui/command_test.rb +110 -0
- data/registry/test/components/ui/date_picker_test.rb +129 -111
- data/registry/test/components/ui/file_field_test.rb +105 -9
- data/registry/test/components/ui/gallery_test.rb +192 -0
- data/registry/test/components/ui/kbd_test.rb +150 -0
- data/registry/test/components/ui/money_input_test.rb +149 -0
- data/registry/test/components/ui/number_input_test.rb +155 -0
- data/registry/test/components/ui/progress_test.rb +188 -0
- data/registry/test/components/ui/scan_input_test.rb +110 -0
- data/registry/test/components/ui/select_test.rb +62 -0
- data/registry/test/components/ui/slider_test.rb +190 -0
- data/registry/test/components/ui/timeline_test.rb +175 -0
- metadata +188 -2
- data/registry/app/javascript/cally.ts +0 -8
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::CommandPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param dialog toggle "Opened with ⌘K, over the page"
|
|
6
|
+
# @param placeholder text
|
|
7
|
+
def playground(dialog: false, placeholder: "Type a command or search…")
|
|
8
|
+
render_with_template(locals: { dialog: dialog, placeholder: placeholder.presence })
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @label ⌘K, Over the Page
|
|
12
|
+
def dialog; render_with_template; end
|
|
13
|
+
|
|
14
|
+
# @label Searching the Server
|
|
15
|
+
def server_search; render_with_template; end
|
|
16
|
+
|
|
17
|
+
# @label On the Page
|
|
18
|
+
def inline; render_with_template; end
|
|
19
|
+
|
|
20
|
+
# @label Shortcuts That Work, Palette Closed or Open
|
|
21
|
+
def shortcuts; render_with_template; end
|
|
22
|
+
|
|
23
|
+
# @label Finding a Product at a Till
|
|
24
|
+
def till; render_with_template; end
|
|
25
|
+
end
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<% today = Date.current %>
|
|
2
|
+
<%= render(UI::DatePicker.new(range: true, label: "Financial year", class: "max-w-sm", presets: [
|
|
3
|
+
[ "This quarter", today.beginning_of_quarter, today ],
|
|
4
|
+
[ "Last quarter", today.prev_quarter.beginning_of_quarter, today.prev_quarter.end_of_quarter ],
|
|
5
|
+
[ "This financial year", Date.new(today.month >= 4 ? today.year : today.year - 1, 4, 1), today ]
|
|
6
|
+
])) %>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<%# With a form builder, the fields take their names and values from the model. %>
|
|
2
|
+
<% promotion = Struct.new(:starts_on, :ends_on, :announced_on) do
|
|
3
|
+
def self.model_name = ActiveModel::Name.new(self, nil, "Promotion")
|
|
4
|
+
def model_name = self.class.model_name
|
|
5
|
+
def to_model = self
|
|
6
|
+
def persisted? = false
|
|
7
|
+
end.new(Date.current + 7, Date.current + 21, Date.current) %>
|
|
8
|
+
<%= form_with model: promotion, url: "/demo/promotions", class: "flex max-w-sm flex-col gap-6" do |f| %>
|
|
9
|
+
<%= render(UI::DatePicker.new(form: f, field: :announced_on, label: "Announced on")) %>
|
|
10
|
+
<%= render(UI::DatePicker.new(range: true, form: f, from_field: :starts_on, to_field: :ends_on, label: "Runs", presets: false)) %>
|
|
11
|
+
<% end %>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<%# Picking a range or a preset fires change on the field, so a filter form can send itself. %>
|
|
2
|
+
<form class="flex max-w-xl flex-wrap items-end gap-3" action="/demo/report" method="get">
|
|
3
|
+
<%= render(UI::DatePicker.new(range: true, label: "Period", hint: false, from: Date.current - 6, to: Date.current, class: "w-auto")) %>
|
|
4
|
+
<%= render(UI::Button.new(type: :submit, variant: :outline)) { "Show sales" } %>
|
|
5
|
+
</form>
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
<div class="flex max-w-
|
|
1
|
+
<div class="flex max-w-sm flex-col gap-6">
|
|
2
2
|
<%= render(UI::DatePicker.new(name: "a", label: "Empty")) %>
|
|
3
3
|
<%= render(UI::DatePicker.new(name: "b", label: "Required", required: true)) %>
|
|
4
|
-
<%= render(UI::DatePicker.new(name: "c", label: "With an error", error:
|
|
4
|
+
<%= render(UI::DatePicker.new(name: "c", label: "With an error", error: "Pick a date this year", value: Date.new(2025, 10, 21))) %>
|
|
5
5
|
<%= render(UI::DatePicker.new(name: "d", label: "Disabled", disabled: true, value: Date.new(2026, 10, 21))) %>
|
|
6
|
-
<%= render(UI::DatePicker.new(
|
|
6
|
+
<%= render(UI::DatePicker.new(range: true, label: "A range without presets", presets: false)) %>
|
|
7
|
+
<%= render(UI::DatePicker.new(range: true, label: "A range with an error", error: "A year at most", from: "2025-01-01", to: "2026-06-30")) %>
|
|
7
8
|
</div>
|
|
@@ -1,13 +1,33 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class UI::DatePickerPreview < ViewComponent::Preview
|
|
4
|
-
# @label
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param range toggle
|
|
6
|
+
# @param presets toggle
|
|
7
|
+
# @param hint toggle
|
|
8
|
+
# @param required toggle
|
|
9
|
+
# @param disabled toggle
|
|
10
|
+
def playground(range: false, presets: true, hint: true, required: false, disabled: false)
|
|
11
|
+
if range
|
|
12
|
+
render(UI::DatePicker.new(range: true, label: "Period", presets: presets, hint: hint, required: required, disabled: disabled,
|
|
13
|
+
from: Date.current.beginning_of_month, to: Date.current, class: "max-w-sm"))
|
|
14
|
+
else
|
|
15
|
+
render(UI::DatePicker.new(name: "date", label: "Date", hint: hint, required: required, disabled: disabled, class: "max-w-xs"))
|
|
16
|
+
end
|
|
7
17
|
end
|
|
8
18
|
|
|
19
|
+
# @label A Date
|
|
20
|
+
def default; render_with_template; end
|
|
21
|
+
|
|
22
|
+
# @label A Range, for Report Filters
|
|
23
|
+
def range; render_with_template; end
|
|
24
|
+
|
|
25
|
+
# @label Your Own Presets
|
|
26
|
+
def custom_presets; render_with_template; end
|
|
27
|
+
|
|
28
|
+
# @label In a Form
|
|
29
|
+
def in_form; render_with_template; end
|
|
30
|
+
|
|
9
31
|
# @label States
|
|
10
|
-
def states
|
|
11
|
-
render_with_template
|
|
12
|
-
end
|
|
32
|
+
def states; render_with_template; end
|
|
13
33
|
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<%# Each photo uploads as soon as it's chosen, with a progress bar, and the form
|
|
2
|
+
sends only the uploaded photos' ids. Saving while a photo is still on its
|
|
3
|
+
way waits for it, then saves. The two already on the product show as tiles;
|
|
4
|
+
take one out and save, and it's gone. Bound to a form, those come from the
|
|
5
|
+
record: render(UI::FileField.new(form: f, field: :photos, ...)). %>
|
|
6
|
+
<form action="/demo/products/1" method="post" class="flex max-w-xl flex-col items-start gap-4">
|
|
7
|
+
<input type="hidden" name="_method" value="patch">
|
|
8
|
+
<%= render(UI::FileField.new(name: "product[photos][]", label: "Photos", hint: "PNG or JPG, up to 5 MB each",
|
|
9
|
+
multiple: true, accept: "image/*", max_size: 5.megabytes, direct_upload: true,
|
|
10
|
+
existing: UI::FileFieldPreview.kept_photos)) %>
|
|
11
|
+
<%= render(UI::Button.new(type: :submit)) { "Save product" } %>
|
|
12
|
+
</form>
|
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
class UI::FileFieldPreview < ViewComponent::Preview
|
|
4
|
+
# A stand-in for an Active Storage attachment: what UI::FileField reads to
|
|
5
|
+
# show a file the record already has.
|
|
6
|
+
KeptFile = Struct.new(:signed_id, :filename, :byte_size, :content_type, :url, keyword_init: true)
|
|
7
|
+
|
|
8
|
+
def self.photo(title, color)
|
|
9
|
+
svg = "<svg xmlns='http://www.w3.org/2000/svg' width='600' height='600'><rect width='100%' height='100%' fill='#{color}'/>" \
|
|
10
|
+
"<text x='50%' y='50%' dy='.35em' text-anchor='middle' font-family='sans-serif' font-size='64' fill='#fff'>#{title}</text></svg>"
|
|
11
|
+
"data:image/svg+xml,#{ERB::Util.url_encode(svg)}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.kept_photos
|
|
15
|
+
[ [ "Front", "#793cbb" ], [ "Side", "#1baf7a" ] ].map.with_index do |(title, color), index|
|
|
16
|
+
KeptFile.new(signed_id: "kept-#{index}", filename: "mug-#{title.downcase}.svg", byte_size: 182_000 + (index * 41_000),
|
|
17
|
+
content_type: "image/svg+xml", url: photo(title, color))
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
4
21
|
# @label Playground
|
|
5
22
|
# @param label text
|
|
6
23
|
# @param hint text
|
|
7
24
|
# @param multiple toggle
|
|
25
|
+
# @param preview toggle
|
|
26
|
+
# @param direct_upload toggle
|
|
8
27
|
# @param disabled toggle
|
|
9
|
-
def playground(label: "
|
|
10
|
-
|
|
28
|
+
def playground(label: "Photos", hint: "PNG or JPG, up to 5 MB", multiple: true, preview: true, direct_upload: false,
|
|
29
|
+
disabled: false)
|
|
30
|
+
render(UI::FileField.new(label: label, hint: hint, multiple: multiple, preview: preview, direct_upload: direct_upload,
|
|
31
|
+
disabled: disabled, accept: "image/*", max_size: 5.megabytes, name: "photos"))
|
|
11
32
|
end
|
|
12
33
|
|
|
13
|
-
# @label
|
|
14
|
-
def
|
|
34
|
+
# @label Product Photos, Uploaded Straight Away
|
|
35
|
+
def product_photos; render_with_template; end
|
|
36
|
+
|
|
37
|
+
# @label One Image
|
|
38
|
+
def single_image; render_with_template; end
|
|
15
39
|
|
|
16
|
-
# @label
|
|
40
|
+
# @label Names Only, No Previews
|
|
17
41
|
def multiple_files; render_with_template; end
|
|
42
|
+
|
|
43
|
+
# @label With Error
|
|
44
|
+
def with_error; render_with_template; end
|
|
18
45
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div class="grid max-w-3xl gap-8 sm:grid-cols-2">
|
|
2
|
+
<%= render(UI::Gallery.new(label: "Photos of the ceramic mug", zoom: :hover)) do |gallery| %>
|
|
3
|
+
<% UI::GalleryPreview.photos.each do |title, src| %>
|
|
4
|
+
<% gallery.with_image(src: src, alt: "Ceramic mug: #{title}") %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<div class="space-y-3">
|
|
8
|
+
<h2 class="text-xl font-semibold">Ceramic mug</h2>
|
|
9
|
+
<p class="text-lg">$14.00</p>
|
|
10
|
+
<p class="text-sm text-muted-foreground">Hand-glazed stoneware that holds 350 ml. Move your mouse over the photo to magnify it, or click to open the overlay.</p>
|
|
11
|
+
<%= render(UI::Button.new) { "Add to cart" } %>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<%= render(UI::Gallery.new(label: "Photos of the workshop", aspect: :landscape, fit: :cover, class: "max-w-xl")) do |gallery| %>
|
|
2
|
+
<% UI::GalleryPreview::PHOTOS.first(3).each do |title, color, background| %>
|
|
3
|
+
<% gallery.with_image(src: UI::GalleryPreview.photo(title, color, background, width: 1600, height: 1000), alt: "Workshop: #{title}") %>
|
|
4
|
+
<% end %>
|
|
5
|
+
<% end %>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<div class="grid max-w-3xl gap-8 sm:grid-cols-2">
|
|
2
|
+
<%= render(UI::Gallery.new(label: "Photos of the ceramic mug")) do |gallery| %>
|
|
3
|
+
<% UI::GalleryPreview.photos.each do |title, src| %>
|
|
4
|
+
<% gallery.with_image(src: src, alt: "Ceramic mug: #{title}") %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<div class="space-y-3">
|
|
8
|
+
<h2 class="text-xl font-semibold">Ceramic mug</h2>
|
|
9
|
+
<p class="text-lg">$14.00</p>
|
|
10
|
+
<p class="text-sm text-muted-foreground">Hand-glazed stoneware that holds 350 ml. Click the photo to see it over the page and zoom in.</p>
|
|
11
|
+
<%= render(UI::Button.new) { "Add to cart" } %>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::GalleryPreview < ViewComponent::Preview
|
|
4
|
+
# Drawn here so the previews need no image files. The fine grid shows off zoom.
|
|
5
|
+
PHOTOS = [ [ "Front", "#7c3aed", "#ede9fe" ], [ "Side", "#0f766e", "#ccfbf1" ], [ "Handle", "#b45309", "#fef3c7" ],
|
|
6
|
+
[ "Base", "#be123c", "#ffe4e6" ], [ "In use", "#1d4ed8", "#dbeafe" ] ].freeze
|
|
7
|
+
|
|
8
|
+
def self.photo(title, color, background, width: 1600, height: 1600)
|
|
9
|
+
grid = (0..(width / 40)).map { |i| "<path d='M#{i * 40} 0V#{height}' stroke='#{color}' stroke-opacity='.15'/>" }.join +
|
|
10
|
+
(0..(height / 40)).map { |i| "<path d='M0 #{i * 40}H#{width}' stroke='#{color}' stroke-opacity='.15'/>" }.join
|
|
11
|
+
svg = "<svg xmlns='http://www.w3.org/2000/svg' width='#{width}' height='#{height}'>" \
|
|
12
|
+
"<rect width='100%' height='100%' fill='#{background}'/>#{grid}" \
|
|
13
|
+
"<circle cx='#{width / 2}' cy='#{height / 2}' r='#{[ width, height ].min / 4}' fill='#{color}'/>" \
|
|
14
|
+
"<text x='50%' y='50%' dy='.35em' text-anchor='middle' font-family='sans-serif' " \
|
|
15
|
+
"font-size='#{[ width, height ].min / 14}' fill='#fff'>#{title}</text></svg>"
|
|
16
|
+
"data:image/svg+xml,#{ERB::Util.url_encode(svg)}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.photos = PHOTOS.map { |title, color, background| [ title, photo(title, color, background) ] }
|
|
20
|
+
|
|
21
|
+
# @label Playground
|
|
22
|
+
# @param zoom select { choices: [overlay, hover] }
|
|
23
|
+
# @param zoom_scale number { min: 1.5, max: 5, step: 0.5 }
|
|
24
|
+
# @param aspect select { choices: [square, landscape, portrait] }
|
|
25
|
+
# @param fit select { choices: [contain, cover] }
|
|
26
|
+
# @param count number { min: 1, max: 5 }
|
|
27
|
+
def playground(zoom: :overlay, zoom_scale: 2.5, aspect: :square, fit: :contain, count: 5)
|
|
28
|
+
render(UI::Gallery.new(label: "Photos of the ceramic mug", zoom: zoom.to_sym, zoom_scale: zoom_scale.to_f,
|
|
29
|
+
aspect: aspect.to_sym, fit: fit.to_sym, class: "max-w-md")) do |gallery|
|
|
30
|
+
self.class.photos.first(count.to_i).each { |title, src| gallery.with_image(src: src, alt: "Ceramic mug: #{title}") }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @label Overlay
|
|
35
|
+
def product_page; render_with_template; end
|
|
36
|
+
|
|
37
|
+
# @label Hover Zoom
|
|
38
|
+
def hover_zoom; render_with_template; end
|
|
39
|
+
|
|
40
|
+
# @label Landscape, Cropped to Fill
|
|
41
|
+
def landscape; render_with_template; end
|
|
42
|
+
|
|
43
|
+
# @label One Image
|
|
44
|
+
def single; render_with_template; end
|
|
45
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%# bind: true makes the shortcut press the button the hint is in. Try them. %>
|
|
2
|
+
<div id="kbd-bound-demo" class="max-w-md space-y-4">
|
|
3
|
+
<%= render(UI::Textarea.new(name: "note", rows: 3, placeholder: "Write something, then save with the shortcut…", aria: { label: "Note" })) %>
|
|
4
|
+
<div class="flex flex-wrap items-center gap-3">
|
|
5
|
+
<%= render(UI::Button.new(data: { demo: "save" })) do %>Save <%= render(UI::Kbd.new("mod+s", size: :sm, bind: true)) %><% end %>
|
|
6
|
+
<%= render(UI::Button.new(variant: :outline, data: { demo: "clear" })) do %>Clear <%= render(UI::Kbd.new("alt+c", size: :sm, bind: true)) %><% end %>
|
|
7
|
+
<span class="text-sm text-muted-foreground" data-demo="status" role="status"></span>
|
|
8
|
+
</div>
|
|
9
|
+
</div>
|
|
10
|
+
<script>
|
|
11
|
+
(() => {
|
|
12
|
+
const root = document.getElementById("kbd-bound-demo");
|
|
13
|
+
const status = root.querySelector('[data-demo="status"]');
|
|
14
|
+
const note = root.querySelector("textarea");
|
|
15
|
+
root.querySelector('[data-demo="save"]').addEventListener("click", () => {
|
|
16
|
+
status.textContent = `Saved at ${new Date().toLocaleTimeString([], { hour: "numeric", minute: "2-digit", second: "2-digit" })}`;
|
|
17
|
+
});
|
|
18
|
+
root.querySelector('[data-demo="clear"]').addEventListener("click", () => { note.value = ""; status.textContent = "Cleared"; note.focus(); });
|
|
19
|
+
})();
|
|
20
|
+
</script>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%# On a Mac these show ⌘ ⌥ ⇧ symbols; elsewhere Ctrl, Alt and Shift, with a +.
|
|
2
|
+
cmd is ⌘ on a Mac, the Windows key on Windows, and Super on Linux. %>
|
|
3
|
+
<dl class="grid max-w-md grid-cols-[1fr_auto] items-center gap-x-8 gap-y-3 text-sm">
|
|
4
|
+
<% [["One key", "k"], ["Escape", "esc"], ["Enter", "enter"], ["Arrows", "up"], ["A combination", "mod+k"],
|
|
5
|
+
["Three keys", "mod+shift+p"], ["Option, or Alt", "alt+n"], ["Command, Win or Super", "cmd+l"], ["A symbol", "?"], ["Function key", "F5"]].each do |name, keys| %>
|
|
6
|
+
<dt class="text-muted-foreground"><%= name %></dt>
|
|
7
|
+
<dd><%= render(UI::Kbd.new(keys)) %></dd>
|
|
8
|
+
<% end %>
|
|
9
|
+
<dt class="text-muted-foreground">A sequence</dt>
|
|
10
|
+
<dd><%= render(UI::Kbd.new(%w[g i])) %></dd>
|
|
11
|
+
<dt class="text-muted-foreground">Written as given</dt>
|
|
12
|
+
<dd><%= render(UI::Kbd.new) { "Fn" } %></dd>
|
|
13
|
+
</dl>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<%= render(UI::Menu.new) do |menu| %>
|
|
2
|
+
<% menu.with_trigger(variant: :outline) { "Edit" } %>
|
|
3
|
+
<% menu.with_content(class: "w-56") do |content| %>
|
|
4
|
+
<% content.with_item do %>Undo<%= render(UI::Kbd.new("mod+z", size: :sm, class: "ms-auto")) %><% end %>
|
|
5
|
+
<% content.with_item do %>Redo<%= render(UI::Kbd.new("mod+shift+z", size: :sm, class: "ms-auto")) %><% end %>
|
|
6
|
+
<% content.with_divider %>
|
|
7
|
+
<% content.with_item do %>Cut<%= render(UI::Kbd.new("mod+x", size: :sm, class: "ms-auto")) %><% end %>
|
|
8
|
+
<% content.with_item do %>Copy<%= render(UI::Kbd.new("mod+c", size: :sm, class: "ms-auto")) %><% end %>
|
|
9
|
+
<% content.with_item do %>Paste<%= render(UI::Kbd.new("mod+v", size: :sm, class: "ms-auto")) %><% end %>
|
|
10
|
+
<% content.with_divider %>
|
|
11
|
+
<% content.with_item(variant: :destructive) do %>Delete<%= render(UI::Kbd.new("backspace", size: :sm, class: "ms-auto")) %><% end %>
|
|
12
|
+
<% end %>
|
|
13
|
+
<% end %>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<%# Press / anywhere on the page (not in a field) to jump to the search box. %>
|
|
2
|
+
<div class="max-w-sm">
|
|
3
|
+
<%= render(UI::InputGroup.new) do |g| %>
|
|
4
|
+
<%= g.with_addon(align: "inline-start") { |a| a.with_icon(name: "search") } %>
|
|
5
|
+
<%= g.with_field(id: "kbd-demo-search", type: :search, placeholder: "Search docs…", aria: { label: "Search docs" }) %>
|
|
6
|
+
<%= g.with_addon(align: "inline-end") { render(UI::Kbd.new("/", bind: "#kbd-demo-search")) } %>
|
|
7
|
+
<% end %>
|
|
8
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<%= render(UI::Card.new(class: "max-w-md")) do |card| %>
|
|
2
|
+
<% card.with_header do |header| %>
|
|
3
|
+
<% header.with_title { "Keyboard shortcuts" } %>
|
|
4
|
+
<% header.with_description { "Press ? to see this list again." } %>
|
|
5
|
+
<% end %>
|
|
6
|
+
<% card.with_content do %>
|
|
7
|
+
<% [["Navigation", [["Go to inbox", %w[g i]], ["Go to drafts", %w[g d]], ["Search", "/"]]],
|
|
8
|
+
["Messages", [["New message", "c"], ["Reply", "r"], ["Send", "mod+enter"], ["Archive", "e"]]]].each do |group, rows| %>
|
|
9
|
+
<h4 class="mt-4 mb-2 text-xs font-medium tracking-wide text-muted-foreground uppercase first:mt-0"><%= group %></h4>
|
|
10
|
+
<dl class="divide-y text-sm">
|
|
11
|
+
<% rows.each do |action, keys| %>
|
|
12
|
+
<div class="flex items-center justify-between py-2"><dt><%= action %></dt><dd><%= render(UI::Kbd.new(keys)) %></dd></div>
|
|
13
|
+
<% end %>
|
|
14
|
+
</dl>
|
|
15
|
+
<% end %>
|
|
16
|
+
<% end %>
|
|
17
|
+
<% end %>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<%# A point-of-sale screen, where cashiers keep their hands on the keyboard. The keys work. %>
|
|
2
|
+
<div id="kbd-till-demo" class="max-w-lg space-y-3 rounded-lg border p-4">
|
|
3
|
+
<div class="flex items-baseline justify-between">
|
|
4
|
+
<span class="text-sm text-muted-foreground">Sale #1042 · 3 items</span>
|
|
5
|
+
<span class="text-2xl font-semibold tabular-nums">$27.40</span>
|
|
6
|
+
</div>
|
|
7
|
+
<div class="grid grid-cols-2 gap-2 sm:grid-cols-4">
|
|
8
|
+
<%= render(UI::Button.new(variant: :outline, class: "justify-between", data: { demo: "New sale" })) do %>New sale <%= render(UI::Kbd.new("F2", size: :sm, bind: true)) %><% end %>
|
|
9
|
+
<%= render(UI::Button.new(variant: :outline, class: "justify-between", data: { demo: "Discount" })) do %>Discount <%= render(UI::Kbd.new("F6", size: :sm, bind: true)) %><% end %>
|
|
10
|
+
<%= render(UI::Button.new(variant: :outline, class: "justify-between", data: { demo: "Cancelled" })) do %>Cancel <%= render(UI::Kbd.new("esc", size: :sm, bind: true)) %><% end %>
|
|
11
|
+
<%= render(UI::Button.new(class: "justify-between", data: { demo: "Paid" })) do %>Pay <%= render(UI::Kbd.new("F4", size: :sm, bind: true)) %><% end %>
|
|
12
|
+
</div>
|
|
13
|
+
<p class="text-sm text-muted-foreground" data-demo="status" role="status">Press a key.</p>
|
|
14
|
+
</div>
|
|
15
|
+
<script>
|
|
16
|
+
(() => {
|
|
17
|
+
const root = document.getElementById("kbd-till-demo");
|
|
18
|
+
const status = root.querySelector('[data-demo="status"]');
|
|
19
|
+
root.querySelectorAll("button[data-demo]").forEach((button) => {
|
|
20
|
+
button.addEventListener("click", () => { status.textContent = button.dataset.demo; });
|
|
21
|
+
});
|
|
22
|
+
})();
|
|
23
|
+
</script>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<%# The key takes its colours from where it sits: dark tooltip, filled or outline button. %>
|
|
2
|
+
<div class="flex flex-wrap items-center gap-4">
|
|
3
|
+
<%= render(UI::Tooltip.new) do |tooltip| %>
|
|
4
|
+
<% tooltip.with_trigger do %>
|
|
5
|
+
<%= render(UI::Button.new(variant: :outline, size: :icon, aria: { label: "Bold" })) { render(UI::Icon.new(name: "bold", size: :sm)) } %>
|
|
6
|
+
<% end %>
|
|
7
|
+
<% tooltip.with_content do %>
|
|
8
|
+
<span class="flex items-center gap-2">Bold <%= render(UI::Kbd.new("mod+b", size: :sm)) %></span>
|
|
9
|
+
<% end %>
|
|
10
|
+
<% end %>
|
|
11
|
+
<%= render(UI::Button.new) do %>New note <%= render(UI::Kbd.new("n", size: :sm)) %><% end %>
|
|
12
|
+
<%= render(UI::Button.new(variant: :outline)) do %>Cancel <%= render(UI::Kbd.new("esc", size: :sm)) %><% end %>
|
|
13
|
+
<%= render(UI::Button.new(variant: :secondary)) do %>Send <%= render(UI::Kbd.new("mod+enter", size: :sm)) %><% end %>
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::KbdPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param keys text "Keys joined by +, like mod+shift+k"
|
|
6
|
+
# @param then_keys text "A second step, for a sequence like G then I"
|
|
7
|
+
# @param size select { choices: [sm, default, lg] }
|
|
8
|
+
def playground(keys: "mod+k", then_keys: "", size: :default)
|
|
9
|
+
render(UI::Kbd.new([ keys, then_keys.presence ].compact, size: size.to_sym))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @label Keys and Shortcuts
|
|
13
|
+
def keys; render_with_template; end
|
|
14
|
+
|
|
15
|
+
# @label In a Search Field
|
|
16
|
+
def search_field; render_with_template; end
|
|
17
|
+
|
|
18
|
+
# @label In a Menu
|
|
19
|
+
def menu; render_with_template; end
|
|
20
|
+
|
|
21
|
+
# @label In a Tooltip and on Buttons
|
|
22
|
+
def tooltip_and_buttons; render_with_template; end
|
|
23
|
+
|
|
24
|
+
# @label Shortcuts That Work
|
|
25
|
+
def bound; render_with_template; end
|
|
26
|
+
|
|
27
|
+
# @label Shortcuts List
|
|
28
|
+
def shortcuts_list; render_with_template; end
|
|
29
|
+
|
|
30
|
+
# @label Billing Keys at a Till
|
|
31
|
+
def till; render_with_template; end
|
|
32
|
+
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,11 @@
|
|
|
1
|
+
<ul class="flex max-w-md flex-col divide-y">
|
|
2
|
+
<% [ [ "Oat milk, 1 L", "$3.20", 2 ], [ "Filter coffee, 250 g", "$11.50", 1 ], [ "Ceramic mug", "$14.00", 4 ] ].each do |name, price, quantity| %>
|
|
3
|
+
<li class="flex items-center justify-between gap-4 py-3">
|
|
4
|
+
<span class="min-w-0 text-sm">
|
|
5
|
+
<span class="block font-medium"><%= name %></span>
|
|
6
|
+
<span class="text-muted-foreground"><%= price %></span>
|
|
7
|
+
</span>
|
|
8
|
+
<%= render(UI::NumberInput.new(value: quantity, min: 1, max: 20, name: "quantity[]", "aria-label": "Quantity of #{name}", class: "w-28 shrink-0")) %>
|
|
9
|
+
</li>
|
|
10
|
+
<% end %>
|
|
11
|
+
</ul>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<div class="flex w-48 flex-col gap-4">
|
|
2
|
+
<%= render(UI::NumberInput.new(label: "Weight (kg)", value: 1.5, min: 0, step: 0.25, name: "weight", hint: "In steps of 0.25")) %>
|
|
3
|
+
<%= render(UI::NumberInput.new(label: "Any amount", value: 2.75, min: 0, step: "any", name: "amount", hint: "Buttons move by 1")) %>
|
|
4
|
+
</div>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<div class="flex w-48 flex-col gap-4">
|
|
2
|
+
<%= render(UI::NumberInput.new(size: :sm, label: "Small", value: 1, min: 0, name: "small")) %>
|
|
3
|
+
<%= render(UI::NumberInput.new(label: "Default", value: 2, min: 0, name: "default")) %>
|
|
4
|
+
<%= render(UI::NumberInput.new(size: :lg, label: "Large, for touch screens", value: 3, min: 0, name: "large")) %>
|
|
5
|
+
</div>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
<div class="flex w-48 flex-col gap-4">
|
|
2
|
+
<%= render(UI::NumberInput.new(label: "At its minimum", value: 1, min: 1, max: 5, name: "at_min")) %>
|
|
3
|
+
<%= render(UI::NumberInput.new(label: "At its maximum", value: 5, min: 1, max: 5, name: "at_max")) %>
|
|
4
|
+
<%= render(UI::NumberInput.new(label: "Disabled", value: 3, disabled: true, name: "disabled")) %>
|
|
5
|
+
<%= render(UI::NumberInput.new(label: "Read only", value: 3, readonly: true, name: "readonly")) %>
|
|
6
|
+
<%= render(UI::NumberInput.new(label: "With an error", value: 0, error: "Must be at least 1", name: "invalid")) %>
|
|
7
|
+
</div>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class UI::NumberInputPreview < ViewComponent::Preview
|
|
4
|
+
# @label Playground
|
|
5
|
+
# @param size select { choices: [sm, default, lg] }
|
|
6
|
+
# @param label text
|
|
7
|
+
# @param hint text
|
|
8
|
+
# @param value number
|
|
9
|
+
# @param min number
|
|
10
|
+
# @param max number
|
|
11
|
+
# @param step number
|
|
12
|
+
# @param disabled toggle
|
|
13
|
+
# @param readonly toggle
|
|
14
|
+
# @param error text
|
|
15
|
+
def playground(size: :default, label: "Quantity", hint: "", value: 2, min: 1, max: 10, step: 1,
|
|
16
|
+
disabled: false, readonly: false, error: "")
|
|
17
|
+
render(UI::NumberInput.new(size: size.to_sym, label: label.presence, hint: hint.presence, value: value, min: min,
|
|
18
|
+
max: max, step: step, disabled: disabled, readonly: readonly,
|
|
19
|
+
error: error.presence, name: "quantity", class: "w-40"))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# @label Sizes
|
|
23
|
+
def sizes; render_with_template; end
|
|
24
|
+
|
|
25
|
+
# @label Cart Rows
|
|
26
|
+
def cart; render_with_template; end
|
|
27
|
+
|
|
28
|
+
# @label Decimal Steps
|
|
29
|
+
def decimals; render_with_template; end
|
|
30
|
+
|
|
31
|
+
# @label Stock Adjustment, Below Zero Allowed
|
|
32
|
+
def stock_adjustment; render_with_template; end
|
|
33
|
+
|
|
34
|
+
# @label States
|
|
35
|
+
def states; render_with_template; end
|
|
36
|
+
end
|