@dumiflex/wp-kit 0.0.0-stage → 0.3.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.
Files changed (128) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE +674 -0
  3. package/README.md +76 -3
  4. package/package.json +77 -6
  5. package/src/Avatar.vue +83 -0
  6. package/src/Badge.vue +97 -0
  7. package/src/Banner.vue +118 -0
  8. package/src/BookmarkButton.vue +27 -0
  9. package/src/BundleMeta.vue +51 -0
  10. package/src/Button.vue +103 -0
  11. package/src/Card.vue +68 -0
  12. package/src/Checkbox.vue +107 -0
  13. package/src/Chip.vue +97 -0
  14. package/src/ChipToggle.vue +92 -0
  15. package/src/ChoiceCards.vue +133 -0
  16. package/src/CloseButton.vue +69 -0
  17. package/src/CodeBlock.vue +119 -0
  18. package/src/ColorField.vue +206 -0
  19. package/src/ColorPicker.vue +201 -0
  20. package/src/Combobox.vue +334 -0
  21. package/src/ConfirmDialog.vue +163 -0
  22. package/src/ConfirmModal.vue +147 -0
  23. package/src/ConstraintMatrixPreview.vue +708 -0
  24. package/src/ContextMenu.vue +379 -0
  25. package/src/CopyButton.vue +156 -0
  26. package/src/DataTable.vue +292 -0
  27. package/src/DatePicker.vue +234 -0
  28. package/src/DescriptionList.vue +73 -0
  29. package/src/DiffView.vue +68 -0
  30. package/src/Disclosure.vue +166 -0
  31. package/src/DragHandle.vue +49 -0
  32. package/src/Drawer.vue +131 -0
  33. package/src/DropZone.vue +196 -0
  34. package/src/DropdownMenu.vue +72 -0
  35. package/src/EmptyState.vue +111 -0
  36. package/src/Field.vue +28 -0
  37. package/src/HsvPicker.vue +208 -0
  38. package/src/Icon.vue +39 -0
  39. package/src/IconPicker.vue +209 -0
  40. package/src/ImageGrid.vue +125 -0
  41. package/src/InlineEdit.vue +183 -0
  42. package/src/Input.vue +99 -0
  43. package/src/Kbd.vue +56 -0
  44. package/src/KindChip.vue +53 -0
  45. package/src/Lightbox.vue +173 -0
  46. package/src/ListFilter.vue +85 -0
  47. package/src/ListRow.vue +204 -0
  48. package/src/LoadingMark.vue +161 -0
  49. package/src/Logo.vue +60 -0
  50. package/src/Modal.vue +76 -0
  51. package/src/ModalShell.vue +107 -0
  52. package/src/Pagination.vue +106 -0
  53. package/src/Popover.vue +171 -0
  54. package/src/PostCard.vue +211 -0
  55. package/src/ProgressBar.vue +90 -0
  56. package/src/RadioGroup.vue +177 -0
  57. package/src/RangeSlider.vue +183 -0
  58. package/src/RatingBadge.vue +42 -0
  59. package/src/RelativeDate.vue +35 -0
  60. package/src/ResizeHandle.vue +143 -0
  61. package/src/SearchInput.vue +199 -0
  62. package/src/Select.vue +641 -0
  63. package/src/Separator.vue +54 -0
  64. package/src/Skeleton.vue +82 -0
  65. package/src/Slider.vue +198 -0
  66. package/src/SortableList.vue +260 -0
  67. package/src/SplitPane.vue +68 -0
  68. package/src/StarButton.vue +40 -0
  69. package/src/Stepper.vue +141 -0
  70. package/src/SupportLinks.vue +93 -0
  71. package/src/TagInput.vue +300 -0
  72. package/src/Textarea.vue +57 -0
  73. package/src/Timeline.vue +92 -0
  74. package/src/ToastCard.vue +119 -0
  75. package/src/ToastHost.vue +40 -0
  76. package/src/Toggle.vue +36 -0
  77. package/src/TokenizedValue.vue +310 -0
  78. package/src/Toolbar.vue +110 -0
  79. package/src/VirtualList.vue +87 -0
  80. package/src/VisuallyHidden.vue +29 -0
  81. package/src/WpButton.vue +75 -0
  82. package/src/WpCheck.vue +102 -0
  83. package/src/WpIconButton.vue +107 -0
  84. package/src/WpImageZoom.vue +544 -0
  85. package/src/WpNumber.vue +183 -0
  86. package/src/WpSegmented.vue +175 -0
  87. package/src/WpSelect.vue +89 -0
  88. package/src/WpSwitch.vue +163 -0
  89. package/src/WpTabs.vue +188 -0
  90. package/src/_modal-motion.css +33 -0
  91. package/src/_skeleton.css +50 -0
  92. package/src/axis-color.ts +42 -0
  93. package/src/button.css +169 -0
  94. package/src/calendar.ts +59 -0
  95. package/src/clipboard.ts +50 -0
  96. package/src/colour-presets.ts +12 -0
  97. package/src/diff.ts +51 -0
  98. package/src/drop-zone.ts +41 -0
  99. package/src/flip.ts +237 -0
  100. package/src/floating.ts +99 -0
  101. package/src/hsv.ts +100 -0
  102. package/src/icon-catalog.ts +52 -0
  103. package/src/image-zoom.ts +93 -0
  104. package/src/logo-paths.ts +21 -0
  105. package/src/matrix-axis.ts +91 -0
  106. package/src/pagination.ts +27 -0
  107. package/src/platform-keys.ts +29 -0
  108. package/src/rich-tokenize.ts +357 -0
  109. package/src/select-types.ts +32 -0
  110. package/src/slider-math.ts +45 -0
  111. package/src/sortable.ts +22 -0
  112. package/src/theme/fonts/OFL-Fraunces.txt +93 -0
  113. package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -0
  114. package/src/theme/fonts/OFL-Manrope.txt +93 -0
  115. package/src/theme/fonts/fraunces-latin-wght-normal.woff2 +0 -0
  116. package/src/theme/fonts/jetbrains-mono-latin.woff2 +0 -0
  117. package/src/theme/fonts/manrope-latin-wght-normal.woff2 +0 -0
  118. package/src/theme/looks.css +428 -0
  119. package/src/theme/palettes.css +254 -0
  120. package/src/theme/tokens.css +2894 -0
  121. package/src/tokens.ts +56 -0
  122. package/src/tooltip.css +43 -0
  123. package/src/tooltip.ts +146 -0
  124. package/src/useDialogFocus.ts +73 -0
  125. package/src/useGrowableField.ts +357 -0
  126. package/src/useModalKeyShield.ts +116 -0
  127. package/src/useToast.ts +48 -0
  128. package/src/wp-logo.svg +14 -0
