@dumiflex/wp-kit 0.3.0 → 0.4.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.
- package/CHANGELOG.md +77 -51
- package/LICENSE +674 -674
- package/README.md +73 -76
- package/package.json +78 -77
- package/src/Avatar.vue +83 -83
- package/src/Badge.vue +97 -97
- package/src/Banner.vue +118 -118
- package/src/BookmarkButton.vue +27 -27
- package/src/BundleMeta.vue +51 -51
- package/src/Button.vue +103 -103
- package/src/Card.vue +68 -68
- package/src/Checkbox.vue +109 -107
- package/src/Chip.vue +163 -97
- package/src/ChoiceCards.vue +133 -133
- package/src/CloseButton.vue +69 -69
- package/src/CodeBlock.vue +119 -119
- package/src/ColorField.vue +188 -206
- package/src/ColorPicker.vue +201 -201
- package/src/Combobox.vue +331 -334
- package/src/ConfirmDialog.vue +165 -163
- package/src/ConfirmModal.vue +147 -147
- package/src/ConstraintMatrixPreview.vue +708 -708
- package/src/ContextMenu.vue +386 -379
- package/src/CopyButton.vue +156 -156
- package/src/DataTable.vue +292 -292
- package/src/DatePicker.vue +234 -234
- package/src/DescriptionList.vue +73 -73
- package/src/DiffView.vue +68 -68
- package/src/Disclosure.vue +166 -166
- package/src/DragHandle.vue +49 -49
- package/src/Drawer.vue +131 -131
- package/src/DropZone.vue +196 -196
- package/src/DropdownMenu.vue +72 -72
- package/src/EmptyState.vue +111 -111
- package/src/Field.vue +28 -28
- package/src/HsvPicker.vue +208 -208
- package/src/Icon.vue +39 -39
- package/src/IconPicker.vue +209 -209
- package/src/ImageGrid.vue +125 -125
- package/src/InlineEdit.vue +183 -183
- package/src/Input.vue +99 -99
- package/src/Kbd.vue +56 -56
- package/src/Lightbox.vue +173 -173
- package/src/ListFilter.vue +85 -85
- package/src/ListRow.vue +204 -204
- package/src/LoadingMark.vue +175 -161
- package/src/Logo.vue +60 -60
- package/src/Modal.vue +78 -76
- package/src/ModalShell.vue +109 -107
- package/src/Pagination.vue +106 -106
- package/src/Popover.vue +180 -171
- package/src/PostCard.vue +210 -211
- package/src/ProgressBar.vue +90 -90
- package/src/RadioGroup.vue +177 -177
- package/src/RangeSlider.vue +183 -183
- package/src/RelativeDate.vue +35 -35
- package/src/ResizeHandle.vue +143 -143
- package/src/SearchInput.vue +192 -199
- package/src/Select.vue +644 -641
- package/src/Separator.vue +54 -54
- package/src/Skeleton.vue +82 -82
- package/src/Slider.vue +198 -198
- package/src/SortableList.vue +260 -260
- package/src/SplitPane.vue +68 -68
- package/src/StarButton.vue +40 -40
- package/src/Stepper.vue +141 -141
- package/src/SupportLinks.vue +93 -93
- package/src/TagInput.vue +297 -300
- package/src/Textarea.vue +57 -57
- package/src/Timeline.vue +92 -92
- package/src/ToastCard.vue +119 -119
- package/src/ToastHost.vue +40 -40
- package/src/Toggle.vue +36 -36
- package/src/TokenizedValue.vue +310 -310
- package/src/Toolbar.vue +110 -110
- package/src/VirtualList.vue +87 -87
- package/src/VisuallyHidden.vue +29 -29
- package/src/WpButton.vue +75 -75
- package/src/WpCheck.vue +104 -102
- package/src/WpIconButton.vue +107 -107
- package/src/WpImageZoom.vue +544 -544
- package/src/WpNumber.vue +178 -183
- package/src/WpSegmented.vue +175 -175
- package/src/WpSelect.vue +93 -89
- package/src/WpSwitch.vue +163 -163
- package/src/WpTabs.vue +188 -188
- package/src/_modal-motion.css +33 -33
- package/src/_skeleton.css +50 -50
- package/src/axis-color.ts +42 -42
- package/src/button.css +169 -169
- package/src/calendar.ts +59 -59
- package/src/clipboard.ts +50 -50
- package/src/colour-presets.ts +12 -12
- package/src/diff.ts +51 -51
- package/src/drop-zone.ts +41 -41
- package/src/field.css +50 -0
- package/src/flip.ts +237 -237
- package/src/floating-layer.ts +48 -0
- package/src/floating.ts +99 -99
- package/src/hsv.ts +100 -100
- package/src/icon-catalog.ts +52 -52
- package/src/image-zoom.ts +93 -93
- package/src/kind-colour.ts +28 -0
- package/src/logo-paths.ts +21 -21
- package/src/matrix-axis.ts +91 -91
- package/src/pagination.ts +27 -27
- package/src/platform-keys.ts +29 -29
- package/src/rich-tokenize.ts +357 -357
- package/src/select-types.ts +32 -32
- package/src/slider-math.ts +45 -45
- package/src/sortable.ts +22 -22
- package/src/theme/fonts/OFL-Fraunces.txt +93 -93
- package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -93
- package/src/theme/fonts/OFL-Manrope.txt +93 -93
- package/src/theme/looks.css +428 -428
- package/src/theme/palettes.css +254 -254
- package/src/theme/tokens.css +2896 -2894
- package/src/tokens.ts +56 -56
- package/src/tooltip.css +43 -43
- package/src/tooltip.ts +146 -146
- package/src/useDialogFocus.ts +73 -73
- package/src/useGrowableField.ts +357 -357
- package/src/useModalKeyShield.ts +116 -116
- package/src/useToast.ts +48 -48
- package/src/wp-logo.svg +14 -14
- package/src/ChipToggle.vue +0 -92
- package/src/KindChip.vue +0 -53
- package/src/RatingBadge.vue +0 -42
package/src/ListRow.vue
CHANGED
|
@@ -1,204 +1,204 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* One row of a list you click through: a facet ("portrait 12"), a child in a
|
|
4
|
-
* bundle's list, a category in a tree, a dependency that opens its page. The
|
|
5
|
-
* whole row is the target, full width, with an optional icon (or `#start`
|
|
6
|
-
* for anything else, e.g. a
|
|
7
|
-
* and a `count` or `#end` at the right; `arrow` adds a "goes somewhere"
|
|
8
|
-
* arrow that moves on hover.
|
|
9
|
-
*
|
|
10
|
-
* <ListRow :selected="tag === t" toggle icon="tag" :count="12" @click="pick(t)">portrait</ListRow>
|
|
11
|
-
* <ListRow :selected="current === c.key" :icon="kindIcon(c.type)" :description="summary(c)" :muted="!c.enabled">{{ c.name }}</ListRow>
|
|
12
|
-
* <ListRow :as="RouterLink" :to="`/p/${dep.slug}`" arrow><template #start><
|
|
13
|
-
*
|
|
14
|
-
* `selected` marks the row in the accent with a bar on its left. A row that
|
|
15
|
-
* turns a filter on and off says so with `aria-pressed` (pass `toggle`);
|
|
16
|
-
* otherwise a selected row is `aria-current`, the one being shown. `muted`
|
|
17
|
-
* dims a row that is still clickable (a child that is switched off);
|
|
18
|
-
* `disabled` stops it. `depth` indents a row for a simple tree.
|
|
19
|
-
*
|
|
20
|
-
* ArrowUp / ArrowDown / Home / End move between the rows of the same list:
|
|
21
|
-
* the nearest ancestor with `data-wp-rows` (put it on the outer element of a
|
|
22
|
-
* nested tree), else the row's parent. It reads only the shared tokens, so it
|
|
23
|
-
* works on a page and on the canvas.
|
|
24
|
-
*/
|
|
25
|
-
import { computed, useSlots, type Component } from "vue";
|
|
26
|
-
import Icon from "./Icon.vue";
|
|
27
|
-
|
|
28
|
-
const props = withDefaults(defineProps<{
|
|
29
|
-
/** What to render: a button (default), `"a"`, or a link component such as RouterLink. */
|
|
30
|
-
as?: string | Component | undefined;
|
|
31
|
-
selected?: boolean | undefined;
|
|
32
|
-
/** The row turns something on and off: `aria-pressed` instead of `aria-current`. */
|
|
33
|
-
toggle?: boolean | undefined;
|
|
34
|
-
/** PrimeIcons name (`tag` or `pi-tag`) before the label. */
|
|
35
|
-
icon?: string | undefined;
|
|
36
|
-
/** Colour of the icon: any CSS colour. */
|
|
37
|
-
iconColor?: string | undefined;
|
|
38
|
-
/** A second, smaller line under the label. */
|
|
39
|
-
description?: string | undefined;
|
|
40
|
-
count?: number | string | undefined;
|
|
41
|
-
/** An arrow at the right end, for a row that opens another page. */
|
|
42
|
-
arrow?: boolean | undefined;
|
|
43
|
-
/** Dim the row; it stays clickable. */
|
|
44
|
-
muted?: boolean | undefined;
|
|
45
|
-
disabled?: boolean | undefined;
|
|
46
|
-
/** Indent level for a simple tree (0 = top). */
|
|
47
|
-
depth?: number | undefined;
|
|
48
|
-
size?: "sm" | "md" | undefined;
|
|
49
|
-
}>(), { as: "button", size: "md", depth: 0 });
|
|
50
|
-
|
|
51
|
-
const slots = useSlots();
|
|
52
|
-
const isButton = computed(() => props.as === "button");
|
|
53
|
-
|
|
54
|
-
const aria = computed(() => {
|
|
55
|
-
const a: Record<string, string | boolean | undefined> = {};
|
|
56
|
-
if (props.toggle) a["aria-pressed"] = !!props.selected;
|
|
57
|
-
else if (props.selected) a["aria-current"] = "true";
|
|
58
|
-
if (props.disabled && !isButton.value) a["aria-disabled"] = "true";
|
|
59
|
-
return a;
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const style = computed(() => {
|
|
63
|
-
const s: Record<string, string> = {};
|
|
64
|
-
if (props.depth) s["--wp-list-row-depth"] = String(props.depth);
|
|
65
|
-
if (props.iconColor) s["--wp-list-row-icon"] = props.iconColor;
|
|
66
|
-
return Object.keys(s).length ? s : undefined;
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
function onKey(e: KeyboardEvent): void {
|
|
70
|
-
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(e.key)) return;
|
|
71
|
-
const el = e.currentTarget as HTMLElement;
|
|
72
|
-
const list = el.closest("[data-wp-rows]") ?? el.parentElement;
|
|
73
|
-
if (!list) return;
|
|
74
|
-
const rows = Array.from(list.querySelectorAll<HTMLElement>(".wp-list-row"))
|
|
75
|
-
.filter((r) => !r.matches(":disabled, [aria-disabled='true']"));
|
|
76
|
-
const at = rows.indexOf(el);
|
|
77
|
-
if (at < 0) return;
|
|
78
|
-
const next = e.key === "Home" ? 0
|
|
79
|
-
: e.key === "End" ? rows.length - 1
|
|
80
|
-
: e.key === "ArrowDown" ? Math.min(rows.length - 1, at + 1)
|
|
81
|
-
: Math.max(0, at - 1);
|
|
82
|
-
e.preventDefault();
|
|
83
|
-
rows[next]?.focus();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function onClick(e: MouseEvent): void {
|
|
87
|
-
// A link can't be disabled natively; stop it here.
|
|
88
|
-
if (props.disabled && !isButton.value) {
|
|
89
|
-
e.preventDefault();
|
|
90
|
-
e.stopImmediatePropagation();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
</script>
|
|
94
|
-
|
|
95
|
-
<template>
|
|
96
|
-
<component
|
|
97
|
-
:is="as"
|
|
98
|
-
class="wp-list-row"
|
|
99
|
-
:class="[`wp-list-row--${size}`, { 'wp-list-row--muted': muted, 'wp-list-row--two-line': !!description || !!slots.description }]"
|
|
100
|
-
:type="isButton ? 'button' : undefined"
|
|
101
|
-
:disabled="isButton ? disabled : undefined"
|
|
102
|
-
:data-selected="selected || undefined"
|
|
103
|
-
:style="style"
|
|
104
|
-
v-bind="aria"
|
|
105
|
-
@keydown="onKey"
|
|
106
|
-
@click.capture="onClick"
|
|
107
|
-
>
|
|
108
|
-
<span v-if="slots.start" class="wp-list-row__start"><slot name="start" /></span>
|
|
109
|
-
<Icon v-else-if="icon" class="wp-list-row__icon" :name="icon" />
|
|
110
|
-
<span class="wp-list-row__main">
|
|
111
|
-
<span class="wp-list-row__label"><slot /></span>
|
|
112
|
-
<span v-if="description || slots.description" class="wp-list-row__desc">
|
|
113
|
-
<slot name="description">{{ description }}</slot>
|
|
114
|
-
</span>
|
|
115
|
-
</span>
|
|
116
|
-
<span v-if="count !== undefined" class="wp-list-row__count">{{ count }}</span>
|
|
117
|
-
<span v-if="slots.end" class="wp-list-row__end"><slot name="end" /></span>
|
|
118
|
-
<Icon v-if="arrow" class="wp-list-row__arrow" name="arrow-right" />
|
|
119
|
-
</component>
|
|
120
|
-
</template>
|
|
121
|
-
|
|
122
|
-
<style scoped>
|
|
123
|
-
.wp-list-row {
|
|
124
|
-
--wp-list-row-icon: var(--wp-text-muted);
|
|
125
|
-
display: flex;
|
|
126
|
-
align-items: center;
|
|
127
|
-
gap: var(--wp-space-3);
|
|
128
|
-
box-sizing: border-box;
|
|
129
|
-
width: 100%;
|
|
130
|
-
min-height: var(--wp-control-h-md);
|
|
131
|
-
margin: 0;
|
|
132
|
-
padding: var(--wp-space-2) var(--wp-space-4);
|
|
133
|
-
padding-left: calc(var(--wp-space-4) + var(--wp-list-row-depth, 0) * var(--wp-space-6));
|
|
134
|
-
border: 0;
|
|
135
|
-
border-radius: min(6px, var(--wp-radius-cap, 999px));
|
|
136
|
-
background: transparent;
|
|
137
|
-
color: var(--wp-text);
|
|
138
|
-
font: inherit;
|
|
139
|
-
font-family: var(--wp-font-sans);
|
|
140
|
-
font-size: var(--wp-text-sm);
|
|
141
|
-
line-height: 1.35;
|
|
142
|
-
text-align: left;
|
|
143
|
-
text-decoration: none;
|
|
144
|
-
cursor: pointer;
|
|
145
|
-
transition: background var(--wp-motion-quick) ease, color var(--wp-motion-quick) ease;
|
|
146
|
-
}
|
|
147
|
-
.wp-list-row--sm {
|
|
148
|
-
min-height: var(--wp-control-h-sm);
|
|
149
|
-
padding-top: var(--wp-space-1);
|
|
150
|
-
padding-bottom: var(--wp-space-1);
|
|
151
|
-
gap: var(--wp-space-2);
|
|
152
|
-
color: var(--wp-text-muted);
|
|
153
|
-
font-size: var(--wp-text-xs);
|
|
154
|
-
}
|
|
155
|
-
.wp-list-row--two-line { align-items: flex-start; }
|
|
156
|
-
.wp-list-row:hover:not(:disabled) { background: var(--wp-row-hover); color: var(--wp-text); }
|
|
157
|
-
.wp-list-row:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
|
|
158
|
-
.wp-list-row:disabled, .wp-list-row[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
|
|
159
|
-
.wp-list-row--muted { opacity: 0.55; }
|
|
160
|
-
.wp-list-row[data-selected] {
|
|
161
|
-
background: color-mix(in oklab, var(--wp-accent-500) 12%, transparent);
|
|
162
|
-
box-shadow: inset 2px 0 var(--wp-accent-500);
|
|
163
|
-
color: var(--wp-accent-text-strong);
|
|
164
|
-
}
|
|
165
|
-
.wp-list-row[data-selected]:focus-visible { box-shadow: inset 2px 0 var(--wp-accent-500), var(--wp-focus-ring); }
|
|
166
|
-
.wp-list-row__icon {
|
|
167
|
-
flex: none;
|
|
168
|
-
width: 1.1em;
|
|
169
|
-
font-size: 0.9em;
|
|
170
|
-
text-align: center;
|
|
171
|
-
color: var(--wp-list-row-icon);
|
|
172
|
-
}
|
|
173
|
-
.wp-list-row--two-line .wp-list-row__icon { padding-top: 0.25em; }
|
|
174
|
-
.wp-list-row[data-selected] .wp-list-row__icon { color: var(--wp-accent-text); }
|
|
175
|
-
.wp-list-row__start { display: inline-flex; align-items: center; flex: none; }
|
|
176
|
-
.wp-list-row__main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
|
|
177
|
-
.wp-list-row__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
178
|
-
.wp-list-row__desc {
|
|
179
|
-
color: var(--wp-text-dim);
|
|
180
|
-
font-size: var(--wp-text-xs);
|
|
181
|
-
overflow-wrap: anywhere;
|
|
182
|
-
}
|
|
183
|
-
.wp-list-row__count {
|
|
184
|
-
flex: none;
|
|
185
|
-
color: var(--wp-text-dim);
|
|
186
|
-
font-family: var(--wp-font-mono);
|
|
187
|
-
font-size: var(--wp-text-xs);
|
|
188
|
-
font-variant-numeric: tabular-nums;
|
|
189
|
-
}
|
|
190
|
-
.wp-list-row[data-selected] .wp-list-row__count { color: inherit; }
|
|
191
|
-
.wp-list-row__end { display: inline-flex; align-items: center; gap: var(--wp-space-2); flex: none; }
|
|
192
|
-
.wp-list-row__arrow {
|
|
193
|
-
flex: none;
|
|
194
|
-
align-self: center;
|
|
195
|
-
font-size: 0.85em;
|
|
196
|
-
color: var(--wp-text-dim);
|
|
197
|
-
transition: transform var(--wp-motion-quick) ease, color var(--wp-motion-quick) ease;
|
|
198
|
-
}
|
|
199
|
-
.wp-list-row:hover .wp-list-row__arrow { color: var(--wp-accent-text); transform: translateX(2px); }
|
|
200
|
-
@media (prefers-reduced-motion: reduce) {
|
|
201
|
-
.wp-list-row, .wp-list-row__arrow { transition: none; }
|
|
202
|
-
.wp-list-row:hover .wp-list-row__arrow { transform: none; }
|
|
203
|
-
}
|
|
204
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* One row of a list you click through: a facet ("portrait 12"), a child in a
|
|
4
|
+
* bundle's list, a category in a tree, a dependency that opens its page. The
|
|
5
|
+
* whole row is the target, full width, with an optional icon (or `#start`
|
|
6
|
+
* for anything else, e.g. a kind Chip), a label, a second `description` line,
|
|
7
|
+
* and a `count` or `#end` at the right; `arrow` adds a "goes somewhere"
|
|
8
|
+
* arrow that moves on hover.
|
|
9
|
+
*
|
|
10
|
+
* <ListRow :selected="tag === t" toggle icon="tag" :count="12" @click="pick(t)">portrait</ListRow>
|
|
11
|
+
* <ListRow :selected="current === c.key" :icon="kindIcon(c.type)" :description="summary(c)" :muted="!c.enabled">{{ c.name }}</ListRow>
|
|
12
|
+
* <ListRow :as="RouterLink" :to="`/p/${dep.slug}`" arrow><template #start><Chip :color="kindColour(t)">{{ t }}</Chip></template>{{ dep.slug }}</ListRow>
|
|
13
|
+
*
|
|
14
|
+
* `selected` marks the row in the accent with a bar on its left. A row that
|
|
15
|
+
* turns a filter on and off says so with `aria-pressed` (pass `toggle`);
|
|
16
|
+
* otherwise a selected row is `aria-current`, the one being shown. `muted`
|
|
17
|
+
* dims a row that is still clickable (a child that is switched off);
|
|
18
|
+
* `disabled` stops it. `depth` indents a row for a simple tree.
|
|
19
|
+
*
|
|
20
|
+
* ArrowUp / ArrowDown / Home / End move between the rows of the same list:
|
|
21
|
+
* the nearest ancestor with `data-wp-rows` (put it on the outer element of a
|
|
22
|
+
* nested tree), else the row's parent. It reads only the shared tokens, so it
|
|
23
|
+
* works on a page and on the canvas.
|
|
24
|
+
*/
|
|
25
|
+
import { computed, useSlots, type Component } from "vue";
|
|
26
|
+
import Icon from "./Icon.vue";
|
|
27
|
+
|
|
28
|
+
const props = withDefaults(defineProps<{
|
|
29
|
+
/** What to render: a button (default), `"a"`, or a link component such as RouterLink. */
|
|
30
|
+
as?: string | Component | undefined;
|
|
31
|
+
selected?: boolean | undefined;
|
|
32
|
+
/** The row turns something on and off: `aria-pressed` instead of `aria-current`. */
|
|
33
|
+
toggle?: boolean | undefined;
|
|
34
|
+
/** PrimeIcons name (`tag` or `pi-tag`) before the label. */
|
|
35
|
+
icon?: string | undefined;
|
|
36
|
+
/** Colour of the icon: any CSS colour. */
|
|
37
|
+
iconColor?: string | undefined;
|
|
38
|
+
/** A second, smaller line under the label. */
|
|
39
|
+
description?: string | undefined;
|
|
40
|
+
count?: number | string | undefined;
|
|
41
|
+
/** An arrow at the right end, for a row that opens another page. */
|
|
42
|
+
arrow?: boolean | undefined;
|
|
43
|
+
/** Dim the row; it stays clickable. */
|
|
44
|
+
muted?: boolean | undefined;
|
|
45
|
+
disabled?: boolean | undefined;
|
|
46
|
+
/** Indent level for a simple tree (0 = top). */
|
|
47
|
+
depth?: number | undefined;
|
|
48
|
+
size?: "sm" | "md" | undefined;
|
|
49
|
+
}>(), { as: "button", size: "md", depth: 0 });
|
|
50
|
+
|
|
51
|
+
const slots = useSlots();
|
|
52
|
+
const isButton = computed(() => props.as === "button");
|
|
53
|
+
|
|
54
|
+
const aria = computed(() => {
|
|
55
|
+
const a: Record<string, string | boolean | undefined> = {};
|
|
56
|
+
if (props.toggle) a["aria-pressed"] = !!props.selected;
|
|
57
|
+
else if (props.selected) a["aria-current"] = "true";
|
|
58
|
+
if (props.disabled && !isButton.value) a["aria-disabled"] = "true";
|
|
59
|
+
return a;
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const style = computed(() => {
|
|
63
|
+
const s: Record<string, string> = {};
|
|
64
|
+
if (props.depth) s["--wp-list-row-depth"] = String(props.depth);
|
|
65
|
+
if (props.iconColor) s["--wp-list-row-icon"] = props.iconColor;
|
|
66
|
+
return Object.keys(s).length ? s : undefined;
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function onKey(e: KeyboardEvent): void {
|
|
70
|
+
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(e.key)) return;
|
|
71
|
+
const el = e.currentTarget as HTMLElement;
|
|
72
|
+
const list = el.closest("[data-wp-rows]") ?? el.parentElement;
|
|
73
|
+
if (!list) return;
|
|
74
|
+
const rows = Array.from(list.querySelectorAll<HTMLElement>(".wp-list-row"))
|
|
75
|
+
.filter((r) => !r.matches(":disabled, [aria-disabled='true']"));
|
|
76
|
+
const at = rows.indexOf(el);
|
|
77
|
+
if (at < 0) return;
|
|
78
|
+
const next = e.key === "Home" ? 0
|
|
79
|
+
: e.key === "End" ? rows.length - 1
|
|
80
|
+
: e.key === "ArrowDown" ? Math.min(rows.length - 1, at + 1)
|
|
81
|
+
: Math.max(0, at - 1);
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
rows[next]?.focus();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function onClick(e: MouseEvent): void {
|
|
87
|
+
// A link can't be disabled natively; stop it here.
|
|
88
|
+
if (props.disabled && !isButton.value) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
e.stopImmediatePropagation();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<template>
|
|
96
|
+
<component
|
|
97
|
+
:is="as"
|
|
98
|
+
class="wp-list-row"
|
|
99
|
+
:class="[`wp-list-row--${size}`, { 'wp-list-row--muted': muted, 'wp-list-row--two-line': !!description || !!slots.description }]"
|
|
100
|
+
:type="isButton ? 'button' : undefined"
|
|
101
|
+
:disabled="isButton ? disabled : undefined"
|
|
102
|
+
:data-selected="selected || undefined"
|
|
103
|
+
:style="style"
|
|
104
|
+
v-bind="aria"
|
|
105
|
+
@keydown="onKey"
|
|
106
|
+
@click.capture="onClick"
|
|
107
|
+
>
|
|
108
|
+
<span v-if="slots.start" class="wp-list-row__start"><slot name="start" /></span>
|
|
109
|
+
<Icon v-else-if="icon" class="wp-list-row__icon" :name="icon" />
|
|
110
|
+
<span class="wp-list-row__main">
|
|
111
|
+
<span class="wp-list-row__label"><slot /></span>
|
|
112
|
+
<span v-if="description || slots.description" class="wp-list-row__desc">
|
|
113
|
+
<slot name="description">{{ description }}</slot>
|
|
114
|
+
</span>
|
|
115
|
+
</span>
|
|
116
|
+
<span v-if="count !== undefined" class="wp-list-row__count">{{ count }}</span>
|
|
117
|
+
<span v-if="slots.end" class="wp-list-row__end"><slot name="end" /></span>
|
|
118
|
+
<Icon v-if="arrow" class="wp-list-row__arrow" name="arrow-right" />
|
|
119
|
+
</component>
|
|
120
|
+
</template>
|
|
121
|
+
|
|
122
|
+
<style scoped>
|
|
123
|
+
.wp-list-row {
|
|
124
|
+
--wp-list-row-icon: var(--wp-text-muted);
|
|
125
|
+
display: flex;
|
|
126
|
+
align-items: center;
|
|
127
|
+
gap: var(--wp-space-3);
|
|
128
|
+
box-sizing: border-box;
|
|
129
|
+
width: 100%;
|
|
130
|
+
min-height: var(--wp-control-h-md);
|
|
131
|
+
margin: 0;
|
|
132
|
+
padding: var(--wp-space-2) var(--wp-space-4);
|
|
133
|
+
padding-left: calc(var(--wp-space-4) + var(--wp-list-row-depth, 0) * var(--wp-space-6));
|
|
134
|
+
border: 0;
|
|
135
|
+
border-radius: min(6px, var(--wp-radius-cap, 999px));
|
|
136
|
+
background: transparent;
|
|
137
|
+
color: var(--wp-text);
|
|
138
|
+
font: inherit;
|
|
139
|
+
font-family: var(--wp-font-sans);
|
|
140
|
+
font-size: var(--wp-text-sm);
|
|
141
|
+
line-height: 1.35;
|
|
142
|
+
text-align: left;
|
|
143
|
+
text-decoration: none;
|
|
144
|
+
cursor: pointer;
|
|
145
|
+
transition: background var(--wp-motion-quick) ease, color var(--wp-motion-quick) ease;
|
|
146
|
+
}
|
|
147
|
+
.wp-list-row--sm {
|
|
148
|
+
min-height: var(--wp-control-h-sm);
|
|
149
|
+
padding-top: var(--wp-space-1);
|
|
150
|
+
padding-bottom: var(--wp-space-1);
|
|
151
|
+
gap: var(--wp-space-2);
|
|
152
|
+
color: var(--wp-text-muted);
|
|
153
|
+
font-size: var(--wp-text-xs);
|
|
154
|
+
}
|
|
155
|
+
.wp-list-row--two-line { align-items: flex-start; }
|
|
156
|
+
.wp-list-row:hover:not(:disabled) { background: var(--wp-row-hover); color: var(--wp-text); }
|
|
157
|
+
.wp-list-row:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
|
|
158
|
+
.wp-list-row:disabled, .wp-list-row[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
|
|
159
|
+
.wp-list-row--muted { opacity: 0.55; }
|
|
160
|
+
.wp-list-row[data-selected] {
|
|
161
|
+
background: color-mix(in oklab, var(--wp-accent-500) 12%, transparent);
|
|
162
|
+
box-shadow: inset 2px 0 var(--wp-accent-500);
|
|
163
|
+
color: var(--wp-accent-text-strong);
|
|
164
|
+
}
|
|
165
|
+
.wp-list-row[data-selected]:focus-visible { box-shadow: inset 2px 0 var(--wp-accent-500), var(--wp-focus-ring); }
|
|
166
|
+
.wp-list-row__icon {
|
|
167
|
+
flex: none;
|
|
168
|
+
width: 1.1em;
|
|
169
|
+
font-size: 0.9em;
|
|
170
|
+
text-align: center;
|
|
171
|
+
color: var(--wp-list-row-icon);
|
|
172
|
+
}
|
|
173
|
+
.wp-list-row--two-line .wp-list-row__icon { padding-top: 0.25em; }
|
|
174
|
+
.wp-list-row[data-selected] .wp-list-row__icon { color: var(--wp-accent-text); }
|
|
175
|
+
.wp-list-row__start { display: inline-flex; align-items: center; flex: none; }
|
|
176
|
+
.wp-list-row__main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
|
|
177
|
+
.wp-list-row__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
178
|
+
.wp-list-row__desc {
|
|
179
|
+
color: var(--wp-text-dim);
|
|
180
|
+
font-size: var(--wp-text-xs);
|
|
181
|
+
overflow-wrap: anywhere;
|
|
182
|
+
}
|
|
183
|
+
.wp-list-row__count {
|
|
184
|
+
flex: none;
|
|
185
|
+
color: var(--wp-text-dim);
|
|
186
|
+
font-family: var(--wp-font-mono);
|
|
187
|
+
font-size: var(--wp-text-xs);
|
|
188
|
+
font-variant-numeric: tabular-nums;
|
|
189
|
+
}
|
|
190
|
+
.wp-list-row[data-selected] .wp-list-row__count { color: inherit; }
|
|
191
|
+
.wp-list-row__end { display: inline-flex; align-items: center; gap: var(--wp-space-2); flex: none; }
|
|
192
|
+
.wp-list-row__arrow {
|
|
193
|
+
flex: none;
|
|
194
|
+
align-self: center;
|
|
195
|
+
font-size: 0.85em;
|
|
196
|
+
color: var(--wp-text-dim);
|
|
197
|
+
transition: transform var(--wp-motion-quick) ease, color var(--wp-motion-quick) ease;
|
|
198
|
+
}
|
|
199
|
+
.wp-list-row:hover .wp-list-row__arrow { color: var(--wp-accent-text); transform: translateX(2px); }
|
|
200
|
+
@media (prefers-reduced-motion: reduce) {
|
|
201
|
+
.wp-list-row, .wp-list-row__arrow { transition: none; }
|
|
202
|
+
.wp-list-row:hover .wp-list-row__arrow { transform: none; }
|
|
203
|
+
}
|
|
204
|
+
</style>
|