Files
heroui-vue/packages/vue/src/components/pagination/PaginationLink.vue
T

80 lines
2.0 KiB
Vue

<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>