Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination with href #1528

Open
while1618 opened this issue Dec 1, 2024 · 2 comments
Open

Pagination with href #1528

while1618 opened this issue Dec 1, 2024 · 2 comments
Labels
docs A change or addition to the documentation

Comments

@while1618
Copy link

Change Type

Addition

Proposed Changes

Hi @huntabyte,

Is it possible to add an example of how to use pagination component with href in docs? I assume that this is a commonly used feature (original shadcn is supporting this), but I couldn't find anything in the shadcn-svelte. Looked through all the issues on both shadcn-svelte and bits-ui, but nothing.

I mentioned in this issue #945 what have I tried, but at the end I couldn't find a solution, so I ditched Pagination component completely and created my own, but it would be great if I could go back to shadcn-svelte one.

@while1618 while1618 added the docs A change or addition to the documentation label Dec 1, 2024
@asalimonov
Copy link

I support this request. Pagination with links allows web crawlers to index all content, not just the first page. It eliminates the need to spend time generating and updating sitemap.xml or similar.

@asalimonov
Copy link

It's my hack for implementing paging with links. Google and other crawlers are processed it successfully.

pagination-link.svelte:

<script lang="ts">
	import { Pagination as PaginationPrimitive } from 'bits-ui';
	import { type Props, buttonVariants } from '$lib/components/ui/button/index.js';
	import { cn } from '$lib/utils.js';

	type $$Props = PaginationPrimitive.PageProps &
		Props & {
			isActive: boolean;
			href?: string;
		};

	type $$Events = PaginationPrimitive.PageEvents;

	let className: $$Props['class'] = undefined;
	export let page: $$Props['page'];
	export let size: $$Props['size'] = 'icon';
	export let isActive: $$Props['isActive'] = false;
	export let href: $$Props['href'] = undefined;

	export { className as class };
</script>
{#if href !== undefined}
	<a {href}>
{/if}
		<PaginationPrimitive.Page
			bind:page
			class={cn(
				buttonVariants({
					variant: isActive ? 'outline' : 'ghost',
					size
				}),
				className
			)}
			{...$$restProps}
			on:click
		>
			<slot>{page.value}</slot>
		</PaginationPrimitive.Page>
{#if href !== undefined}
	</a>
{/if}

On a page:

<Pagination.Link
    {page}
    isActive={$Search.page !== page.value}
    href={$Search.page === page.value ? undefined : buildPageUrl(page.value)}
>
{page.value}
</Pagination.Link>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs A change or addition to the documentation
Projects
None yet
Development

No branches or pull requests

2 participants