@stacksjs/components 0.2.383 → 0.2.385

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.
Files changed (28) hide show
  1. package/dist/{Badge-4jxqhkv9.stx → Badge-33phrqza.stx} +25 -1
  2. package/dist/{Button-k2q6811a.stx → Button-bpjmfkq6.stx} +32 -1
  3. package/dist/{Checkbox-tt8bze29.stx → Checkbox-8kw03j51.stx} +10 -0
  4. package/dist/{EmailInput-agb8kqae.stx → EmailInput-ffzwvp9r.stx} +18 -0
  5. package/dist/{NumberInput-g3jfy120.stx → NumberInput-q5qjdwbt.stx} +26 -0
  6. package/dist/{PasswordInput-p2rt5926.stx → PasswordInput-zr84vsv4.stx} +26 -0
  7. package/dist/{Radio-50f4wq25.stx → Radio-8j21bgbg.stx} +10 -0
  8. package/dist/{SearchInput-psbjk2ye.stx → SearchInput-w15r5t95.stx} +18 -0
  9. package/dist/{Select-1p9mcbsb.stx → Select-nbr6aaxk.stx} +22 -0
  10. package/dist/{Switch-27hp6pq5.stx → Switch-acwd7n07.stx} +31 -0
  11. package/dist/{TextInput-t0a4ch49.stx → TextInput-165w1cth.stx} +26 -0
  12. package/dist/{Textarea-4zzr72zh.stx → Textarea-1yd7aswb.stx} +26 -0
  13. package/dist/{Tooltip-sq6tfy00.stx → Tooltip-cqp0hz6h.stx} +30 -1
  14. package/dist/index.js +7 -7
  15. package/package.json +3 -3
  16. package/src/ui/badge/Badge.stx +25 -1
  17. package/src/ui/button/Button.stx +32 -1
  18. package/src/ui/checkbox/Checkbox.stx +10 -0
  19. package/src/ui/input/EmailInput.stx +18 -0
  20. package/src/ui/input/NumberInput.stx +26 -0
  21. package/src/ui/input/PasswordInput.stx +26 -0
  22. package/src/ui/input/SearchInput.stx +18 -0
  23. package/src/ui/input/TextInput.stx +26 -0
  24. package/src/ui/radio/Radio.stx +10 -0
  25. package/src/ui/select/Select.stx +22 -0
  26. package/src/ui/switch/Switch.stx +31 -0
  27. package/src/ui/textarea/Textarea.stx +26 -0
  28. package/src/ui/tooltip/Tooltip.stx +30 -1
