feat: migrate Pagination Header and InputOTP with field and event regressions

This commit is contained in:
maoyingjie
2026-10-23 13:49:44 +08:00
parent b2525bb04d
commit 1fa2929a24
72 changed files with 5784 additions and 16 deletions
@@ -0,0 +1,30 @@
<script lang="ts">
/** Baseline IconChevronLeft from HeroUI icons.tsx (Apache-2.0). */
export default {
name: "PaginationChevronLeftIcon",
};
</script>
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<svg
aria-hidden="true"
fill="none"
height="16"
role="presentation"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
v-bind="$attrs"
>
<path
clip-rule="evenodd"
d="M10.53 2.97a.75.75 0 0 1 0 1.06L6.56 8l3.97 3.97a.75.75 0 1 1-1.06 1.06l-4.5-4.5a.75.75 0 0 1 0-1.06l4.5-4.5a.75.75 0 0 1 1.06 0"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</template>
@@ -0,0 +1,30 @@
<script lang="ts">
/** Baseline IconChevronRight from HeroUI icons.tsx (Apache-2.0). */
export default {
name: "PaginationChevronRightIcon",
};
</script>
<script setup lang="ts">
defineOptions({ inheritAttrs: false });
</script>
<template>
<svg
aria-hidden="true"
fill="none"
height="16"
role="presentation"
viewBox="0 0 16 16"
width="16"
xmlns="http://www.w3.org/2000/svg"
v-bind="$attrs"
>
<path
clip-rule="evenodd"
d="M5.47 2.97a.75.75 0 0 1 1.06 0l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 0 1-1.06-1.06L9.44 8 5.47 4.03a.75.75 0 0 1 0-1.06Z"
fill="currentColor"
fill-rule="evenodd"
/>
</svg>
</template>
@@ -0,0 +1,34 @@
<script lang="ts">
import { defineComponent, h, inject, useAttrs } from "vue";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationContent",
inheritAttrs: false,
props: {
/** Render the content list as a custom element instead of `ul`. */
as: {
type: String,
default: "ul",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const context = inject(paginationContextKey, null);
function render() {
return h(
props.as,
{
...attrs,
class: [context?.slots.value.content(), attrs.class],
"data-slot": "pagination-content",
},
slots.default?.(),
);
}
return render;
},
});
</script>
@@ -0,0 +1,36 @@
<script lang="ts">
import { defineComponent, h, inject, useAttrs } from "vue";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationEllipsis",
inheritAttrs: false,
props: {
/** Render the ellipsis as a custom element instead of `span`. */
as: {
type: String,
default: "span",
},
},
setup(props) {
const attrs = useAttrs();
const context = inject(paginationContextKey, null);
function render() {
// Upstream always renders &hellip; and does not take custom children.
return h(
props.as,
{
...attrs,
class: [context?.slots.value.ellipsis(), attrs.class],
"aria-hidden": "true",
"data-slot": "pagination-ellipsis",
},
["…"],
);
}
return render;
},
});
</script>
@@ -0,0 +1,34 @@
<script lang="ts">
import { defineComponent, h, inject, useAttrs } from "vue";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationItem",
inheritAttrs: false,
props: {
/** Render the item as a custom element instead of `li`. */
as: {
type: String,
default: "li",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const context = inject(paginationContextKey, null);
function render() {
return h(
props.as,
{
...attrs,
class: [context?.slots.value.item(), attrs.class],
"data-slot": "pagination-item",
},
slots.default?.(),
);
}
return render;
},
});
</script>
@@ -0,0 +1,79 @@
<script lang="ts">
import { computed, defineComponent, h, inject, useAttrs } from "vue";
import { Primitive } from "reka-ui";
import type { ButtonHTMLAttributes, PropType } from "vue";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationLink",
inheritAttrs: false,
props: {
/** Whether this link is the current page. */
isActive: {
type: Boolean,
default: false,
},
isDisabled: {
type: Boolean,
default: undefined,
},
disabled: {
type: Boolean,
default: undefined,
},
type: {
type: String as PropType<ButtonHTMLAttributes["type"]>,
default: "button",
},
asChild: {
type: Boolean,
default: false,
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const context = inject(paginationContextKey, null);
const disabled = computed(
() => props.isDisabled ?? props.disabled ?? undefined,
);
function render() {
const {
class: cls,
"aria-current": explicitCurrent,
"data-active": explicitActive,
...rest
} = attrs as Record<string, unknown>;
const bind: Record<string, unknown> = { ...rest };
if (disabled.value !== undefined) bind.disabled = disabled.value;
return h(
Primitive,
{
as: "button",
asChild: props.asChild,
type: props.asChild ? undefined : props.type,
...bind,
class: [context?.slots.value.link(), cls],
// Explicit caller attributes win over isActive defaults.
"aria-current":
explicitCurrent !== undefined
? explicitCurrent
: props.isActive
? "page"
: undefined,
"data-active":
explicitActive !== undefined
? explicitActive
: props.isActive
? "true"
: undefined,
"data-slot": "pagination-link",
},
slots,
);
}
return render;
},
});
</script>
@@ -0,0 +1,60 @@
<script lang="ts">
import { computed, defineComponent, h, inject, useAttrs } from "vue";
import { Primitive } from "reka-ui";
import type { ButtonHTMLAttributes, PropType } from "vue";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationNext",
inheritAttrs: false,
props: {
isDisabled: {
type: Boolean,
default: undefined,
},
disabled: {
type: Boolean,
default: undefined,
},
type: {
type: String as PropType<ButtonHTMLAttributes["type"]>,
default: "button",
},
asChild: {
type: Boolean,
default: false,
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const context = inject(paginationContextKey, null);
const disabled = computed(
() => props.isDisabled ?? props.disabled ?? undefined,
);
const linkClass = computed(() =>
[context?.slots.value.link(), "hv-pagination__link--nav"]
.filter(Boolean)
.join(" "),
);
function render() {
const bind: Record<string, unknown> = { ...attrs };
if (disabled.value !== undefined) bind.disabled = disabled.value;
return h(
Primitive,
{
as: "button",
asChild: props.asChild,
type: props.asChild ? undefined : props.type,
...bind,
class: [linkClass.value, attrs.class],
"data-slot": "pagination-next",
},
slots,
);
}
return render;
},
});
</script>
@@ -0,0 +1,45 @@
<script lang="ts">
import { defineComponent, h, useAttrs, type VNodeChild } from "vue";
import PaginationChevronRightIcon from "./PaginationChevronRightIcon.vue";
function hasContent(nodes: VNodeChild[] | undefined): boolean {
if (!nodes || nodes.length === 0) return false;
return nodes.some((node) => {
if (node == null || node === false || node === true) return false;
if (typeof node === "string") return node.trim() !== "";
if (typeof node === "number") return true;
return true;
});
}
export default defineComponent({
name: "PaginationNextIcon",
inheritAttrs: false,
props: {
/** Render the icon wrapper as a custom element instead of `span`. */
as: {
type: String,
default: "span",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
function render() {
const content = slots.default?.() as VNodeChild[] | undefined;
return h(
props.as,
{
...attrs,
class: attrs.class,
"aria-hidden": "true",
"data-slot": "pagination-next-icon",
},
hasContent(content) ? content : [h(PaginationChevronRightIcon)],
);
}
return render;
},
});
</script>
@@ -0,0 +1,60 @@
<script lang="ts">
import { computed, defineComponent, h, inject, useAttrs } from "vue";
import { Primitive } from "reka-ui";
import type { ButtonHTMLAttributes, PropType } from "vue";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationPrevious",
inheritAttrs: false,
props: {
isDisabled: {
type: Boolean,
default: undefined,
},
disabled: {
type: Boolean,
default: undefined,
},
type: {
type: String as PropType<ButtonHTMLAttributes["type"]>,
default: "button",
},
asChild: {
type: Boolean,
default: false,
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const context = inject(paginationContextKey, null);
const disabled = computed(
() => props.isDisabled ?? props.disabled ?? undefined,
);
const linkClass = computed(() =>
[context?.slots.value.link(), "hv-pagination__link--nav"]
.filter(Boolean)
.join(" "),
);
function render() {
const bind: Record<string, unknown> = { ...attrs };
if (disabled.value !== undefined) bind.disabled = disabled.value;
return h(
Primitive,
{
as: "button",
asChild: props.asChild,
type: props.asChild ? undefined : props.type,
...bind,
class: [linkClass.value, attrs.class],
"data-slot": "pagination-previous",
},
slots,
);
}
return render;
},
});
</script>
@@ -0,0 +1,45 @@
<script lang="ts">
import { defineComponent, h, useAttrs, type VNodeChild } from "vue";
import PaginationChevronLeftIcon from "./PaginationChevronLeftIcon.vue";
function hasContent(nodes: VNodeChild[] | undefined): boolean {
if (!nodes || nodes.length === 0) return false;
return nodes.some((node) => {
if (node == null || node === false || node === true) return false;
if (typeof node === "string") return node.trim() !== "";
if (typeof node === "number") return true;
return true;
});
}
export default defineComponent({
name: "PaginationPreviousIcon",
inheritAttrs: false,
props: {
/** Render the icon wrapper as a custom element instead of `span`. */
as: {
type: String,
default: "span",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
function render() {
const content = slots.default?.() as VNodeChild[] | undefined;
return h(
props.as,
{
...attrs,
class: attrs.class,
"aria-hidden": "true",
"data-slot": "pagination-previous-icon",
},
hasContent(content) ? content : [h(PaginationChevronLeftIcon)],
);
}
return render;
},
});
</script>
@@ -0,0 +1,55 @@
<script lang="ts">
import {
computed,
defineComponent,
h,
provide,
useAttrs,
type PropType,
} from "vue";
import {
paginationVariants,
type PaginationVariants,
} from "@heroui-vue/styles";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationRoot",
inheritAttrs: false,
props: {
/** Pagination size. */
size: {
type: String as PropType<PaginationVariants["size"]>,
default: "md",
},
/** Render the root as a custom element instead of `nav`. */
as: {
type: String,
default: "nav",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const variantSlots = computed(() =>
paginationVariants({ size: props.size }),
);
provide(paginationContextKey, { slots: variantSlots });
function render() {
return h(
props.as,
{
...attrs,
class: [variantSlots.value.base(), attrs.class],
"aria-label": attrs["aria-label"] ?? "pagination",
role: attrs.role ?? "navigation",
"data-slot": "pagination",
},
slots.default?.(),
);
}
return render;
},
});
</script>
@@ -0,0 +1,39 @@
<script lang="ts">
import { defineComponent, h, inject, useAttrs } from "vue";
import { paginationContextKey } from "./context";
export default defineComponent({
name: "PaginationSummary",
inheritAttrs: false,
props: {
/** Render the summary as a custom element instead of `div`. */
as: {
type: String,
default: "div",
},
},
setup(props, { slots }) {
const attrs = useAttrs();
const context = inject(paginationContextKey, null);
function render() {
const { class: cls, dir, ...rest } = attrs as Record<string, unknown>;
return h(
props.as,
{
...rest,
// Auto-detect base direction from the summary's own text so mixed
// number/word content is not bidi-reordered by an RTL ancestor.
// Explicit `dir` still overrides.
dir: dir === undefined ? "auto" : dir,
class: [context?.slots.value.summary(), cls],
"data-slot": "pagination-summary",
},
slots.default?.(),
);
}
return render;
},
});
</script>
@@ -0,0 +1,11 @@
import type { InjectionKey, ComputedRef } from "vue";
import type { paginationVariants } from "@heroui-vue/styles";
export type PaginationSlots = ReturnType<typeof paginationVariants>;
export type PaginationContextValue = {
slots: ComputedRef<PaginationSlots>;
};
export const paginationContextKey: InjectionKey<PaginationContextValue> =
Symbol("heroui-vue.pagination");