@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.
- package/CHANGELOG.md +92 -51
- package/LICENSE +674 -674
- package/README.md +73 -76
- package/package.json +78 -77
- package/src/Avatar.vue +83 -83
- package/src/Badge.vue +97 -97
- package/src/Banner.vue +118 -118
- package/src/BookmarkButton.vue +27 -27
- package/src/BundleMeta.vue +51 -51
- package/src/Button.vue +103 -103
- package/src/Card.vue +68 -68
- package/src/Checkbox.vue +109 -107
- package/src/Chip.vue +163 -97
- package/src/ChoiceCards.vue +133 -133
- package/src/CloseButton.vue +69 -69
- package/src/CodeBlock.vue +146 -119
- package/src/ColorField.vue +188 -206
- package/src/ColorPicker.vue +201 -201
- package/src/Combobox.vue +331 -334
- package/src/ConfirmDialog.vue +165 -163
- package/src/ConfirmModal.vue +147 -147
- package/src/ConstraintMatrixPreview.vue +708 -708
- package/src/ContextMenu.vue +386 -379
- package/src/CopyButton.vue +156 -156
- package/src/DataTable.vue +293 -292
- package/src/DatePicker.vue +234 -234
- package/src/DescriptionList.vue +73 -73
- package/src/DiffView.vue +68 -68
- package/src/Disclosure.vue +166 -166
- package/src/DragHandle.vue +49 -49
- package/src/Drawer.vue +131 -131
- package/src/DropZone.vue +196 -196
- package/src/DropdownMenu.vue +72 -72
- package/src/EmptyState.vue +111 -111
- package/src/Field.vue +28 -28
- package/src/HsvPicker.vue +208 -208
- package/src/Icon.vue +39 -39
- package/src/IconPicker.vue +209 -209
- package/src/ImageGrid.vue +127 -125
- package/src/InlineEdit.vue +183 -183
- package/src/Input.vue +99 -99
- package/src/Kbd.vue +56 -56
- package/src/Lightbox.vue +176 -173
- package/src/ListFilter.vue +85 -85
- package/src/ListRow.vue +204 -204
- package/src/LoadingMark.vue +217 -161
- package/src/Logo.vue +60 -60
- package/src/Modal.vue +78 -76
- package/src/ModalShell.vue +109 -107
- package/src/Pagination.vue +106 -106
- package/src/Popover.vue +180 -171
- package/src/PostCard.vue +210 -211
- package/src/ProgressBar.vue +90 -90
- package/src/RadioGroup.vue +177 -177
- package/src/RangeSlider.vue +183 -183
- package/src/RelativeDate.vue +35 -35
- package/src/ResizeHandle.vue +143 -143
- package/src/SearchInput.vue +192 -199
- package/src/Select.vue +644 -641
- package/src/Separator.vue +54 -54
- package/src/Skeleton.vue +98 -82
- package/src/Slider.vue +198 -198
- package/src/SortableList.vue +260 -260
- package/src/SplitPane.vue +68 -68
- package/src/StarButton.vue +40 -40
- package/src/Stepper.vue +141 -141
- package/src/SupportLinks.vue +93 -93
- package/src/TagInput.vue +297 -300
- package/src/Textarea.vue +57 -57
- package/src/Timeline.vue +92 -92
- package/src/ToastCard.vue +119 -119
- package/src/ToastHost.vue +40 -40
- package/src/Toggle.vue +36 -36
- package/src/TokenizedValue.vue +310 -310
- package/src/Toolbar.vue +110 -110
- package/src/VirtualList.vue +87 -87
- package/src/VisuallyHidden.vue +29 -29
- package/src/WpButton.vue +75 -75
- package/src/WpCheck.vue +104 -102
- package/src/WpIconButton.vue +107 -107
- package/src/WpImageZoom.vue +544 -544
- package/src/WpNumber.vue +178 -183
- package/src/WpSegmented.vue +175 -175
- package/src/WpSelect.vue +93 -89
- package/src/WpSwitch.vue +163 -163
- package/src/WpTabs.vue +188 -188
- package/src/_modal-motion.css +33 -33
- package/src/_skeleton.css +50 -50
- package/src/axis-color.ts +42 -42
- package/src/button.css +169 -169
- package/src/calendar.ts +59 -59
- package/src/clipboard.ts +50 -50
- package/src/colour-presets.ts +12 -12
- package/src/diff.ts +51 -51
- package/src/drop-zone.ts +41 -41
- package/src/field.css +50 -0
- package/src/flip.ts +237 -237
- package/src/floating-layer.ts +48 -0
- package/src/floating.ts +99 -99
- package/src/highlight.ts +199 -0
- package/src/hsv.ts +100 -100
- package/src/icon-catalog.ts +52 -52
- package/src/image-zoom.ts +93 -93
- package/src/kind-colour.ts +28 -0
- package/src/loading-mark-motion.ts +249 -0
- package/src/logo-paths.ts +21 -21
- package/src/matrix-axis.ts +91 -91
- package/src/pagination.ts +27 -27
- package/src/platform-keys.ts +29 -29
- package/src/rich-tokenize.ts +357 -357
- package/src/select-types.ts +32 -32
- package/src/slider-math.ts +45 -45
- package/src/sortable.ts +22 -22
- package/src/theme/fonts/OFL-Fraunces.txt +93 -93
- package/src/theme/fonts/OFL-JetBrainsMono.txt +93 -93
- package/src/theme/fonts/OFL-Manrope.txt +93 -93
- package/src/theme/looks.css +428 -428
- package/src/theme/palettes.css +254 -254
- package/src/theme/tokens.css +2896 -2894
- package/src/tokens.ts +56 -56
- package/src/tooltip.css +43 -43
- package/src/tooltip.ts +146 -146
- package/src/useDialogFocus.ts +73 -73
- package/src/useGrowableField.ts +357 -357
- package/src/useModalKeyShield.ts +116 -116
- package/src/useToast.ts +48 -48
- package/src/wp-logo.svg +14 -14
- package/src/ChipToggle.vue +0 -92
- package/src/KindChip.vue +0 -53
- package/src/RatingBadge.vue +0 -42
package/src/Modal.vue
CHANGED
|
@@ -1,76 +1,78 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import CloseButton from "./CloseButton.vue";
|
|
3
|
-
import { computed, ref, useId, useSlots } from "vue";
|
|
4
|
-
import { useDialogFocus } from "./useDialogFocus";
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
open: boolean;
|
|
8
|
-
title?: string | undefined;
|
|
9
|
-
size?: "sm" | "md" | "lg" | undefined;
|
|
10
|
-
closeOnBackdrop?: boolean | undefined;
|
|
11
|
-
}
|
|
12
|
-
const props = withDefaults(defineProps<Props>(), { size: "md", closeOnBackdrop: true });
|
|
13
|
-
|
|
14
|
-
const emit = defineEmits<{
|
|
15
|
-
(e: "update:open", v: boolean): void;
|
|
16
|
-
}>();
|
|
17
|
-
|
|
18
|
-
const slots = useSlots();
|
|
19
|
-
|
|
20
|
-
const modalClasses = computed(() => ["wp-modal", `wp-modal--${props.size}`]);
|
|
21
|
-
const dialog = ref<HTMLElement | null>(null);
|
|
22
|
-
const titleId = `wp-modal-title-${useId()}`;
|
|
23
|
-
|
|
24
|
-
function close() {
|
|
25
|
-
emit("update:open", false);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function onBackdrop() {
|
|
29
|
-
if (props.closeOnBackdrop) close();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
useDialogFocus(dialog, () => props.open, {
|
|
33
|
-
onEscape: close,
|
|
34
|
-
// The first control in the body, else the dialog itself (the close button
|
|
35
|
-
// would make Enter close it).
|
|
36
|
-
initial: (root, els) => {
|
|
37
|
-
const body = root.querySelector(".wp-modal__body");
|
|
38
|
-
return els.find((el) => body?.contains(el)) ?? root;
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
</script>
|
|
42
|
-
|
|
43
|
-
<template>
|
|
44
|
-
<Teleport to="body">
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
</
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import CloseButton from "./CloseButton.vue";
|
|
3
|
+
import { computed, ref, useId, useSlots } from "vue";
|
|
4
|
+
import { useDialogFocus } from "./useDialogFocus";
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
open: boolean;
|
|
8
|
+
title?: string | undefined;
|
|
9
|
+
size?: "sm" | "md" | "lg" | undefined;
|
|
10
|
+
closeOnBackdrop?: boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
const props = withDefaults(defineProps<Props>(), { size: "md", closeOnBackdrop: true });
|
|
13
|
+
|
|
14
|
+
const emit = defineEmits<{
|
|
15
|
+
(e: "update:open", v: boolean): void;
|
|
16
|
+
}>();
|
|
17
|
+
|
|
18
|
+
const slots = useSlots();
|
|
19
|
+
|
|
20
|
+
const modalClasses = computed(() => ["wp-modal", `wp-modal--${props.size}`]);
|
|
21
|
+
const dialog = ref<HTMLElement | null>(null);
|
|
22
|
+
const titleId = `wp-modal-title-${useId()}`;
|
|
23
|
+
|
|
24
|
+
function close() {
|
|
25
|
+
emit("update:open", false);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function onBackdrop() {
|
|
29
|
+
if (props.closeOnBackdrop) close();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
useDialogFocus(dialog, () => props.open, {
|
|
33
|
+
onEscape: close,
|
|
34
|
+
// The first control in the body, else the dialog itself (the close button
|
|
35
|
+
// would make Enter close it).
|
|
36
|
+
initial: (root, els) => {
|
|
37
|
+
const body = root.querySelector(".wp-modal__body");
|
|
38
|
+
return els.find((el) => body?.contains(el)) ?? root;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<Teleport to="body">
|
|
45
|
+
<!-- The backdrop is a click target only; keyboard users close with Escape. -->
|
|
46
|
+
<!-- eslint-disable-next-line vuejs-accessibility/no-static-element-interactions -->
|
|
47
|
+
<div
|
|
48
|
+
v-if="open"
|
|
49
|
+
class="wp-modal__backdrop"
|
|
50
|
+
data-test="modal-backdrop"
|
|
51
|
+
@mousedown.self="onBackdrop"
|
|
52
|
+
>
|
|
53
|
+
<div
|
|
54
|
+
ref="dialog"
|
|
55
|
+
:class="modalClasses"
|
|
56
|
+
role="dialog"
|
|
57
|
+
aria-modal="true"
|
|
58
|
+
:aria-labelledby="title || slots.header ? titleId : undefined"
|
|
59
|
+
tabindex="-1"
|
|
60
|
+
@mousedown.stop
|
|
61
|
+
>
|
|
62
|
+
<header v-if="title || slots.header" class="wp-modal__head">
|
|
63
|
+
<h3 v-if="title" :id="titleId" class="wp-modal__title">{{ title }}</h3>
|
|
64
|
+
<!-- A custom header puts :id="titleId" on its own heading. -->
|
|
65
|
+
<slot name="header" :title-id="titleId" />
|
|
66
|
+
<span class="wp-spacer" />
|
|
67
|
+
<CloseButton kbd="Esc" @click="close" />
|
|
68
|
+
</header>
|
|
69
|
+
<div class="wp-modal__body">
|
|
70
|
+
<slot />
|
|
71
|
+
</div>
|
|
72
|
+
<footer v-if="slots.footer" class="wp-modal__foot">
|
|
73
|
+
<slot name="footer" />
|
|
74
|
+
</footer>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</Teleport>
|
|
78
|
+
</template>
|
package/src/ModalShell.vue
CHANGED
|
@@ -1,107 +1,109 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<Teleport to="body">
|
|
3
|
-
<Transition name="wp-modal" appear>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
</
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<Teleport to="body">
|
|
3
|
+
<Transition name="wp-modal" appear>
|
|
4
|
+
<!-- The overlay is a click target only; keyboard users close with Escape. -->
|
|
5
|
+
<!-- eslint-disable-next-line vuejs-accessibility/click-events-have-key-events, vuejs-accessibility/no-static-element-interactions -->
|
|
6
|
+
<div v-if="visible" ref="overlayEl" class="wp-modal-overlay" @click="$emit('close')">
|
|
7
|
+
<div
|
|
8
|
+
class="wp-modal-wrapper"
|
|
9
|
+
role="dialog"
|
|
10
|
+
aria-modal="true"
|
|
11
|
+
:aria-label="label"
|
|
12
|
+
:aria-labelledby="labelledby"
|
|
13
|
+
@click.stop
|
|
14
|
+
>
|
|
15
|
+
<slot></slot>
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
18
|
+
</Transition>
|
|
19
|
+
</Teleport>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
import { ref, watch, onBeforeUnmount } from "vue";
|
|
24
|
+
import { useModalKeyShield } from "./useModalKeyShield";
|
|
25
|
+
|
|
26
|
+
const props = defineProps<{
|
|
27
|
+
visible: boolean;
|
|
28
|
+
/** The dialog's name when it has no visible title. */
|
|
29
|
+
label?: string | undefined;
|
|
30
|
+
/** Id of the element that names the dialog (its title). */
|
|
31
|
+
labelledby?: string | undefined;
|
|
32
|
+
}>();
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
(e: "close"): void;
|
|
35
|
+
/** Every keydown inside the modal. Consumers MUST use this instead of a
|
|
36
|
+
* window listener: the shield stops inside-modal keys at the overlay, so a
|
|
37
|
+
* window listener would never see them. */
|
|
38
|
+
(e: "keydown", ev: KeyboardEvent): void;
|
|
39
|
+
}>();
|
|
40
|
+
|
|
41
|
+
const overlayEl = ref<HTMLElement | null>(null);
|
|
42
|
+
|
|
43
|
+
function closeOnEscape(event: KeyboardEvent): void {
|
|
44
|
+
if (!props.visible || event.key !== "Escape") return;
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
emit("close");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Keys pressed INSIDE the modal are handled here and stop at the overlay, so
|
|
50
|
+
// they never reach ComfyUI's global shortcuts (see useModalKeyShield).
|
|
51
|
+
useModalKeyShield(overlayEl, {
|
|
52
|
+
onKey: (ev) => {
|
|
53
|
+
emit("keydown", ev);
|
|
54
|
+
closeOnEscape(ev);
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// The window listener still covers the case where focus is OUTSIDE the modal
|
|
59
|
+
// — clicking the canvas leaves the modal open but unfocused, and Escape should
|
|
60
|
+
// still close it. Events from inside never get here; the shield stops them.
|
|
61
|
+
function onKeydown(event: KeyboardEvent) {
|
|
62
|
+
closeOnEscape(event);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
watch(
|
|
66
|
+
() => props.visible,
|
|
67
|
+
(visible) => {
|
|
68
|
+
if (visible) window.addEventListener("keydown", onKeydown);
|
|
69
|
+
else window.removeEventListener("keydown", onKeydown);
|
|
70
|
+
},
|
|
71
|
+
{ immediate: true },
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
onBeforeUnmount(() => window.removeEventListener("keydown", onKeydown));
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<style>
|
|
78
|
+
@import "./_modal-motion.css";
|
|
79
|
+
</style>
|
|
80
|
+
|
|
81
|
+
<style scoped>
|
|
82
|
+
.wp-modal-overlay,
|
|
83
|
+
.wp-modal-overlay * {
|
|
84
|
+
box-sizing: border-box;
|
|
85
|
+
}
|
|
86
|
+
.wp-modal-overlay {
|
|
87
|
+
position: fixed;
|
|
88
|
+
inset: 0;
|
|
89
|
+
z-index: 9999;
|
|
90
|
+
display: flex;
|
|
91
|
+
align-items: center;
|
|
92
|
+
justify-content: center;
|
|
93
|
+
padding: 20px;
|
|
94
|
+
background: var(--wp-overlay-bg, rgba(0, 0, 0, 0.62));
|
|
95
|
+
font-family: var(--wp-font-sans, sans-serif);
|
|
96
|
+
cursor: default;
|
|
97
|
+
}
|
|
98
|
+
.wp-modal-wrapper {
|
|
99
|
+
display: flex;
|
|
100
|
+
justify-content: center;
|
|
101
|
+
width: 100%;
|
|
102
|
+
max-height: 100%;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* `wp-modal` open/close transition lives in
|
|
106
|
+
* src/components/shared/_modal-motion.css (imported globally via
|
|
107
|
+
* ContextWidget) so every modal — ModalShell consumers, ConfirmDialog,
|
|
108
|
+
* InjectorBindingModal — animates with the same rules. */
|
|
109
|
+
</style>
|
package/src/Pagination.vue
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
/**
|
|
3
|
-
* Pagination: move through a long list a page at a time, or load more at
|
|
4
|
-
* its end. Works on the canvas and in the manager.
|
|
5
|
-
*
|
|
6
|
-
* <Pagination v-model:page="page" :total="rows.length" :page-size="50" />
|
|
7
|
-
* <Pagination mode="more" :shown="shown.length" :total="230" :loading="busy" @more="loadMore" />
|
|
8
|
-
*
|
|
9
|
-
* Pages: a `nav` with Previous / Next and the page numbers (first, last, the
|
|
10
|
-
* current page with `siblings` either side, "…" between), the current one
|
|
11
|
-
* marked `aria-current="page"`. More: one "Load more" button under a
|
|
12
|
-
* "Showing 50 of 230" line. Nothing is drawn when everything fits on one page.
|
|
13
|
-
*/
|
|
14
|
-
import { computed } from "vue";
|
|
15
|
-
import { pageItems } from "./pagination";
|
|
16
|
-
import WpButton from "./WpButton.vue";
|
|
17
|
-
|
|
18
|
-
const props = withDefaults(defineProps<{
|
|
19
|
-
/** pages: numbered pages. more: a Load more button. */
|
|
20
|
-
mode?: "pages" | "more" | undefined;
|
|
21
|
-
/** The current page, from 1. */
|
|
22
|
-
page?: number | undefined;
|
|
23
|
-
/** How many items there are in all. */
|
|
24
|
-
total: number;
|
|
25
|
-
pageSize?: number | undefined;
|
|
26
|
-
/** Pages shown either side of the current one. */
|
|
27
|
-
siblings?: number | undefined;
|
|
28
|
-
/** In "more" mode: how many items are on screen. */
|
|
29
|
-
shown?: number | undefined;
|
|
30
|
-
loading?: boolean | undefined;
|
|
31
|
-
disabled?: boolean | undefined;
|
|
32
|
-
size?: "sm" | "md" | undefined;
|
|
33
|
-
/** The item's name in "Showing 50 of 230 modules". */
|
|
34
|
-
noun?: string | undefined;
|
|
35
|
-
ariaLabel?: string | undefined;
|
|
36
|
-
}>(), { mode: "pages", page: 1, pageSize: 25, siblings: 1, shown: 0, size: "md", noun: undefined, ariaLabel: "Pages" });
|
|
37
|
-
|
|
38
|
-
const emit = defineEmits<{ (e: "update:page", v: number): void; (e: "more"): void }>();
|
|
39
|
-
|
|
40
|
-
const pages = computed(() => Math.max(1, Math.ceil(props.total / Math.max(1, props.pageSize))));
|
|
41
|
-
const items = computed(() => pageItems(props.page, pages.value, props.siblings));
|
|
42
|
-
const from = computed(() => Math.min(props.total, (props.page - 1) * props.pageSize + 1));
|
|
43
|
-
const to = computed(() => Math.min(props.total, props.page * props.pageSize));
|
|
44
|
-
|
|
45
|
-
function go(p: number): void {
|
|
46
|
-
const next = Math.min(Math.max(1, p), pages.value);
|
|
47
|
-
if (next !== props.page && !props.disabled) emit("update:page", next);
|
|
48
|
-
}
|
|
49
|
-
const btnSize = computed(() => (props.size === "sm" ? "sm" : "md"));
|
|
50
|
-
</script>
|
|
51
|
-
|
|
52
|
-
<template>
|
|
53
|
-
<nav v-if="mode === 'pages' && pages > 1" class="wp-paging" :data-size="size" :aria-label="ariaLabel">
|
|
54
|
-
<span class="wp-paging__range" aria-live="polite">{{ from }}–{{ to }} of {{ total }}</span>
|
|
55
|
-
<ul class="wp-paging__list">
|
|
56
|
-
<li>
|
|
57
|
-
<WpButton variant="ghost" :size="btnSize" icon="pi-chevron-left" aria-label="Previous page" :disabled="disabled || props.page <= 1" @click="go(props.page - 1)" />
|
|
58
|
-
</li>
|
|
59
|
-
<li v-for="it in items" :key="it">
|
|
60
|
-
<span v-if="typeof it !== 'number'" class="wp-paging__gap" aria-hidden="true">…</span>
|
|
61
|
-
<button
|
|
62
|
-
v-else
|
|
63
|
-
type="button"
|
|
64
|
-
class="wp-paging__page"
|
|
65
|
-
:data-size="size"
|
|
66
|
-
:aria-current="it === page ? 'page' : undefined"
|
|
67
|
-
:aria-label="`Page ${it}`"
|
|
68
|
-
:disabled="disabled"
|
|
69
|
-
@click="go(it)"
|
|
70
|
-
>{{ it }}</button>
|
|
71
|
-
</li>
|
|
72
|
-
<li>
|
|
73
|
-
<WpButton variant="ghost" :size="btnSize" icon="pi-chevron-right" aria-label="Next page" :disabled="disabled || props.page >= pages" @click="go(props.page + 1)" />
|
|
74
|
-
</li>
|
|
75
|
-
</ul>
|
|
76
|
-
</nav>
|
|
77
|
-
<div v-else-if="mode === 'more' && total > 0" class="wp-paging wp-paging--more" :data-size="size">
|
|
78
|
-
<span class="wp-paging__range" aria-live="polite">Showing {{ Math.min(props.shown, total) }} of {{ total }}{{ noun ? ` ${noun}` : "" }}</span>
|
|
79
|
-
<WpButton v-if="props.shown < total" variant="secondary" :size="btnSize" :loading="loading" :disabled="disabled" @click="emit('more')">Load more</WpButton>
|
|
80
|
-
</div>
|
|
81
|
-
</template>
|
|
82
|
-
|
|
83
|
-
<style scoped>
|
|
84
|
-
.wp-paging {
|
|
85
|
-
display: flex; align-items: center; justify-content: space-between; gap: var(--wp-space-4); flex-wrap: wrap;
|
|
86
|
-
min-width: 0; color: var(--wp-text-muted); font: 400 var(--wp-text-sm)/1.2 var(--wp-font-sans);
|
|
87
|
-
}
|
|
88
|
-
.wp-paging[data-size="sm"] { font-size: var(--wp-text-xs); gap: var(--wp-space-3); }
|
|
89
|
-
.wp-paging--more { flex-direction: column; justify-content: center; }
|
|
90
|
-
.wp-paging__range { font-variant-numeric: tabular-nums; }
|
|
91
|
-
.wp-paging__list { display: flex; align-items: center; gap: 2px; margin: 0; padding: 0; list-style: none; }
|
|
92
|
-
.wp-paging__gap { display: inline-grid; place-items: center; min-width: 20px; color: var(--wp-text-dim); }
|
|
93
|
-
.wp-paging__page {
|
|
94
|
-
display: inline-grid; place-items: center; box-sizing: border-box;
|
|
95
|
-
min-width: var(--wp-control-h-md); height: var(--wp-control-h-md); margin: 0; padding: 0 var(--wp-space-2);
|
|
96
|
-
border: 1px solid transparent; border-radius: var(--wp-radius);
|
|
97
|
-
background: transparent; color: var(--wp-text-muted); font: 500 var(--wp-text-sm)/1 var(--wp-font-sans);
|
|
98
|
-
font-variant-numeric: tabular-nums; cursor: pointer;
|
|
99
|
-
transition: background var(--wp-motion-hover), color var(--wp-motion-hover);
|
|
100
|
-
}
|
|
101
|
-
.wp-paging__page[data-size="sm"] { min-width: var(--wp-control-h-sm); height: var(--wp-control-h-sm); border-radius: var(--wp-radius-sm); font-size: var(--wp-text-xs); }
|
|
102
|
-
.wp-paging__page:hover:not(:disabled) { background: var(--wp-row-hover); color: var(--wp-text); }
|
|
103
|
-
.wp-paging__page[aria-current="page"] { border-color: var(--wp-border-strong); background: var(--wp-bg-3); color: var(--wp-text); font-weight: 600; }
|
|
104
|
-
.wp-paging__page:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
105
|
-
.wp-paging__page:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
106
|
-
</style>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Pagination: move through a long list a page at a time, or load more at
|
|
4
|
+
* its end. Works on the canvas and in the manager.
|
|
5
|
+
*
|
|
6
|
+
* <Pagination v-model:page="page" :total="rows.length" :page-size="50" />
|
|
7
|
+
* <Pagination mode="more" :shown="shown.length" :total="230" :loading="busy" @more="loadMore" />
|
|
8
|
+
*
|
|
9
|
+
* Pages: a `nav` with Previous / Next and the page numbers (first, last, the
|
|
10
|
+
* current page with `siblings` either side, "…" between), the current one
|
|
11
|
+
* marked `aria-current="page"`. More: one "Load more" button under a
|
|
12
|
+
* "Showing 50 of 230" line. Nothing is drawn when everything fits on one page.
|
|
13
|
+
*/
|
|
14
|
+
import { computed } from "vue";
|
|
15
|
+
import { pageItems } from "./pagination";
|
|
16
|
+
import WpButton from "./WpButton.vue";
|
|
17
|
+
|
|
18
|
+
const props = withDefaults(defineProps<{
|
|
19
|
+
/** pages: numbered pages. more: a Load more button. */
|
|
20
|
+
mode?: "pages" | "more" | undefined;
|
|
21
|
+
/** The current page, from 1. */
|
|
22
|
+
page?: number | undefined;
|
|
23
|
+
/** How many items there are in all. */
|
|
24
|
+
total: number;
|
|
25
|
+
pageSize?: number | undefined;
|
|
26
|
+
/** Pages shown either side of the current one. */
|
|
27
|
+
siblings?: number | undefined;
|
|
28
|
+
/** In "more" mode: how many items are on screen. */
|
|
29
|
+
shown?: number | undefined;
|
|
30
|
+
loading?: boolean | undefined;
|
|
31
|
+
disabled?: boolean | undefined;
|
|
32
|
+
size?: "sm" | "md" | undefined;
|
|
33
|
+
/** The item's name in "Showing 50 of 230 modules". */
|
|
34
|
+
noun?: string | undefined;
|
|
35
|
+
ariaLabel?: string | undefined;
|
|
36
|
+
}>(), { mode: "pages", page: 1, pageSize: 25, siblings: 1, shown: 0, size: "md", noun: undefined, ariaLabel: "Pages" });
|
|
37
|
+
|
|
38
|
+
const emit = defineEmits<{ (e: "update:page", v: number): void; (e: "more"): void }>();
|
|
39
|
+
|
|
40
|
+
const pages = computed(() => Math.max(1, Math.ceil(props.total / Math.max(1, props.pageSize))));
|
|
41
|
+
const items = computed(() => pageItems(props.page, pages.value, props.siblings));
|
|
42
|
+
const from = computed(() => Math.min(props.total, (props.page - 1) * props.pageSize + 1));
|
|
43
|
+
const to = computed(() => Math.min(props.total, props.page * props.pageSize));
|
|
44
|
+
|
|
45
|
+
function go(p: number): void {
|
|
46
|
+
const next = Math.min(Math.max(1, p), pages.value);
|
|
47
|
+
if (next !== props.page && !props.disabled) emit("update:page", next);
|
|
48
|
+
}
|
|
49
|
+
const btnSize = computed(() => (props.size === "sm" ? "sm" : "md"));
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<nav v-if="mode === 'pages' && pages > 1" class="wp-paging" :data-size="size" :aria-label="ariaLabel">
|
|
54
|
+
<span class="wp-paging__range" aria-live="polite">{{ from }}–{{ to }} of {{ total }}</span>
|
|
55
|
+
<ul class="wp-paging__list">
|
|
56
|
+
<li>
|
|
57
|
+
<WpButton variant="ghost" :size="btnSize" icon="pi-chevron-left" aria-label="Previous page" :disabled="disabled || props.page <= 1" @click="go(props.page - 1)" />
|
|
58
|
+
</li>
|
|
59
|
+
<li v-for="it in items" :key="it">
|
|
60
|
+
<span v-if="typeof it !== 'number'" class="wp-paging__gap" aria-hidden="true">…</span>
|
|
61
|
+
<button
|
|
62
|
+
v-else
|
|
63
|
+
type="button"
|
|
64
|
+
class="wp-paging__page"
|
|
65
|
+
:data-size="size"
|
|
66
|
+
:aria-current="it === page ? 'page' : undefined"
|
|
67
|
+
:aria-label="`Page ${it}`"
|
|
68
|
+
:disabled="disabled"
|
|
69
|
+
@click="go(it)"
|
|
70
|
+
>{{ it }}</button>
|
|
71
|
+
</li>
|
|
72
|
+
<li>
|
|
73
|
+
<WpButton variant="ghost" :size="btnSize" icon="pi-chevron-right" aria-label="Next page" :disabled="disabled || props.page >= pages" @click="go(props.page + 1)" />
|
|
74
|
+
</li>
|
|
75
|
+
</ul>
|
|
76
|
+
</nav>
|
|
77
|
+
<div v-else-if="mode === 'more' && total > 0" class="wp-paging wp-paging--more" :data-size="size">
|
|
78
|
+
<span class="wp-paging__range" aria-live="polite">Showing {{ Math.min(props.shown, total) }} of {{ total }}{{ noun ? ` ${noun}` : "" }}</span>
|
|
79
|
+
<WpButton v-if="props.shown < total" variant="secondary" :size="btnSize" :loading="loading" :disabled="disabled" @click="emit('more')">Load more</WpButton>
|
|
80
|
+
</div>
|
|
81
|
+
</template>
|
|
82
|
+
|
|
83
|
+
<style scoped>
|
|
84
|
+
.wp-paging {
|
|
85
|
+
display: flex; align-items: center; justify-content: space-between; gap: var(--wp-space-4); flex-wrap: wrap;
|
|
86
|
+
min-width: 0; color: var(--wp-text-muted); font: 400 var(--wp-text-sm)/1.2 var(--wp-font-sans);
|
|
87
|
+
}
|
|
88
|
+
.wp-paging[data-size="sm"] { font-size: var(--wp-text-xs); gap: var(--wp-space-3); }
|
|
89
|
+
.wp-paging--more { flex-direction: column; justify-content: center; }
|
|
90
|
+
.wp-paging__range { font-variant-numeric: tabular-nums; }
|
|
91
|
+
.wp-paging__list { display: flex; align-items: center; gap: 2px; margin: 0; padding: 0; list-style: none; }
|
|
92
|
+
.wp-paging__gap { display: inline-grid; place-items: center; min-width: 20px; color: var(--wp-text-dim); }
|
|
93
|
+
.wp-paging__page {
|
|
94
|
+
display: inline-grid; place-items: center; box-sizing: border-box;
|
|
95
|
+
min-width: var(--wp-control-h-md); height: var(--wp-control-h-md); margin: 0; padding: 0 var(--wp-space-2);
|
|
96
|
+
border: 1px solid transparent; border-radius: var(--wp-radius);
|
|
97
|
+
background: transparent; color: var(--wp-text-muted); font: 500 var(--wp-text-sm)/1 var(--wp-font-sans);
|
|
98
|
+
font-variant-numeric: tabular-nums; cursor: pointer;
|
|
99
|
+
transition: background var(--wp-motion-hover), color var(--wp-motion-hover);
|
|
100
|
+
}
|
|
101
|
+
.wp-paging__page[data-size="sm"] { min-width: var(--wp-control-h-sm); height: var(--wp-control-h-sm); border-radius: var(--wp-radius-sm); font-size: var(--wp-text-xs); }
|
|
102
|
+
.wp-paging__page:hover:not(:disabled) { background: var(--wp-row-hover); color: var(--wp-text); }
|
|
103
|
+
.wp-paging__page[aria-current="page"] { border-color: var(--wp-border-strong); background: var(--wp-bg-3); color: var(--wp-text); font-weight: 600; }
|
|
104
|
+
.wp-paging__page:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--wp-border-focus); }
|
|
105
|
+
.wp-paging__page:disabled { opacity: 0.45; cursor: not-allowed; }
|
|
106
|
+
</style>
|