@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/Chip.vue
CHANGED
|
@@ -1,97 +1,163 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
<
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
.
|
|
97
|
-
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* The one pill in the kit: a tag, a status, a count, a category, a module
|
|
4
|
+
* type, a filter you turn on and off. Everything else is a prop:
|
|
5
|
+
*
|
|
6
|
+
* <Chip>portrait</Chip> a label
|
|
7
|
+
* <Chip tone="warn" icon="pi-exclamation-triangle">2 conflicts</Chip>
|
|
8
|
+
* <Chip :color="cat.color" :icon="cat.icon">{{ cat.name }}</Chip>
|
|
9
|
+
* <Chip :color="kindColour(type)">{{ type }}</Chip> a module type
|
|
10
|
+
* <Chip tone="success" dot>recommended</Chip>
|
|
11
|
+
* <Chip removable @remove="drop(t)">{{ t }}</Chip>
|
|
12
|
+
* <Chip as="button" icon="tag" @click="open(t)">{{ t }}</Chip> takes you somewhere
|
|
13
|
+
* <Chip :pressed="tag === t" :count="12" size="sm" @click="pick(t)">{{ t }}</Chip> a filter
|
|
14
|
+
*
|
|
15
|
+
* `pressed` (true or false) makes it a toggle: a `<button>` with
|
|
16
|
+
* `aria-pressed`, neutral when off and lit in the accent (or `color`) when
|
|
17
|
+
* on; with `color` its icon wears the colour even when off, so a row of type
|
|
18
|
+
* filters reads at a glance. `count` puts a small number after the label.
|
|
19
|
+
* `size`: `xs` (default, a label in a line of text), `sm` (24px, a filter
|
|
20
|
+
* row) or `md` (32px, next to a md control).
|
|
21
|
+
*/
|
|
22
|
+
import { computed, type Component } from "vue";
|
|
23
|
+
import Icon from "./Icon.vue";
|
|
24
|
+
|
|
25
|
+
type Tone = "default" | "accent" | "success" | "warn" | "danger" | "info";
|
|
26
|
+
|
|
27
|
+
interface Props {
|
|
28
|
+
tone?: Tone | undefined;
|
|
29
|
+
icon?: string | null | undefined;
|
|
30
|
+
removable?: boolean | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Free-form colour (hex or any CSS colour), e.g. a category's or a kind's.
|
|
33
|
+
* On a label it overrides the tone and tints the pill: background = colour
|
|
34
|
+
* @ 18%, border = colour @ 42%, and the text blends the colour toward
|
|
35
|
+
* `--wp-text` so a pale pick stays readable in light mode and a dark pick
|
|
36
|
+
* in dark mode. On a toggle it is the "on" colour. `null` reads as none.
|
|
37
|
+
*/
|
|
38
|
+
color?: string | null | undefined;
|
|
39
|
+
/** What to render: a span (default), a button, or a link. A toggle is always a button. */
|
|
40
|
+
as?: string | Component | undefined;
|
|
41
|
+
/** Makes it a toggle (`aria-pressed`). Leave unset for a plain label. */
|
|
42
|
+
pressed?: boolean | undefined;
|
|
43
|
+
/** A small number after the label. */
|
|
44
|
+
count?: number | string | undefined;
|
|
45
|
+
/** A status dot before the label, in the chip's colour. */
|
|
46
|
+
dot?: boolean | undefined;
|
|
47
|
+
size?: "xs" | "sm" | "md" | undefined;
|
|
48
|
+
disabled?: boolean | undefined;
|
|
49
|
+
}
|
|
50
|
+
const props = withDefaults(defineProps<Props>(), { tone: "default", as: "span", size: "xs", pressed: undefined });
|
|
51
|
+
|
|
52
|
+
const emit = defineEmits<{
|
|
53
|
+
(e: "remove"): void;
|
|
54
|
+
}>();
|
|
55
|
+
|
|
56
|
+
const toggle = computed(() => props.pressed !== undefined);
|
|
57
|
+
const tag = computed(() => (toggle.value ? "button" : props.as));
|
|
58
|
+
const pressable = computed(() => tag.value !== "span");
|
|
59
|
+
const classes = computed(() => [
|
|
60
|
+
"wp-chip",
|
|
61
|
+
`wp-chip--${props.size}`,
|
|
62
|
+
pressable.value && "wp-chip--action",
|
|
63
|
+
toggle.value && "wp-chip--toggle",
|
|
64
|
+
toggle.value && props.color && "wp-chip--tinted",
|
|
65
|
+
!toggle.value && (props.color ? "wp-chip--color" : props.tone !== "default" && `wp-chip--${props.tone}`),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
const colorStyle = computed(() => {
|
|
69
|
+
if (!props.color) return undefined;
|
|
70
|
+
const c = props.color;
|
|
71
|
+
if (toggle.value) return { "--wp-chip-c": c };
|
|
72
|
+
return {
|
|
73
|
+
color: `color-mix(in oklab, ${c} 65%, var(--wp-text))`,
|
|
74
|
+
background: `color-mix(in oklab, ${c} 18%, transparent)`,
|
|
75
|
+
borderColor: `color-mix(in oklab, ${c} 42%, transparent)`,
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
function onRemove(e: MouseEvent) {
|
|
80
|
+
e.stopPropagation();
|
|
81
|
+
emit("remove");
|
|
82
|
+
}
|
|
83
|
+
</script>
|
|
84
|
+
|
|
85
|
+
<template>
|
|
86
|
+
<component
|
|
87
|
+
:is="tag"
|
|
88
|
+
:class="classes"
|
|
89
|
+
:style="colorStyle"
|
|
90
|
+
:type="tag === 'button' ? 'button' : undefined"
|
|
91
|
+
:aria-pressed="toggle ? pressed : undefined"
|
|
92
|
+
:disabled="tag === 'button' ? disabled : undefined"
|
|
93
|
+
>
|
|
94
|
+
<span v-if="dot" class="wp-chip__dot" aria-hidden="true" />
|
|
95
|
+
<!-- 10px sub-ICON_SM: the chip font is 10.5px and a 12px icon read
|
|
96
|
+
oversized next to it. Larger chips get a larger icon. -->
|
|
97
|
+
<Icon v-if="icon" class="wp-chip__icon" :name="icon" :size="size === 'xs' ? 10 : 11" />
|
|
98
|
+
<slot />
|
|
99
|
+
<span v-if="count !== undefined" class="wp-chip__count">{{ count }}</span>
|
|
100
|
+
<button
|
|
101
|
+
v-if="removable && !pressable"
|
|
102
|
+
type="button"
|
|
103
|
+
class="wp-chip__close"
|
|
104
|
+
aria-label="Remove"
|
|
105
|
+
@click="onRemove"
|
|
106
|
+
>
|
|
107
|
+
<!-- Close glyph also drops to 10px so chip-with-X stays balanced
|
|
108
|
+
against the slimmer body. Hit target stays 20×20 via the
|
|
109
|
+
button's min sizing in tokens.css. -->
|
|
110
|
+
<Icon name="times" :size="10" />
|
|
111
|
+
</button>
|
|
112
|
+
</component>
|
|
113
|
+
</template>
|
|
114
|
+
|
|
115
|
+
<style scoped>
|
|
116
|
+
/* xs is the base `.wp-chip` in theme/tokens.css (19px). sm and md sit on the
|
|
117
|
+
control height scale so a filter row lines up with the fields beside it. */
|
|
118
|
+
.wp-chip--sm, .wp-chip--md {
|
|
119
|
+
height: var(--wp-control-h-sm);
|
|
120
|
+
padding: 0 var(--wp-space-4);
|
|
121
|
+
gap: var(--wp-space-2);
|
|
122
|
+
font-size: var(--wp-text-sm);
|
|
123
|
+
line-height: 1;
|
|
124
|
+
}
|
|
125
|
+
.wp-chip--md { height: var(--wp-control-h-md); padding: 0 var(--wp-space-5); font-size: var(--wp-text-base); }
|
|
126
|
+
|
|
127
|
+
.wp-chip--action {
|
|
128
|
+
font-family: inherit;
|
|
129
|
+
text-decoration: none;
|
|
130
|
+
cursor: pointer;
|
|
131
|
+
transition: background var(--wp-motion-quick) ease, border-color var(--wp-motion-quick) ease, color var(--wp-motion-quick) ease, filter var(--wp-motion-quick) ease;
|
|
132
|
+
}
|
|
133
|
+
.wp-chip--action:hover:not(:disabled) { border-color: var(--wp-border-strong); color: var(--wp-text); }
|
|
134
|
+
.wp-chip--action.wp-chip--color:hover,
|
|
135
|
+
.wp-chip--action.wp-chip--accent:hover { color: inherit; filter: brightness(1.08); }
|
|
136
|
+
.wp-chip--action:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
|
|
137
|
+
.wp-chip--action:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
138
|
+
|
|
139
|
+
/* A toggle: neutral when off, lit in the accent or its colour when on. */
|
|
140
|
+
.wp-chip--toggle { --wp-chip-c: var(--wp-accent-500); }
|
|
141
|
+
.wp-chip--tinted .wp-chip__icon { color: var(--wp-chip-c); }
|
|
142
|
+
.wp-chip--toggle[aria-pressed="true"] {
|
|
143
|
+
border-color: color-mix(in oklab, var(--wp-chip-c) 45%, transparent);
|
|
144
|
+
background: color-mix(in oklab, var(--wp-chip-c) 16%, transparent);
|
|
145
|
+
color: var(--wp-accent-text-strong);
|
|
146
|
+
}
|
|
147
|
+
.wp-chip--tinted[aria-pressed="true"] { color: var(--wp-chip-c); }
|
|
148
|
+
|
|
149
|
+
.wp-chip__count {
|
|
150
|
+
padding: 0 var(--wp-space-2);
|
|
151
|
+
border-radius: var(--wp-radius-cap, 999px);
|
|
152
|
+
background: var(--wp-bg-4, var(--wp-bg-2));
|
|
153
|
+
color: var(--wp-text-dim);
|
|
154
|
+
font-family: var(--wp-font-mono);
|
|
155
|
+
font-size: 0.9em;
|
|
156
|
+
line-height: 1.4;
|
|
157
|
+
}
|
|
158
|
+
.wp-chip--sm .wp-chip__count, .wp-chip--md .wp-chip__count { padding: 1px var(--wp-space-3); font-size: var(--wp-text-xs); }
|
|
159
|
+
.wp-chip--toggle[aria-pressed="true"] .wp-chip__count {
|
|
160
|
+
background: color-mix(in oklab, var(--wp-chip-c) 22%, transparent);
|
|
161
|
+
color: inherit;
|
|
162
|
+
}
|
|
163
|
+
</style>
|
package/src/ChoiceCards.vue
CHANGED
|
@@ -1,133 +1,133 @@
|
|
|
1
|
-
<script setup lang="ts" generic="T extends string">
|
|
2
|
-
/**
|
|
3
|
-
* Choice cards: pick one of a handful of options that each need a picture to
|
|
4
|
-
* be understood (a colour theme, a look, a layout). Each card shows the
|
|
5
|
-
* `preview` slot, a name and, unless `compact`, a one-line hint (compact puts
|
|
6
|
-
* the hint in the card's tooltip).
|
|
7
|
-
*
|
|
8
|
-
* It is a radio group (APG), like the segmented control: only the chosen card
|
|
9
|
-
* is in the Tab order, the arrow keys move to the next card and choose it,
|
|
10
|
-
* Home/End jump to the ends.
|
|
11
|
-
*
|
|
12
|
-
* <ChoiceCards v-model="look" :options="LOOKS" aria-label="Look">
|
|
13
|
-
* <template #preview="{ option }"><LookDrawing :id="option.value" /></template>
|
|
14
|
-
* </ChoiceCards>
|
|
15
|
-
*/
|
|
16
|
-
import { nextTick, ref } from "vue";
|
|
17
|
-
|
|
18
|
-
export interface ChoiceCardOption<V extends string = string> {
|
|
19
|
-
value: V;
|
|
20
|
-
label: string;
|
|
21
|
-
hint?: string | undefined;
|
|
22
|
-
/** Inline style for the card, e.g. CSS variables its preview reads. */
|
|
23
|
-
style?: Record<string, string> | undefined;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const props = defineProps<{
|
|
27
|
-
modelValue: T;
|
|
28
|
-
options: ChoiceCardOption<T>[];
|
|
29
|
-
/** Three to a row, smaller, hint as tooltip: for narrow panels. */
|
|
30
|
-
compact?: boolean | undefined;
|
|
31
|
-
ariaLabel?: string | undefined;
|
|
32
|
-
/** `data-test` of each card is `<testPrefix>-<value>`. */
|
|
33
|
-
testPrefix?: string | undefined;
|
|
34
|
-
}>();
|
|
35
|
-
|
|
36
|
-
const emit = defineEmits<{ (e: "update:modelValue", v: T): void }>();
|
|
37
|
-
defineSlots<{ preview?(p: { option: ChoiceCardOption<T>; on: boolean }): unknown }>();
|
|
38
|
-
const rootEl = ref<HTMLElement | null>(null);
|
|
39
|
-
|
|
40
|
-
function pick(v: T): void {
|
|
41
|
-
if (v !== props.modelValue) emit("update:modelValue", v);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function tabStop(): T | undefined {
|
|
45
|
-
return (props.options.find((o) => o.value === props.modelValue) ?? props.options[0])?.value;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function onKeydown(ev: KeyboardEvent): void {
|
|
49
|
-
const all = props.options;
|
|
50
|
-
if (!all.length) return;
|
|
51
|
-
const at = all.findIndex((o) => o.value === props.modelValue);
|
|
52
|
-
let next: number;
|
|
53
|
-
switch (ev.key) {
|
|
54
|
-
case "ArrowRight": case "ArrowDown": next = (at + 1) % all.length; break;
|
|
55
|
-
case "ArrowLeft": case "ArrowUp": next = at < 0 ? all.length - 1 : (at - 1 + all.length) % all.length; break;
|
|
56
|
-
case "Home": next = 0; break;
|
|
57
|
-
case "End": next = all.length - 1; break;
|
|
58
|
-
default: return;
|
|
59
|
-
}
|
|
60
|
-
ev.preventDefault();
|
|
61
|
-
pick(all[next].value);
|
|
62
|
-
void nextTick(() => rootEl.value?.querySelectorAll<HTMLElement>("[role=radio]")[next]?.focus());
|
|
63
|
-
}
|
|
64
|
-
</script>
|
|
65
|
-
|
|
66
|
-
<template>
|
|
67
|
-
<div
|
|
68
|
-
ref="rootEl"
|
|
69
|
-
class="wp-choice-cards"
|
|
70
|
-
:class="{ 'wp-choice-cards--compact': compact }"
|
|
71
|
-
role="radiogroup"
|
|
72
|
-
:aria-label="ariaLabel"
|
|
73
|
-
>
|
|
74
|
-
<button
|
|
75
|
-
v-for="o in options"
|
|
76
|
-
:key="o.value"
|
|
77
|
-
:title="compact ? o.hint : undefined"
|
|
78
|
-
type="button"
|
|
79
|
-
role="radio"
|
|
80
|
-
class="wp-choice-card"
|
|
81
|
-
:aria-checked="modelValue === o.value"
|
|
82
|
-
:tabindex="o.value === tabStop() ? 0 : -1"
|
|
83
|
-
:data-test="testPrefix ? `${testPrefix}-${o.value}` : undefined"
|
|
84
|
-
:style="o.style"
|
|
85
|
-
@click="pick(o.value)"
|
|
86
|
-
@keydown="onKeydown"
|
|
87
|
-
>
|
|
88
|
-
<slot name="preview" :option="o" :on="modelValue === o.value" />
|
|
89
|
-
<span class="wp-choice-card__name">{{ o.label }}</span>
|
|
90
|
-
<span v-if="!compact && o.hint" class="wp-choice-card__hint">{{ o.hint }}</span>
|
|
91
|
-
</button>
|
|
92
|
-
</div>
|
|
93
|
-
</template>
|
|
94
|
-
|
|
95
|
-
<style scoped>
|
|
96
|
-
.wp-choice-cards {
|
|
97
|
-
display: grid;
|
|
98
|
-
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
|
99
|
-
gap: var(--wp-space-4);
|
|
100
|
-
width: 100%;
|
|
101
|
-
}
|
|
102
|
-
.wp-choice-cards--compact { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--wp-space-3); }
|
|
103
|
-
.wp-choice-card {
|
|
104
|
-
display: flex;
|
|
105
|
-
flex-direction: column;
|
|
106
|
-
align-items: stretch;
|
|
107
|
-
gap: var(--wp-space-3);
|
|
108
|
-
min-width: 0;
|
|
109
|
-
padding: var(--wp-space-4);
|
|
110
|
-
border: 1px solid var(--wp-border);
|
|
111
|
-
border-radius: var(--wp-radius);
|
|
112
|
-
background: var(--wp-bg-2);
|
|
113
|
-
color: var(--wp-text);
|
|
114
|
-
font: inherit;
|
|
115
|
-
text-align: left;
|
|
116
|
-
cursor: pointer;
|
|
117
|
-
transition: border-color var(--wp-motion-hover), background var(--wp-motion-hover);
|
|
118
|
-
}
|
|
119
|
-
.wp-choice-card:hover { border-color: var(--wp-border-strong); background: var(--wp-bg-3); }
|
|
120
|
-
.wp-choice-card[aria-checked="true"] {
|
|
121
|
-
border-color: var(--wp-accent-500);
|
|
122
|
-
box-shadow: inset 0 0 0 1px var(--wp-accent-500);
|
|
123
|
-
background: color-mix(in oklab, var(--wp-accent-500) 10%, var(--wp-bg-2));
|
|
124
|
-
}
|
|
125
|
-
.wp-choice-card:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
|
|
126
|
-
.wp-choice-card__name { font-size: var(--wp-text-base); font-weight: 600; line-height: var(--wp-line-base); }
|
|
127
|
-
.wp-choice-card__hint { font-size: var(--wp-text-xs); line-height: var(--wp-line-xs); color: var(--wp-text-muted); }
|
|
128
|
-
.wp-choice-cards--compact .wp-choice-card { padding: var(--wp-space-3); gap: var(--wp-space-2); }
|
|
129
|
-
.wp-choice-cards--compact .wp-choice-card__name { font-size: var(--wp-text-xs); }
|
|
130
|
-
@media (prefers-reduced-motion: reduce) {
|
|
131
|
-
.wp-choice-card { transition: none; }
|
|
132
|
-
}
|
|
133
|
-
</style>
|
|
1
|
+
<script setup lang="ts" generic="T extends string">
|
|
2
|
+
/**
|
|
3
|
+
* Choice cards: pick one of a handful of options that each need a picture to
|
|
4
|
+
* be understood (a colour theme, a look, a layout). Each card shows the
|
|
5
|
+
* `preview` slot, a name and, unless `compact`, a one-line hint (compact puts
|
|
6
|
+
* the hint in the card's tooltip).
|
|
7
|
+
*
|
|
8
|
+
* It is a radio group (APG), like the segmented control: only the chosen card
|
|
9
|
+
* is in the Tab order, the arrow keys move to the next card and choose it,
|
|
10
|
+
* Home/End jump to the ends.
|
|
11
|
+
*
|
|
12
|
+
* <ChoiceCards v-model="look" :options="LOOKS" aria-label="Look">
|
|
13
|
+
* <template #preview="{ option }"><LookDrawing :id="option.value" /></template>
|
|
14
|
+
* </ChoiceCards>
|
|
15
|
+
*/
|
|
16
|
+
import { nextTick, ref } from "vue";
|
|
17
|
+
|
|
18
|
+
export interface ChoiceCardOption<V extends string = string> {
|
|
19
|
+
value: V;
|
|
20
|
+
label: string;
|
|
21
|
+
hint?: string | undefined;
|
|
22
|
+
/** Inline style for the card, e.g. CSS variables its preview reads. */
|
|
23
|
+
style?: Record<string, string> | undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const props = defineProps<{
|
|
27
|
+
modelValue: T;
|
|
28
|
+
options: ChoiceCardOption<T>[];
|
|
29
|
+
/** Three to a row, smaller, hint as tooltip: for narrow panels. */
|
|
30
|
+
compact?: boolean | undefined;
|
|
31
|
+
ariaLabel?: string | undefined;
|
|
32
|
+
/** `data-test` of each card is `<testPrefix>-<value>`. */
|
|
33
|
+
testPrefix?: string | undefined;
|
|
34
|
+
}>();
|
|
35
|
+
|
|
36
|
+
const emit = defineEmits<{ (e: "update:modelValue", v: T): void }>();
|
|
37
|
+
defineSlots<{ preview?(p: { option: ChoiceCardOption<T>; on: boolean }): unknown }>();
|
|
38
|
+
const rootEl = ref<HTMLElement | null>(null);
|
|
39
|
+
|
|
40
|
+
function pick(v: T): void {
|
|
41
|
+
if (v !== props.modelValue) emit("update:modelValue", v);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function tabStop(): T | undefined {
|
|
45
|
+
return (props.options.find((o) => o.value === props.modelValue) ?? props.options[0])?.value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function onKeydown(ev: KeyboardEvent): void {
|
|
49
|
+
const all = props.options;
|
|
50
|
+
if (!all.length) return;
|
|
51
|
+
const at = all.findIndex((o) => o.value === props.modelValue);
|
|
52
|
+
let next: number;
|
|
53
|
+
switch (ev.key) {
|
|
54
|
+
case "ArrowRight": case "ArrowDown": next = (at + 1) % all.length; break;
|
|
55
|
+
case "ArrowLeft": case "ArrowUp": next = at < 0 ? all.length - 1 : (at - 1 + all.length) % all.length; break;
|
|
56
|
+
case "Home": next = 0; break;
|
|
57
|
+
case "End": next = all.length - 1; break;
|
|
58
|
+
default: return;
|
|
59
|
+
}
|
|
60
|
+
ev.preventDefault();
|
|
61
|
+
pick(all[next].value);
|
|
62
|
+
void nextTick(() => rootEl.value?.querySelectorAll<HTMLElement>("[role=radio]")[next]?.focus());
|
|
63
|
+
}
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div
|
|
68
|
+
ref="rootEl"
|
|
69
|
+
class="wp-choice-cards"
|
|
70
|
+
:class="{ 'wp-choice-cards--compact': compact }"
|
|
71
|
+
role="radiogroup"
|
|
72
|
+
:aria-label="ariaLabel"
|
|
73
|
+
>
|
|
74
|
+
<button
|
|
75
|
+
v-for="o in options"
|
|
76
|
+
:key="o.value"
|
|
77
|
+
:title="compact ? o.hint : undefined"
|
|
78
|
+
type="button"
|
|
79
|
+
role="radio"
|
|
80
|
+
class="wp-choice-card"
|
|
81
|
+
:aria-checked="modelValue === o.value"
|
|
82
|
+
:tabindex="o.value === tabStop() ? 0 : -1"
|
|
83
|
+
:data-test="testPrefix ? `${testPrefix}-${o.value}` : undefined"
|
|
84
|
+
:style="o.style"
|
|
85
|
+
@click="pick(o.value)"
|
|
86
|
+
@keydown="onKeydown"
|
|
87
|
+
>
|
|
88
|
+
<slot name="preview" :option="o" :on="modelValue === o.value" />
|
|
89
|
+
<span class="wp-choice-card__name">{{ o.label }}</span>
|
|
90
|
+
<span v-if="!compact && o.hint" class="wp-choice-card__hint">{{ o.hint }}</span>
|
|
91
|
+
</button>
|
|
92
|
+
</div>
|
|
93
|
+
</template>
|
|
94
|
+
|
|
95
|
+
<style scoped>
|
|
96
|
+
.wp-choice-cards {
|
|
97
|
+
display: grid;
|
|
98
|
+
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
|
99
|
+
gap: var(--wp-space-4);
|
|
100
|
+
width: 100%;
|
|
101
|
+
}
|
|
102
|
+
.wp-choice-cards--compact { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--wp-space-3); }
|
|
103
|
+
.wp-choice-card {
|
|
104
|
+
display: flex;
|
|
105
|
+
flex-direction: column;
|
|
106
|
+
align-items: stretch;
|
|
107
|
+
gap: var(--wp-space-3);
|
|
108
|
+
min-width: 0;
|
|
109
|
+
padding: var(--wp-space-4);
|
|
110
|
+
border: 1px solid var(--wp-border);
|
|
111
|
+
border-radius: var(--wp-radius);
|
|
112
|
+
background: var(--wp-bg-2);
|
|
113
|
+
color: var(--wp-text);
|
|
114
|
+
font: inherit;
|
|
115
|
+
text-align: left;
|
|
116
|
+
cursor: pointer;
|
|
117
|
+
transition: border-color var(--wp-motion-hover), background var(--wp-motion-hover);
|
|
118
|
+
}
|
|
119
|
+
.wp-choice-card:hover { border-color: var(--wp-border-strong); background: var(--wp-bg-3); }
|
|
120
|
+
.wp-choice-card[aria-checked="true"] {
|
|
121
|
+
border-color: var(--wp-accent-500);
|
|
122
|
+
box-shadow: inset 0 0 0 1px var(--wp-accent-500);
|
|
123
|
+
background: color-mix(in oklab, var(--wp-accent-500) 10%, var(--wp-bg-2));
|
|
124
|
+
}
|
|
125
|
+
.wp-choice-card:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
|
|
126
|
+
.wp-choice-card__name { font-size: var(--wp-text-base); font-weight: 600; line-height: var(--wp-line-base); }
|
|
127
|
+
.wp-choice-card__hint { font-size: var(--wp-text-xs); line-height: var(--wp-line-xs); color: var(--wp-text-muted); }
|
|
128
|
+
.wp-choice-cards--compact .wp-choice-card { padding: var(--wp-space-3); gap: var(--wp-space-2); }
|
|
129
|
+
.wp-choice-cards--compact .wp-choice-card__name { font-size: var(--wp-text-xs); }
|
|
130
|
+
@media (prefers-reduced-motion: reduce) {
|
|
131
|
+
.wp-choice-card { transition: none; }
|
|
132
|
+
}
|
|
133
|
+
</style>
|