@@ -57,6 +57,27 @@ const paddingClasses = showControls ? 'pr-10' : ''
57
57
  export const inputClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses} ${paddingClasses} ${inputClassName}`.trim()
58
58
  export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
59
59
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
60
+ /*
61
+ * The attributes that make this a form control (stacksjs/stx#2043).
62
+ *
63
+ * A control with no `name` is not a form control in the HTML sense: it is left
64
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
65
+ * non-JS POST. A form built from these components submitted nothing for every
66
+ * field, silently -- which is how six apps read their forms.
67
+ *
68
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
69
+ * and a password manager identify a field, so a password input without
70
+ * `autocomplete="current-password"` is never offered for autofill and is not
71
+ * recognised as part of a sign-in form at all.
72
+ *
73
+ * Emitted only when given, so a control that passes none of them renders
74
+ * exactly the markup it did before.
75
+ */
76
+ export const name = $props.name || ''
77
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
78
+ export const form = $props.form || ''
79
+ export const inputMode = $props.inputMode || $props.inputmode || ''
80
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
60
81
  </script>
61
82
 
62
83
  <script client>
@@ -103,6 +124,11 @@ defineExpose({ value: inputValue, increment, decrement })
103
124
 
104
125
  <div class="relative">
105
126
  <input
127
+ @if(name)name="{{ name }}"@endif
128
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
129
+ @if(form)form="{{ form }}"@endif
130
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
131
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
106
132
  type="number"
107
133
  id="{{ inputId }}"
108
134
  class="{{ inputClasses }}"
@@ -56,6 +56,27 @@ export const inputClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.m
56
56
  export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
57
57
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
58
58
  export const iconClasses = iconSizeClasses[size] || iconSizeClasses.md
59
+ /*
60
+ * The attributes that make this a form control (stacksjs/stx#2043).
61
+ *
62
+ * A control with no `name` is not a form control in the HTML sense: it is left
63
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
64
+ * non-JS POST. A form built from these components submitted nothing for every
65
+ * field, silently -- which is how six apps read their forms.
66
+ *
67
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
68
+ * and a password manager identify a field, so a password input without
69
+ * `autocomplete="current-password"` is never offered for autofill and is not
70
+ * recognised as part of a sign-in form at all.
71
+ *
72
+ * Emitted only when given, so a control that passes none of them renders
73
+ * exactly the markup it did before.
74
+ */
75
+ export const name = $props.name || ''
76
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
77
+ export const form = $props.form || ''
78
+ export const inputMode = $props.inputMode || $props.inputmode || ''
79
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
59
80
  </script>
60
81
 
61
82
  <script client>
@@ -115,6 +136,11 @@ defineExpose({ value: inputValue })
115
136
 
116
137
  <div class="relative">
117
138
  <input
139
+ @if(name)name="{{ name }}"@endif
140
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
141
+ @if(form)form="{{ form }}"@endif
142
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
143
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
118
144
  :type="inputType()"
119
145
  id="{{ inputId }}"
120
146
  class="{{ inputClasses }}"
@@ -12,6 +12,19 @@ export const className = $props.className || ''
12
12
  export const searchIcon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>'
13
13
  export const spinnerIcon = '<svg class="animate-spin" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg>'
14
14
  export const rightIcon = loading ? spinnerIcon : ''
15
+ /*
16
+ * Forwarded to the TextInput this renders (stacksjs/stx#2043).
17
+ *
18
+ * A wrapper that does not pass them through is as unsubmittable as a control
19
+ * that never accepted them: the inner input is the one that lands in FormData.
20
+ * `type` is the wrapper's own business, but `name`, `autocomplete` and `form`
21
+ * belong to the caller.
22
+ */
23
+ export const name = $props.name || ''
24
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
25
+ export const form = $props.form || ''
26
+ export const inputMode = $props.inputMode || $props.inputmode || ''
27
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
15
28
  </script>
16
29
 
17
30
  <script client>
@@ -28,6 +41,11 @@ function onSearchInput(event) {
28
41
 
29
42
  <div @input="onSearchInput($event)">
30
43
  <TextInput
44
+ :name="name"
45
+ :autocomplete="autocomplete"
46
+ :form="form"
47
+ :inputMode="inputMode"
48
+ :enterKeyHint="enterKeyHint"
31
49
  :value="value"
32
50
  :placeholder="placeholder"
33
51
  :disabled="disabled"
@@ -61,6 +61,27 @@ export const iconClasses = iconSizeClasses[size] || iconSizeClasses.md
61
61
  */
62
62
  export const inputId = $props.id || `input-${$uid}`
63
63
  export const helperId = `${inputId}-helper`
64
+ /*
65
+ * The attributes that make this a form control (stacksjs/stx#2043).
66
+ *
67
+ * A control with no `name` is not a form control in the HTML sense: it is left
68
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
69
+ * non-JS POST. A form built from these components submitted nothing for every
70
+ * field, silently -- which is how six apps read their forms.
71
+ *
72
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
73
+ * and a password manager identify a field, so a password input without
74
+ * `autocomplete="current-password"` is never offered for autofill and is not
75
+ * recognised as part of a sign-in form at all.
76
+ *
77
+ * Emitted only when given, so a control that passes none of them renders
78
+ * exactly the markup it did before.
79
+ */
80
+ export const name = $props.name || ''
81
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
82
+ export const form = $props.form || ''
83
+ export const inputMode = $props.inputMode || $props.inputmode || ''
84
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
64
85
  </script>
65
86
 
66
87
  <script client>
@@ -108,6 +129,11 @@ defineExpose({ value: inputValue, clear: onClear })
108
129
  @endif
109
130
 
110
131
  <input
132
+ @if(name)name="{{ name }}"@endif
133
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
134
+ @if(form)form="{{ form }}"@endif
135
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
136
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
111
137
  type="text"
112
138
  id="{{ inputId }}"
113
139
  class="{{ inputClasses }}"
@@ -35,6 +35,14 @@ export const descriptionClasses = `text-sm ${error ? 'text-danger' : 'text-fg-so
35
35
  */
36
36
  export const inputId = $props.id || `radio-${$uid}`
37
37
  export const descriptionId = `${inputId}-description`
38
+ /*
39
+ * `autocomplete` and `form`, alongside the `name` this already had
40
+ * (stacksjs/stx#2043). `autocomplete` is how the browser and a password
41
+ * manager identify a field; `form` lets a control live outside the <form>
42
+ * element it belongs to. Emitted only when given.
43
+ */
44
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
45
+ export const form = $props.form || ''
38
46
  </script>
39
47
 
40
48
  <script client>
@@ -75,6 +83,8 @@ defineExpose({ isChecked })
75
83
  id="{{ inputId }}"
76
84
  type="radio"
77
85
  name="{{ name }}"
86
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
87
+ @if(form)form="{{ form }}"@endif
78
88
  value="{{ value }}"
79
89
  :value="radioValue()"
80
90
  :checked="isChecked()"
@@ -49,6 +49,25 @@ export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-so
49
49
  */
50
50
  export const selectId = $props.id || `select-${$uid}`
51
51
  export const helperId = `${selectId}-helper`
52
+ /*
53
+ * The attributes that make this a form control (stacksjs/stx#2043).
54
+ *
55
+ * A control with no `name` is not a form control in the HTML sense: it is left
56
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
57
+ * non-JS POST. A form built from these components submitted nothing for every
58
+ * field, silently -- which is how six apps read their forms.
59
+ *
60
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
61
+ * and a password manager identify a field, so a password input without
62
+ * `autocomplete="current-password"` is never offered for autofill and is not
63
+ * recognised as part of a sign-in form at all.
64
+ *
65
+ * Emitted only when given, so a control that passes none of them renders
66
+ * exactly the markup it did before.
67
+ */
68
+ export const name = $props.name || ''
69
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
70
+ export const form = $props.form || ''
52
71
  </script>
53
72
 
54
73
  <script client>
@@ -76,6 +95,9 @@ defineExpose({ value: selectedValue })
76
95
 
77
96
  <div class="{{ label ? 'mt-2' : '' }}">
78
97
  <select
98
+ @if(name)name="{{ name }}"@endif
99
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
100
+ @if(form)form="{{ form }}"@endif
79
101
  id="{{ selectId }}"
80
102
  class="{{ selectClasses }}"
81
103
  :value="selectedValue()"
@@ -1,5 +1,22 @@
1
1
  <script server>
2
2
  export const checked = $bool($props.checked)
3
+
4
+ /*
5
+ * Form participation, which a <button role="switch"> cannot have on its own
6
+ * (stacksjs/stx#2043).
7
+ *
8
+ * The control the user operates is a button, and a button is never submitted
9
+ * by name -- so a Switch inside a form contributed nothing to FormData no
10
+ * matter what it was set to. A hidden input carries the state instead, which
11
+ * is what it takes for a custom switch to be readable the way a checkbox is.
12
+ *
13
+ * Only rendered when a `name` is given, so a Switch used as a plain toggle
14
+ * emits exactly the markup it did before.
15
+ */
16
+ export const name = $props.name || ''
17
+ export const form = $props.form || ''
18
+ export const checkedValue = $props.checkedValue || 'true'
19
+ export const uncheckedValue = $props.uncheckedValue || 'false'
3
20
  export const disabled = $bool($props.disabled)
4
21
  export const size = $props.size || 'md'
5
22
  export const className = $props.className || ''
@@ -60,6 +77,20 @@ defineExpose({ isChecked, toggle })
60
77
  </span>
61
78
  @endif
62
79
 
80
+ @if(name)
81
+ {{-- Always submitted, carrying one of two values, rather than a checkbox's
82
+ present-or-absent convention: a reader then gets an explicit "false"
83
+ instead of a missing key, which is the difference between "switched
84
+ off" and "field was never in the form". --}}
85
+ <input
86
+ type="hidden"
87
+ name="{{ name }}"
88
+ @if(form)form="{{ form }}"@endif
89
+ value="{{ checked ? checkedValue : uncheckedValue }}"
90
+ :value="isChecked() ? '{{ checkedValue }}' : '{{ uncheckedValue }}'"
91
+ />
92
+ @endif
93
+
63
94
  <button
64
95
  type="button"
65
96
  role="switch"
@@ -46,6 +46,27 @@ const disabledClasses = disabled
46
46
  export const textareaClasses = `${baseClasses} ${stateClasses} ${disabledClasses} ${resizeClasses[resize] || resizeClasses.vertical} ${className}`.trim()
47
47
  export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
48
48
  export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
49
+ /*
50
+ * The attributes that make this a form control (stacksjs/stx#2043).
51
+ *
52
+ * A control with no `name` is not a form control in the HTML sense: it is left
53
+ * out of FormData, out of form.elements.namedItem(), and out of an ordinary
54
+ * non-JS POST. A form built from these components submitted nothing for every
55
+ * field, silently -- which is how six apps read their forms.
56
+ *
57
+ * `autocomplete` is separate and just as load-bearing: it is how the browser
58
+ * and a password manager identify a field, so a password input without
59
+ * `autocomplete="current-password"` is never offered for autofill and is not
60
+ * recognised as part of a sign-in form at all.
61
+ *
62
+ * Emitted only when given, so a control that passes none of them renders
63
+ * exactly the markup it did before.
64
+ */
65
+ export const name = $props.name || ''
66
+ export const autocomplete = $props.autocomplete || $props.autoComplete || ''
67
+ export const form = $props.form || ''
68
+ export const inputMode = $props.inputMode || $props.inputmode || ''
69
+ export const enterKeyHint = $props.enterKeyHint || $props.enterkeyhint || ''
49
70
  </script>
50
71
 
51
72
  <script client>
@@ -94,6 +115,11 @@ defineExpose({ value: inputValue })
94
115
  @endif
95
116
 
96
117
  <textarea
118
+ @if(name)name="{{ name }}"@endif
119
+ @if(autocomplete)autocomplete="{{ autocomplete }}"@endif
120
+ @if(form)form="{{ form }}"@endif
121
+ @if(inputMode)inputmode="{{ inputMode }}"@endif
122
+ @if(enterKeyHint)enterkeyhint="{{ enterKeyHint }}"@endif
97
123
  id="{{ inputId }}"
98
124
  class="{{ textareaClasses }}"
99
125
  rows="{{ rows }}"
@@ -6,6 +6,28 @@ export const className = $props.className || ''
6
6
  export const show = $bool($props.show)
7
7
  export const disabled = $bool($props.disabled)
8
8
 
9
+ /*
10
+ * The id that makes the tooltip reachable from its trigger.
11
+ *
12
+ * `role="tooltip"` names what the element IS; it does not attach it to
13
+ * anything. Without `aria-describedby` on the trigger pointing here, a screen
14
+ * reader never reaches this element at all and the role announces nothing --
15
+ * so the component was a DOWNGRADE from the native `title=` it replaces, which
16
+ * at least is announced.
17
+ */
18
+ export const tooltipId = `tooltip-${$uid}`
19
+
20
+ /*
21
+ * Whether the text may wrap. It may, by default.
22
+ *
23
+ * `whitespace-nowrap` keeps a two-word hint on one line, which is what a
24
+ * tooltip usually is -- but a sentence-length one then grows past the viewport
25
+ * instead of wrapping, and on a phone the end of it is simply unreachable.
26
+ * Wrapping with a sensible max width is right for both; `nowrap` is there for
27
+ * a caller who knows the content is short.
28
+ */
29
+ export const nowrap = $bool($props.nowrap)
30
+
9
31
  const positionClasses = {
10
32
  top: 'bottom-full left-1/2 -translate-x-1/2 mb-2',
11
33
  bottom: 'top-full left-1/2 -translate-x-1/2 mt-2',
@@ -20,7 +42,8 @@ const arrowClasses = {
20
42
  right: 'right-full top-1/2 -translate-y-1/2 border-r-inverse',
21
43
  }
22
44
 
23
- export const tooltipClasses = `absolute z-50 px-3 py-2 text-sm font-medium text-inverse-ink bg-inverse rounded-panel shadow-lg whitespace-nowrap pointer-events-none transition-opacity duration-200 ${positionClasses[position] || positionClasses.top} ${className}`.trim()
45
+ const wrapClasses = nowrap ? 'whitespace-nowrap' : 'max-w-xs break-words'
46
+ export const tooltipClasses = `absolute z-50 px-3 py-2 text-sm font-medium text-inverse-ink bg-inverse rounded-panel shadow-lg ${wrapClasses} pointer-events-none transition-opacity duration-200 ${positionClasses[position] || positionClasses.top} ${className}`.trim()
24
47
  export const arrowClass = `absolute w-0 h-0 border-4 border-transparent ${arrowClasses[position] || arrowClasses.top}`.trim()
25
48
  </script>
26
49
 
@@ -54,7 +77,12 @@ function hideTooltip() {
54
77
  </script>
55
78
 
56
79
  <div class="relative inline-block {{ disabled ? 'cursor-not-allowed' : '' }}">
80
+ {{-- aria-describedby is what attaches the tooltip to what it describes.
81
+ The element is always in the DOM -- :show toggles it -- so the
82
+ description resolves whether or not the tooltip is on screen, which is
83
+ how a screen reader is meant to reach it. --}}
57
84
  <div
85
+ aria-describedby="{{ tooltipId }}"
58
86
  @mouseenter="showTooltip()"
59
87
  @mouseleave="hideTooltip()"
60
88
  @focusin="showTooltip()"
@@ -64,6 +92,7 @@ function hideTooltip() {
64
92
  </div>
65
93
 
66
94
  <div
95
+ id="{{ tooltipId }}"
67
96
  :show="isVisible() && !{{ disabled }}"
68
97
  class="{{ tooltipClasses }}"
69
98
  role="tooltip"