UNPKG

@ark-ui/vue

Version:

A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.

36 lines (35 loc) 1.37 kB
import { DEFAULT_ENVIRONMENT, useEnvironmentContext } from "../../providers/environment/use-environment-context.js"; import { DEFAULT_LOCALE, useLocaleContext } from "../../providers/locale/use-locale-context.js"; import { cleanProps } from "../../utils/clean-props.js"; import * as pagination from "@zag-js/pagination"; import { computed, toValue, useId } from "vue"; import { normalizeProps as normalizeProps$1, useMachine } from "@zag-js/vue"; //#region src/components/pagination/use-pagination.ts var usePagination = (props = {}, emit) => { const id = useId(); const env = useEnvironmentContext(DEFAULT_ENVIRONMENT); const locale = useLocaleContext(DEFAULT_LOCALE); const context = computed(() => { const localeProps = toValue(props); return { id, dir: locale.value.dir, getRootNode: env?.value.getRootNode, ...cleanProps(localeProps), onPageChange: (details) => { emit?.("pageChange", details); emit?.("update:page", details.page); localeProps.onPageChange?.(details); }, onPageSizeChange: (details) => { emit?.("pageSizeChange", details); emit?.("update:pageSize", details.pageSize); localeProps.onPageSizeChange?.(details); } }; }); const service = useMachine(pagination.machine, context); return computed(() => pagination.connect(service, normalizeProps$1)); }; //#endregion export { usePagination };