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

Add UsePagination #101

Open
Tyson910 opened this issue Jun 25, 2024 · 3 comments
Open

Add UsePagination #101

Tyson910 opened this issue Jun 25, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Tyson910
Copy link
Contributor

Describe the feature in detail (code, mocks, or screenshots encouraged)

Create a usePagination rune for pagination component, allowing users to manage active page state and navigate between multiple pages. Implementation would follow these interfaces:

export interface PaginationParams {
  /** Page selected on initial render, defaults to 1 */
  initialPage?: number;

  /** Total amount of pages */
  total: number;

  /** Callback fired after change of each page */
  onChange?: (page: number) => void;
}

export interface PaginationReturn {
  currentPage: number
  pageCount: number
  prev: () => void
  next: () => void
  // not sure if these last 2 are valuable or not
  isFirstPage: boolean
  isLastPage: boolean
}

What type of pull request would this be?

New Feature

Provide relevant links or additional information.

This implementation could follow the UseIdle hook created by VueUse or Mantine

@Tyson910 Tyson910 added the enhancement New feature or request label Jun 25, 2024
@specialdoom
Copy link

is somebody working on this?

@abdel-17
Copy link
Collaborator

abdel-17 commented Jan 7, 2025

I don't think this is a good inclusion to the library. You should probably use the URL as your source of truth for pagination state to preserve the page across navigations and/or sharing links. The best we could do is provide a wrapper around SvelteKit APIs, but not everyone uses SvelteKit.

Thoughts? @huntabyte

@Tyson910
Copy link
Contributor Author

I don't think this is a good inclusion to the library. You should probably use the URL as your source of truth for pagination state to preserve the page across navigations and/or sharing links. The best we could do is provide a wrapper around SvelteKit APIs, but not everyone uses SvelteKit.

Thoughts? @huntabyte

I agree that the URL should be the source of truth & this util would allow users to follow that pattern, or opt out if they so chose.

That being said

  • The URL doesn't always provide the same amount of context as a pagination fn (e.g. total pages, isFirst/LastPage), & these values are useful for building pagination components.
  • I agree we wouldn't want to wrap the Sveltekit APIs around this for the reason you listed. That being said this function provides flexibility such that a consumer is able to define behavior via the onChange handler in the constructor args OR via the next() or prev() fns, without making any assumptions about data loading/routing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants