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

[#280] Fixed pagination and removed active_is_link prop. #289

Merged
merged 1 commit into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ exports[`Pagination Component renders current page correctly 1`] = `


<li
class="ct-pagination__item ct-pagination__item--active"
class="ct-pagination__item ct-pagination__item--active"
>


Expand Down Expand Up @@ -461,7 +461,7 @@ exports[`Pagination Component renders with optional attributes 1`] = `


<li
class="ct-pagination__item ct-pagination__item--active"
class="ct-pagination__item ct-pagination__item--active"
>


Expand Down Expand Up @@ -739,7 +739,7 @@ exports[`Pagination Component renders with required attributes 1`] = `


<li
class="ct-pagination__item ct-pagination__item--active"
class="ct-pagination__item ct-pagination__item--active"
>


Expand Down
22 changes: 7 additions & 15 deletions components/02-molecules/pagination/pagination.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const Pagination = (parentKnobs = {}) => {
parentKnobs.theme,
parentKnobs.knobTab,
),
active_is_link: knobBoolean('Active is a link', true, parentKnobs.active_is_link, parentKnobs.knobTab),
use_ellipsis: knobBoolean('With ellipsis', false, parentKnobs.use_ellipsis, parentKnobs.knobTab),
with_items_per_page: knobBoolean('With items per page', true, parentKnobs.with_items_per_page, parentKnobs.knobTab),
heading_id: knobText('Heading ID', 'ct-pagination-demo', parentKnobs.heading_id, parentKnobs.knobTab),
Expand Down Expand Up @@ -54,19 +53,13 @@ export const Pagination = (parentKnobs = {}) => {
parentKnobs.knobTab,
);

const paginationMiddle = Math.ceil(knobs.count_of_pages / 2);
const paginationFirst = knobs.current - paginationMiddle + 1;
const paginationLast = knobs.current + knobs.count_of_pages - paginationMiddle;

const pages = {};
for (let i = 0; i < knobs.count_of_pages; i++) {
if (knobs.use_ellipsis) {
if (i === 0 || (i > paginationFirst && i < paginationLast) || i === (knobs.count_of_pages - 1)) {
pages[i + 1] = {
href: randomUrl(),
};
}
} else {
if (knobs.use_ellipsis) {
pages[knobs.current_page] = {
href: randomUrl(),
};
} else {
for (let i = 0; i < knobs.count_of_pages; i++) {
pages[i + 1] = {
href: randomUrl(),
};
Expand All @@ -85,12 +78,11 @@ export const Pagination = (parentKnobs = {}) => {

const props = {
theme: knobs.theme,
active_is_link: knobs.active_is_link,
items,
heading_id: knobs.heading_id,
use_ellipsis: knobs.use_ellipsis,
total_pages: knobs.count_of_pages,
current: knobs.current,
current: knobs.current_page,
modifier_class: knobs.modifier_class,
attributes: knobs.attributes,
};
Expand Down
2 changes: 1 addition & 1 deletion components/02-molecules/pagination/pagination.twig
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
{% endif %}
{% endif %}

<li class="ct-pagination__item {{ current == key ? ' ct-pagination__item--active' : 'hide-xxs show-m' }}">
<li class="ct-pagination__item {% if current == key %}ct-pagination__item--active{% else %}hide-xxs show-m{% endif %}">
{% if current == key %}
{% set attributes = 'title="Current page"' %}
{% else %}
Expand Down