@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.
- package/CHANGELOG.md +77 -0
- package/LICENSE +674 -0
- package/README.md +72 -2
- package/package.json +76 -4
- package/src/Avatar.vue +83 -0
- package/src/Badge.vue +97 -0
- package/src/Banner.vue +118 -0
- package/src/BookmarkButton.vue +27 -0
- package/src/BundleMeta.vue +51 -0
- package/src/Button.vue +103 -0
- package/src/Card.vue +68 -0
- package/src/Checkbox.vue +109 -0
- package/src/Chip.vue +163 -0
- package/src/ChoiceCards.vue +133 -0
- package/src/CloseButton.vue +69 -0
- package/src/CodeBlock.vue +119 -0
- package/src/ColorField.vue +188 -0
- package/src/ColorPicker.vue +201 -0
- package/src/Combobox.vue +331 -0
- package/src/ConfirmDialog.vue +165 -0
- package/src/ConfirmModal.vue +147 -0
- package/src/ConstraintMatrixPreview.vue +708 -0
- package/src/ContextMenu.vue +386 -0
- package/src/CopyButton.vue +156 -0
- package/src/DataTable.vue +292 -0
- package/src/DatePicker.vue +234 -0
- package/src/DescriptionList.vue +73 -0
- package/src/DiffView.vue +68 -0
- package/src/Disclosure.vue +166 -0
- package/src/DragHandle.vue +49 -0
- package/src/Drawer.vue +131 -0
- package/src/DropZone.vue +196 -0
- package/src/DropdownMenu.vue +72 -0
- package/src/EmptyState.vue +111 -0
- package/src/Field.vue +28 -0
- package/src/HsvPicker.vue +208 -0
- package/src/Icon.vue +39 -0
- package/src/IconPicker.vue +209 -0
- package/src/ImageGrid.vue +125 -0
- package/src/InlineEdit.vue +183 -0
- package/src/Input.vue +99 -0
- package/src/Kbd.vue +56 -0
- package/src/Lightbox.vue +173 -0
- package/src/ListFilter.vue +85 -0
- package/src/ListRow.vue +204 -0
- package/src/LoadingMark.vue +175 -0
- package/src/Logo.vue +60 -0
- package/src/Modal.vue +78 -0
- package/src/ModalShell.vue +109 -0
- package/src/Pagination.vue +106 -0
- package/src/Popover.vue +180 -0
- package/src/PostCard.vue +210 -0
- package/src/ProgressBar.vue +90 -0
- package/src/RadioGroup.vue +177 -0
- package/src/RangeSlider.vue +183 -0
- package/src/RelativeDate.vue +35 -0
- package/src/ResizeHandle.vue +143 -0
- package/src/SearchInput.vue +192 -0
- package/src/Select.vue +644 -0
- package/src/Separator.vue +54 -0
- package/src/Skeleton.vue +82 -0
- package/src/Slider.vue +198 -0
- package/src/SortableList.vue +260 -0
- package/src/SplitPane.vue +68 -0
- package/src/StarButton.vue +40 -0
- package/src/Stepper.vue +141 -0
- package/src/SupportLinks.vue +93 -0
- package/src/TagInput.vue +297 -0
- package/src/Textarea.vue +57 -0
- package/src/Timeline.vue +92 -0
- package/src/ToastCard.vue +119 -0
- package/src/ToastHost.vue +40 -0
- package/src/Toggle.vue +36 -0
- package/src/TokenizedValue.vue +310 -0
- package/src/Toolbar.vue +110 -0
- package/src/VirtualList.vue +87 -0
- package/src/VisuallyHidden.vue +29 -0
- package/src/WpButton.vue +75 -0
- package/src/WpCheck.vue +104 -0
- package/src/WpIconButton.vue +107 -0
- package/src/WpImageZoom.vue +544 -0
- package/src/WpNumber.vue +178 -0
- package/src/WpSegmented.vue +175 -0
- package/src/WpSelect.vue +93 -0
- package/src/WpSwitch.vue +163 -0
- package/src/WpTabs.vue +188 -0
- package/src/_modal-motion.css +33 -0
- package/src/_skeleton.css +50 -0
- package/src/axis-color.ts +42 -0
- package/src/button.css +169 -0
- package/src/calendar.ts +59 -0
- package/src/clipboard.ts +50 -0
- package/src/colour-presets.ts +12 -0
- package/src/diff.ts +51 -0
- package/src/drop-zone.ts +41 -0
- package/src/field.css +50 -0
- package/src/flip.ts +237 -0
- package/src/floating-layer.ts +48 -0
- package/src/floating.ts +99 -0
- package/src/hsv.ts +100 -0
- package/src/icon-catalog.ts +52 -0
- package/src/image-zoom.ts +93 -0
- package/src/kind-colour.ts +28 -0
- package/src/logo-paths.ts +21 -0
- package/src/matrix-axis.ts +91 -0
- package/src/pagination.ts +27 -0
- package/src/platform-keys.ts +29 -0
- package/src/rich-tokenize.ts +357 -0
- package/src/select-types.ts +32 -0
- package/src/slider-math.ts +45 -0
- package/src/sortable.ts +22 -0
- package/src/theme/fonts/OFL-Fraunces.txt +93 -0
- package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -0
- package/src/theme/fonts/OFL-Manrope.txt +93 -0
- package/src/theme/fonts/fraunces-latin-wght-normal.woff2 +0 -0
- package/src/theme/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/src/theme/fonts/manrope-latin-wght-normal.woff2 +0 -0
- package/src/theme/looks.css +428 -0
- package/src/theme/palettes.css +254 -0
- package/src/theme/tokens.css +2896 -0
- package/src/tokens.ts +56 -0
- package/src/tooltip.css +43 -0
- package/src/tooltip.ts +146 -0
- package/src/useDialogFocus.ts +73 -0
- package/src/useGrowableField.ts +357 -0
- package/src/useModalKeyShield.ts +116 -0
- package/src/useToast.ts +48 -0
- 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>
|
package/src/Checkbox.vue
ADDED
|
@@ -0,0 +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
|
+
<!-- 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>
|
package/src/Chip.vue
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
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>
|
|
@@ -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>
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Code block: text that must stay as written (JSON, a prompt as sent, a log,
|
|
4
|
+
* a snippet), in the mono font, with a copy button and a wrap switch in its
|
|
5
|
+
* head. Long text scrolls inside `max-height`. Works on the canvas and in the
|
|
6
|
+
* manager.
|
|
7
|
+
*
|
|
8
|
+
* <CodeBlock :code="json" language="JSON" max-height="240px" />
|
|
9
|
+
* <CodeBlock :code="log" title="Request" line-numbers v-model:wrap="wrap" />
|
|
10
|
+
*
|
|
11
|
+
* No syntax colours (they cost bundle for little gain here). A block that
|
|
12
|
+
* scrolls can be focused, so the keyboard can scroll it too.
|
|
13
|
+
*/
|
|
14
|
+
import { computed, ref, watch } from "vue";
|
|
15
|
+
import CopyButton from "./CopyButton.vue";
|
|
16
|
+
import { vTooltip } from "./tooltip";
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(defineProps<{
|
|
19
|
+
code: string;
|
|
20
|
+
/** A small tag in the head, e.g. "JSON". */
|
|
21
|
+
language?: string | undefined;
|
|
22
|
+
/** A name in the head, e.g. "Prompt as sent". */
|
|
23
|
+
title?: string | undefined;
|
|
24
|
+
/** Wrap long lines. Bind with v-model:wrap, or leave it to the button. */
|
|
25
|
+
wrap?: boolean | undefined;
|
|
26
|
+
/** Where wrap starts when nobody binds `wrap`. */
|
|
27
|
+
defaultWrap?: boolean | undefined;
|
|
28
|
+
/** CSS max height; the block scrolls past it. */
|
|
29
|
+
maxHeight?: string | undefined;
|
|
30
|
+
lineNumbers?: boolean | undefined;
|
|
31
|
+
/** Leave out the head (copy and wrap). */
|
|
32
|
+
bare?: boolean | undefined;
|
|
33
|
+
size?: "sm" | "md" | undefined;
|
|
34
|
+
}>(), { language: undefined, title: undefined, wrap: undefined, maxHeight: undefined, size: "md" });
|
|
35
|
+
|
|
36
|
+
const emit = defineEmits<{ (e: "update:wrap", v: boolean): void }>();
|
|
37
|
+
|
|
38
|
+
const own = ref(props.wrap ?? props.defaultWrap ?? false);
|
|
39
|
+
watch(() => props.wrap, (v) => { if (v !== undefined) own.value = v; });
|
|
40
|
+
const wrapped = computed(() => props.wrap ?? own.value);
|
|
41
|
+
function toggleWrap(): void {
|
|
42
|
+
own.value = !wrapped.value;
|
|
43
|
+
emit("update:wrap", own.value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const lines = computed(() => props.code.replace(/\n$/, "").split("\n"));
|
|
47
|
+
const name = computed(() => props.title ?? props.language ?? "Code");
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<figure class="wp-code" :data-size="size" :data-wrap="wrapped || undefined">
|
|
52
|
+
<figcaption v-if="!bare" class="wp-code__head">
|
|
53
|
+
<span class="wp-code__title">{{ title }}</span>
|
|
54
|
+
<span v-if="language" class="wp-code__lang">{{ language }}</span>
|
|
55
|
+
<span class="wp-code__tools">
|
|
56
|
+
<button
|
|
57
|
+
v-tooltip="wrapped ? 'Don’t wrap lines' : 'Wrap lines'"
|
|
58
|
+
type="button"
|
|
59
|
+
class="wp-code__tool"
|
|
60
|
+
:aria-pressed="wrapped"
|
|
61
|
+
aria-label="Wrap lines"
|
|
62
|
+
@click="toggleWrap"
|
|
63
|
+
><i class="pi pi-align-left" aria-hidden="true" /></button>
|
|
64
|
+
<CopyButton :text="code" :label="`Copy ${name.toLowerCase() === 'code' ? 'code' : name}`" size="sm" />
|
|
65
|
+
</span>
|
|
66
|
+
</figcaption>
|
|
67
|
+
<pre
|
|
68
|
+
class="wp-code__pre"
|
|
69
|
+
tabindex="0"
|
|
70
|
+
:aria-label="name"
|
|
71
|
+
:style="{ maxHeight }"
|
|
72
|
+
><code v-if="!lineNumbers" class="wp-code__code">{{ code }}</code><code v-else class="wp-code__code wp-code__code--numbered"><span v-for="(l, i) in lines" :key="i" class="wp-code__line"><span class="wp-code__num" aria-hidden="true">{{ i + 1 }}</span><span class="wp-code__text">{{ l || "\u00a0" }}</span></span></code></pre>
|
|
73
|
+
</figure>
|
|
74
|
+
</template>
|
|
75
|
+
|
|
76
|
+
<style scoped>
|
|
77
|
+
.wp-code {
|
|
78
|
+
display: flex; flex-direction: column; min-width: 0; margin: 0;
|
|
79
|
+
border: 1px solid var(--wp-border); border-radius: var(--wp-radius);
|
|
80
|
+
background: var(--wp-bg-1); overflow: hidden;
|
|
81
|
+
}
|
|
82
|
+
.wp-code__head {
|
|
83
|
+
display: flex; align-items: center; gap: var(--wp-space-3); min-height: 28px;
|
|
84
|
+
padding: 2px var(--wp-space-2) 2px var(--wp-space-4);
|
|
85
|
+
border-bottom: 1px solid var(--wp-border-soft); background: var(--wp-bg-2);
|
|
86
|
+
color: var(--wp-text-muted); font: 500 var(--wp-text-xs)/1.2 var(--wp-font-sans);
|
|
87
|
+
}
|
|
88
|
+
.wp-code__title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--wp-text); }
|
|
89
|
+
.wp-code__lang {
|
|
90
|
+
padding: 1px 6px; border-radius: var(--wp-radius-sm); background: var(--wp-bg-3);
|
|
91
|
+
font: 600 10px/1.4 var(--wp-font-mono); letter-spacing: 0.04em; text-transform: uppercase;
|
|
92
|
+
}
|
|
93
|
+
.wp-code__tools { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; }
|
|
94
|
+
.wp-code__tool {
|
|
95
|
+
display: inline-grid; place-items: center; width: var(--wp-control-h-sm); height: var(--wp-control-h-sm);
|
|
96
|
+
margin: 0; padding: 0; border: 0; border-radius: var(--wp-radius-sm);
|
|
97
|
+
background: transparent; color: var(--wp-text-muted); cursor: pointer;
|
|
98
|
+
}
|
|
99
|
+
.wp-code__tool .pi { font-size: 11px; }
|
|
100
|
+
.wp-code__tool:hover { background: var(--wp-row-hover); color: var(--wp-text); }
|
|
101
|
+
.wp-code__tool[aria-pressed="true"] { color: var(--wp-accent-text); background: var(--wp-bg-3); }
|
|
102
|
+
.wp-code__tool:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
103
|
+
.wp-code__pre {
|
|
104
|
+
margin: 0; padding: var(--wp-space-4); overflow: auto;
|
|
105
|
+
color: var(--wp-text); font: 400 var(--wp-text-sm)/1.55 var(--wp-font-mono);
|
|
106
|
+
white-space: pre; tab-size: 2;
|
|
107
|
+
}
|
|
108
|
+
.wp-code[data-size="sm"] .wp-code__pre { padding: var(--wp-space-3); font-size: var(--wp-text-xs); }
|
|
109
|
+
.wp-code[data-wrap] .wp-code__pre { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
110
|
+
.wp-code__pre:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--wp-border-focus); }
|
|
111
|
+
.wp-code__code { font: inherit; background: none; padding: 0; color: inherit; }
|
|
112
|
+
.wp-code__code--numbered { display: table; }
|
|
113
|
+
.wp-code__line { display: table-row; }
|
|
114
|
+
.wp-code__num {
|
|
115
|
+
display: table-cell; padding-right: var(--wp-space-4); text-align: right;
|
|
116
|
+
color: var(--wp-text-dim); user-select: none; font-variant-numeric: tabular-nums;
|
|
117
|
+
}
|
|
118
|
+
.wp-code__text { display: table-cell; }
|
|
119
|
+
</style>
|