@dumiflex/wp-kit 0.0.0-stage → 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.
Files changed (128) hide show
  1. package/CHANGELOG.md +77 -0
  2. package/LICENSE +674 -0
  3. package/README.md +72 -2
  4. package/package.json +76 -4
  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 +109 -0
  13. package/src/Chip.vue +163 -0
  14. package/src/ChoiceCards.vue +133 -0
  15. package/src/CloseButton.vue +69 -0
  16. package/src/CodeBlock.vue +119 -0
  17. package/src/ColorField.vue +188 -0
  18. package/src/ColorPicker.vue +201 -0
  19. package/src/Combobox.vue +331 -0
  20. package/src/ConfirmDialog.vue +165 -0
  21. package/src/ConfirmModal.vue +147 -0
  22. package/src/ConstraintMatrixPreview.vue +708 -0
  23. package/src/ContextMenu.vue +386 -0
  24. package/src/CopyButton.vue +156 -0
  25. package/src/DataTable.vue +292 -0
  26. package/src/DatePicker.vue +234 -0
  27. package/src/DescriptionList.vue +73 -0
  28. package/src/DiffView.vue +68 -0
  29. package/src/Disclosure.vue +166 -0
  30. package/src/DragHandle.vue +49 -0
  31. package/src/Drawer.vue +131 -0
  32. package/src/DropZone.vue +196 -0
  33. package/src/DropdownMenu.vue +72 -0
  34. package/src/EmptyState.vue +111 -0
  35. package/src/Field.vue +28 -0
  36. package/src/HsvPicker.vue +208 -0
  37. package/src/Icon.vue +39 -0
  38. package/src/IconPicker.vue +209 -0
  39. package/src/ImageGrid.vue +125 -0
  40. package/src/InlineEdit.vue +183 -0
  41. package/src/Input.vue +99 -0
  42. package/src/Kbd.vue +56 -0
  43. package/src/Lightbox.vue +173 -0
  44. package/src/ListFilter.vue +85 -0
  45. package/src/ListRow.vue +204 -0
  46. package/src/LoadingMark.vue +175 -0
  47. package/src/Logo.vue +60 -0
  48. package/src/Modal.vue +78 -0
  49. package/src/ModalShell.vue +109 -0
  50. package/src/Pagination.vue +106 -0
  51. package/src/Popover.vue +180 -0
  52. package/src/PostCard.vue +210 -0
  53. package/src/ProgressBar.vue +90 -0
  54. package/src/RadioGroup.vue +177 -0
  55. package/src/RangeSlider.vue +183 -0
  56. package/src/RelativeDate.vue +35 -0
  57. package/src/ResizeHandle.vue +143 -0
  58. package/src/SearchInput.vue +192 -0
  59. package/src/Select.vue +644 -0
  60. package/src/Separator.vue +54 -0
  61. package/src/Skeleton.vue +82 -0
  62. package/src/Slider.vue +198 -0
  63. package/src/SortableList.vue +260 -0
  64. package/src/SplitPane.vue +68 -0
  65. package/src/StarButton.vue +40 -0
  66. package/src/Stepper.vue +141 -0
  67. package/src/SupportLinks.vue +93 -0
  68. package/src/TagInput.vue +297 -0
  69. package/src/Textarea.vue +57 -0
  70. package/src/Timeline.vue +92 -0
  71. package/src/ToastCard.vue +119 -0
  72. package/src/ToastHost.vue +40 -0
  73. package/src/Toggle.vue +36 -0
  74. package/src/TokenizedValue.vue +310 -0
  75. package/src/Toolbar.vue +110 -0
  76. package/src/VirtualList.vue +87 -0
  77. package/src/VisuallyHidden.vue +29 -0
  78. package/src/WpButton.vue +75 -0
  79. package/src/WpCheck.vue +104 -0
  80. package/src/WpIconButton.vue +107 -0
  81. package/src/WpImageZoom.vue +544 -0
  82. package/src/WpNumber.vue +178 -0
  83. package/src/WpSegmented.vue +175 -0
  84. package/src/WpSelect.vue +93 -0
  85. package/src/WpSwitch.vue +163 -0
  86. package/src/WpTabs.vue +188 -0
  87. package/src/_modal-motion.css +33 -0
  88. package/src/_skeleton.css +50 -0
  89. package/src/axis-color.ts +42 -0
  90. package/src/button.css +169 -0
  91. package/src/calendar.ts +59 -0
  92. package/src/clipboard.ts +50 -0
  93. package/src/colour-presets.ts +12 -0
  94. package/src/diff.ts +51 -0
  95. package/src/drop-zone.ts +41 -0
  96. package/src/field.css +50 -0
  97. package/src/flip.ts +237 -0
  98. package/src/floating-layer.ts +48 -0
  99. package/src/floating.ts +99 -0
  100. package/src/hsv.ts +100 -0
  101. package/src/icon-catalog.ts +52 -0
  102. package/src/image-zoom.ts +93 -0
  103. package/src/kind-colour.ts +28 -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 +2896 -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