package/src/Card.vue ADDED
@@ -0,0 +1,68 @@
1
+ <script setup lang="ts">
2
+ import { useSlots, ref, onMounted, onBeforeUnmount } from "vue";
3
+
4
+ interface Props {
5
+ title?: string | undefined;
6
+ subtitle?: string | undefined;
7
+ padding?: boolean | undefined;
8
+ /** Stick the card header (and its `subheader` slot, e.g. a bulk-edit
9
+ * toolbar) to the top of the nearest scroll container so its actions stay
10
+ * reachable when scrolling a long list — new rows always land at the
11
+ * bottom, so the toolbar must follow. Publishes the measured height of the
12
+ * whole stuck region as `--wp-card-header-h` so a sticky `<thead>` inside
13
+ * the body can offset itself right below it (updates as the subheader
14
+ * toolbar appears/disappears or density changes). */
15
+ stickyHeader?: boolean | undefined;
16
+ }
17
+ const props = withDefaults(defineProps<Props>(), { padding: true, stickyHeader: false });
18
+
19
+ const slots = useSlots();
20
+ const root = ref<HTMLElement | null>(null);
21
+ const stickyEl = ref<HTMLElement | null>(null);
22
+ let ro: ResizeObserver | null = null;
23
+ /** The stuck region is taller than a third of the window (an AI draft or a
24
+ * bulk-add box open in the subheader): it would cover the list it belongs
25
+ * to and the page couldn't scroll past it, so it scrolls with the card. */
26
+ const tooTall = ref(false);
27
+
28
+ function syncStickyHeight(): void {
29
+ if (!root.value || !stickyEl.value) return;
30
+ const h = Math.round(stickyEl.value.getBoundingClientRect().height);
31
+ tooTall.value = typeof window !== "undefined" && window.innerHeight > 0 && h > window.innerHeight / 3;
32
+ root.value.style.setProperty("--wp-card-header-h", tooTall.value ? "0px" : `${h}px`);
33
+ }
34
+
35
+ onMounted(() => {
36
+ if (!props.stickyHeader || !stickyEl.value) return;
37
+ syncStickyHeight();
38
+ if (typeof ResizeObserver !== "undefined") {
39
+ ro = new ResizeObserver(syncStickyHeight);
40
+ ro.observe(stickyEl.value);
41
+ }
42
+ window.addEventListener("resize", syncStickyHeight);
43
+ });
44
+ onBeforeUnmount(() => {
45
+ ro?.disconnect();
46
+ ro = null;
47
+ window.removeEventListener("resize", syncStickyHeight);
48
+ });
49
+ </script>
50
+
51
+ <template>
52
+ <section ref="root" class="wp-card" :class="{ 'wp-card--sticky-header': stickyHeader && !tooTall }">
53
+ <div ref="stickyEl" class="wp-card__sticky">
54
+ <header v-if="title || slots.actions" class="wp-card__header">
55
+ <div class="wp-card__title-wrap">
56
+ <h2 v-if="title" class="wp-card__title">{{ title }}</h2>
57
+ <p v-if="subtitle" class="wp-card__subtitle">{{ subtitle }}</p>
58
+ </div>
59
+ <span class="wp-spacer" />
60
+ <slot name="actions" />
61
+ </header>
62
+ <slot name="subheader" />
63
+ </div>
64
+ <div :class="padding ? 'wp-card__body' : ''">
65
+ <slot />
66
+ </div>
67
+ </section>
68
+ </template>
@@ -0,0 +1,107 @@
1
+ <script setup lang="ts">
2
+ import { computed } from "vue";
3
+
4
+ interface Props {
5
+ modelValue: boolean;
6
+ label?: string | undefined;
7
+ disabled?: boolean | undefined;
8
+ error?: boolean | undefined;
9
+ id?: string | undefined;
10
+ ariaLabel?: string | undefined;
11
+ /**
12
+ * Tri-state indicator. When true AND `modelValue` is false, the
13
+ * checkbox renders a horizontal dash instead of a checkmark and
14
+ * announces `aria-checked="mixed"`. Used by group/select-all
15
+ * controls where the underlying collection is partially selected.
16
+ * `modelValue=true` always wins — a fully-checked box never
17
+ * renders as indeterminate even if the prop is set.
18
+ */
19
+ indeterminate?: boolean | undefined;
20
+ /**
21
+ * Draw the whole row as an input-height field (border, fill, full width)
22
+ * whose label fills it, for a yes/no filter that sits in a form grid
23
+ * beside Selects (the list pages' "Favorites only").
24
+ */
25
+ field?: boolean | undefined;
26
+ }
27
+ const props = defineProps<Props>();
28
+
29
+ const emit = defineEmits<{
30
+ (e: "update:modelValue", v: boolean): void;
31
+ }>();
32
+
33
+ const showIndeterminate = computed<boolean>(
34
+ () => !!props.indeterminate && !props.modelValue,
35
+ );
36
+
37
+ const ariaChecked = computed<"true" | "false" | "mixed">(() => {
38
+ if (props.modelValue) return "true";
39
+ if (showIndeterminate.value) return "mixed";
40
+ return "false";
41
+ });
42
+
43
+ function toggle() {
44
+ if (props.disabled) return;
45
+ emit("update:modelValue", !props.modelValue);
46
+ }
47
+ </script>
48
+
49
+ <template>
50
+ <span class="wp-checkbox" :class="{ 'is-disabled': disabled, 'wp-checkbox--field': field }">
51
+ <!-- Wrapper is a <span> rather than a <label> on purpose. Native <label>
52
+ re-dispatches click on its associated form control in some pointer
53
+ paths (notably when the click target is the SVG inside the button),
54
+ firing the button's @click twice — which double-toggled and left
55
+ the underlying model unchanged when a parent also wired a click
56
+ handler. The span wrapper has no synthetic-dispatch behavior. -->
57
+ <button
58
+ type="button"
59
+ class="wp-check"
60
+ :data-checked="modelValue ? 'true' : 'false'"
61
+ :data-indeterminate="showIndeterminate ? 'true' : 'false'"
62
+ :aria-checked="ariaChecked"
63
+ :aria-label="ariaLabel ?? label"
64
+ :aria-invalid="error || undefined"
65
+ :disabled="disabled"
66
+ role="checkbox"
67
+ @click="toggle"
68
+ >
69
+ <!-- tokens.css gives `.wp-check svg` pointer-events: none so the entire
70
+ button area (including the check mark) is a single click target —
71
+ clicks land on the button itself, not the SVG child. Without this,
72
+ a click on the SVG centerpoint could route through wrapper-bubble
73
+ paths in some browsers/automation drivers and double-fire toggle.
74
+ No inline style here: the TUI look hides the drawn mark (it reads
75
+ [x] instead), and an inline display would beat it. -->
76
+ <svg
77
+ v-if="modelValue"
78
+ viewBox="0 0 12 12"
79
+ fill="none"
80
+ aria-hidden="true"
81
+ >
82
+ <path
83
+ d="M3 6.2l2.2 2.2L9 4.4"
84
+ stroke="currentColor"
85
+ stroke-width="1.8"
86
+ stroke-linecap="round"
87
+ stroke-linejoin="round"
88
+ />
89
+ </svg>
90
+ <!-- Indeterminate dash. Same pointer-events rule as the checkmark. -->
91
+ <svg
92
+ v-else-if="showIndeterminate"
93
+ viewBox="0 0 12 12"
94
+ fill="none"
95
+ aria-hidden="true"
96
+ >
97
+ <path
98
+ d="M3 6h6"
99
+ stroke="currentColor"
100
+ stroke-width="1.8"
101
+ stroke-linecap="round"
102
+ />
103
+ </svg>
104
+ </button>
105
+ <span v-if="label" class="wp-checkbox__label" @click="toggle">{{ label }}</span>
106
+ </span>
107
+ </template>
package/src/Chip.vue ADDED
@@ -0,0 +1,97 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A small tag: a post's tag, a category, a status. `removable` adds a ✕
4
+ * that emits `remove`. `as="button"` (or `as="a"` / a link component such as
5
+ * RouterLink) makes the whole chip something you press, for a chip that
6
+ * takes you somewhere ("show everything tagged portrait"); a pressable
7
+ * chip has no ✕. For a filter that turns on and off, use ChipToggle.
8
+ */
9
+ import { computed, type Component } from "vue";
10
+ import Icon from "./Icon.vue";
11
+
12
+ type Tone = "default" | "accent" | "success" | "warn" | "danger" | "info";
13
+
14
+ interface Props {
15
+ tone?: Tone | undefined;
16
+ icon?: string | null | undefined;
17
+ removable?: boolean | undefined;
18
+ /**
19
+ * Free-form colour (hex or any CSS colour), e.g. a category's. When set it
20
+ * overrides the tone and renders a tinted pill: background = colour @ 18%,
21
+ * border = colour @ 42%, and the text blends the colour toward
22
+ * `--wp-text` so a pale pick stays readable in light mode and a dark pick
23
+ * in dark mode. `null` reads as no colour (a category without one).
24
+ * This is what CategoryChip used to be: `<Chip :color :icon>{{ name }}</Chip>`.
25
+ */
26
+ color?: string | null | undefined;
27
+ /** What to render: a span (default), a button, or a link. */
28
+ as?: string | Component | undefined;
29
+ }
30
+ const props = withDefaults(defineProps<Props>(), { tone: "default", as: "span" });
31
+
32
+ const emit = defineEmits<{
33
+ (e: "remove"): void;
34
+ }>();
35
+
36
+ const pressable = computed(() => props.as !== "span");
37
+ const classes = computed(() => [
38
+ "wp-chip",
39
+ pressable.value && "wp-chip--action",
40
+ props.color ? "wp-chip--color" : props.tone !== "default" && `wp-chip--${props.tone}`,
41
+ ]);
42
+
43
+ const colorStyle = computed(() => {
44
+ if (!props.color) return undefined;
45
+ const c = props.color;
46
+ return {
47
+ color: `color-mix(in oklab, ${c} 65%, var(--wp-text))`,
48
+ background: `color-mix(in oklab, ${c} 18%, transparent)`,
49
+ borderColor: `color-mix(in oklab, ${c} 42%, transparent)`,
50
+ };
51
+ });
52
+
53
+ function onRemove(e: MouseEvent) {
54
+ e.stopPropagation();
55
+ emit("remove");
56
+ }
57
+ </script>
58
+
59
+ <template>
60
+ <component
61
+ :is="as"
62
+ :class="classes"
63
+ :style="colorStyle"
64
+ :type="as === 'button' ? 'button' : undefined"
65
+ >
66
+ <!-- 10px sub-ICON_SM — pill density pass dropped chip font 11→10.5
67
+ and the previous 12px icon read oversized next to the smaller
68
+ label. Matches the new chip body weight. -->
69
+ <Icon v-if="icon" :name="icon" :size="10" />
70
+ <slot />
71
+ <button
72
+ v-if="removable && !pressable"
73
+ type="button"
74
+ class="wp-chip__close"
75
+ aria-label="Remove"
76
+ @click="onRemove"
77
+ >
78
+ <!-- Close glyph also drops to 10px so chip-with-X stays balanced
79
+ against the slimmer body. Hit target stays 20×20 via the
80
+ button's min sizing in tokens.css. -->
81
+ <Icon name="times" :size="10" />
82
+ </button>
83
+ </component>
84
+ </template>
85
+
86
+ <style scoped>
87
+ .wp-chip--action {
88
+ font-family: inherit;
89
+ text-decoration: none;
90
+ cursor: pointer;
91
+ transition: border-color var(--wp-motion-quick) ease, color var(--wp-motion-quick) ease, filter var(--wp-motion-quick) ease;
92
+ }
93
+ .wp-chip--action:hover { border-color: var(--wp-border-strong); color: var(--wp-text); }
94
+ .wp-chip--action.wp-chip--color:hover,
95
+ .wp-chip--action.wp-chip--accent:hover { color: inherit; filter: brightness(1.08); }
96
+ .wp-chip--action:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
97
+ </style>
@@ -0,0 +1,92 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A pill you press to turn a filter or flag on and off: a tag filter, a
4
+ * module-type filter, "Recommended" on a version, a category you pick.
5
+ * `pressed` lights it in the accent, or in `color` (a kind colour, a
6
+ * category's colour) when given; with `color` the icon wears it even when
7
+ * off, so a row of type filters reads at a glance. `count` shows a small
8
+ * number after the label.
9
+ *
10
+ * <ChipToggle :pressed="tag === t.slug" icon="pi-tag" :count="t.usage" @click="pick(t)">{{ t.name }}</ChipToggle>
11
+ * <ChipToggle :pressed="kind === 'wildcard'" color="var(--wp-kind-wildcard)" icon="pi-sparkles">Wildcard</ChipToggle>
12
+ *
13
+ * A real `<button>` with `aria-pressed`; it reads only the shared tokens, so
14
+ * it works on a page and on the canvas.
15
+ */
16
+ import { computed } from "vue";
17
+ import Icon from "./Icon.vue";
18
+
19
+ const props = withDefaults(defineProps<{
20
+ pressed?: boolean | undefined;
21
+ /** PrimeIcons name (`tag` or `pi-tag`) before the label. */
22
+ icon?: string | undefined;
23
+ /** Tint when pressed (and of the icon): any CSS colour. Default the accent. */
24
+ color?: string | null | undefined;
25
+ count?: number | string | undefined;
26
+ size?: "sm" | "md" | undefined;
27
+ disabled?: boolean | undefined;
28
+ }>(), { pressed: false, size: "sm" });
29
+
30
+ const style = computed(() => (props.color ? { "--chip-toggle-c": props.color } : undefined));
31
+ </script>
32
+
33
+ <template>
34
+ <button
35
+ type="button"
36
+ class="wp-chip-toggle"
37
+ :class="[`wp-chip-toggle--${size}`, { 'wp-chip-toggle--tinted': !!color }]"
38
+ :style="style"
39
+ :aria-pressed="pressed"
40
+ :disabled="disabled"
41
+ >
42
+ <Icon v-if="icon" class="wp-chip-toggle__icon" :name="icon" :size="11" />
43
+ <span class="wp-chip-toggle__label"><slot /></span>
44
+ <span v-if="count !== undefined" class="wp-chip-toggle__count">{{ count }}</span>
45
+ </button>
46
+ </template>
47
+
48
+ <style scoped>
49
+ .wp-chip-toggle {
50
+ --chip-toggle-c: var(--wp-accent-500);
51
+ display: inline-flex;
52
+ align-items: center;
53
+ gap: var(--wp-space-2);
54
+ height: var(--wp-control-h-sm);
55
+ padding: 0 var(--wp-space-4);
56
+ border: 1px solid var(--wp-border);
57
+ border-radius: var(--wp-radius-cap, 999px);
58
+ background: var(--wp-bg-3);
59
+ color: var(--wp-text-muted);
60
+ font: inherit;
61
+ font-family: var(--wp-font-sans);
62
+ font-size: var(--wp-text-sm);
63
+ font-weight: 500;
64
+ line-height: 1;
65
+ white-space: nowrap;
66
+ cursor: pointer;
67
+ transition: background var(--wp-motion-quick) ease, border-color var(--wp-motion-quick) ease, color var(--wp-motion-quick) ease;
68
+ }
69
+ .wp-chip-toggle--md { height: var(--wp-control-h-md); padding: 0 var(--wp-space-5); font-size: var(--wp-text-base); }
70
+ .wp-chip-toggle:hover:not(:disabled) { border-color: var(--wp-border-strong); color: var(--wp-text); }
71
+ .wp-chip-toggle:focus-visible { outline: none; box-shadow: var(--wp-focus-ring); }
72
+ .wp-chip-toggle:disabled { opacity: 0.45; cursor: not-allowed; }
73
+ .wp-chip-toggle--tinted .wp-chip-toggle__icon { color: var(--chip-toggle-c); }
74
+ .wp-chip-toggle[aria-pressed="true"] {
75
+ border-color: color-mix(in oklab, var(--chip-toggle-c) 45%, transparent);
76
+ background: color-mix(in oklab, var(--chip-toggle-c) 16%, transparent);
77
+ color: var(--wp-accent-text-strong);
78
+ }
79
+ .wp-chip-toggle--tinted[aria-pressed="true"] { color: var(--chip-toggle-c); }
80
+ .wp-chip-toggle__count {
81
+ padding: 1px var(--wp-space-3);
82
+ border-radius: var(--wp-radius-cap, 999px);
83
+ background: var(--wp-bg-4, var(--wp-bg-2));
84
+ color: var(--wp-text-dim);
85
+ font-family: var(--wp-font-mono);
86
+ font-size: var(--wp-text-xs);
87
+ }
88
+ .wp-chip-toggle[aria-pressed="true"] .wp-chip-toggle__count {
89
+ background: color-mix(in oklab, var(--chip-toggle-c) 22%, transparent);
90
+ color: inherit;
91
+ }
92
+ </style>
@@ -0,0 +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>
@@ -0,0 +1,69 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Close button: the one × that closes a dialog, drawer, panel or banner. A
4
+ * square, quiet icon button on the 24/32/40 height scale, named by `label`
5
+ * for screen readers and shown as its tooltip. Works on the canvas
6
+ * (`size="sm"`) and in the manager (`md`).
7
+ *
8
+ * <CloseButton @click="close" />
9
+ * <CloseButton label="Dismiss" size="sm" @click="hide" />
10
+ *
11
+ * Manager icon actions other than closing use `Button` with an icon and no
12
+ * text.
13
+ */
14
+ import { vTooltip } from "./tooltip";
15
+
16
+ withDefaults(defineProps<{
17
+ label?: string | undefined;
18
+ size?: "sm" | "md" | "lg" | undefined;
19
+ disabled?: boolean | undefined;
20
+ /** A shortcut for the tooltip, e.g. "Esc". */
21
+ kbd?: string | undefined;
22
+ }>(), { label: "Close", size: "md", kbd: undefined });
23
+
24
+ const emit = defineEmits<{ (e: "click", ev: MouseEvent): void }>();
25
+ </script>
26
+
27
+ <template>
28
+ <button
29
+ v-tooltip="{ text: label, kbd }"
30
+ type="button"
31
+ class="wp-close-btn"
32
+ :data-size="size"
33
+ :aria-label="label"
34
+ :disabled="disabled"
35
+ @click="emit('click', $event)"
36
+ >
37
+ <i class="pi pi-times" aria-hidden="true" />
38
+ </button>
39
+ </template>
40
+
41
+ <style scoped>
42
+ .wp-close-btn {
43
+ display: inline-grid;
44
+ place-items: center;
45
+ flex: none;
46
+ width: var(--wp-control-h-md);
47
+ height: var(--wp-control-h-md);
48
+ margin: 0;
49
+ padding: 0;
50
+ border: 1px solid transparent;
51
+ border-radius: var(--wp-radius);
52
+ background: transparent;
53
+ color: var(--wp-text-muted);
54
+ cursor: pointer;
55
+ transition: background var(--wp-motion-hover), color var(--wp-motion-hover), border-color var(--wp-motion-hover);
56
+ }
57
+ .wp-close-btn[data-size="sm"] { width: var(--wp-control-h-sm); height: var(--wp-control-h-sm); border-radius: var(--wp-radius-sm); }
58
+ .wp-close-btn[data-size="lg"] { width: var(--wp-control-h-lg); height: var(--wp-control-h-lg); }
59
+ .wp-close-btn .pi { font-size: 12px; }
60
+ .wp-close-btn[data-size="sm"] .pi { font-size: 10px; }
61
+ .wp-close-btn[data-size="lg"] .pi { font-size: 14px; }
62
+ .wp-close-btn:hover:not(:disabled) { background: var(--wp-bg-3); color: var(--wp-text); border-color: var(--wp-border); }
63
+ .wp-close-btn:active:not(:disabled) { background: var(--wp-bg-4); }
64
+ .wp-close-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
65
+ .wp-close-btn:disabled { opacity: 0.45; cursor: not-allowed; }
66
+ @media (prefers-reduced-motion: reduce) {
67
+ .wp-close-btn { transition: none; }
68
+ }
69
+ </style>