-
-
Notifications
You must be signed in to change notification settings - Fork 426
Add new UX Pagination component #3753
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
base: 3.x
Are you sure you want to change the base?
Changes from all commits
22613b0
8adf225
cca0026
4ef0e42
98f3994
0be19ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /.git* export-ignore | ||
| /.symfony.bundle.yaml export-ignore | ||
| /phpstan.dist.neon export-ignore | ||
| /phpunit.dist.xml export-ignore | ||
| /assets/src export-ignore | ||
| /doc export-ignore | ||
| /tests export-ignore |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /assets/node_modules/ | ||
| /config/reference.php | ||
| /vendor/ | ||
| /composer.lock | ||
| /phpunit.xml | ||
| /.phpunit.cache | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| branches: ['3.x'] | ||
| maintained_branches: ['3.x'] | ||
| doc_dir: 'doc' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # CHANGELOG | ||
|
|
||
| ## 3.5.0 | ||
|
|
||
| - Add the component. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Copyright (c) 2026-present Fabien Potencier | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # Symfony UX Pagination | ||
|
|
||
| **EXPERIMENTAL** This bundle is currently experimental and is likely to change, | ||
| possibly significantly, before its first stable release. | ||
|
|
||
| Ship stable cursor feeds or classic numbered pages through one request-aware | ||
| Symfony service. PHP owns the query, Twig renders accessible navigation, and | ||
| the browser follows ordinary links without requiring JavaScript. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| composer require symfony/ux-pagination | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ```php | ||
| // src/Controller/EventController.php | ||
| namespace App\Controller; | ||
|
|
||
| use App\Repository\EventRepository; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
| use Symfony\Component\Routing\Attribute\Route; | ||
| use Symfony\UX\Pagination\PaginatorInterface; | ||
|
|
||
| final class EventController extends AbstractController | ||
| { | ||
| #[Route('/events', name: 'event_index')] | ||
| public function __invoke( | ||
| EventRepository $events, | ||
| PaginatorInterface $paginator, | ||
| ): Response { | ||
| $pagination = $paginator | ||
| ->cursor($events->createQueryBuilder('event')) | ||
| ->orderBy(['createdAt', 'id'], 'DESC') | ||
| ->perPage(20) | ||
| ->paginate(); | ||
|
|
||
| return $this->render('event/index.html.twig', [ | ||
| 'pagination' => $pagination, | ||
| ]); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ```twig | ||
| {# templates/event/index.html.twig #} | ||
| {% for event in pagination %} | ||
| <article>{{ event.name }}</article> | ||
| {% endfor %} | ||
|
|
||
| {{ ux_pagination(pagination) }} | ||
| ``` | ||
|
|
||
| The paginator reads and validates `?cursor=`, preserves the current filters and | ||
| generates previous/next URLs. Use `query($source)` for numbered pagination or | ||
| `query($source)->lookahead()` when the UI needs only previous/next without an | ||
| exact total. Use `total($counter)` when an aggregate query needs an | ||
| application-provided total; invokable Symfony services work directly. | ||
|
|
||
| ## What it provides | ||
|
|
||
| - First-class signed cursor pagination with forward and backward navigation | ||
| - Offset pagination with lazy totals and numbered pages | ||
| - Lookahead pagination without a count query | ||
| - Doctrine ORM 3 and DBAL 4.4+ adapters | ||
| - Callback builders and custom adapters for APIs, search engines and | ||
| application sources | ||
| - Request-aware URLs generated through the Symfony Router | ||
| - Accessible, translated Twig navigation with Bootstrap, Tailwind and custom | ||
| themes, plus validated attribute hooks | ||
| - Named paginator policies with Symfony autowiring | ||
| - PHP, Twig, JSON and LiveComponent integration | ||
| - Real test helpers for page, URL and signed-cursor behavior | ||
|
|
||
| | Need | Strategy | | ||
| | ----------------------------------------------------- | --------- | | ||
| | Resist offset shifts while ordered values stay stable | Cursor | | ||
| | Page numbers and an exact total | Offset | | ||
| | Previous/next without a total | Lookahead | | ||
|
|
||
| ## Documentation | ||
|
|
||
| - [Getting started](doc/getting-started.rst) | ||
| - [Choosing a strategy](doc/strategies.rst) | ||
| - [Cursor pagination](doc/cursor.rst) | ||
| - [Rendering and customization](doc/rendering.rst) | ||
| - [Configuration](doc/configuration.rst) | ||
| - [Testing](doc/testing.rst) and [debugging](doc/debugging.rst) | ||
|
|
||
| The complete documentation is published on | ||
| [symfony.com](https://symfony.com/bundles/ux-pagination/current/index.html). | ||
|
|
||
| **This repository is a READ-ONLY subtree split.** |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| Copyright (c) 2026-present Fabien Potencier | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "name": "@symfony/ux-pagination", | ||
| "description": "Pagination controls for Symfony applications", | ||
| "license": "MIT", | ||
| "version": "3.5.0", | ||
| "keywords": [ | ||
| "symfony-ux", | ||
| "pagination", | ||
| "paginator" | ||
| ], | ||
| "homepage": "https://ux.symfony.com/pagination", | ||
| "repository": "https://github.com/symfony/ux", | ||
| "type": "module", | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "style": "dist/style.min.css", | ||
| "exports": { | ||
| "./style.min.css": "./dist/style.min.css" | ||
| }, | ||
| "config": { | ||
| "css_source": "src/style.css" | ||
| }, | ||
| "scripts": { | ||
| "build": "node ../../../bin/build_package.ts .", | ||
| "watch": "node ../../../bin/build_package.ts . --watch" | ||
| } | ||
| } |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sshipping default styles is indeed super useful, but I'm a little worried about what will happen when users want to make more significant changes to styles. What if users use CSS layers, etc.. This is also a subject of BC. I'm not sure if we should ship default styles like that or not, what about moving it in a dedicated Flex recipe?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having one is like having a default theme, it allows to work out of the box, but this is clearly documented to be something user would need/want to override or probably even rewrite themselves... Here it's really about "plug and play and basic working behaviour". Problem with a recipe is also it cannot differenciate "first install" and update, so it would bring the same problems (if not worst, as we cannot control we does or does not its recipe:updates out there)... Maybe though this is something we can solve later on, providing URL / commands to get theme from ux toolkit or something ? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /** | ||
| * UX Pagination styles. | ||
| * | ||
| * The component selectors are intentionally scoped: importing this file must | ||
| * not change unrelated aria-current elements in the app. | ||
| */ | ||
|
|
||
| .ux-pagination { | ||
| --ux-pagination-color: #1f2937; | ||
| --ux-pagination-muted-color: #6b7280; | ||
| --ux-pagination-border-color: #d1d5db; | ||
| --ux-pagination-background: #fff; | ||
| --ux-pagination-active-background: #111827; | ||
| --ux-pagination-active-color: #fff; | ||
| --ux-pagination-focus-color: #2563eb; | ||
|
|
||
| color: var(--ux-pagination-color); | ||
| } | ||
|
|
||
| .ux-pagination__info { | ||
| margin-block: 0 0.75rem; | ||
| color: var(--ux-pagination-muted-color); | ||
| font-size: 0.875rem; | ||
| } | ||
|
|
||
| .ux-pagination__list { | ||
| display: flex; | ||
| flex-wrap: wrap; | ||
| align-items: center; | ||
| gap: 0.375rem; | ||
| margin: 0; | ||
| padding: 0; | ||
| list-style: none; | ||
| } | ||
|
|
||
| .ux-pagination__item { | ||
| display: inline-flex; | ||
| } | ||
|
|
||
| .ux-pagination__link { | ||
| display: inline-flex; | ||
| min-width: 2.5rem; | ||
| min-height: 2.5rem; | ||
| align-items: center; | ||
| justify-content: center; | ||
| padding: 0.5rem 0.75rem; | ||
| border: 1px solid var(--ux-pagination-border-color); | ||
| border-radius: 0.375rem; | ||
| background: var(--ux-pagination-background); | ||
| color: inherit; | ||
| line-height: 1; | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| a.ux-pagination__link:hover { | ||
| border-color: currentColor; | ||
| } | ||
|
|
||
| .ux-pagination__link--current { | ||
| border-color: var(--ux-pagination-active-background); | ||
| background: var(--ux-pagination-active-background); | ||
| color: var(--ux-pagination-active-color); | ||
| font-weight: 600; | ||
| } | ||
|
|
||
| .ux-pagination__link--disabled { | ||
| cursor: not-allowed; | ||
| opacity: 0.55; | ||
| } | ||
|
|
||
| .ux-pagination__ellipsis { | ||
| display: inline-flex; | ||
| min-width: 2rem; | ||
| min-height: 2.5rem; | ||
| align-items: center; | ||
| justify-content: center; | ||
| color: var(--ux-pagination-muted-color); | ||
| } | ||
|
|
||
| .ux-pagination__link:focus-visible { | ||
| outline: 3px solid var(--ux-pagination-focus-color, #2563eb); | ||
| outline-offset: 2px; | ||
| } | ||
|
|
||
| .ux-pagination [aria-current='page'] { | ||
| font-weight: 600; | ||
| } | ||
|
|
||
| @media (prefers-color-scheme: dark) { | ||
| .ux-pagination { | ||
| --ux-pagination-color: #f3f4f6; | ||
| --ux-pagination-muted-color: #9ca3af; | ||
| --ux-pagination-border-color: #4b5563; | ||
| --ux-pagination-background: #111827; | ||
| --ux-pagination-active-background: #f3f4f6; | ||
| --ux-pagination-active-color: #111827; | ||
| --ux-pagination-focus-color: #60a5fa; | ||
| } | ||
| } | ||
|
|
||
| @media (prefers-contrast: more) { | ||
| .ux-pagination__link { | ||
| border: 1px solid currentColor; | ||
| } | ||
|
|
||
| .ux-pagination :focus-visible { | ||
| outline-width: 4px; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "extends": "../../../tsconfig.package.json" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to ping Fabien for creating the repo on GitHub/Packagist