velvetkit 0.4.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 +31 -2
- data/lib/velvetkit/version.rb +1 -1
- 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 +6 -0
- 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/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/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 +42 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::MoneyInputTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_money(**opts) = render_inline(UI::MoneyInput.new(name: "amount", **opts))
|
|
10
|
+
|
|
11
|
+
def field = page.find("input[data-ui--money-input-target='field']")
|
|
12
|
+
def hidden = page.find("input[type='hidden'][data-ui--money-input-target='value']", visible: :all)
|
|
13
|
+
|
|
14
|
+
def test_shows_the_amount_grouped_and_posts_it_plain
|
|
15
|
+
render_money(value: 1_234_567.5, unit: "$")
|
|
16
|
+
assert_equal "1,234,567.50", field.value
|
|
17
|
+
assert_equal "1234567.50", hidden.value
|
|
18
|
+
assert_equal "amount", hidden[:name]
|
|
19
|
+
assert_nil field[:name]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_rupees_group_the_indian_way
|
|
23
|
+
render_money(value: 12_345_678.9, unit: "₹")
|
|
24
|
+
assert_equal "1,23,45,678.90", field.value
|
|
25
|
+
assert_equal "12345678.90", hidden.value
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_grouping_can_be_chosen
|
|
29
|
+
render_money(value: 1_234_567, unit: "₹", grouping: :thousands)
|
|
30
|
+
assert_equal "1,234,567.00", field.value
|
|
31
|
+
render_money(value: 1_234_567, unit: "$", grouping: :indian)
|
|
32
|
+
assert_equal "12,34,567.00", field.value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_small_amounts_are_not_grouped
|
|
36
|
+
render_money(value: 999, unit: "₹")
|
|
37
|
+
assert_equal "999.00", field.value
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_a_typed_string_is_read_with_the_delimiters_in_it
|
|
41
|
+
render_money(value: "1,23,456.789", unit: "₹")
|
|
42
|
+
assert_equal "1,23,456.79", field.value
|
|
43
|
+
assert_equal "123456.79", hidden.value
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def test_large_amounts_keep_every_digit
|
|
47
|
+
render_money(value: "123456789012345.67", unit: "$")
|
|
48
|
+
assert_equal "123456789012345.67", hidden.value
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_no_value_is_empty_with_a_zero_placeholder
|
|
52
|
+
render_money(unit: "₹")
|
|
53
|
+
assert_equal "", field.value.to_s
|
|
54
|
+
assert_equal "0.00", field[:placeholder]
|
|
55
|
+
assert_equal "", hidden.value.to_s
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_precision_zero_is_whole_amounts
|
|
59
|
+
render_money(value: 1500.6, unit: "¥", precision: 0)
|
|
60
|
+
assert_equal "1,501", field.value
|
|
61
|
+
assert_equal "1501", hidden.value
|
|
62
|
+
assert_equal "0", field[:placeholder]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_locale_separators
|
|
66
|
+
render_money(value: 1234.5, unit: "€", separator: ",", delimiter: ".")
|
|
67
|
+
assert_equal "1.234,50", field.value
|
|
68
|
+
assert_equal "1234.50", hidden.value
|
|
69
|
+
assert_equal ",", root["data-ui--money-input-separator-value"]
|
|
70
|
+
assert_equal ".", root["data-ui--money-input-delimiter-value"]
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def test_negative_amounts_only_when_allowed
|
|
74
|
+
render_money(value: -250)
|
|
75
|
+
assert_equal "250.00", field.value
|
|
76
|
+
render_money(value: -250, negative: true)
|
|
77
|
+
assert_equal "-250.00", field.value
|
|
78
|
+
assert_equal "-250.00", hidden.value
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_sign_sits_where_the_locale_writes_it
|
|
82
|
+
render_money(unit: "₹")
|
|
83
|
+
assert_selector "[data-align='inline-start']", text: "₹"
|
|
84
|
+
I18n.with_locale(:en) do
|
|
85
|
+
I18n.backend.store_translations(:en, number: { currency: { format: { format: "%n %u" } } })
|
|
86
|
+
render_money(unit: "kr")
|
|
87
|
+
assert_selector "[data-align='inline-end']", text: "kr"
|
|
88
|
+
ensure
|
|
89
|
+
I18n.backend.store_translations(:en, number: { currency: { format: { format: "%u%n" } } })
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def test_the_field_is_a_decimal_text_field_wired_to_the_controller
|
|
94
|
+
render_money
|
|
95
|
+
assert_selector "[data-slot='money-input'][data-controller='ui--money-input']"
|
|
96
|
+
assert_equal "text", field[:type]
|
|
97
|
+
assert_equal "decimal", field[:inputmode]
|
|
98
|
+
assert_equal "off", field[:autocomplete]
|
|
99
|
+
assert_equal "beforeinput->ui--money-input#guard keydown->ui--money-input#nudge input->ui--money-input#type " \
|
|
100
|
+
"blur->ui--money-input#finish", field["data-action"]
|
|
101
|
+
assert_equal "1", root["data-ui--money-input-step-value"]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_step_is_written_plainly_for_the_arrow_keys
|
|
105
|
+
render_money(step: 0.5)
|
|
106
|
+
assert_equal "0.5", root["data-ui--money-input-step-value"]
|
|
107
|
+
render_money(step: 100)
|
|
108
|
+
assert_equal "100", root["data-ui--money-input-step-value"]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_label_hint_and_error
|
|
112
|
+
render_money(id: "amt", label: "Amount", hint: "Including GST", error: "Can't be blank", required: true)
|
|
113
|
+
assert_selector "label[for='amt']", text: "Amount"
|
|
114
|
+
assert_equal "amt-hint amt-error", field["aria-describedby"]
|
|
115
|
+
assert_equal "true", field["aria-invalid"]
|
|
116
|
+
assert field[:required]
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_disabled_turns_off_both_fields
|
|
120
|
+
render_money(value: 10, disabled: true)
|
|
121
|
+
assert field[:disabled]
|
|
122
|
+
assert hidden[:disabled]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def test_passes_attributes_to_the_field_and_class_to_the_root
|
|
126
|
+
render_money(class: "max-w-xs", autofocus: true, data: { action: "change->cart#total" })
|
|
127
|
+
assert_selector "[data-slot='money-input'].max-w-xs"
|
|
128
|
+
assert field[:autofocus]
|
|
129
|
+
assert_includes field["data-action"], "change->cart#total"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def root = page.find("[data-slot='money-input']")
|
|
133
|
+
|
|
134
|
+
Invoice = Struct.new(:total) do
|
|
135
|
+
def self.human_attribute_name(name, *) = name.to_s.humanize
|
|
136
|
+
def to_model = self
|
|
137
|
+
def model_name = ActiveModel::Name.new(self.class, nil, "Invoice")
|
|
138
|
+
def persisted? = false
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def test_form_binding_names_the_hidden_field_reads_the_value_and_derives_the_label
|
|
142
|
+
form = ActionView::Helpers::FormBuilder.new(:invoice, Invoice.new(BigDecimal("4999.5")), vc_test_controller.view_context, {})
|
|
143
|
+
render_inline(UI::MoneyInput.new(form: form, field: :total, unit: "₹"))
|
|
144
|
+
assert_equal "invoice[total]", hidden[:name]
|
|
145
|
+
assert_equal "4999.50", hidden.value
|
|
146
|
+
assert_equal "4,999.50", field.value
|
|
147
|
+
assert_selector "label[for='#{field[:id]}']", text: "Total"
|
|
148
|
+
end
|
|
149
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::ScanInputTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_scan(**opts) = render_inline(UI::ScanInput.new(name: "code", **opts))
|
|
10
|
+
|
|
11
|
+
def field = page.find("input[data-ui--scan-input-target='field']")
|
|
12
|
+
def group = page.find("[data-controller='ui--scan-input']")
|
|
13
|
+
|
|
14
|
+
def test_renders_a_text_field_in_a_group_with_the_controller_and_an_icon
|
|
15
|
+
render_scan
|
|
16
|
+
assert_equal "ui--scan-input", group["data-controller"]
|
|
17
|
+
assert_equal "text", field[:type]
|
|
18
|
+
assert_equal "code", field[:name]
|
|
19
|
+
assert_equal "keydown->ui--scan-input#key", field["data-action"]
|
|
20
|
+
assert_selector "[data-align='inline-start'] svg"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_a_code_is_not_a_word
|
|
24
|
+
render_scan
|
|
25
|
+
assert_equal "off", field[:autocomplete]
|
|
26
|
+
assert_equal "off", field[:autocapitalize]
|
|
27
|
+
assert_equal "off", field[:autocorrect]
|
|
28
|
+
assert_equal "false", field[:spellcheck]
|
|
29
|
+
assert_equal "go", field[:enterkeyhint]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def test_focused_on_load_unless_told_not_to
|
|
33
|
+
render_scan
|
|
34
|
+
assert field[:autofocus]
|
|
35
|
+
render_scan(autofocus: false)
|
|
36
|
+
assert_nil field[:autofocus]
|
|
37
|
+
render_scan(disabled: true)
|
|
38
|
+
assert_nil field[:autofocus]
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def test_defaults_submit_clear_and_keep_focus
|
|
42
|
+
render_scan
|
|
43
|
+
assert_equal "true", group["data-ui--scan-input-submit-value"]
|
|
44
|
+
assert_equal "true", group["data-ui--scan-input-clear-value"]
|
|
45
|
+
assert_equal "true", group["data-ui--scan-input-keep-focus-value"]
|
|
46
|
+
assert_equal "false", group["data-ui--scan-input-capture-value"]
|
|
47
|
+
assert_equal "enter", group["data-ui--scan-input-suffix-value"]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def test_options_reach_the_controller
|
|
51
|
+
render_scan(submit: false, clear: false, keep_focus: false, capture: true, suffix: :tab)
|
|
52
|
+
assert_equal "false", group["data-ui--scan-input-submit-value"]
|
|
53
|
+
assert_equal "false", group["data-ui--scan-input-clear-value"]
|
|
54
|
+
assert_equal "false", group["data-ui--scan-input-keep-focus-value"]
|
|
55
|
+
assert_equal "true", group["data-ui--scan-input-capture-value"]
|
|
56
|
+
assert_equal "tab", group["data-ui--scan-input-suffix-value"]
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_an_unknown_suffix_is_enter
|
|
60
|
+
render_scan(suffix: :space)
|
|
61
|
+
assert_equal "enter", group["data-ui--scan-input-suffix-value"]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def test_keyboard_false_keeps_the_on_screen_keyboard_down
|
|
65
|
+
render_scan
|
|
66
|
+
assert_nil field[:inputmode]
|
|
67
|
+
render_scan(keyboard: false)
|
|
68
|
+
assert_equal "none", field[:inputmode]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_placeholder_defaults_and_can_be_set
|
|
72
|
+
render_scan
|
|
73
|
+
assert_equal "Scan or type a code", field[:placeholder]
|
|
74
|
+
render_scan(placeholder: "Scan a ticket")
|
|
75
|
+
assert_equal "Scan a ticket", field[:placeholder]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_label_hint_and_error
|
|
79
|
+
render_scan(id: "sku", label: "Item", hint: "EAN or SKU", error: "Not found")
|
|
80
|
+
assert_selector "label[for='sku']", text: "Item"
|
|
81
|
+
assert_equal "sku-hint sku-error", field["aria-describedby"]
|
|
82
|
+
assert_equal "true", field["aria-invalid"]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def test_sizes_and_class_go_on_the_group
|
|
86
|
+
render_scan(size: :lg, class: "max-w-sm")
|
|
87
|
+
assert_includes group[:class], "h-12"
|
|
88
|
+
assert_includes group[:class], "max-w-sm"
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_extra_actions_are_kept
|
|
92
|
+
render_scan(data: { action: "input->lookup#search" })
|
|
93
|
+
assert_equal "keydown->ui--scan-input#key input->lookup#search", field["data-action"]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
Ticket = Struct.new(:code) do
|
|
97
|
+
def self.human_attribute_name(name, *) = name.to_s.humanize
|
|
98
|
+
def to_model = self
|
|
99
|
+
def model_name = ActiveModel::Name.new(self.class, nil, "Ticket")
|
|
100
|
+
def persisted? = false
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def test_form_binding
|
|
104
|
+
form = ActionView::Helpers::FormBuilder.new(:ticket, Ticket.new("QR-123"), vc_test_controller.view_context, {})
|
|
105
|
+
render_inline(UI::ScanInput.new(form: form, field: :code))
|
|
106
|
+
assert_equal "ticket[code]", field[:name]
|
|
107
|
+
assert_equal "QR-123", field.value
|
|
108
|
+
assert_selector "label[for='#{field[:id]}']", text: "Code"
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class UI::SliderTest < ViewComponent::TestCase
|
|
6
|
+
def setup_fixtures(*); end
|
|
7
|
+
def teardown_fixtures(*); end
|
|
8
|
+
|
|
9
|
+
def render_slider(**opts) = render_inline(UI::Slider.new(name: "volume", **opts))
|
|
10
|
+
|
|
11
|
+
def root = page.find("[data-slot='slider']")
|
|
12
|
+
|
|
13
|
+
def test_renders_a_native_range_input_with_the_controller
|
|
14
|
+
render_slider(value: 40)
|
|
15
|
+
assert_selector "[data-slot='slider'][data-controller='ui--slider']"
|
|
16
|
+
assert_selector "input[type='range'][name='volume'][value='40'][min='0'][max='100'][step='1']" \
|
|
17
|
+
"[data-ui--slider-target='input'][data-action='input->ui--slider#sync']"
|
|
18
|
+
assert_selector "[data-ui--slider-target='track'][data-action='pointerdown->ui--slider#press']"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def test_each_handle_has_a_knob_drawn_after_its_input
|
|
22
|
+
render_slider(value: 40)
|
|
23
|
+
assert_selector "span.contents > input[type='range'].peer + span[data-slot='slider-thumb'][aria-hidden='true']"
|
|
24
|
+
assert_includes page.find("[data-slot='slider-thumb']")[:style], "(100% - var(--thumb)) * var(--to)"
|
|
25
|
+
render_inline(UI::Slider.new(range: true))
|
|
26
|
+
knobs = page.all("[data-slot='slider-thumb']")
|
|
27
|
+
assert_includes knobs[0][:style], "var(--from)"
|
|
28
|
+
assert_includes knobs[1][:style], "var(--to)"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_takes_limits_and_step
|
|
32
|
+
render_slider(value: 2.5, min: 1, max: 5, step: 0.5)
|
|
33
|
+
assert_selector "input[min='1'][max='5'][step='0.5'][value='2.5']"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def test_value_is_clamped_and_snapped_to_step
|
|
37
|
+
render_slider(value: 140)
|
|
38
|
+
assert_selector "input[value='100']"
|
|
39
|
+
render_slider(value: 23, step: 5)
|
|
40
|
+
assert_selector "input[value='25']"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_no_value_starts_in_the_middle_as_the_browser_would
|
|
44
|
+
render_slider(min: 0, max: 10)
|
|
45
|
+
assert_selector "input[value='5']"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def test_fill_reaches_the_value
|
|
49
|
+
render_slider(value: 25)
|
|
50
|
+
assert_includes root[:style], "--from: 0;"
|
|
51
|
+
assert_includes root[:style], "--to: 0.25"
|
|
52
|
+
fill = page.find("[data-slot='slider-fill']")
|
|
53
|
+
assert_includes fill[:style], "inset-inline-start: 0px"
|
|
54
|
+
assert_includes fill[:style], "var(--to)"
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def test_sizes_set_the_thumb_and_track
|
|
58
|
+
render_slider(size: :lg)
|
|
59
|
+
assert_includes root[:style], "--thumb: 2.25rem; --thumb-h: 1.625rem"
|
|
60
|
+
assert_selector ".h-3\\.5.rounded-full"
|
|
61
|
+
render_slider(size: :nonsense)
|
|
62
|
+
assert_includes root[:style], "--thumb: 1.75rem; --thumb-h: 1.25rem"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_label_points_at_the_input
|
|
66
|
+
render_slider(label: "Volume", id: "vol")
|
|
67
|
+
assert_selector "label[for='vol']", text: "Volume"
|
|
68
|
+
assert_selector "input#vol"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_value_text_is_shown_and_heard
|
|
72
|
+
render_slider(value: 40, value_text: "%{value}%", show_value: true)
|
|
73
|
+
assert_selector "output[aria-hidden='true'][data-ui--slider-target='output']", text: "40%"
|
|
74
|
+
assert_selector "input[aria-valuetext='40%']"
|
|
75
|
+
assert_equal "%{value}%", root["data-ui--slider-format-value"]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def test_value_is_not_shown_unless_asked
|
|
79
|
+
render_slider(value: 40)
|
|
80
|
+
assert_no_selector "output"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def test_decimals_follow_the_step
|
|
84
|
+
render_slider(value: 3, min: 0, max: 5, step: 0.5, show_value: true)
|
|
85
|
+
assert_selector "output", text: /\A3\z/
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_range_has_two_handles_that_name_themselves
|
|
89
|
+
render_inline(UI::Slider.new(range: true, label: "Price", from: 20, to: 80, from_name: "min", to_name: "max",
|
|
90
|
+
id: "price"))
|
|
91
|
+
assert_selector "[role='group'][aria-labelledby='price-label']"
|
|
92
|
+
assert_selector "#price-label", text: "Price"
|
|
93
|
+
assert_selector "label:not([for])", text: "Price"
|
|
94
|
+
assert_selector "input#price[name='min'][value='20'][aria-label='Minimum']"
|
|
95
|
+
assert_selector "input#price-to[name='max'][value='80'][aria-label='Maximum']"
|
|
96
|
+
assert_includes root[:style], "--from: 0.2;"
|
|
97
|
+
assert_includes root[:style], "--to: 0.8"
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def test_range_defaults_to_the_whole_track_and_puts_values_in_order
|
|
101
|
+
render_inline(UI::Slider.new(range: true))
|
|
102
|
+
assert_selector "input[name='from'][value='0']"
|
|
103
|
+
assert_selector "input[name='to'][value='100']"
|
|
104
|
+
render_inline(UI::Slider.new(range: true, from: 70, to: 30))
|
|
105
|
+
assert_selector "input[name='from'][value='30']"
|
|
106
|
+
assert_selector "input[name='to'][value='70']"
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def test_range_shows_both_values
|
|
110
|
+
render_inline(UI::Slider.new(range: true, from: 20, to: 80, value_text: "$%{value}", show_value: true))
|
|
111
|
+
assert_selector "output", text: "$20 – $80"
|
|
112
|
+
assert_selector "input[aria-valuetext='$20']"
|
|
113
|
+
assert_selector "input[aria-valuetext='$80']"
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_marks_are_labelled_and_placed
|
|
117
|
+
render_slider(min: 0, max: 100, marks: [ 0, 50, 100 ])
|
|
118
|
+
marks = page.all("[aria-hidden='true'] span[data-action='click->ui--slider#pick']")
|
|
119
|
+
assert_equal %w[0 50 100], marks.map(&:text)
|
|
120
|
+
assert_equal "50", marks[1]["data-ui--slider-value-param"]
|
|
121
|
+
assert_includes marks[0][:style], "inset-inline-start: 0px"
|
|
122
|
+
assert_includes marks[1][:style], "calc(var(--thumb) / 2 + (100% - var(--thumb)) * 0.5)"
|
|
123
|
+
assert_includes marks[2][:style], "inset-inline-start: 100%"
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def test_labelled_marks_are_what_the_value_says
|
|
127
|
+
render_slider(min: 1, max: 3, value: 2, show_value: true, marks: { 1 => "Low", 2 => "Medium", 3 => "High" })
|
|
128
|
+
assert_selector "output", text: "Medium"
|
|
129
|
+
assert_selector "input[aria-valuetext='Medium']"
|
|
130
|
+
assert_equal({ "1" => "Low", "2" => "Medium", "3" => "High" }, JSON.parse(root["data-ui--slider-labels-value"]))
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def test_marks_outside_the_track_are_left_out
|
|
134
|
+
render_slider(min: 0, max: 10, marks: [ -5, 5, 15 ])
|
|
135
|
+
assert_selector "span[data-ui--slider-value-param]", count: 1
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def test_disabled_turns_off_the_input_and_the_track
|
|
139
|
+
render_slider(disabled: true, marks: [ 0, 100 ])
|
|
140
|
+
assert_selector "input[disabled]"
|
|
141
|
+
assert_selector ".opacity-50[data-slot='slider']"
|
|
142
|
+
assert_no_selector "[data-action='pointerdown->ui--slider#press']"
|
|
143
|
+
assert_no_selector "span[data-action]"
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def test_hint_and_error_describe_the_input
|
|
147
|
+
render_slider(id: "vol", hint: "Applies to alerts", error: "Too loud")
|
|
148
|
+
assert_selector "input#vol[aria-describedby='vol-hint vol-error'][aria-invalid='true']"
|
|
149
|
+
assert_text "Applies to alerts"
|
|
150
|
+
assert_text "Too loud"
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def test_aria_names_an_unlabelled_input_or_a_range_group
|
|
154
|
+
render_slider(label: false, aria: { label: "Volume" })
|
|
155
|
+
assert_selector "input[aria-label='Volume']"
|
|
156
|
+
assert_no_selector "[data-slot='slider'][aria-label]"
|
|
157
|
+
render_inline(UI::Slider.new(range: true, aria: { label: "Price" }))
|
|
158
|
+
assert_selector "[role='group'][aria-label='Price']"
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def test_passes_class_and_attributes_to_the_root
|
|
162
|
+
render_slider(class: "max-w-xs", data: { testid: "s" })
|
|
163
|
+
assert_selector "[data-slot='slider'].max-w-xs[data-testid='s'][data-controller='ui--slider']"
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
Settings = Struct.new(:alert_at, :opens_at, :closes_at) do
|
|
167
|
+
def self.human_attribute_name(name, *) = name.to_s.humanize
|
|
168
|
+
def to_model = self
|
|
169
|
+
def model_name = ActiveModel::Name.new(self.class, nil, "Settings")
|
|
170
|
+
def persisted? = false
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def builder(record) = ActionView::Helpers::FormBuilder.new(:settings, record, vc_test_controller.view_context, {})
|
|
174
|
+
|
|
175
|
+
def test_form_binding_names_the_input_reads_the_value_and_derives_the_label
|
|
176
|
+
render_inline(UI::Slider.new(form: builder(Settings.new(80)), field: :alert_at, min: 50, max: 100))
|
|
177
|
+
input = page.find("input[type='range']")
|
|
178
|
+
assert_equal "settings[alert_at]", input[:name]
|
|
179
|
+
assert_equal "80", input[:value]
|
|
180
|
+
assert_selector "label[for='#{input[:id]}']", text: "Alert at"
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
def test_form_binding_for_a_range
|
|
184
|
+
render_inline(UI::Slider.new(range: true, form: builder(Settings.new(nil, 9, 17)), from_field: :opens_at,
|
|
185
|
+
to_field: :closes_at, max: 24))
|
|
186
|
+
assert_selector "input[name='settings[opens_at]'][value='9']"
|
|
187
|
+
assert_selector "input[name='settings[closes_at]'][value='17']"
|
|
188
|
+
assert_selector "label", text: "Opens at"
|
|
189
|
+
end
|
|
190
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: velvetkit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rathan Kumar
|
|
@@ -181,6 +181,8 @@ files:
|
|
|
181
181
|
- registry/app/components/ui/menu/separator.rb
|
|
182
182
|
- registry/app/components/ui/menu/trigger.html.erb
|
|
183
183
|
- registry/app/components/ui/menu/trigger.rb
|
|
184
|
+
- registry/app/components/ui/money_input.html.erb
|
|
185
|
+
- registry/app/components/ui/money_input.rb
|
|
184
186
|
- registry/app/components/ui/native_select.html.erb
|
|
185
187
|
- registry/app/components/ui/native_select.rb
|
|
186
188
|
- registry/app/components/ui/navigation_menu.html.erb
|
|
@@ -208,6 +210,8 @@ files:
|
|
|
208
210
|
- registry/app/components/ui/radio_group.rb
|
|
209
211
|
- registry/app/components/ui/radio_group/item.html.erb
|
|
210
212
|
- registry/app/components/ui/radio_group/item.rb
|
|
213
|
+
- registry/app/components/ui/scan_input.html.erb
|
|
214
|
+
- registry/app/components/ui/scan_input.rb
|
|
211
215
|
- registry/app/components/ui/select.html.erb
|
|
212
216
|
- registry/app/components/ui/select.rb
|
|
213
217
|
- registry/app/components/ui/session_tabs.html.erb
|
|
@@ -248,6 +252,8 @@ files:
|
|
|
248
252
|
- registry/app/components/ui/sidebar/wrapper.rb
|
|
249
253
|
- registry/app/components/ui/skeleton.html.erb
|
|
250
254
|
- registry/app/components/ui/skeleton.rb
|
|
255
|
+
- registry/app/components/ui/slider.html.erb
|
|
256
|
+
- registry/app/components/ui/slider.rb
|
|
251
257
|
- registry/app/components/ui/spinner.html.erb
|
|
252
258
|
- registry/app/components/ui/spinner.rb
|
|
253
259
|
- registry/app/components/ui/stepper.html.erb
|
|
@@ -333,14 +339,17 @@ files:
|
|
|
333
339
|
- registry/app/javascript/controllers/ui/gallery_controller.ts
|
|
334
340
|
- registry/app/javascript/controllers/ui/kbd_controller.ts
|
|
335
341
|
- registry/app/javascript/controllers/ui/menu_controller.ts
|
|
342
|
+
- registry/app/javascript/controllers/ui/money_input_controller.ts
|
|
336
343
|
- registry/app/javascript/controllers/ui/navigation_menu_controller.ts
|
|
337
344
|
- registry/app/javascript/controllers/ui/number_input_controller.ts
|
|
338
345
|
- registry/app/javascript/controllers/ui/password_visibility_controller.ts
|
|
339
346
|
- registry/app/javascript/controllers/ui/popover_controller.ts
|
|
340
347
|
- registry/app/javascript/controllers/ui/progress_controller.ts
|
|
348
|
+
- registry/app/javascript/controllers/ui/scan_input_controller.ts
|
|
341
349
|
- registry/app/javascript/controllers/ui/select_controller.ts
|
|
342
350
|
- registry/app/javascript/controllers/ui/session_tabs_controller.ts
|
|
343
351
|
- registry/app/javascript/controllers/ui/sidebar_controller.ts
|
|
352
|
+
- registry/app/javascript/controllers/ui/slider_controller.ts
|
|
344
353
|
- registry/app/javascript/controllers/ui/stepper_controller.ts
|
|
345
354
|
- registry/app/javascript/controllers/ui/table_of_contents_controller.ts
|
|
346
355
|
- registry/app/javascript/controllers/ui/tabs_controller.ts
|
|
@@ -419,6 +428,7 @@ files:
|
|
|
419
428
|
- registry/icons/lucide/receipt.svg
|
|
420
429
|
- registry/icons/lucide/rocket.svg
|
|
421
430
|
- registry/icons/lucide/rotate-cw.svg
|
|
431
|
+
- registry/icons/lucide/scan-barcode.svg
|
|
422
432
|
- registry/icons/lucide/search.svg
|
|
423
433
|
- registry/icons/lucide/settings.svg
|
|
424
434
|
- registry/icons/lucide/shield-check.svg
|
|
@@ -433,6 +443,8 @@ files:
|
|
|
433
443
|
- registry/icons/lucide/user-plus.svg
|
|
434
444
|
- registry/icons/lucide/user.svg
|
|
435
445
|
- registry/icons/lucide/users.svg
|
|
446
|
+
- registry/icons/lucide/volume-2.svg
|
|
447
|
+
- registry/icons/lucide/volume-x.svg
|
|
436
448
|
- registry/icons/lucide/workflow.svg
|
|
437
449
|
- registry/icons/lucide/x.svg
|
|
438
450
|
- registry/icons/lucide/zoom-in.svg
|
|
@@ -441,6 +453,7 @@ files:
|
|
|
441
453
|
- registry/icons/phosphor/arrow-clockwise.svg
|
|
442
454
|
- registry/icons/phosphor/arrow-left.svg
|
|
443
455
|
- registry/icons/phosphor/arrow-right.svg
|
|
456
|
+
- registry/icons/phosphor/barcode.svg
|
|
444
457
|
- registry/icons/phosphor/bell.svg
|
|
445
458
|
- registry/icons/phosphor/book-open.svg
|
|
446
459
|
- registry/icons/phosphor/calendar-blank.svg
|
|
@@ -499,6 +512,8 @@ files:
|
|
|
499
512
|
- registry/icons/phosphor/shield.svg
|
|
500
513
|
- registry/icons/phosphor/sidebar.svg
|
|
501
514
|
- registry/icons/phosphor/sign-out.svg
|
|
515
|
+
- registry/icons/phosphor/speaker-high.svg
|
|
516
|
+
- registry/icons/phosphor/speaker-x.svg
|
|
502
517
|
- registry/icons/phosphor/spinner.svg
|
|
503
518
|
- registry/icons/phosphor/squares-four.svg
|
|
504
519
|
- registry/icons/phosphor/storefront.svg
|
|
@@ -525,6 +540,7 @@ files:
|
|
|
525
540
|
- registry/icons/tabler/align-right.svg
|
|
526
541
|
- registry/icons/tabler/arrow-left.svg
|
|
527
542
|
- registry/icons/tabler/arrow-right.svg
|
|
543
|
+
- registry/icons/tabler/barcode.svg
|
|
528
544
|
- registry/icons/tabler/bell.svg
|
|
529
545
|
- registry/icons/tabler/bold.svg
|
|
530
546
|
- registry/icons/tabler/book.svg
|
|
@@ -596,6 +612,8 @@ files:
|
|
|
596
612
|
- registry/icons/tabler/user-plus.svg
|
|
597
613
|
- registry/icons/tabler/user.svg
|
|
598
614
|
- registry/icons/tabler/users.svg
|
|
615
|
+
- registry/icons/tabler/volume-3.svg
|
|
616
|
+
- registry/icons/tabler/volume.svg
|
|
599
617
|
- registry/icons/tabler/world.svg
|
|
600
618
|
- registry/icons/tabler/x.svg
|
|
601
619
|
- registry/icons/tabler/zoom-in.svg
|
|
@@ -756,6 +774,11 @@ files:
|
|
|
756
774
|
- registry/test/components/previews/ui/menu_preview.rb
|
|
757
775
|
- registry/test/components/previews/ui/menu_preview/positions.html.erb
|
|
758
776
|
- registry/test/components/previews/ui/menu_preview/variants.html.erb
|
|
777
|
+
- registry/test/components/previews/ui/money_input_preview.rb
|
|
778
|
+
- registry/test/components/previews/ui/money_input_preview/cash_tendered.html.erb
|
|
779
|
+
- registry/test/components/previews/ui/money_input_preview/currencies.html.erb
|
|
780
|
+
- registry/test/components/previews/ui/money_input_preview/invoice.html.erb
|
|
781
|
+
- registry/test/components/previews/ui/money_input_preview/sizes_and_states.html.erb
|
|
759
782
|
- registry/test/components/previews/ui/native_select_preview.rb
|
|
760
783
|
- registry/test/components/previews/ui/native_select_preview/sizes.html.erb
|
|
761
784
|
- registry/test/components/previews/ui/native_select_preview/states.html.erb
|
|
@@ -793,6 +816,13 @@ files:
|
|
|
793
816
|
- registry/test/components/previews/ui/radio_group_preview/default.html.erb
|
|
794
817
|
- registry/test/components/previews/ui/radio_group_preview/disabled.html.erb
|
|
795
818
|
- registry/test/components/previews/ui/radio_group_preview/with_required.html.erb
|
|
819
|
+
- registry/test/components/previews/ui/scan_input_preview.rb
|
|
820
|
+
- registry/test/components/previews/ui/scan_input_preview/_simulate.html.erb
|
|
821
|
+
- registry/test/components/previews/ui/scan_input_preview/library_checkout.html.erb
|
|
822
|
+
- registry/test/components/previews/ui/scan_input_preview/playground.html.erb
|
|
823
|
+
- registry/test/components/previews/ui/scan_input_preview/stock_count.html.erb
|
|
824
|
+
- registry/test/components/previews/ui/scan_input_preview/ticket_check_in.html.erb
|
|
825
|
+
- registry/test/components/previews/ui/scan_input_preview/till.html.erb
|
|
796
826
|
- registry/test/components/previews/ui/select_preview.rb
|
|
797
827
|
- registry/test/components/previews/ui/select_preview/default.html.erb
|
|
798
828
|
- registry/test/components/previews/ui/select_preview/long_list.html.erb
|
|
@@ -820,6 +850,14 @@ files:
|
|
|
820
850
|
- registry/test/components/previews/ui/skeleton_preview.rb
|
|
821
851
|
- registry/test/components/previews/ui/skeleton_preview/card_placeholder.html.erb
|
|
822
852
|
- registry/test/components/previews/ui/skeleton_preview/shapes.html.erb
|
|
853
|
+
- registry/test/components/previews/ui/slider_preview.rb
|
|
854
|
+
- registry/test/components/previews/ui/slider_preview/named_steps.html.erb
|
|
855
|
+
- registry/test/components/previews/ui/slider_preview/opening_hours.html.erb
|
|
856
|
+
- registry/test/components/previews/ui/slider_preview/price_range.html.erb
|
|
857
|
+
- registry/test/components/previews/ui/slider_preview/sizes_and_states.html.erb
|
|
858
|
+
- registry/test/components/previews/ui/slider_preview/text_size.html.erb
|
|
859
|
+
- registry/test/components/previews/ui/slider_preview/tip.html.erb
|
|
860
|
+
- registry/test/components/previews/ui/slider_preview/volume.html.erb
|
|
823
861
|
- registry/test/components/previews/ui/spinner_preview.rb
|
|
824
862
|
- registry/test/components/previews/ui/spinner_preview/in_buttons.html.erb
|
|
825
863
|
- registry/test/components/previews/ui/spinner_preview/sizes.html.erb
|
|
@@ -949,6 +987,7 @@ files:
|
|
|
949
987
|
- registry/test/components/ui/menu/separator_test.rb
|
|
950
988
|
- registry/test/components/ui/menu/trigger_test.rb
|
|
951
989
|
- registry/test/components/ui/menu_test.rb
|
|
990
|
+
- registry/test/components/ui/money_input_test.rb
|
|
952
991
|
- registry/test/components/ui/native_select_test.rb
|
|
953
992
|
- registry/test/components/ui/navigation_menu_test.rb
|
|
954
993
|
- registry/test/components/ui/number_input_test.rb
|
|
@@ -960,6 +999,7 @@ files:
|
|
|
960
999
|
- registry/test/components/ui/progress_test.rb
|
|
961
1000
|
- registry/test/components/ui/radio_group/item_test.rb
|
|
962
1001
|
- registry/test/components/ui/radio_group_test.rb
|
|
1002
|
+
- registry/test/components/ui/scan_input_test.rb
|
|
963
1003
|
- registry/test/components/ui/select_test.rb
|
|
964
1004
|
- registry/test/components/ui/session_tabs/add_test.rb
|
|
965
1005
|
- registry/test/components/ui/session_tabs_test.rb
|
|
@@ -971,6 +1011,7 @@ files:
|
|
|
971
1011
|
- registry/test/components/ui/sidebar/wrapper_test.rb
|
|
972
1012
|
- registry/test/components/ui/sidebar_test.rb
|
|
973
1013
|
- registry/test/components/ui/skeleton_test.rb
|
|
1014
|
+
- registry/test/components/ui/slider_test.rb
|
|
974
1015
|
- registry/test/components/ui/spinner_test.rb
|
|
975
1016
|
- registry/test/components/ui/stepper_test.rb
|
|
976
1017
|
- registry/test/components/ui/switch_test.rb
|