@stacksjs/components 0.2.466 → 0.2.468
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.
- package/dist/{EmailInput-ffzwvp9r.stx → EmailInput-57626391.stx} +3 -0
- package/dist/{NumberInput-r2wsh8w9.stx → NumberInput-pq4k2k4k.stx} +31 -10
- package/dist/{PasswordInput-36bws0kf.stx → PasswordInput-dg41ktgd.stx} +8 -1
- package/dist/{Select-pv44ngbe.stx → Select-61zv5tr7.stx} +98 -17
- package/dist/Table-0a4y46vd.stx +43 -0
- package/dist/TableCell-jhvsxw8b.stx +17 -0
- package/dist/TableHeader-krzcx4sv.stx +62 -0
- package/dist/{TextInput-h9trj9f9.stx → TextInput-nknmz9md.stx} +57 -4
- package/dist/{Textarea-k8cjs4zs.stx → Textarea-9xmhjqp8.stx} +30 -7
- package/dist/index.js +5 -5
- package/dist/overlays/overlays.js +22 -0
- package/dist/ui/input/index.d.ts +18 -5
- package/dist/ui/select/index.d.ts +1 -1
- package/dist/ui/table/index.d.ts +4 -0
- package/dist/utils/overlays.d.ts +5 -1
- package/package.json +8 -3
- package/src/ui/input/EmailInput.stx +3 -0
- package/src/ui/input/NumberInput.stx +31 -10
- package/src/ui/input/PasswordInput.stx +8 -1
- package/src/ui/input/TextInput.stx +57 -4
- package/src/ui/input/index.ts +31 -5
- package/src/ui/select/README.md +59 -21
- package/src/ui/select/Select.stx +98 -17
- package/src/ui/select/index.ts +8 -1
- package/src/ui/table/README.md +69 -1
- package/src/ui/table/Table.stx +31 -2
- package/src/ui/table/TableCell.stx +8 -1
- package/src/ui/table/TableHeader.stx +47 -5
- package/src/ui/table/index.ts +9 -0
- package/src/ui/textarea/Textarea.stx +30 -7
- package/src/utils/overlays.ts +5 -1
- package/dist/Table-3ek3w95h.stx +0 -14
- package/dist/TableCell-8swtcq8s.stx +0 -10
- package/dist/TableHeader-qsc3e208.stx +0 -20
package/src/ui/table/Table.stx
CHANGED
|
@@ -3,12 +3,41 @@ export const className = $props.className || ''
|
|
|
3
3
|
export const striped = $bool($props.striped)
|
|
4
4
|
export const hoverable = $bool($props.hoverable, true)
|
|
5
5
|
|
|
6
|
+
/*
|
|
7
|
+
* The table's accessible name (stacksjs/stx#2060).
|
|
8
|
+
*
|
|
9
|
+
* A table is named by its <caption>, and there was no way to give a library
|
|
10
|
+
* table one: no prop, and no slot ahead of <thead>. It is the table's first
|
|
11
|
+
* child, as HTML requires, and visually hidden unless `captionVisible` -- most
|
|
12
|
+
* tables sit under a heading that already says what they are, and a second
|
|
13
|
+
* visible title would repeat it.
|
|
14
|
+
*/
|
|
15
|
+
export const caption = $props.caption || ''
|
|
16
|
+
export const captionVisible = $bool($props.captionVisible)
|
|
17
|
+
export const captionClasses = captionVisible
|
|
18
|
+
? 'caption-top px-cell-x py-2 text-left text-sm font-semibold text-fg'
|
|
19
|
+
: 'sr-only'
|
|
20
|
+
|
|
6
21
|
const baseClasses = 'min-w-full divide-y divide-line'
|
|
7
|
-
const tableClasses = `${baseClasses} ${className}`.trim()
|
|
22
|
+
export const tableClasses = `${baseClasses} ${className}`.trim()
|
|
8
23
|
</script>
|
|
9
24
|
|
|
10
25
|
<div class="overflow-x-auto">
|
|
11
|
-
<table class="{{ tableClasses }}">
|
|
26
|
+
<table class="{{ tableClasses }}" @if(caption)data-stx-caption@endif>
|
|
27
|
+
@if(caption)<caption class="{{ captionClasses }}">{{ caption }}</caption>@endif
|
|
12
28
|
<slot :striped="striped" :hoverable="hoverable" />
|
|
13
29
|
</table>
|
|
14
30
|
</div>
|
|
31
|
+
|
|
32
|
+
<style>
|
|
33
|
+
/*
|
|
34
|
+
* `divide-y` borders every child after the first, and with a caption first
|
|
35
|
+
* that includes the header row: a captioned table grew a rule along its top
|
|
36
|
+
* edge that an uncaptioned one does not have. This takes it back off. The
|
|
37
|
+
* selector has to outrank divide-y's own (0,3,0) -- hence the table's
|
|
38
|
+
* :not([hidden]) -- or which one won would be stylesheet order again.
|
|
39
|
+
*/
|
|
40
|
+
table[data-stx-caption]:not([hidden]) > caption + :not([hidden]) {
|
|
41
|
+
border-top-width: 0;
|
|
42
|
+
}
|
|
43
|
+
</style>
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/*
|
|
5
|
+
* Padding and type read the density roles, so an app's tables take its own
|
|
6
|
+
* cell size from --stx-cell-px, --stx-cell-py, --stx-cell-text and
|
|
7
|
+
* --stx-cell-leading -- a className of py-2 ties with py-4 on
|
|
8
|
+
* specificity and wins only by stylesheet order. The fallbacks are px-6 /
|
|
9
|
+
* py-4 / text-sm, so nothing moves by default (stacksjs/stx#1993).
|
|
10
|
+
*/
|
|
11
|
+
const baseClasses = 'px-cell-x py-cell-y whitespace-nowrap text-cell text-fg'
|
|
5
12
|
const cellClasses = `${baseClasses} ${className}`.trim()
|
|
6
13
|
</script>
|
|
7
14
|
|
|
@@ -2,19 +2,61 @@
|
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const sortable = $bool($props.sortable)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/*
|
|
6
|
+
* Which cells this header heads (stacksjs/stx#2060).
|
|
7
|
+
*
|
|
8
|
+
* A <th> without `scope` leaves a screen reader to guess, and it guesses wrong
|
|
9
|
+
* in any table with row headers. `col` by default, because that is what a
|
|
10
|
+
* header in a <thead> is; `row` for a header at the start of a body row. An
|
|
11
|
+
* attribute written on <TableHeader> never reached the <th>, so there was no
|
|
12
|
+
* way to say it at all.
|
|
13
|
+
*/
|
|
14
|
+
const SCOPES = ['col', 'row', 'colgroup', 'rowgroup']
|
|
15
|
+
export const scope = SCOPES.includes(String($props.scope)) ? String($props.scope) : 'col'
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Which way the column is sorted now, as `aria-sort` on the <th> -- the one
|
|
19
|
+
* place a screen reader looks for it. `asc` / `desc`; anything else is
|
|
20
|
+
* unsorted, `none`. Served on every sortable header (and on any header given
|
|
21
|
+
* a `sort`), and live, so a page re-sorting a table moves it without a
|
|
22
|
+
* re-render.
|
|
23
|
+
*/
|
|
24
|
+
const SORTS = { asc: 'ascending', desc: 'descending' }
|
|
25
|
+
export const sortDirection = SORTS[String($props.sort)] ? String($props.sort) : ''
|
|
26
|
+
export const announcesSort = sortable || ($props.sort !== undefined && $props.sort !== null)
|
|
27
|
+
export const servedAriaSort = SORTS[sortDirection] || 'none'
|
|
28
|
+
|
|
29
|
+
const baseClasses = 'px-cell-x py-cell-head-y text-left text-cell-head font-medium text-fg-soft uppercase tracking-wider'
|
|
30
|
+
export const headerClasses = `${baseClasses} ${className}`.trim()
|
|
31
|
+
/*
|
|
32
|
+
* The control that sorts. A <th> is not focusable, so a click handler on it
|
|
33
|
+
* made sorting mouse-only (stacksjs/stx#2060); a <button> inside it is
|
|
34
|
+
* reachable by Tab and operated by Enter and Space, and it is what emits
|
|
35
|
+
* `click`. It takes on the header's type -- the preflight resets a button's
|
|
36
|
+
* text-transform, so `uppercase` is restated -- and draws a ring on keyboard
|
|
37
|
+
* focus only.
|
|
38
|
+
*/
|
|
39
|
+
export const buttonClasses = 'inline-flex items-center gap-1 uppercase tracking-wider text-left rounded-control cursor-pointer hover:text-fg-strong focus:outline-none focus-visible:ring-2 focus-visible:ring-accent'
|
|
8
40
|
</script>
|
|
9
41
|
|
|
10
42
|
<script client>
|
|
11
43
|
const emit = defineEmits()
|
|
44
|
+
const sortState = useReactiveProp('sort', {{ sortDirection }}, { parse: v => v === 'asc' || v === 'desc' ? v : '' })
|
|
45
|
+
const ariaSort = derived(() => sortState() === 'asc' ? 'ascending' : sortState() === 'desc' ? 'descending' : 'none')
|
|
12
46
|
|
|
13
47
|
function onClick() {
|
|
14
48
|
emit('click')
|
|
15
49
|
}
|
|
16
50
|
</script>
|
|
17
51
|
|
|
18
|
-
<th
|
|
19
|
-
|
|
52
|
+
<th
|
|
53
|
+
scope="{{ scope }}"
|
|
54
|
+
class="{{ headerClasses }}"
|
|
55
|
+
@if(announcesSort)aria-sort="{{ servedAriaSort }}" :aria-sort="ariaSort()"@endif
|
|
56
|
+
>
|
|
57
|
+
@if(sortable)
|
|
58
|
+
<button type="button" class="{{ buttonClasses }}" @click="onClick()"><slot /></button>
|
|
59
|
+
@else
|
|
60
|
+
<slot />
|
|
61
|
+
@endif
|
|
20
62
|
</th>
|
package/src/ui/table/index.ts
CHANGED
|
@@ -6,6 +6,10 @@ export { default as TableHeader } from './TableHeader.stx'
|
|
|
6
6
|
export { default as TableRow } from './TableRow.stx'
|
|
7
7
|
|
|
8
8
|
export interface TableProps {
|
|
9
|
+
/** The table's accessible name, rendered as its first child `<caption>`. */
|
|
10
|
+
caption?: string
|
|
11
|
+
/** Show the caption; it is visually hidden (`sr-only`) by default. */
|
|
12
|
+
captionVisible?: boolean
|
|
9
13
|
className?: string
|
|
10
14
|
striped?: boolean
|
|
11
15
|
hoverable?: boolean
|
|
@@ -26,7 +30,12 @@ export interface TableRowProps {
|
|
|
26
30
|
|
|
27
31
|
export interface TableHeaderProps {
|
|
28
32
|
className?: string
|
|
33
|
+
/** Which cells this header heads; `col` by default. */
|
|
34
|
+
scope?: 'col' | 'row' | 'colgroup' | 'rowgroup'
|
|
35
|
+
/** Render the label as a `<button>` that emits `click`. */
|
|
29
36
|
sortable?: boolean
|
|
37
|
+
/** The current direction, set as `aria-sort` on the `<th>`. */
|
|
38
|
+
sort?: 'asc' | 'desc' | ''
|
|
30
39
|
onClick?: () => void
|
|
31
40
|
}
|
|
32
41
|
|
|
@@ -33,7 +33,14 @@ export const resize = $props.resize || 'vertical'
|
|
|
33
33
|
export const className = $props.className || ''
|
|
34
34
|
|
|
35
35
|
const resizeClasses = { none: 'resize-none', vertical: 'resize-y', horizontal: 'resize-x', both: 'resize' }
|
|
36
|
-
|
|
36
|
+
/*
|
|
37
|
+
* The padding and type read the density roles, so an
|
|
38
|
+
* app sets its own field size with --stx-control-px, --stx-control-py,
|
|
39
|
+
* --stx-control-text and --stx-control-leading instead of a className
|
|
40
|
+
* that ties with py-2 on specificity. The fallbacks are px-4 / py-2 /
|
|
41
|
+
* text-base, so nothing moves by default (stacksjs/stx#1993).
|
|
42
|
+
*/
|
|
43
|
+
const baseClasses = 'block w-full border-0 rounded-control shadow-sm ring-1 ring-inset transition-colors duration-200 focus:ring-2 focus:ring-inset px-control-x py-control-y text-control bg-field'
|
|
37
44
|
/*
|
|
38
45
|
* The two halves of the validity state, exported so the CLIENT can swap them
|
|
39
46
|
* (stacksjs/stx#2047). Toggled per class rather than as a whole string,
|
|
@@ -82,8 +89,12 @@ const emit = defineEmits()
|
|
|
82
89
|
const isError = useReactiveProp('error', {{ error }})
|
|
83
90
|
const autoResize = {{ autoResize }}
|
|
84
91
|
const maxRows = {{ maxRows }}
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
/*
|
|
93
|
+
* Two-way, like TextInput (stacksjs/stx#2059): `v-model:value="bio"` keeps the
|
|
94
|
+
* page's signal in step, with `.lazy` and `.trim` honoured. `input` is still
|
|
95
|
+
* emitted for the callers that listen for it.
|
|
96
|
+
*/
|
|
97
|
+
const inputValue = useModel('value', { default: {{ value }}, parse: (v) => v == null ? '' : String(v) })
|
|
87
98
|
|
|
88
99
|
function resizeTextarea(el) {
|
|
89
100
|
if (!autoResize) return
|
|
@@ -96,19 +107,26 @@ function resizeTextarea(el) {
|
|
|
96
107
|
}
|
|
97
108
|
|
|
98
109
|
function onInput(event) {
|
|
99
|
-
inputValue.
|
|
110
|
+
inputValue.input(event.target.value)
|
|
100
111
|
resizeTextarea(event.target)
|
|
101
|
-
emit('input', inputValue())
|
|
112
|
+
if (!inputValue.modifiers.lazy) emit('input', inputValue())
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function onChange(event) {
|
|
116
|
+
inputValue.change(event.target.value)
|
|
117
|
+
if (inputValue.modifiers.lazy) emit('input', inputValue())
|
|
102
118
|
}
|
|
103
119
|
|
|
104
120
|
onMount(() => {
|
|
105
121
|
if (autoResize) {
|
|
106
|
-
|
|
122
|
+
// The instance's own id: a fixed 'textarea-input' stopped matching
|
|
123
|
+
// anything once ids became unique per instance.
|
|
124
|
+
const el = document.getElementById({{ inputId }})
|
|
107
125
|
if (el) resizeTextarea(el)
|
|
108
126
|
}
|
|
109
127
|
})
|
|
110
128
|
|
|
111
|
-
const charCount = derived(() => `${inputValue().length} / {{ maxLength || 0 }}`)
|
|
129
|
+
const charCount = derived(() => `${String(inputValue()).length} / {{ maxLength || 0 }}`)
|
|
112
130
|
|
|
113
131
|
defineExpose({ value: inputValue })
|
|
114
132
|
</script>
|
|
@@ -137,7 +155,12 @@ defineExpose({ value: inputValue })
|
|
|
137
155
|
@if(readonly)readonly@endif
|
|
138
156
|
@if(required)required@endif
|
|
139
157
|
@if(maxLength)maxlength="{{ maxLength }}"@endif
|
|
158
|
+
{{-- The live value. The served text between the tags is the default
|
|
159
|
+
value; this keeps the element in step when the page's signal moves,
|
|
160
|
+
which nothing did before -- the field had no binding at all. --}}
|
|
161
|
+
:value="inputValue()"
|
|
140
162
|
@input="onInput($event)"
|
|
163
|
+
@change="onChange($event)"
|
|
141
164
|
aria-invalid="{{ error ? 'true' : 'false' }}"
|
|
142
165
|
:aria-invalid="isError() ? 'true' : 'false'"
|
|
143
166
|
:class="{ '{{ stateInvalidClasses }}': isError(), '{{ stateValidClasses }}': !isError() }"
|
package/src/utils/overlays.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* library's dialogs instead of competing with them (stacksjs/stx#2057).
|
|
10
10
|
*
|
|
11
11
|
* ```ts
|
|
12
|
-
* import { closeOverlay, openOverlay } from '@stacksjs/components'
|
|
12
|
+
* import { closeOverlay, openOverlay } from '@stacksjs/components/overlays'
|
|
13
13
|
*
|
|
14
14
|
* effect(() => {
|
|
15
15
|
* if (panelOpen()) openOverlay('workout-panel', { panel: '#wp-panel', onEscape: close })
|
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
*
|
|
21
21
|
* Every call is a no-op where there is no runtime (server rendering, tests
|
|
22
22
|
* without a DOM), so shared code can call them unguarded.
|
|
23
|
+
*
|
|
24
|
+
* Import them from `@stacksjs/components/overlays` in a `<script client>`. The
|
|
25
|
+
* package root re-exports them too, but the root also reaches the syntax
|
|
26
|
+
* highlighter, which needs Node's streams and cannot be bundled for a browser.
|
|
23
27
|
*/
|
|
24
28
|
|
|
25
29
|
export interface OverlayOptions {
|
package/dist/Table-3ek3w95h.stx
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<script server>
|
|
2
|
-
export const className = $props.className || ''
|
|
3
|
-
export const striped = $bool($props.striped)
|
|
4
|
-
export const hoverable = $bool($props.hoverable, true)
|
|
5
|
-
|
|
6
|
-
const baseClasses = 'min-w-full divide-y divide-line'
|
|
7
|
-
const tableClasses = `${baseClasses} ${className}`.trim()
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<div class="overflow-x-auto">
|
|
11
|
-
<table class="{{ tableClasses }}">
|
|
12
|
-
<slot :striped="striped" :hoverable="hoverable" />
|
|
13
|
-
</table>
|
|
14
|
-
</div>
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
<script server>
|
|
2
|
-
export const className = $props.className || ''
|
|
3
|
-
|
|
4
|
-
const baseClasses = 'px-6 py-4 whitespace-nowrap text-sm text-fg'
|
|
5
|
-
const cellClasses = `${baseClasses} ${className}`.trim()
|
|
6
|
-
</script>
|
|
7
|
-
|
|
8
|
-
<td class="{{ cellClasses }}">
|
|
9
|
-
<slot />
|
|
10
|
-
</td>
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
<script server>
|
|
2
|
-
export const className = $props.className || ''
|
|
3
|
-
export const sortable = $bool($props.sortable)
|
|
4
|
-
|
|
5
|
-
const baseClasses = 'px-6 py-3 text-left text-xs font-medium text-fg-soft uppercase tracking-wider'
|
|
6
|
-
const sortableClasses = sortable ? 'cursor-pointer hover:text-fg-strong' : ''
|
|
7
|
-
export const headerClasses = `${baseClasses} ${sortableClasses} ${className}`.trim()
|
|
8
|
-
</script>
|
|
9
|
-
|
|
10
|
-
<script client>
|
|
11
|
-
const emit = defineEmits()
|
|
12
|
-
|
|
13
|
-
function onClick() {
|
|
14
|
-
emit('click')
|
|
15
|
-
}
|
|
16
|
-
</script>
|
|
17
|
-
|
|
18
|
-
<th class="{{ headerClasses }}" @if(sortable)@click="onClick()"@endif>
|
|
19
|
-
<slot />
|
|
20
|
-
</th>
|