Skip to content

Commit

Permalink
fix: pagination consistent width across html and react platforms (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza14khan authored Nov 26, 2024
1 parent dde8465 commit 0d8cef1
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 24 deletions.
65 changes: 51 additions & 14 deletions apps/docs/content/3-components/2-library/pagination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,24 @@ libraries:
data-total-pages="10"
data-testid="govie-pagination"
data-module="gieds-pagination"
>
>
<a
href="#"
target="_self"
data-testid="govie-pagination-prev-btn"
data-element="button-container"
data-module="gieds-button"
class="gi-btn gi-btn-flat-dark gi-btn-large"
class="gi-pagination-prev-btn gi-btn gi-btn-flat-dark gi-btn-large"
>
<span data-testid="govie-icon" role="presentation" class="material-symbols-outlined gi-block gi-text-[24px]">arrow_left_alt</span>
<span class="sm:gi-block gi-hidden">Previous</span>
<span data-testid="govie-icon" role="presentation" class="material-symbols-outlined gi-block gi-text-[24px]">arrow_left_alt</span> <span class='sm:gi-block gi-hidden'>Previous</span>
</a>
<div class="xs:gi-hidden gi-block gi-text-md">
<span class="gi-font-bold">Page 5</span> of 10
<span class="gi-font-bold">Page 5</span> of 10
</div>
<div class="sm:gi-flex xs:gi-flex gi-items-center gi-justify-between gi-gap-2 md:gi-hidden gi-hidden">

<div
class="sm:gi-flex xs:gi-flex gi-items-center gi-justify-between gi-gap-2 md:gi-hidden gi-hidden"
>
<a
href="#"
target="_self"
Expand All @@ -70,7 +72,14 @@ libraries:
>
1
</a>
<span class="material-symbols-outlined gi-gray-700">more_horiz</span>

<span
data-testid="govie-icon"
class="material-symbols-outlined gi-gray-700"
>
more_horiz
</span>

<a
href="#"
target="_self"
Expand All @@ -81,7 +90,14 @@ libraries:
>
5
</a>
<span class="material-symbols-outlined gi-gray-700">more_horiz</span>

<span
data-testid="govie-icon"
class="material-symbols-outlined gi-gray-700"
>
more_horiz
</span>

<a
href="#"
target="_self"
Expand All @@ -92,7 +108,9 @@ libraries:
>
10
</a>

</div>

<div class="md:gi-flex gi-items-center gi-justify-between gi-gap-2 gi-hidden">
<a
href="#"
Expand All @@ -104,7 +122,14 @@ libraries:
>
1
</a>
<span class="material-symbols-outlined gi-gray-700">more_horiz</span>

<span
data-testid="govie-icon"
class="material-symbols-outlined gi-gray-700"
>
more_horiz
</span>

<a
href="#"
target="_self"
Expand All @@ -115,6 +140,7 @@ libraries:
>
3
</a>

<a
href="#"
target="_self"
Expand All @@ -125,6 +151,7 @@ libraries:
>
4
</a>

<a
href="#"
target="_self"
Expand All @@ -135,6 +162,7 @@ libraries:
>
5
</a>

<a
href="#"
target="_self"
Expand All @@ -145,6 +173,7 @@ libraries:
>
6
</a>

<a
href="#"
target="_self"
Expand All @@ -155,7 +184,14 @@ libraries:
>
7
</a>
<span class="material-symbols-outlined gi-gray-700">more_horiz</span>

<span
data-testid="govie-icon"
class="material-symbols-outlined gi-gray-700"
>
more_horiz
</span>

<a
href="#"
target="_self"
Expand All @@ -166,19 +202,20 @@ libraries:
>
10
</a>

</div>

<a
href="#"
target="_self"
data-testid="govie-pagination-next-btn"
data-element="button-container"
data-module="gieds-button"
class="gi-btn gi-btn-flat-dark gi-btn-large"
class="gi-pagination-next-btn gi-btn gi-btn-flat-dark gi-btn-large"
>
<span class="sm:gi-block gi-hidden">Next</span>
<span data-testid="govie-icon" role="presentation" class="material-symbols-outlined gi-block gi-text-[24px]">arrow_right_alt</span>
<span class='sm:gi-block gi-hidden'>Next</span> <span data-testid="govie-icon" role="presentation" class="material-symbols-outlined gi-block gi-text-[24px]">arrow_right_alt</span>
</a>
</div>
</div>
```
</TabPanel>
<TabPanel value="tab13">
Expand Down
6 changes: 5 additions & 1 deletion apps/docs/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,8 @@ itemsDistribution
fixedHeight
groupId
hideToc
Dismissible
Dismissible
gi-pagination-next-btn
gi-btn
gi-btn-flat-dark
gi-btn-large
13 changes: 12 additions & 1 deletion packages/design/tailwind/css/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -904,10 +904,21 @@ input[type='file' i] {
}

/* End of Toast */

/* Pagination */

.gi-pagination {
@apply gi-flex xs:gi-justify-center gi-justify-between gi-items-center gi-gap-2;
@apply gi-flex xs:gi-justify-center gi-justify-between gi-items-center gi-gap-2;
}

@media (max-width: 640px) {
.gi-pagination-next-btn,
.gi-pagination-prev-btn {
padding: var(--gieds-space-3);
height: var(--gieds-space-12);
width: var(--gieds-space-12);
justify-content: center;
}
}
/* End of Pagination */

8 changes: 6 additions & 2 deletions packages/html/ds/src/button/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
{% set size = props.size or 'medium' %}
{% set isDisabled = 'disabled' if props.disabled else 'notDisabled' %}
{% set testId = props.testId or 'govieButton-' ~ appearance ~ '-' ~ variant ~ '-' ~ size ~ '-' ~ isDisabled %}
{% set commonClasses = getVariantAppearanceClass(props.disabled, props.variant, props.appearance) | trim %}
{% set sizeClasses = getSizeClass(props.size) | trim %}
{% set disabledClasses = isButtonDisabled(props.disabled, props.variant, props.appearance) | trim %}
{% set allClasses = (props.className or '') ~ ' ' ~ 'gi-btn ' ~ commonClasses ~ ' ' ~ sizeClasses ~ ' ' ~ disabledClasses %}

{% if props.href %}
<a
Expand All @@ -19,7 +23,7 @@
data-testid="{{ testId }}"
data-element="button-container"
data-module="gieds-button"
class="gi-btn {{ getVariantAppearanceClass(props.disabled, props.variant, props.appearance) | trim }} {{ getSizeClass(props.size) | trim }} {{ isButtonDisabled(props.disabled, props.variant, props.appearance) | trim }}"
class="{{ allClasses | trim }}"
>
{{ props.content | safe | trim }}
</a>
Expand All @@ -32,7 +36,7 @@
data-testid="{{ testId }}"
data-element="button-container"
data-module="gieds-button"
class="gi-btn {{ getVariantAppearanceClass(props.disabled, props.variant, props.appearance) | trim }} {{ getSizeClass(props.size) | trim }} {{ isButtonDisabled(props.disabled, props.variant, props.appearance) | trim }}"
class="{{ allClasses | trim }}"
>
{{ props.content | safe | trim }}
</button>
Expand Down
6 changes: 4 additions & 2 deletions packages/html/ds/src/pagination/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"href": "#",
"target": "_self",
"testId": "govie-pagination-prev-btn",
"data-current-page": props.currentPage - 1
"data-current-page": props.currentPage - 1,
"className": "gi-pagination-prev-btn"
})
}}

Expand All @@ -41,7 +42,8 @@
"target": "_self",
"disabled": props.currentPage == props.totalPages,
"testId": "govie-pagination-next-btn",
"data-current-page": props.currentPage + 1
"data-current-page": props.currentPage + 1,
"className": "gi-pagination-next-btn"
})
}}
</div>
Expand Down
10 changes: 6 additions & 4 deletions packages/react/ds/src/pagination/pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const Pagination: React.FC<PaginationProps> = ({
onPageChange,
}) => {
const { breakpoint, width } = useBreakpoint();
const isCompactView = breakpoint === Breakpoint.XS; // Custom breakpoint for compact view.
const showLabel = width < 639;
const isCompactView = breakpoint === Breakpoint.XS;
const isSMWidth = width < 639;

const displayedPages = getDisplayPages(currentPage, totalPages, breakpoint);

Expand Down Expand Up @@ -57,11 +57,12 @@ export const Pagination: React.FC<PaginationProps> = ({
appearance="dark"
disabled={currentPage === 1}
onClick={() => onPageChange(currentPage - 1)}
className={isSMWidth ? 'gi-icon-btn-large' : ''}
>
<React.Fragment key="previous-btn-pagination">
<Icon icon="arrow_left_alt" />
</React.Fragment>
{!showLabel && 'Previous'}
{!isSMWidth && 'Previous'}
</Button>

{isCompactView ? renderPaginationLabel() : renderPaginationBtns()}
Expand All @@ -72,8 +73,9 @@ export const Pagination: React.FC<PaginationProps> = ({
size="large"
appearance="dark"
onClick={() => onPageChange(currentPage + 1)}
className={isSMWidth ? 'gi-icon-btn-large' : ''}
>
{!showLabel && 'Next'}
{!isSMWidth && 'Next'}
<React.Fragment key="next-btn-pagination">
<Icon icon="arrow_right_alt" />
</React.Fragment>
Expand Down

0 comments on commit 0d8cef1

Please sign in to comment.