@stacksjs/components 0.2.588 → 0.2.589
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/ChoiceChips-1vn8zsv0.stx +100 -0
- package/dist/{EmptyState-s790dbym.stx → EmptyState-snj7gbsn.stx} +17 -8
- package/dist/ErrorState-py6hga8x.stx +56 -0
- package/dist/GroupedList-mx0b5fe7.stx +44 -0
- package/dist/GroupedListRow-nz8b6vx4.stx +76 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -7
- package/dist/ui/choice-chips/ChoiceChips.d.ts +30 -0
- package/dist/ui/choice-chips/index.d.ts +21 -0
- package/dist/ui/empty-state/EmptyState.d.ts +2 -1
- package/dist/ui/error-state/ErrorState.d.ts +28 -0
- package/dist/ui/error-state/index.d.ts +15 -0
- package/dist/ui/grouped-list/GroupedList.d.ts +32 -0
- package/dist/ui/grouped-list/GroupedListRow.d.ts +39 -0
- package/dist/ui/grouped-list/index.d.ts +25 -0
- package/package.json +3 -3
- package/src/index.ts +3 -0
- package/src/ui/choice-chips/ChoiceChips.stx +100 -0
- package/src/ui/choice-chips/index.ts +27 -0
- package/src/ui/empty-state/EmptyState.stx +17 -8
- package/src/ui/error-state/ErrorState.stx +56 -0
- package/src/ui/error-state/index.ts +20 -0
- package/src/ui/grouped-list/GroupedList.stx +44 -0
- package/src/ui/grouped-list/GroupedListRow.stx +76 -0
- package/src/ui/grouped-list/index.ts +34 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* One choice from a row of pills that scrolls sideways: the filter row under
|
|
4
|
+
* a list title when there are more choices than a segmented control can hold
|
|
5
|
+
* ("All", "Unread", "Conquests", "Kudos", "Challenges").
|
|
6
|
+
*
|
|
7
|
+
* A segmented control fits two to four short words across a phone. Past that
|
|
8
|
+
* the words truncate, so apps fell back to a button that cycled through the
|
|
9
|
+
* choices one tap at a time. This scrolls instead: on the web through
|
|
10
|
+
* `overflow-x-auto`, on a phone as a horizontal ScrollView, from the same
|
|
11
|
+
* source.
|
|
12
|
+
*
|
|
13
|
+
* <ChoiceChips v-model:value="filter" label="Show" testID="filter"
|
|
14
|
+
* :options="[{ value: 'all', label: 'All' }, { value: 'unread', label: 'Unread', count: 3 }]" />
|
|
15
|
+
*
|
|
16
|
+
* `options` takes strings or `{ value, label, count?, disabled? }`, and is
|
|
17
|
+
* reactive. Each chip is a button with `aria-pressed`, which the native host
|
|
18
|
+
* announces as selected. `testID` names the row, each chip `<testID>-<value>`.
|
|
19
|
+
* The chosen chip is `accent-solid` with `accent-ink`; the rest
|
|
20
|
+
* `surface-sunken`; the shape `rounded-pill`.
|
|
21
|
+
*/
|
|
22
|
+
export const value = $props.value ?? ''
|
|
23
|
+
export const options = $props.options || []
|
|
24
|
+
export const label = $props.label || ''
|
|
25
|
+
export const testID = $props.testID || ''
|
|
26
|
+
export const className = $props.className || ''
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script client>
|
|
30
|
+
const emit = defineEmits(['change'])
|
|
31
|
+
const selected = useModel('value', { default: {{ value }}, parse: v => v == null ? '' : String(v) })
|
|
32
|
+
const choices = useReactiveProp('options', {{ options }})
|
|
33
|
+
const groupID = {{ testID }}
|
|
34
|
+
|
|
35
|
+
function normalise(choice) {
|
|
36
|
+
if (choice !== null && typeof choice === 'object') {
|
|
37
|
+
const value = choice.value == null ? '' : String(choice.value)
|
|
38
|
+
const count = Number(choice.count)
|
|
39
|
+
return { value, label: choice.label == null ? value : String(choice.label), count: Number.isFinite(count) && count > 0 ? count : 0, disabled: choice.disabled === true }
|
|
40
|
+
}
|
|
41
|
+
const value = choice == null ? '' : String(choice)
|
|
42
|
+
return { value, label: value, count: 0, disabled: false }
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function chips() {
|
|
46
|
+
const list = choices()
|
|
47
|
+
return Array.isArray(list) ? list.map(normalise) : []
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function isOn(chip) {
|
|
51
|
+
return chip.value === selected()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function choose(chip) {
|
|
55
|
+
if (chip.disabled || isOn(chip)) return
|
|
56
|
+
selected.set(chip.value)
|
|
57
|
+
emit('change', chip.value)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function chipClasses(chip) {
|
|
61
|
+
const state = isOn(chip) ? 'bg-accent-solid' : 'bg-surface-sunken'
|
|
62
|
+
return `flex flex-row shrink-0 items-center gap-1.5 min-h-[36px] px-4 rounded-pill ${state} ${chip.disabled ? 'opacity-50' : ''}`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function textClasses(chip) {
|
|
66
|
+
return `text-[15px] font-medium ${isOn(chip) ? 'text-accent-ink' : 'text-fg'}`
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function chipLabel(chip) {
|
|
70
|
+
return chip.count ? `${chip.label} ${chip.count}` : chip.label
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function chipID(chip) {
|
|
74
|
+
return groupID ? `${groupID}-${chip.value}` : ''
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
defineExpose({ selected })
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<div
|
|
81
|
+
role="group"
|
|
82
|
+
@if(label)aria-label="{{ label }}"@endif
|
|
83
|
+
@if(testID)testID="{{ testID }}"@endif
|
|
84
|
+
class="w-full overflow-x-auto {{ className }}"
|
|
85
|
+
data-stx-choice-chips
|
|
86
|
+
>
|
|
87
|
+
<div class="flex flex-row gap-2 px-4">
|
|
88
|
+
<button
|
|
89
|
+
:for="chip in chips()"
|
|
90
|
+
:key="chip.value"
|
|
91
|
+
type="button"
|
|
92
|
+
:testID="chipID(chip)"
|
|
93
|
+
:aria-pressed="isOn(chip) ? 'true' : 'false'"
|
|
94
|
+
:aria-disabled="chip.disabled ? 'true' : 'false'"
|
|
95
|
+
:disabled="chip.disabled"
|
|
96
|
+
:class="chipClasses(chip)"
|
|
97
|
+
@click="choose(chip)"
|
|
98
|
+
><span :class="textClasses(chip)" :text="chipLabel(chip)"></span></button>
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
@@ -22,6 +22,7 @@ export const as = $props.as || 'div'
|
|
|
22
22
|
export const variant = $props.variant === 'bare' ? 'bare' : 'panel'
|
|
23
23
|
export const align = $props.align === 'left' ? 'left' : 'center'
|
|
24
24
|
export const className = $props.className || ''
|
|
25
|
+
export const testID = $props.testID || ''
|
|
25
26
|
|
|
26
27
|
const panel = variant === 'panel' ? 'bg-panel rounded-panel ring-1 ring-line' : ''
|
|
27
28
|
const alignment = align === 'left' ? 'items-start text-left' : 'items-center text-center'
|
|
@@ -33,7 +34,18 @@ export const actionClasses = 'mt-2 flex flex-wrap items-center gap-2'
|
|
|
33
34
|
export const hasIcon = icon !== ''
|
|
34
35
|
</script>
|
|
35
36
|
|
|
36
|
-
<
|
|
37
|
+
<script client>
|
|
38
|
+
/*
|
|
39
|
+
* The words follow their props after the first paint. They were fixed when the
|
|
40
|
+
* server rendered them, so an app whose empty state names a filter or a count,
|
|
41
|
+
* or speaks the viewer's language, drew the shape itself instead
|
|
42
|
+
* (stacksjs/stx#1981 follow-up).
|
|
43
|
+
*/
|
|
44
|
+
const heading = useReactiveProp('title', {{ title }})
|
|
45
|
+
const explanation = useReactiveProp('description', {{ description }})
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<component :is="{{ as }}" class="{{ rootClasses }}" @if(testID)testID="{{ testID }}"@endif data-stx-empty-state>
|
|
37
49
|
{{-- Only when there is one: an empty state without an icon would otherwise
|
|
38
50
|
carry a floating grey disc. A named slot is not offered because stx
|
|
39
51
|
cannot tell an empty slot from an absent one at render time, so the
|
|
@@ -43,13 +55,10 @@ export const hasIcon = icon !== ''
|
|
|
43
55
|
<div class="{{ iconWrapClasses }}">{!! icon !!}</div>
|
|
44
56
|
@endif
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@if(description)
|
|
51
|
-
<p class="{{ descriptionClasses }}">{{ description }}</p>
|
|
52
|
-
@endif
|
|
58
|
+
{{-- Always present and shown by value, so a title that arrives later has a
|
|
59
|
+
node to land in; the server text is the first paint. --}}
|
|
60
|
+
<h3 :show="heading()" :text="heading()" class="{{ titleClasses }}">{{ title }}</h3>
|
|
61
|
+
<p :show="explanation()" :text="explanation()" class="{{ descriptionClasses }}">{{ description }}</p>
|
|
53
62
|
|
|
54
63
|
<div class="{{ actionClasses }}">
|
|
55
64
|
<slot />
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* Something did not load, said where the content would have been, with a way
|
|
4
|
+
* to try again.
|
|
5
|
+
*
|
|
6
|
+
* Apps wrote this as a line of red text, often with "pull down to retry"
|
|
7
|
+
* inside the message, and rarely offered the button. It is `role="alert"`, so
|
|
8
|
+
* a screen reader announces it when it appears rather than leaving it to be
|
|
9
|
+
* found, on the web and - through the translated role - on a phone.
|
|
10
|
+
*
|
|
11
|
+
* <ErrorState :show="failed()" title="Couldn't load your clubs" :message="problem()"
|
|
12
|
+
* :busy="loading()" @retry="load()" />
|
|
13
|
+
*
|
|
14
|
+
* `title`, `message` and `busy` are reactive. While `busy`, the button is
|
|
15
|
+
* disabled and says `busyLabel`, so a second tap cannot queue a second load.
|
|
16
|
+
* Leave `retryLabel` empty for an error nothing can retry.
|
|
17
|
+
*/
|
|
18
|
+
export const title = $props.title || ''
|
|
19
|
+
export const message = $props.message || ''
|
|
20
|
+
export const retryLabel = $props.retryLabel ?? 'Try again'
|
|
21
|
+
export const busyLabel = $props.busyLabel || 'Trying again…'
|
|
22
|
+
export const busy = $bool($props.busy)
|
|
23
|
+
export const testID = $props.testID || ''
|
|
24
|
+
export const className = $props.className || ''
|
|
25
|
+
|
|
26
|
+
export const rootClasses = `flex flex-col items-center gap-2 px-6 py-8 text-center ${className}`.trim()
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<script client>
|
|
30
|
+
const emit = defineEmits(['retry'])
|
|
31
|
+
const heading = useReactiveProp('title', {{ title }})
|
|
32
|
+
const detail = useReactiveProp('message', {{ message }})
|
|
33
|
+
const retryText = useReactiveProp('retryLabel', {{ retryLabel }})
|
|
34
|
+
const isBusy = useReactiveProp('busy', {{ busy }})
|
|
35
|
+
const busyText = {{ busyLabel }}
|
|
36
|
+
|
|
37
|
+
function retry() {
|
|
38
|
+
if (isBusy()) return
|
|
39
|
+
emit('retry')
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<div role="alert" class="{{ rootClasses }}" @if(testID)testID="{{ testID }}"@endif data-stx-error-state>
|
|
44
|
+
<svg class="h-7 w-7 text-danger" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="10" /><path d="M12 8v4" /><path d="M12 16h.01" /></svg>
|
|
45
|
+
<p :show="heading()" :text="heading()" class="text-base font-semibold text-fg">{{ title }}</p>
|
|
46
|
+
<p :show="detail()" :text="detail()" class="max-w-sm text-sm text-fg-muted">{{ message }}</p>
|
|
47
|
+
<button
|
|
48
|
+
type="button"
|
|
49
|
+
:show="retryText()"
|
|
50
|
+
@if(testID):testID="'{{ testID }}-retry'"@endif
|
|
51
|
+
:disabled="isBusy()"
|
|
52
|
+
:aria-busy="isBusy() ? 'true' : 'false'"
|
|
53
|
+
class="mt-2 min-h-[44px] items-center justify-center rounded-control bg-accent-solid px-5 text-[15px] font-semibold text-accent-ink disabled:opacity-60"
|
|
54
|
+
@click="retry()"
|
|
55
|
+
><span :text="isBusy() ? busyText : retryText()">{{ retryLabel }}</span></button>
|
|
56
|
+
</div>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* An inset grouped section: a heading above a rounded group of rows and an
|
|
4
|
+
* optional note below it. The Settings-app list, which a phone app reaches for
|
|
5
|
+
* whenever a screen is a list of things to open or toggle.
|
|
6
|
+
*
|
|
7
|
+
* One app drew it from a token file and markup copied into some thirty native
|
|
8
|
+
* screens; another drew one card per row with no separators at all. Here the
|
|
9
|
+
* group is the card and the rows are `<GroupedListRow>`s inside it, each
|
|
10
|
+
* drawing its own inset hairline when it is not the first (`separator`), so
|
|
11
|
+
* the same source works on a phone, where there is no `divide-y`.
|
|
12
|
+
*
|
|
13
|
+
* <GroupedList title="Account" footer="Signed in as ada@example.com">
|
|
14
|
+
* <GroupedListRow title="Profile" chevron @select="openProfile()" />
|
|
15
|
+
* <GroupedListRow title="Notifications" separator chevron @select="openAlerts()" />
|
|
16
|
+
* </GroupedList>
|
|
17
|
+
*
|
|
18
|
+
* `title` and `footer` are reactive, so a count or a translated label can
|
|
19
|
+
* change in place. Colours are roles: the group is `panel` on the page, the
|
|
20
|
+
* heading and note `fg-soft`, the corners `rounded-panel`.
|
|
21
|
+
*/
|
|
22
|
+
export const title = $props.title || ''
|
|
23
|
+
export const footer = $props.footer || ''
|
|
24
|
+
/** Flush to the screen edges rather than inset by the gutter. */
|
|
25
|
+
export const flush = $bool($props.flush)
|
|
26
|
+
export const testID = $props.testID || ''
|
|
27
|
+
export const className = $props.className || ''
|
|
28
|
+
|
|
29
|
+
export const groupClasses = `overflow-hidden bg-panel ${flush ? '' : 'mx-4 rounded-panel'}`.replace(/\s+/g, ' ').trim()
|
|
30
|
+
export const noteInset = flush ? 'mx-4' : 'mx-8'
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<script client>
|
|
34
|
+
const heading = useReactiveProp('title', {{ title }})
|
|
35
|
+
const note = useReactiveProp('footer', {{ footer }})
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<section class="flex flex-col {{ className }}" @if(testID)testID="{{ testID }}"@endif data-stx-grouped-list>
|
|
39
|
+
<h2 :show="heading()" :text="heading()" class="mb-1.5 {{ noteInset }} text-[13px] uppercase text-fg-soft">{{ title }}</h2>
|
|
40
|
+
<div class="{{ groupClasses }}">
|
|
41
|
+
<slot />
|
|
42
|
+
</div>
|
|
43
|
+
<p :show="note()" :text="note()" class="mt-1.5 {{ noteInset }} text-[13px] text-fg-soft">{{ footer }}</p>
|
|
44
|
+
</section>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script server>
|
|
2
|
+
/*
|
|
3
|
+
* One row of a `<GroupedList>`: an optional icon tile, a title over an
|
|
4
|
+
* optional subtitle, a value at the end, an optional control in the slot and
|
|
5
|
+
* a disclosure chevron. At least 44pt tall, as a touch target has to be.
|
|
6
|
+
*
|
|
7
|
+
* `separator` draws the hairline above the row, inset to where the text
|
|
8
|
+
* starts (past the tile when there is one). The group cannot draw it on a
|
|
9
|
+
* phone, so the row does; pass it for every row but the first, which in a
|
|
10
|
+
* `:for` is `:separator="index > 0"`.
|
|
11
|
+
*
|
|
12
|
+
* A row is pressable when it has a `chevron` or is `pressable`, and then it
|
|
13
|
+
* emits `select`. Otherwise it is static, for a row that only carries a
|
|
14
|
+
* control in its slot (a Switch) or a value to read.
|
|
15
|
+
*
|
|
16
|
+
* `icon` is inline SVG, drawn white on a tile of the `tint` role (`accent`,
|
|
17
|
+
* `success`, `danger`, `warning`, `info`, `secondary`) - the coloured square
|
|
18
|
+
* a Settings row leads with. `destructive` paints the title `danger`.
|
|
19
|
+
*/
|
|
20
|
+
export const title = $props.title || ''
|
|
21
|
+
export const subtitle = $props.subtitle || ''
|
|
22
|
+
export const value = $props.value || ''
|
|
23
|
+
export const icon = $props.icon || ''
|
|
24
|
+
export const tint = ['accent', 'success', 'danger', 'warning', 'info', 'secondary'].includes($props.tint) ? $props.tint : 'accent'
|
|
25
|
+
export const chevron = $bool($props.chevron)
|
|
26
|
+
export const pressable = $bool($props.pressable) || chevron
|
|
27
|
+
export const destructive = $bool($props.destructive)
|
|
28
|
+
export const separator = $bool($props.separator)
|
|
29
|
+
export const testID = $props.testID || ''
|
|
30
|
+
export const className = $props.className || ''
|
|
31
|
+
|
|
32
|
+
const tintFills = {
|
|
33
|
+
accent: 'bg-accent-solid',
|
|
34
|
+
success: 'bg-success-solid',
|
|
35
|
+
danger: 'bg-danger-solid',
|
|
36
|
+
warning: 'bg-warning-solid',
|
|
37
|
+
info: 'bg-info-solid',
|
|
38
|
+
secondary: 'bg-secondary-solid',
|
|
39
|
+
}
|
|
40
|
+
export const hasIcon = icon !== ''
|
|
41
|
+
export const tag = pressable ? 'button' : 'div'
|
|
42
|
+
export const tileClasses = `flex shrink-0 items-center justify-center h-[29px] w-[29px] rounded-[7px] text-white ${tintFills[tint]}`
|
|
43
|
+
export const rowClasses = `flex flex-row items-center gap-3 w-full min-h-[44px] px-4 py-2.5 text-left ${pressable ? 'cursor-pointer active:bg-surface-hover focus:outline-none focus-visible:bg-surface-hover' : ''} ${className}`.replace(/\s+/g, ' ').trim()
|
|
44
|
+
export const ruleClasses = `h-[0.5px] bg-line ${hasIcon ? 'ml-[57px]' : 'ml-4'}`
|
|
45
|
+
export const titleClasses = `text-[17px] ${destructive ? 'text-danger' : 'text-fg'}`
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<script client>
|
|
49
|
+
const emit = defineEmits(['select'])
|
|
50
|
+
const heading = useReactiveProp('title', {{ title }})
|
|
51
|
+
const detail = useReactiveProp('subtitle', {{ subtitle }})
|
|
52
|
+
const trailing = useReactiveProp('value', {{ value }})
|
|
53
|
+
const ruled = useReactiveProp('separator', {{ separator }})
|
|
54
|
+
|
|
55
|
+
function select() {
|
|
56
|
+
emit('select')
|
|
57
|
+
}
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<div class="flex flex-col" data-stx-grouped-list-row>
|
|
61
|
+
<div :show="ruled()" class="{{ ruleClasses }}" aria-hidden="true"></div>
|
|
62
|
+
<{{ tag }} @if(pressable)type="button" @click="select()"@endif class="{{ rowClasses }}" @if(testID)testID="{{ testID }}"@endif>
|
|
63
|
+
@if(hasIcon)
|
|
64
|
+
<span class="{{ tileClasses }}" aria-hidden="true">{!! icon !!}</span>
|
|
65
|
+
@endif
|
|
66
|
+
<span class="flex flex-1 min-w-0 flex-col">
|
|
67
|
+
<span :text="heading()" class="{{ titleClasses }}">{{ title }}</span>
|
|
68
|
+
<span :show="detail()" :text="detail()" class="text-[15px] text-fg-soft">{{ subtitle }}</span>
|
|
69
|
+
</span>
|
|
70
|
+
<span :show="trailing()" :text="trailing()" class="shrink-0 text-[17px] text-fg-soft">{{ value }}</span>
|
|
71
|
+
<slot />
|
|
72
|
+
@if(chevron)
|
|
73
|
+
<svg class="h-3.5 w-3.5 shrink-0 text-fg-soft" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 18 6-6-6-6" /></svg>
|
|
74
|
+
@endif
|
|
75
|
+
</{{ tag }}>
|
|
76
|
+
</div>
|
package/dist/index.d.ts
CHANGED
|
@@ -49,15 +49,18 @@ export * from './ui/button/index';
|
|
|
49
49
|
export * from './ui/calendar/index';
|
|
50
50
|
export * from './ui/date-range-picker/index';
|
|
51
51
|
export * from './ui/empty-state/index';
|
|
52
|
+
export * from './ui/error-state/index';
|
|
52
53
|
export * from './ui/theme-toggle/index';
|
|
53
54
|
export * from './ui/card/index';
|
|
54
55
|
export * from './ui/checkbox/index';
|
|
56
|
+
export * from './ui/choice-chips/index';
|
|
55
57
|
export * from './ui/combobox/index';
|
|
56
58
|
export * from './ui/command-palette/index';
|
|
57
59
|
export * from './ui/dialog/index';
|
|
58
60
|
export * from './ui/drawer/index';
|
|
59
61
|
export * from './ui/dropdown/index';
|
|
60
62
|
export * from './ui/form/index';
|
|
63
|
+
export * from './ui/grouped-list/index';
|
|
61
64
|
export * from './ui/image/index';
|
|
62
65
|
export * from './ui/input/index';
|
|
63
66
|
export * from './ui/listbox/index';
|