@@ -0,0 +1,188 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A colour swatch that opens a picker: the colour square, a hex box, and
4
+ * (with `alpha`) an opacity number, or (with `allowNone`) a "None" choice.
5
+ * The value is a hex string, `#rrggbb` or `#rrggbbaa` once it is
6
+ * see-through, or `none`. Other text (a colour name typed in a workflow) is
7
+ * kept and shown as it is until a pick replaces it. Sits on the kit Popover,
8
+ * so it follows the swatch on scroll and closes on Escape or a click
9
+ * outside. Works on the canvas (`size="sm"`) and in the manager.
10
+ *
11
+ * <ColorField v-model="labelColor" alpha allow-none size="sm" aria-label="Label band" />
12
+ */
13
+ import { computed, ref, watch } from "vue";
14
+ import HsvPicker from "./HsvPicker.vue";
15
+ import Popover from "./Popover.vue";
16
+ import WpNumber from "./WpNumber.vue";
17
+ import WpButton from "./WpButton.vue";
18
+ import { rgbToHex } from "./hsv";
19
+
20
+ const props = withDefaults(defineProps<{
21
+ modelValue: string;
22
+ /** Offer an opacity number (writes `#rrggbbaa`). */
23
+ alpha?: boolean | undefined;
24
+ /** Offer "None" (writes `none`). */
25
+ allowNone?: boolean | undefined;
26
+ size?: "sm" | "md" | undefined;
27
+ ariaLabel?: string | undefined;
28
+ disabled?: boolean | undefined;
29
+ dataTest?: string | undefined;
30
+ }>(), { alpha: false, allowNone: false, size: "sm", ariaLabel: "Colour", disabled: false, dataTest: undefined });
31
+
32
+ const emit = defineEmits<{ "update:modelValue": [value: string] }>();
33
+
34
+ const HEX = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
35
+
36
+ /** `#rgb` / `#rgba` / `#rrggbb` / `#rrggbbaa` → `{ rgb: "#rrggbb", alpha: 0-255 }`. */
37
+ function parse(value: string): { rgb: string; alpha: number } | null {
38
+ const v = value.trim();
39
+ if (!HEX.test(v)) return null;
40
+ let h = v.slice(1).toLowerCase();
41
+ if (h.length <= 4) h = h.split("").map((c) => c + c).join("");
42
+ return { rgb: `#${h.slice(0, 6)}`, alpha: h.length === 8 ? parseInt(h.slice(6), 16) : 255 };
43
+ }
44
+ function compose(rgb: string, alpha: number): string {
45
+ const a = Math.max(0, Math.min(255, Math.round(alpha)));
46
+ return a >= 255 ? rgb : `${rgb}${a.toString(16).padStart(2, "0")}`;
47
+ }
48
+
49
+ const open = ref(false);
50
+ const isNone = computed(() => props.modelValue.trim().toLowerCase() === "none");
51
+ const parsed = computed(() => parse(props.modelValue));
52
+ const BLACK = rgbToHex({ r: 0, g: 0, b: 0 });
53
+ const rgb = computed(() => parsed.value?.rgb ?? BLACK);
54
+ const alphaValue = computed(() => (parsed.value ? parsed.value.alpha : 255));
55
+ const opacity = computed(() => Math.round((alphaValue.value / 255) * 100));
56
+
57
+ const shown = computed(() => (isNone.value ? "none" : props.modelValue.trim() || "none"));
58
+ const swatch = computed(() => {
59
+ if (isNone.value) return "transparent";
60
+ const p = parsed.value;
61
+ if (!p) return props.modelValue;
62
+ return `rgba(${parseInt(p.rgb.slice(1, 3), 16)}, ${parseInt(p.rgb.slice(3, 5), 16)}, ${parseInt(p.rgb.slice(5, 7), 16)}, ${p.alpha / 255})`;
63
+ });
64
+
65
+ const draft = ref(props.modelValue);
66
+ watch(() => props.modelValue, (v) => { draft.value = v; });
67
+ watch(open, (v) => { if (v) draft.value = props.modelValue; });
68
+
69
+ function onHsv(hex: string): void {
70
+ emit("update:modelValue", compose(hex, props.alpha ? alphaValue.value : 255));
71
+ }
72
+ function onOpacity(pct: number | null): void {
73
+ if (pct === null) return;
74
+ emit("update:modelValue", compose(rgb.value, (pct / 100) * 255));
75
+ }
76
+ function onDraft(ev: Event): void {
77
+ const v = (ev.target as HTMLInputElement).value.trim();
78
+ draft.value = v;
79
+ const p = parse(v);
80
+ if (p) emit("update:modelValue", compose(p.rgb, props.alpha ? p.alpha : 255));
81
+ }
82
+ function pickNone(): void {
83
+ emit("update:modelValue", "none");
84
+ open.value = false;
85
+ }
86
+ </script>
87
+
88
+ <template>
89
+ <Popover v-model:open="open" :label="ariaLabel">
90
+ <template #trigger="{ props: triggerProps }">
91
+ <button
92
+ v-bind="triggerProps"
93
+ type="button"
94
+ class="wp-color-field wp-field-box"
95
+ :class="[`wp-color-field--${size}`, `wp-field-box--${size}`, { 'is-none': isNone }]"
96
+ :disabled="disabled"
97
+ :aria-label="`${ariaLabel}: ${shown}`"
98
+ :data-test="dataTest"
99
+ >
100
+ <span class="wp-color-field__chip" aria-hidden="true">
101
+ <span class="wp-color-field__fill" :style="{ background: swatch }" />
102
+ </span>
103
+ <span class="wp-color-field__value" aria-hidden="true">{{ shown }}</span>
104
+ </button>
105
+ </template>
106
+ <div class="wp-color-field__panel" @keydown.stop>
107
+ <HsvPicker :model-value="rgb" :aria-label="ariaLabel" @update:model-value="onHsv" />
108
+ <div class="wp-color-field__row">
109
+ <input
110
+ class="wp-color-field__hex wp-field-box wp-field-box--sm"
111
+ :value="draft"
112
+ :aria-label="`${ariaLabel} hex`"
113
+ spellcheck="false"
114
+ :data-test="dataTest ? `${dataTest}-hex` : undefined"
115
+ @change="onDraft"
116
+ @keydown.enter="onDraft"
117
+ >
118
+ <WpNumber
119
+ v-if="alpha"
120
+ class="wp-color-field__alpha"
121
+ :model-value="isNone ? 0 : opacity"
122
+ :min="0"
123
+ :max="100"
124
+ suffix="%"
125
+ size="sm"
126
+ :aria-label="`${ariaLabel} opacity`"
127
+ :data-test="dataTest ? `${dataTest}-alpha` : undefined"
128
+ @update:model-value="onOpacity"
129
+ />
130
+ </div>
131
+ <WpButton
132
+ v-if="allowNone"
133
+ size="sm"
134
+ variant="ghost"
135
+ icon="pi-ban"
136
+ :pressed="isNone"
137
+ :data-test="dataTest ? `${dataTest}-none` : undefined"
138
+ @click="pickNone"
139
+ >None</WpButton>
140
+ </div>
141
+ </Popover>
142
+ </template>
143
+
144
+ <style scoped src="./field.css"></style>
145
+
146
+ <style scoped>
147
+ .wp-color-field {
148
+ display: inline-flex;
149
+ align-items: center;
150
+ gap: 6px;
151
+ min-width: 0;
152
+ height: var(--wp-field-h);
153
+ padding: 0 8px 0 3px;
154
+ font-family: var(--wp-font-mono, monospace);
155
+ cursor: pointer;
156
+ }
157
+ .wp-color-field__chip {
158
+ position: relative;
159
+ flex: none;
160
+ width: 16px;
161
+ height: 16px;
162
+ overflow: hidden;
163
+ border: 1px solid var(--wp-border-strong);
164
+ border-radius: min(3px, var(--wp-radius-cap, 999px));
165
+ /* Checks show through a see-through colour. */
166
+ background: repeating-conic-gradient(var(--wp-bg-4) 0 25%, var(--wp-bg-1) 0 50%) 0 0 / 8px 8px;
167
+ }
168
+ .wp-color-field__fill { position: absolute; inset: 0; }
169
+ .wp-color-field.is-none .wp-color-field__chip::after {
170
+ content: "";
171
+ position: absolute;
172
+ inset: 0;
173
+ background: linear-gradient(to top right, transparent calc(50% - 1px), var(--wp-danger) 50%, transparent calc(50% + 1px));
174
+ }
175
+ .wp-color-field__value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
176
+ .wp-color-field.is-none .wp-color-field__value { color: var(--wp-text-dim); font-family: var(--wp-font-sans, sans-serif); }
177
+
178
+ .wp-color-field__panel {
179
+ display: flex;
180
+ flex-direction: column;
181
+ gap: 8px;
182
+ width: 200px;
183
+ padding: 0;
184
+ }
185
+ .wp-color-field__row { display: flex; gap: 6px; align-items: center; }
186
+ .wp-color-field__hex { flex: 1; min-width: 0; height: var(--wp-field-h); padding: 0 6px; font-family: var(--wp-font-mono, monospace); }
187
+ .wp-color-field__alpha { width: 72px; flex: none; }
188
+ </style>
@@ -0,0 +1,201 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref, watch } from "vue";
3
+ import Popover from "./Popover.vue";
4
+ import Input from "./Input.vue";
5
+ import HsvPicker from "./HsvPicker.vue";
6
+ import { COLOUR_PRESETS } from "./colour-presets";
7
+
8
+ interface Props {
9
+ modelValue: string;
10
+ presets?: string[] | undefined;
11
+ ariaLabel?: string | undefined;
12
+ /** Swatch and chevron only, for a tight spot such as a name row. */
13
+ compact?: boolean | undefined;
14
+ }
15
+
16
+ const props = withDefaults(defineProps<Props>(), {
17
+ presets: () => [...COLOUR_PRESETS],
18
+ ariaLabel: undefined,
19
+ compact: false,
20
+ });
21
+
22
+ const emit = defineEmits<{
23
+ "update:modelValue": [value: string];
24
+ }>();
25
+
26
+ const HEX_RE = /^#[0-9a-fA-F]{6}$/;
27
+
28
+ const open = ref(false);
29
+ const hexDraft = ref(props.modelValue);
30
+
31
+ watch(() => props.modelValue, (v) => {
32
+ hexDraft.value = v;
33
+ });
34
+ // A fresh draft each time it opens, so a half-typed hex doesn't linger.
35
+ watch(open, (v) => { if (v) hexDraft.value = props.modelValue; });
36
+
37
+ const swatchColor = computed(() => (HEX_RE.test(props.modelValue) ? props.modelValue : "transparent"));
38
+ const shownHex = computed(() => (HEX_RE.test(props.modelValue) ? props.modelValue.toLowerCase() : "No colour"));
39
+
40
+ const swatchAriaLabel = computed(
41
+ () => props.ariaLabel ?? `Pick color, current ${props.modelValue}`,
42
+ );
43
+
44
+ function close() {
45
+ open.value = false;
46
+ }
47
+
48
+ function selectPreset(preset: string) {
49
+ emit("update:modelValue", preset);
50
+ close();
51
+ }
52
+
53
+ function onHexInput(value: string) {
54
+ hexDraft.value = value;
55
+ if (HEX_RE.test(value)) {
56
+ emit("update:modelValue", value);
57
+ }
58
+ }
59
+
60
+ function isActivePreset(preset: string): boolean {
61
+ return preset.toLowerCase() === props.modelValue.toLowerCase();
62
+ }
63
+ </script>
64
+
65
+ <template>
66
+ <!-- A swatch button that says what it holds (colour, hex, chevron), on the
67
+ kit Popover so the panel follows it on scroll and closes on Escape or
68
+ a click outside. -->
69
+ <Popover v-model:open="open" :label="swatchAriaLabel">
70
+ <template #trigger="{ props: triggerProps }">
71
+ <button
72
+ v-bind="triggerProps"
73
+ type="button"
74
+ class="wp-color-picker__trigger"
75
+ :class="{ 'wp-color-picker__trigger--compact': compact }"
76
+ :aria-label="swatchAriaLabel"
77
+ data-test="color-trigger"
78
+ >
79
+ <span
80
+ class="wp-color-picker__swatch"
81
+ :style="{ background: swatchColor }"
82
+ data-test="color-swatch"
83
+ aria-hidden="true"
84
+ />
85
+ <span v-if="!compact" class="wp-color-picker__value" aria-hidden="true">{{ shownHex }}</span>
86
+ <i class="pi pi-chevron-down wp-color-picker__caret" aria-hidden="true" />
87
+ </button>
88
+ </template>
89
+ <div class="wp-color-picker__popover">
90
+ <div class="wp-color-picker__row">
91
+ <Input
92
+ :model-value="hexDraft"
93
+ aria-label="Hex color value"
94
+ class="wp-color-picker__hex"
95
+ data-test="color-hex-input"
96
+ @update:model-value="(v) => onHexInput(String(v ?? ''))"
97
+ />
98
+ </div>
99
+ <HsvPicker
100
+ :model-value="props.modelValue"
101
+ :aria-label="swatchAriaLabel"
102
+ @update:model-value="(v) => emit('update:modelValue', v)"
103
+ />
104
+ <div class="wp-color-picker__palette" role="listbox" aria-label="Preset colors">
105
+ <button
106
+ v-for="preset in props.presets"
107
+ :key="preset"
108
+ type="button"
109
+ class="wp-color-picker__chip"
110
+ :style="{ background: preset }"
111
+ :title="preset"
112
+ :data-active="isActivePreset(preset)"
113
+ :aria-label="`Use preset ${preset}`"
114
+ data-test="color-preset"
115
+ @click="selectPreset(preset)"
116
+ />
117
+ </div>
118
+ </div>
119
+ </Popover>
120
+ </template>
121
+
122
+ <style scoped>
123
+ .wp-color-picker__trigger {
124
+ display: inline-flex;
125
+ align-items: center;
126
+ gap: var(--wp-space-3);
127
+ height: var(--wp-control-h-md, 32px);
128
+ min-width: 128px;
129
+ padding: 0 var(--wp-space-4) 0 var(--wp-space-2);
130
+ background: var(--wp-bg-2);
131
+ border: 1px solid var(--wp-border);
132
+ border-radius: var(--wp-radius-sm);
133
+ color: var(--wp-text);
134
+ font: inherit;
135
+ cursor: pointer;
136
+ transition: border-color 0.12s, box-shadow 0.12s;
137
+ }
138
+ .wp-color-picker__trigger--compact { min-width: 0; padding: 0 var(--wp-space-3) 0 var(--wp-space-2); gap: var(--wp-space-2); }
139
+ .wp-color-picker__trigger:hover { border-color: var(--wp-border-strong); }
140
+ .wp-color-picker__trigger:focus-visible { outline: none; border-color: var(--wp-accent-500); box-shadow: var(--wp-focus-ring); }
141
+ .wp-color-picker__swatch {
142
+ width: 20px;
143
+ height: 20px;
144
+ flex-shrink: 0;
145
+ border-radius: min(4px, var(--wp-radius-cap, 999px));
146
+ /* An inner ring keeps a dark swatch visible on a dark field. */
147
+ box-shadow: inset 0 0 0 1px color-mix(in oklab, var(--wp-text) 22%, transparent);
148
+ }
149
+ .wp-color-picker__value {
150
+ flex: 1;
151
+ text-align: left;
152
+ font-family: var(--wp-font-mono);
153
+ font-size: 12px;
154
+ color: var(--wp-text-muted);
155
+ }
156
+ .wp-color-picker__caret { font-size: 9px; color: var(--wp-text-dim); }
157
+
158
+ .wp-color-picker__popover {
159
+ width: 220px;
160
+ padding: var(--wp-space-2);
161
+ display: flex;
162
+ flex-direction: column;
163
+ gap: var(--wp-space-5);
164
+ }
165
+ .wp-color-picker__row {
166
+ display: flex;
167
+ align-items: center;
168
+ gap: var(--wp-space-4);
169
+ }
170
+
171
+ .wp-color-picker__hex {
172
+ flex: 1;
173
+ min-width: 0;
174
+ font-family: var(--wp-font-mono);
175
+ font-size: var(--wp-text-sm);
176
+ }
177
+
178
+ .wp-color-picker__palette {
179
+ display: grid;
180
+ grid-template-columns: repeat(4, 1fr);
181
+ gap: var(--wp-space-3);
182
+ }
183
+
184
+ .wp-color-picker__chip {
185
+ /* Span the grid cell instead of locking at 32px so the swatches reach
186
+ * both edges of the popover. aspect-ratio keeps them square as the
187
+ * cell width changes with popover size. */
188
+ width: 100%;
189
+ aspect-ratio: 1 / 1;
190
+ min-width: 0;
191
+ border-radius: var(--wp-radius-sm);
192
+ border: 1px solid var(--wp-border);
193
+ cursor: pointer;
194
+ padding: 0;
195
+ transition: transform 0.08s, box-shadow 0.12s;
196
+ }
197
+ .wp-color-picker__chip:hover { transform: scale(1.08); }
198
+ .wp-color-picker__chip[data-active="true"] {
199
+ box-shadow: 0 0 0 2px var(--wp-bg-2), 0 0 0 4px var(--wp-accent-500);
200
+ }
201
+ </style>