keystone_ui 0.27.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77e17961bce047a1477df49c98660ff0484456e5add3eb78a59b67735296d91b
4
- data.tar.gz: 75fa1c3b979a7490ea47423b5b5d64a075648ff203a9554af170a1dfc06865bf
3
+ metadata.gz: 88ffa01b58c46bdab1ddcf7657b1b60e3caf4320519cb64e5bcf6dfc59e047c9
4
+ data.tar.gz: 151698597ec642c7a410e5835d4b66f3c5b17a1fc778c995f9b583d912e565df
5
5
  SHA512:
6
- metadata.gz: 5f1b133c91668e4fa4886c15f664588d2cec6fd972dae84caf199fd891aeb22c6e48c534f8274b5a64669fb02cd6adb09890f51b75656bd9943a2252b30555a8
7
- data.tar.gz: 34db47e65e4304e7224557d1b29dc1abe8803edd920e851f4a9f8f456d680b71b78710fe2966fd2253b756373a6ca01197dbd1881ec53fa28b730c72e7516a0b
6
+ metadata.gz: 97232de923802fef99483afbdfc76ecc8cac4a7220ed40e97aa4d19426fb885b0d5c012b587ec7e94cd980042fb27d70b99d832e332addd608e4d41645901618
7
+ data.tar.gz: 7b6cf8260919c664248a7246eda7d917e580d6d709737eb83b2d27d7e9e67e37c45fb4302061b8d824cf5e96bd20af403eb07e9f3c6c78f6e4571920f3d0ff6a
@@ -22,6 +22,13 @@
22
22
  </select>
23
23
  <% else %>
24
24
  <%= tag.input(**input_options) %>
25
+ <% if suggestions? %>
26
+ <datalist id="<%= suggestions_id %>">
27
+ <% suggestions.each do |suggestion| %>
28
+ <option value="<%= suggestion %>"></option>
29
+ <% end %>
30
+ </datalist>
31
+ <% end %>
25
32
  <% end %>
26
33
 
27
34
  <% if hint? %>
@@ -11,7 +11,7 @@ module Keystone
11
11
  CHECKBOX_CLASSES = "ks-checkbox"
12
12
  CHECKBOX_WRAPPER_CLASSES = "ks-form-field-checkbox flex items-center"
13
13
 
14
- def initialize(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false)
14
+ def initialize(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false, suggestions: [])
15
15
  @attribute = attribute
16
16
  @label = label
17
17
  @type = type
@@ -26,6 +26,7 @@ module Keystone
26
26
  @errors = Array(errors)
27
27
  @include_blank = include_blank.to_s
28
28
  @disabled = disabled
29
+ @suggestions = Array(suggestions)
29
30
  end
30
31
 
31
32
  def label_text
@@ -83,8 +84,21 @@ module Keystone
83
84
  options[:max] = @max unless @max.nil?
84
85
  options[:step] = @step unless @step.nil?
85
86
  options[:disabled] = true if @disabled
87
+ options[:list] = suggestions_id if suggestions?
86
88
  options
87
89
  end
90
+
91
+ def suggestions?
92
+ @suggestions.any?
93
+ end
94
+
95
+ def suggestions
96
+ @suggestions
97
+ end
98
+
99
+ def suggestions_id
100
+ "#{@attribute.to_s.parameterize}-suggestions"
101
+ end
88
102
  end
89
103
  end
90
104
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module KeystoneUi
4
- VERSION = "0.27.0"
4
+ VERSION = "0.28.0"
5
5
  end
@@ -146,7 +146,7 @@ outer element. See Conventions before using it.
146
146
  The `<form>` wrapper. `method:` may be `:patch`/`:put`/`:delete` and is
147
147
  translated for Rails. Set `multipart: true` when the form contains a file
148
148
  upload.
149
- - `ui_form_field(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false)`
149
+ - `ui_form_field(attribute:, label: nil, type: :text, required: false, hint: nil, placeholder: nil, min: nil, max: nil, step: nil, value: nil, options: [], errors: [], include_blank: nil, disabled: false, suggestions: [])`
150
150
  — a labeled field with hint and error text. This is the default way to render
151
151
  an input. `type:` `:text` `:number` `:email` `:password` `:date` `:textarea`
152
152
  `:checkbox` `:select`. `attribute:` is used verbatim as the input's `name`, so
@@ -159,7 +159,12 @@ outer element. See Conventions before using it.
159
159
  it. Never add your own empty choice to `options:` as well. A
160
160
  `:checkbox` renders its label beside the box, submits `"0"` when unchecked and
161
161
  `"1"` when checked, and pre-checks when `value:` is `"1"`. `errors:` is an
162
- array of message strings.
162
+ array of message strings. `suggestions:` is an array of strings the browser
163
+ offers while the field's text is typed, and the user can still type a value
164
+ that is not in it. It applies to `:text`, `:number`, `:email`, `:password`
165
+ and `:date` fields, and a `:textarea`, `:checkbox` or `:select` ignores it.
166
+ The suggestion list's `id` is built from `attribute:`, so two fields with
167
+ suggestions on one screen need different `attribute:` values.
163
168
  - `ui_input(name:, type: :text, value: nil, placeholder: nil, disabled: false, min: nil, max: nil, step: nil)`
164
169
  — a bare styled input with no label. `type:` `:text` `:number` `:email`
165
170
  `:password` `:date`.
@@ -392,6 +397,10 @@ outer element. See Conventions before using it.
392
397
  To show the arithmetic behind a figure, put `ui_calculation` under it rather
393
398
  than a hand-built list. Which lines and groups to show is the app's own
394
399
  calculation, so ask the developer which steps a reader needs to see.
400
+ A field whose value must be one of a fixed list is a `:select` with
401
+ `options:`, and a field that accepts any text and offers common values is a
402
+ text field with `suggestions:`. Which one a field is, and which values it
403
+ suggests, is the app's own rule, so ask the developer rather than pick.
395
404
  On a radio card or a checkbox row, text every reader needs to choose goes in `hint:` and
396
405
  text only some will want goes in `info:`. Which is which is the app's own
397
406
  wording, so ask the developer rather than pick.
@@ -88,6 +88,12 @@ holds the catalog.
88
88
  and the text stays hidden until the button is hovered or tapped. A piece
89
89
  given no such text shows no button. On a radio card and a checkbox row the
90
90
  button sits on the line with the label.
91
+ - **Suggestions.** A form field can carry a list of suggested values. The
92
+ browser offers them while the field's text is typed, and the user can still
93
+ enter a value that is not on the list. This applies to a field with a typed
94
+ input, such as text, number, email, password or date. A textarea, select or
95
+ checkbox field ignores the list, and a field given no list offers nothing.
96
+ It needs no JavaScript.
91
97
  - **Options are symbols, and each component accepts its own set.** Appearance is
92
98
  chosen by name — `variant:`, `size:`, `type:`, `padding:`, `spacing:`,
93
99
  `max_width:`, `radius:` — on a size scale (`:sm` … `:xl`) or a short list of
@@ -40,7 +40,7 @@ built on ViewComponent; hook it in before building any screen with those helpers
40
40
  ## How to use it
41
41
 
42
42
  1. Confirm the prerequisites: Ruby >= 3.2 and **tailwindcss-rails v4+** in the
43
- host app. The gem brings ViewComponent and keystone_ui-styles 0.6.0 or later with it.
43
+ host app. The gem brings ViewComponent and keystone_ui-styles 0.8.0 or later with it.
44
44
  Tailwind does not have to be initialized first, because the generator creates
45
45
  the stylesheet if it is missing.
46
46
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider