@dumiflex/wp-kit 0.3.0 → 0.5.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 (130) hide show
  1. package/CHANGELOG.md +92 -51
  2. package/LICENSE +674 -674
  3. package/README.md +73 -76
  4. package/package.json +78 -77
  5. package/src/Avatar.vue +83 -83
  6. package/src/Badge.vue +97 -97
  7. package/src/Banner.vue +118 -118
  8. package/src/BookmarkButton.vue +27 -27
  9. package/src/BundleMeta.vue +51 -51
  10. package/src/Button.vue +103 -103
  11. package/src/Card.vue +68 -68
  12. package/src/Checkbox.vue +109 -107
  13. package/src/Chip.vue +163 -97
  14. package/src/ChoiceCards.vue +133 -133
  15. package/src/CloseButton.vue +69 -69
  16. package/src/CodeBlock.vue +146 -119
  17. package/src/ColorField.vue +188 -206
  18. package/src/ColorPicker.vue +201 -201
  19. package/src/Combobox.vue +331 -334
  20. package/src/ConfirmDialog.vue +165 -163
  21. package/src/ConfirmModal.vue +147 -147
  22. package/src/ConstraintMatrixPreview.vue +708 -708
  23. package/src/ContextMenu.vue +386 -379
  24. package/src/CopyButton.vue +156 -156
  25. package/src/DataTable.vue +293 -292
  26. package/src/DatePicker.vue +234 -234
  27. package/src/DescriptionList.vue +73 -73
  28. package/src/DiffView.vue +68 -68
  29. package/src/Disclosure.vue +166 -166
  30. package/src/DragHandle.vue +49 -49
  31. package/src/Drawer.vue +131 -131
  32. package/src/DropZone.vue +196 -196
  33. package/src/DropdownMenu.vue +72 -72
  34. package/src/EmptyState.vue +111 -111
  35. package/src/Field.vue +28 -28
  36. package/src/HsvPicker.vue +208 -208
  37. package/src/Icon.vue +39 -39
  38. package/src/IconPicker.vue +209 -209
  39. package/src/ImageGrid.vue +127 -125
  40. package/src/InlineEdit.vue +183 -183
  41. package/src/Input.vue +99 -99
  42. package/src/Kbd.vue +56 -56
  43. package/src/Lightbox.vue +176 -173
  44. package/src/ListFilter.vue +85 -85
  45. package/src/ListRow.vue +204 -204
  46. package/src/LoadingMark.vue +217 -161
  47. package/src/Logo.vue +60 -60
  48. package/src/Modal.vue +78 -76
  49. package/src/ModalShell.vue +109 -107
  50. package/src/Pagination.vue +106 -106
  51. package/src/Popover.vue +180 -171
  52. package/src/PostCard.vue +210 -211
  53. package/src/ProgressBar.vue +90 -90
  54. package/src/RadioGroup.vue +177 -177
  55. package/src/RangeSlider.vue +183 -183
  56. package/src/RelativeDate.vue +35 -35
  57. package/src/ResizeHandle.vue +143 -143
  58. package/src/SearchInput.vue +192 -199
  59. package/src/Select.vue +644 -641
  60. package/src/Separator.vue +54 -54
  61. package/src/Skeleton.vue +98 -82
  62. package/src/Slider.vue +198 -198
  63. package/src/SortableList.vue +260 -260
  64. package/src/SplitPane.vue +68 -68
  65. package/src/StarButton.vue +40 -40
  66. package/src/Stepper.vue +141 -141
  67. package/src/SupportLinks.vue +93 -93
  68. package/src/TagInput.vue +297 -300
  69. package/src/Textarea.vue +57 -57
  70. package/src/Timeline.vue +92 -92
  71. package/src/ToastCard.vue +119 -119
  72. package/src/ToastHost.vue +40 -40
  73. package/src/Toggle.vue +36 -36
  74. package/src/TokenizedValue.vue +310 -310
  75. package/src/Toolbar.vue +110 -110
  76. package/src/VirtualList.vue +87 -87
  77. package/src/VisuallyHidden.vue +29 -29
  78. package/src/WpButton.vue +75 -75
  79. package/src/WpCheck.vue +104 -102
  80. package/src/WpIconButton.vue +107 -107
  81. package/src/WpImageZoom.vue +544 -544
  82. package/src/WpNumber.vue +178 -183
  83. package/src/WpSegmented.vue +175 -175
  84. package/src/WpSelect.vue +93 -89
  85. package/src/WpSwitch.vue +163 -163
  86. package/src/WpTabs.vue +188 -188
  87. package/src/_modal-motion.css +33 -33
  88. package/src/_skeleton.css +50 -50
  89. package/src/axis-color.ts +42 -42
  90. package/src/button.css +169 -169
  91. package/src/calendar.ts +59 -59
  92. package/src/clipboard.ts +50 -50
  93. package/src/colour-presets.ts +12 -12
  94. package/src/diff.ts +51 -51
  95. package/src/drop-zone.ts +41 -41
  96. package/src/field.css +50 -0
  97. package/src/flip.ts +237 -237
  98. package/src/floating-layer.ts +48 -0
  99. package/src/floating.ts +99 -99
  100. package/src/highlight.ts +199 -0
  101. package/src/hsv.ts +100 -100
  102. package/src/icon-catalog.ts +52 -52
  103. package/src/image-zoom.ts +93 -93
  104. package/src/kind-colour.ts +28 -0
  105. package/src/loading-mark-motion.ts +249 -0
  106. package/src/logo-paths.ts +21 -21
  107. package/src/matrix-axis.ts +91 -91
  108. package/src/pagination.ts +27 -27
  109. package/src/platform-keys.ts +29 -29
  110. package/src/rich-tokenize.ts +357 -357
  111. package/src/select-types.ts +32 -32
  112. package/src/slider-math.ts +45 -45
  113. package/src/sortable.ts +22 -22
  114. package/src/theme/fonts/OFL-Fraunces.txt +93 -93
  115. package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -93
  116. package/src/theme/fonts/OFL-Manrope.txt +93 -93
  117. package/src/theme/looks.css +428 -428
  118. package/src/theme/palettes.css +254 -254
  119. package/src/theme/tokens.css +2896 -2894
  120. package/src/tokens.ts +56 -56
  121. package/src/tooltip.css +43 -43
  122. package/src/tooltip.ts +146 -146
  123. package/src/useDialogFocus.ts +73 -73
  124. package/src/useGrowableField.ts +357 -357
  125. package/src/useModalKeyShield.ts +116 -116
  126. package/src/useToast.ts +48 -48
  127. package/src/wp-logo.svg +14 -14
  128. package/src/ChipToggle.vue +0 -92
  129. package/src/KindChip.vue +0 -53
  130. package/src/RatingBadge.vue +0 -42
