diff --git a/docs/components/content/ComponentCard.vue b/docs/components/content/ComponentCard.vue index 192f67ea..9ef95708 100644 --- a/docs/components/content/ComponentCard.vue +++ b/docs/components/content/ComponentCard.vue @@ -121,7 +121,7 @@ const meta = await fetchComponentMeta(name) // eslint-disable-next-line vue/no-dupe-keys const ui = computed(() => ({ ...appConfig.ui[camelName], ...props.ui })) -const fullProps = computed(() => ({ ...props.baseProps, ...componentProps })) +const fullProps = computed(() => ({ ...baseProps, ...componentProps })) const vModel = computed({ get: () => baseProps.modelValue, set: (value) => { diff --git a/docs/components/content/examples/PaginationExampleBasic.vue b/docs/components/content/examples/PaginationExampleBasic.vue new file mode 100644 index 00000000..be40c31b --- /dev/null +++ b/docs/components/content/examples/PaginationExampleBasic.vue @@ -0,0 +1,8 @@ + + + diff --git a/docs/components/content/examples/PaginationExamplePrevNextSlots.vue b/docs/components/content/examples/PaginationExamplePrevNextSlots.vue new file mode 100644 index 00000000..88f04ca0 --- /dev/null +++ b/docs/components/content/examples/PaginationExamplePrevNextSlots.vue @@ -0,0 +1,20 @@ + + + diff --git a/docs/components/content/examples/TableExamplePaginable.vue b/docs/components/content/examples/TableExamplePaginable.vue new file mode 100644 index 00000000..e783577c --- /dev/null +++ b/docs/components/content/examples/TableExamplePaginable.vue @@ -0,0 +1,98 @@ + + + diff --git a/docs/components/content/themes/PaginationThemeRounded.vue b/docs/components/content/themes/PaginationThemeRounded.vue new file mode 100644 index 00000000..8dc729d0 --- /dev/null +++ b/docs/components/content/themes/PaginationThemeRounded.vue @@ -0,0 +1,21 @@ + + + diff --git a/docs/content/4.data/1.table.md b/docs/content/4.data/1.table.md index 374045d8..75437c0a 100644 --- a/docs/content/4.data/1.table.md +++ b/docs/content/4.data/1.table.md @@ -366,6 +366,41 @@ const filteredRows = computed(() => { ``` :: +### Paginable + +You can easily use the [Pagination](/navigation/pagination) component to paginate the rows. + +::component-example +--- +padding: false +--- + +#default +:table-example-paginable{class="w-full"} + +#code +```vue + + + +``` +:: + ### Empty Use the `empty-state` prop to display a message when there are no results. diff --git a/docs/content/5.navigation/1.vertical-navigation.md b/docs/content/5.navigation/1.vertical-navigation.md index 7603b9ae..8e8d1f1b 100644 --- a/docs/content/5.navigation/1.vertical-navigation.md +++ b/docs/content/5.navigation/1.vertical-navigation.md @@ -39,11 +39,9 @@ const links = [{ ``` :: -## Themes +## Theme -Our theming system provides a lot of flexibility to customize the component. Here is some examples of what you can do. - -### Tailwind +Our theming system provides a lot of flexibility to customize the component. Here is an example of what you can do. ::component-example #default diff --git a/docs/content/5.navigation/3.pagination.md b/docs/content/5.navigation/3.pagination.md new file mode 100644 index 00000000..34dea724 --- /dev/null +++ b/docs/content/5.navigation/3.pagination.md @@ -0,0 +1,186 @@ +--- +github: true +description: Add a pagination to handle pages. +--- + +## Usage + +Use a `v-model` to get a reactive page alongside a `total` which represents the total of items. You can also use the `page-count` prop to define the number of items per page which defaults to `10`. + +::component-example +#default +:pagination-example-basic + +#code +```vue + + + +``` +:: + +### Max + +Use the `max` prop to set a maximum of displayed pages. Defaults to `7`, being the minimum. + +::component-card +--- +baseProps: + modelValue: 1 +props: + max: 5 + pageCount: 5 + total: 100 +excludedProps: + - pageCount + - total +--- +:: + +### Size + +Use the `size` prop to change the size of the buttons. + +::component-card +--- +baseProps: + modelValue: 1 + total: 100 +props: + size: 'sm' +ui: + size: + 2xs: true + xs: true + sm: true + md: true + lg: true + xl: true +--- +:: + +### Active / Inactive + +Use the `active-button` and `inactive-button` props to customize the active and inactive buttons of the Pagination. + +::component-card +--- +baseProps: + modelValue: 1 + total: 100 +props: + activeButton: + variant: 'outline' + inactiveButton: + color: 'gray' +excludedProps: + - activeButton + - inactiveButton +--- +:: + +### Prev / Next + +Use the `prev-button` and `next-button` props to customize the prev and next buttons of the Pagination. + +::component-card +--- +baseProps: + modelValue: 1 + total: 100 +props: + prevButton: + icon: 'i-heroicons-arrow-small-left-20-solid' + label: Prev + color: 'gray' + nextButton: + icon: 'i-heroicons-arrow-small-right-20-solid' + trailing: true + label: Next + color: 'gray' +excludedProps: + - prevButton + - nextButton +--- +:: + +## Theme + +Our theming system provides a lot of flexibility to customize the component. Here is an example of what you can do. + +::component-example +#default +:pagination-theme-rounded +#code +```vue + + + +``` +:: + +## Slots + +### `prev` / `next` + +Use the `#prev` and `#next` slots to set the content of the previous and next buttons. + +::component-example +#default +:pagination-example-prev-next-slots + +#code +```vue + + + +``` +:: + +## Props + +:component-props + +## Preset + +:component-preset diff --git a/src/runtime/app.config.ts b/src/runtime/app.config.ts index def9c403..608aeab8 100644 --- a/src/runtime/app.config.ts +++ b/src/runtime/app.config.ts @@ -634,6 +634,29 @@ const commandPalette = { } } +const pagination = { + wrapper: 'flex items-center -space-x-px', + base: '', + rounded: 'first:rounded-l-md last:rounded-r-md', + default: { + size: 'sm', + activeButton: { + color: 'primary' + }, + inactiveButton: { + color: 'white' + }, + prevButton: { + color: 'white', + icon: 'i-heroicons-chevron-left-20-solid' + }, + nextButton: { + color: 'white', + icon: 'i-heroicons-chevron-right-20-solid' + } + } +} + // Overlays const modal = { @@ -841,6 +864,7 @@ export default { skeleton, verticalNavigation, commandPalette, + pagination, modal, slideover, popover, diff --git a/src/runtime/components/navigation/Pagination.vue b/src/runtime/components/navigation/Pagination.vue new file mode 100644 index 00000000..144f7129 --- /dev/null +++ b/src/runtime/components/navigation/Pagination.vue @@ -0,0 +1,218 @@ + + + diff --git a/src/runtime/utils/index.ts b/src/runtime/utils/index.ts index d2604d00..24ec4ded 100644 --- a/src/runtime/utils/index.ts +++ b/src/runtime/utils/index.ts @@ -18,14 +18,18 @@ export const omit = (obj: object, keys: string[]) => { export const getSlotsChildren = (slots: any) => { let children = slots.default?.() if (children.length) { - if (typeof children[0].type === 'symbol') { - // @ts-ignore-next - children = children[0].children - // @ts-ignore-next - } else if (children[0].type.name === 'ContentSlot') { - // @ts-ignore-next - children = children[0].ctx.slots.default?.() - } + children = children.flatMap(c => { + if (typeof c.type === 'symbol') { + if (typeof c.children === 'string') { + // `v-if="false"` or commented node + return + } + return c.children + } else if (c.type.name === 'ContentSlot') { + return c.ctx.slots.default?.() + } + return c + }).filter(Boolean) } return children }