Skip to content

Commit

Permalink
fix(Pagination): Tighten margins and reduce pages shown to make usabl…
Browse files Browse the repository at this point in the history
…e on 320px
  • Loading branch information
dougmacknz committed Nov 12, 2024
1 parent 59a0cda commit a1c6434
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
8 changes: 8 additions & 0 deletions .changeset/silly-jokes-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@kaizen/components": patch
---

Pagination responsiveness

- Margins and padding tightened up
- Sibling pages shown drops from 1 to 0 on small viewports
12 changes: 0 additions & 12 deletions packages/components/src/Pagination/Pagination.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,3 @@
}
}
}

// Truncate indicator
.truncateIndicatorWrapper {
display: flex;
align-items: center;
justify-content: center;
height: 36px;
width: 36px;
background-color: transparent;
color: rgba($color-purple-800-rgb, 0.7);
margin: 0 5px;
}
5 changes: 5 additions & 0 deletions packages/components/src/Pagination/Pagination.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react"
import { render, screen, waitFor } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { mockMatchMedia } from "~components/utils/useMediaQueries.spec"
import { Pagination } from "./Pagination"

const user = userEvent.setup()
Expand All @@ -15,6 +16,10 @@ const defaultProps = {
}

describe("<Pagination />", () => {
beforeEach(() => {
mockMatchMedia()
})

it("calls onPageChange when clicking page number", async () => {
const onPageChange = vi.fn()

Expand Down
15 changes: 10 additions & 5 deletions packages/components/src/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { HTMLAttributes } from "react"
import classnames from "classnames"
import { OverrideClassName } from "~components/types/OverrideClassName"
import { useMediaQueries } from "~components/utils"
import { DirectionalLink } from "./subcomponents/DirectionalLink"
import { PaginationLink } from "./subcomponents/PaginationLink"
import { TruncateIndicator } from "./subcomponents/TruncateIndicator"
Expand Down Expand Up @@ -32,6 +33,8 @@ export const Pagination = ({
classNameOverride,
...restProps
}: PaginationProps): JSX.Element => {
const { queries } = useMediaQueries()

// Click event for all pagination buttons (next, prev, and the actual numbers)
const handleButtonClick = (newPage: number | PageAction): void => {
if (newPage === "prev") {
Expand All @@ -55,12 +58,12 @@ export const Pagination = ({
/>
)

const pagination = (): JSX.Element[] => {
const pagination = (
boundaryPagesRange: number,
siblingPagesRange: number
): JSX.Element[] => {
const items: JSX.Element[] = []

const boundaryPagesRange = 1
const siblingPagesRange = 1

// truncateSize is 1 now but could be 0 if we add the ability to hide it.
const truncateSize = 1

Expand Down Expand Up @@ -150,7 +153,9 @@ export const Pagination = ({
onClick={(): void => handleButtonClick("prev")}
/>

<div className={styles.pagesIndicatorWrapper}>{pagination()}</div>
<div className={styles.pagesIndicatorWrapper}>
{pagination(1, queries.isSmall ? 0 : 1)}
</div>

<DirectionalLink
label={ariaLabelNextPage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
width: 40px;
height: 40px;
min-height: auto;
margin: 0 $spacing-xs;
margin: 0 var(--spacing-2);
border-radius: 50%;

&:not(:disabled) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
@import "~@kaizen/design-tokens/sass/color";

.truncateIndicatorWrapper {
display: flex;
align-items: center;
justify-content: center;
width: 36px;
background-color: transparent;
color: rgba($color-purple-800-rgb, 0.7);
margin: 0 5px;
color: rgba(var(color-purple-800-rgb), 0.7);
margin: 0 var(--spacing-2);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react"
import { Icon } from "~components/__future__/Icon"
import styles from "./TruncateIndicator.module.scss"
import styles from "./TruncateIndicator.module.css"

export const TruncateIndicator = (): JSX.Element => (
<div
Expand Down

0 comments on commit a1c6434

Please sign in to comment.