package/src/Button.vue CHANGED
@@ -1,103 +1,103 @@
1
- <script setup lang="ts">
2
- /**
3
- * Button — single source of truth for app buttons.
4
- *
5
- * Variants:
6
- * primary — solid accent; main CTA per surface
7
- * secondary — subtle filled; default
8
- * ghost — transparent with hover bg; tertiary
9
- * danger — red-tinted; destructive actions
10
- * link — text-only; inline CTAs
11
- * outline — neutral bordered ghost (not accent: an accent outline read as
12
- * a second primary)
13
- * add — dashed, quiet: the "Add a row" button at the end of a list
14
- *
15
- * `block` stretches it to the full width of its container. `pressed` makes
16
- * it a toggle (aria-pressed, accent tint while on).
17
- *
18
- * Sizes follow the control scale: sm 24 / md 32 (default) / lg 40.
19
- *
20
- * States: default · hover · active · focus-visible · disabled · loading.
21
- * Disabled fades to 45% with a not-allowed cursor and no hover change.
22
- * Loading keeps the variant's own colours, swaps the lead icon for the
23
- * sparkle LoadingMark in the label colour, sets aria-busy and ignores clicks.
24
- *
25
- * Icon-only mode auto-engages when no slot content is provided (.wp-btn--icon).
26
- * Pass `aria-label` for screen reader text when using icon-only mode.
27
- *
28
- * The styles live in kit/button.css, shared with the canvas
29
- * Button twin.
30
- */
31
- import { computed, useSlots } from "vue";
32
- import Icon from "./Icon.vue";
33
- import LoadingMark from "./LoadingMark.vue";
34
-
35
- type Variant = "primary" | "secondary" | "ghost" | "danger" | "link" | "outline" | "add";
36
- type Size = "sm" | "md" | "lg";
37
-
38
- interface Props {
39
- variant?: Variant | undefined;
40
- size?: Size | undefined;
41
- icon?: string | undefined;
42
- iconRight?: string | undefined;
43
- loading?: boolean | undefined;
44
- disabled?: boolean | undefined;
45
- block?: boolean | undefined;
46
- /** Makes it a toggle (`aria-pressed`): on, it wears the accent tint. */
47
- pressed?: boolean | undefined;
48
- type?: "button" | "submit" | "reset" | undefined;
49
- ariaLabel?: string | undefined;
50
- }
51
- const props = withDefaults(defineProps<Props>(), {
52
- variant: "secondary",
53
- size: "md",
54
- type: "button",
55
- pressed: undefined,
56
- });
57
-
58
- const emit = defineEmits<{
59
- (e: "click", evt: MouseEvent): void;
60
- }>();
61
-
62
- const slots = useSlots();
63
-
64
- const hasContent = computed(() => Boolean(slots.default));
65
-
66
- /** Native hover tooltip for icon-only buttons. Their `aria-label` names them
67
- * for screen readers, but a sighted user hovering a bare icon gets nothing —
68
- * so mirror the label into `title` when there's no visible text. A button with
69
- * text already says what it does, so it stays untitled. */
70
- const titleAttr = computed(() =>
71
- !hasContent.value && props.ariaLabel ? props.ariaLabel : undefined);
72
-
73
- const classes = computed(() => [
74
- "wp-btn",
75
- `wp-btn--${props.variant}`,
76
- `wp-btn--${props.size}`,
77
- !hasContent.value && "wp-btn--icon",
78
- props.block && "wp-btn--block",
79
- ]);
80
-
81
- function onClick(e: MouseEvent) {
82
- if (props.disabled || props.loading) return;
83
- emit("click", e);
84
- }
85
- </script>
86
-
87
- <template>
88
- <button
89
- :type="type"
90
- :class="classes"
91
- :disabled="disabled || loading"
92
- :aria-label="ariaLabel"
93
- :title="titleAttr"
94
- :aria-busy="loading || undefined"
95
- :aria-pressed="pressed === undefined ? undefined : pressed"
96
- @click="onClick"
97
- >
98
- <LoadingMark v-if="loading" variant="sparkle" mono :size="size === 'lg' ? 16 : 14" decorative />
99
- <Icon v-else-if="icon" :name="icon" />
100
- <span v-if="hasContent" class="wp-btn__label"><slot /></span>
101
- <Icon v-if="iconRight" :name="iconRight" />
102
- </button>
103
- </template>
1
+ <script setup lang="ts">
2
+ /**
3
+ * Button — single source of truth for app buttons.
4
+ *
5
+ * Variants:
6
+ * primary — solid accent; main CTA per surface
7
+ * secondary — subtle filled; default
8
+ * ghost — transparent with hover bg; tertiary
9
+ * danger — red-tinted; destructive actions
10
+ * link — text-only; inline CTAs
11
+ * outline — neutral bordered ghost (not accent: an accent outline read as
12
+ * a second primary)
13
+ * add — dashed, quiet: the "Add a row" button at the end of a list
14
+ *
15
+ * `block` stretches it to the full width of its container. `pressed` makes
16
+ * it a toggle (aria-pressed, accent tint while on).
17
+ *
18
+ * Sizes follow the control scale: sm 24 / md 32 (default) / lg 40.
19
+ *
20
+ * States: default · hover · active · focus-visible · disabled · loading.
21
+ * Disabled fades to 45% with a not-allowed cursor and no hover change.
22
+ * Loading keeps the variant's own colours, swaps the lead icon for the
23
+ * sparkle LoadingMark in the label colour, sets aria-busy and ignores clicks.
24
+ *
25
+ * Icon-only mode auto-engages when no slot content is provided (.wp-btn--icon).
26
+ * Pass `aria-label` for screen reader text when using icon-only mode.
27
+ *
28
+ * The styles live in kit/button.css, shared with the canvas
29
+ * Button twin.
30
+ */
31
+ import { computed, useSlots } from "vue";
32
+ import Icon from "./Icon.vue";
33
+ import LoadingMark from "./LoadingMark.vue";
34
+
35
+ type Variant = "primary" | "secondary" | "ghost" | "danger" | "link" | "outline" | "add";
36
+ type Size = "sm" | "md" | "lg";
37
+
38
+ interface Props {
39
+ variant?: Variant | undefined;
40
+ size?: Size | undefined;
41
+ icon?: string | undefined;
42
+ iconRight?: string | undefined;
43
+ loading?: boolean | undefined;
44
+ disabled?: boolean | undefined;
45
+ block?: boolean | undefined;
46
+ /** Makes it a toggle (`aria-pressed`): on, it wears the accent tint. */
47
+ pressed?: boolean | undefined;
48
+ type?: "button" | "submit" | "reset" | undefined;
49
+ ariaLabel?: string | undefined;
50
+ }
51
+ const props = withDefaults(defineProps<Props>(), {
52
+ variant: "secondary",
53
+ size: "md",
54
+ type: "button",
55
+ pressed: undefined,
56
+ });
57
+
58
+ const emit = defineEmits<{
59
+ (e: "click", evt: MouseEvent): void;
60
+ }>();
61
+
62
+ const slots = useSlots();
63
+
64
+ const hasContent = computed(() => Boolean(slots.default));
65
+
66
+ /** Native hover tooltip for icon-only buttons. Their `aria-label` names them
67
+ * for screen readers, but a sighted user hovering a bare icon gets nothing —
68
+ * so mirror the label into `title` when there's no visible text. A button with
69
+ * text already says what it does, so it stays untitled. */
70
+ const titleAttr = computed(() =>
71
+ !hasContent.value && props.ariaLabel ? props.ariaLabel : undefined);
72
+
73
+ const classes = computed(() => [
74
+ "wp-btn",
75
+ `wp-btn--${props.variant}`,
76
+ `wp-btn--${props.size}`,
77
+ !hasContent.value && "wp-btn--icon",
78
+ props.block && "wp-btn--block",
79
+ ]);
80
+
81
+ function onClick(e: MouseEvent) {
82
+ if (props.disabled || props.loading) return;
83
+ emit("click", e);
84
+ }
85
+ </script>
86
+
87
+ <template>
88
+ <button
89
+ :type="type"
90
+ :class="classes"
91
+ :disabled="disabled || loading"
92
+ :aria-label="ariaLabel"
93
+ :title="titleAttr"
94
+ :aria-busy="loading || undefined"
95
+ :aria-pressed="pressed === undefined ? undefined : pressed"
96
+ @click="onClick"
97
+ >
98
+ <LoadingMark v-if="loading" variant="sparkle" mono :size="size === 'lg' ? 16 : 14" decorative />
99
+ <Icon v-else-if="icon" :name="icon" />
100
+ <span v-if="hasContent" class="wp-btn__label"><slot /></span>
101
+ <Icon v-if="iconRight" :name="iconRight" />
102
+ </button>
103
+ </template>
package/src/Card.vue CHANGED
@@ -1,68 +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>
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>
package/src/Checkbox.vue CHANGED
@@ -1,107 +1,109 @@
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>
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
+ <!-- A click on the words toggles too, like a <label>; keyboard users use the box itself. -->
106
+ <!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
107
+ <span v-if="label" class="wp-checkbox__label" @click="toggle">{{ label }}</span>
108
+ </span>
109
+ </template>