-
Notifications
You must be signed in to change notification settings - Fork 9
Feat(OnyxPagination): implement inline pagination #4310
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
Open
ChristianBusshoff
wants to merge
8
commits into
main
Choose a base branch
from
feat-1714/Implement-classic-type-for-OnyxPagination
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de15062
add inline pagination
ChristianBusshoff 0b5cb13
add tests
ChristianBusshoff acd9a4b
docs(changeset): feat(OnyxPagination): implement inline pagination
ChristianBusshoff 6a3f811
add storybook tag
ChristianBusshoff 4c1627b
chore: update Playwright screenshots (#4311)
github-actions[bot] 2f21374
Merge branch 'main' into feat-1714/Implement-classic-type-for-OnyxPag…
ChristianBusshoff 1accc36
resolve comments
ChristianBusshoff ba2a342
change
ChristianBusshoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "sit-onyx": minor | ||
| --- | ||
|
|
||
| feat(OnyxPagination): added `type` property that allows to optionally display the pagination in an inline style. |
Binary file added
BIN
+37.3 KB
...laywright/snapshots/components/OnyxPagination/Pagination-inline--edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+75.4 KB
...wright/snapshots/components/OnyxPagination/Pagination-inline--firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.5 KB
...ywright/snapshots/components/OnyxPagination/Pagination-inline--webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+30 KB
...t/snapshots/components/OnyxPagination/Pagination-inline-buttons--edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+54.2 KB
...napshots/components/OnyxPagination/Pagination-inline-buttons--firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+38.4 KB
...snapshots/components/OnyxPagination/Pagination-inline-buttons--webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+69.5 KB
...laywright/snapshots/components/OnyxPagination/Pagination-select--edge-linux.png
|
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. Can you also delete the old screenshots (e.g. packages/sit-onyx/playwright/snapshots/components/OnyxPagination/Pagination-edge-linux.png) that are no longer used due to the test renaming? |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+123 KB
...wright/snapshots/components/OnyxPagination/Pagination-select--firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+91.4 KB
...ywright/snapshots/components/OnyxPagination/Pagination-select--webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.3 KB
...t/snapshots/components/OnyxPagination/Pagination-select-buttons--edge-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+59 KB
...napshots/components/OnyxPagination/Pagination-select-buttons--firefox-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+61.8 KB
...snapshots/components/OnyxPagination/Pagination-select-buttons--webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
207 changes: 207 additions & 0 deletions
207
packages/sit-onyx/src/components/OnyxPagination/OnyxInlinePagination.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| <script lang="ts" setup> | ||
| import { iconChevronLeftSmall, iconChevronRightSmall } from "@sit-onyx/icons"; | ||
| import { computed } from "vue"; | ||
| import { useDensity } from "../../composables/density.js"; | ||
| import { | ||
| SKELETON_INJECTED_SYMBOL, | ||
| useSkeletonContext, | ||
| } from "../../composables/useSkeletonState.js"; | ||
| import { injectI18n } from "../../i18n/index.js"; | ||
| import OnyxIcon from "../OnyxIcon/OnyxIcon.vue"; | ||
| import OnyxSkeleton from "../OnyxSkeleton/OnyxSkeleton.vue"; | ||
| import OnyxVisuallyHidden from "../OnyxVisuallyHidden/OnyxVisuallyHidden.vue"; | ||
| import type { OnyxPaginationProps } from "./types.js"; | ||
|
|
||
| const props = withDefaults(defineProps<OnyxPaginationProps>(), { | ||
| skeleton: SKELETON_INJECTED_SYMBOL, | ||
| }); | ||
|
|
||
| const emit = defineEmits<{ | ||
| /** | ||
| * Emitted when the selected page changes. | ||
| */ | ||
| "update:modelValue": [page: number]; | ||
| }>(); | ||
|
|
||
| const { t } = injectI18n(); | ||
| const { densityClass } = useDensity(props); | ||
| const skeleton = useSkeletonContext(props); | ||
|
|
||
| const hasReachedMin = computed(() => props.modelValue <= 1); | ||
| const hasReachedMax = computed(() => props.modelValue >= props.pages); | ||
|
|
||
| const displayPagesNumbers = computed(() => { | ||
| const currentPage = props.modelValue; | ||
| const totalPages = props.pages; | ||
|
|
||
| const pagesToShow = new Set<number>(); | ||
|
|
||
| pagesToShow.add(1); | ||
| pagesToShow.add(totalPages); | ||
|
|
||
| pagesToShow.add(currentPage); | ||
| pagesToShow.add(currentPage - 1); | ||
| pagesToShow.add(currentPage + 1); | ||
|
|
||
| if (currentPage === 1) pagesToShow.add(3); | ||
| if (currentPage === totalPages) pagesToShow.add(totalPages - 2); | ||
|
|
||
| const uniqueSortedPages = Array.from(pagesToShow) | ||
| .filter((page) => page >= 1 && page <= totalPages) | ||
| .sort((a, b) => a - b); | ||
|
|
||
| const finalPages: (number | "ellipsis")[] = []; | ||
| let lastPageAdded: number | null = null; | ||
|
|
||
| for (const page of uniqueSortedPages) { | ||
| if (lastPageAdded !== null && page > lastPageAdded + 1) { | ||
| finalPages.push("ellipsis"); | ||
| } | ||
| finalPages.push(page); | ||
| lastPageAdded = page; | ||
| } | ||
| return finalPages; | ||
| }); | ||
| </script> | ||
|
|
||
| <template> | ||
| <OnyxSkeleton v-if="skeleton" :class="['onyx-pagination-skeleton', 'onyx-text', densityClass]" /> | ||
|
|
||
| <div | ||
| v-else | ||
| :class="[ | ||
| 'onyx-component', | ||
| 'onyx-pagination', | ||
| 'onyx-pagination--inline', | ||
| 'onyx-text', | ||
| densityClass, | ||
| ]" | ||
| role="group" | ||
| :aria-label="t('pagination.label')" | ||
| :style="{ '--onyx-pagination-character-count': props.modelValue.toString().length }" | ||
| > | ||
| <button | ||
| class="onyx-pagination--inline__button" | ||
| :aria-label="t('pagination.previous')" | ||
| type="button" | ||
| :disabled="props.disabled || hasReachedMin" | ||
| @click="emit('update:modelValue', props.modelValue - 1)" | ||
| > | ||
| <OnyxIcon :icon="iconChevronLeftSmall" /> | ||
| </button> | ||
| <template v-for="pageNumber in displayPagesNumbers" :key="pageNumber"> | ||
| <button | ||
| v-if="typeof pageNumber === 'number'" | ||
| :class="[ | ||
| 'onyx-pagination-inline__button', | ||
| { 'onyx-pagination--inline__button--active': pageNumber === props.modelValue }, | ||
| ]" | ||
| :aria-label="t('pagination.buttonLabel', { page: pageNumber })" | ||
| type="button" | ||
| :disabled="props.disabled" | ||
| @click="emit('update:modelValue', pageNumber)" | ||
| > | ||
| {{ pageNumber }} | ||
| </button> | ||
| <div | ||
| v-else | ||
| :class="['onyx-pagination--inline__ellipsis']" | ||
| :aria-label="t('pagination.morePages')" | ||
| > | ||
| <span aria-hidden="true">...</span> | ||
| <OnyxVisuallyHidden> | ||
ChristianBusshoff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {{ t("pagination.ellipsis") }} | ||
| </OnyxVisuallyHidden> | ||
| </div> | ||
| </template> | ||
|
|
||
| <button | ||
| class="onyx-pagination--inline__button" | ||
| :aria-label="t('pagination.next')" | ||
| type="button" | ||
| :disabled="props.disabled || hasReachedMax" | ||
| @click="emit('update:modelValue', props.modelValue + 1)" | ||
| > | ||
| <OnyxIcon :icon="iconChevronRightSmall" /> | ||
| </button> | ||
| </div> | ||
| </template> | ||
|
|
||
| <style lang="scss"> | ||
| @use "../../styles/mixins/layers.scss"; | ||
|
|
||
| .onyx-pagination--inline { | ||
| @include layers.component() { | ||
| background-color: var(--onyx-color-base-background-blank); | ||
|
|
||
| &__button, | ||
| &__ellipsis { | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| padding: var(--onyx-pagination-padding-vertical); | ||
| height: var(--onyx-pagination-height); | ||
| border: var(--onyx-pagination-border-size) solid var(--onyx-color-component-border-neutral); | ||
| border-left: none; | ||
| background-color: inherit; | ||
| color: inherit; | ||
| aspect-ratio: 1; | ||
| } | ||
| &__ellipsis { | ||
| cursor: default; | ||
| } | ||
| &__button { | ||
| cursor: pointer; | ||
| color: var(--onyx-color-text-icons-neutral-medium); | ||
|
|
||
| &:first-of-type { | ||
| border-radius: var(--onyx-pagination-border-radius) 0 0 var(--onyx-pagination-border-radius); | ||
| border-left: var(--onyx-pagination-border-size) solid | ||
| var(--onyx-color-component-border-neutral); | ||
| } | ||
| &:last-of-type { | ||
| border-radius: 0 var(--onyx-pagination-border-radius) var(--onyx-pagination-border-radius) 0; | ||
| } | ||
|
|
||
| &:hover, | ||
| &:focus-visible { | ||
| color: var(--onyx-color-text-icons-neutral-intense); | ||
| } | ||
|
|
||
| &:hover { | ||
| background-color: var(--onyx-color-base-neutral-200); | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| z-index: 1; | ||
| background-color: var(--onyx-color-base-neutral-200); | ||
| outline: var(--onyx-outline-width) solid var(--onyx-color-component-focus-primary); | ||
| } | ||
| &:active { | ||
| background-color: var(--onyx-color-base-background-blank); | ||
| } | ||
|
|
||
| &--active { | ||
| background-color: var(--onyx-color-base-primary-100); | ||
| color: var(--onyx-color-text-icons-primary-intense); | ||
|
|
||
| &:hover { | ||
| background-color: var(--onyx-color-base-primary-200); | ||
| color: var(--onyx-color-text-icons-primary-intense); | ||
| } | ||
| &:focus-visible { | ||
| background-color: var(--onyx-color-base-primary-300); | ||
| color: var(--onyx-color-text-icons-neutral-inverted); | ||
| } | ||
| &:active { | ||
| background-color: var(--onyx-color-base-primary-100); | ||
| } | ||
| } | ||
| &:disabled { | ||
| background-color: var(--onyx-color-base-background-tinted); | ||
| color: var(--onyx-color-text-icons-neutral-soft); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| </style> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice to have: Currently the skeleton is defined to have a fixed with in Figma. Imo it would be nice if the skeleton has the same width as the "default" variant here in the screenshot (considering density) so the layout does not jump around. Should we clarify this with UX?