Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2221 from teamleadercrm/FRAF-633-Improvements-Pag…
Browse files Browse the repository at this point in the history
…ination-component

Improvements pagination component
  • Loading branch information
qubis741 authored Jun 23, 2022
2 parents 8cc2997 + af66797 commit 061a996
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Changed

- `Pagination`: always show arrows ([@qubis741](https://github.com/qubis741)) in [#2221](https://github.com/teamleadercrm/ui/pull/2221))

### Deprecated

### Removed
Expand Down
36 changes: 16 additions & 20 deletions src/components/pagination/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@ class Pagination extends PureComponent {
return (
<Box data-teamleader-ui="pagination" className={classNames} element="nav" {...others}>
<ul className={theme['list']}>
{currentPage > 1 && (
<li className={theme['list-item']}>
{children({
number: currentPage - 1,
isActive: false,
icon: <IconChevronLeftMediumOutline />,
iconPlacement: 'left',
})}
</li>
)}
<li className={cx(theme['list-item'], theme['list-item__arrowed'])}>
{children({
number: currentPage - 1,
isActive: currentPage === 1,
icon: <IconChevronLeftMediumOutline />,
iconPlacement: 'left',
})}
</li>
{iterator.map((page) => {
const isActive = page === currentPage;

Expand All @@ -75,16 +73,14 @@ class Pagination extends PureComponent {
</li>
);
})}
{currentPage < numPages && (
<li className={theme['list-item']}>
{children({
number: currentPage + 1,
isActive: false,
icon: <IconChevronRightMediumOutline />,
iconPlacement: 'right',
})}
</li>
)}
<li className={cx(theme['list-item'], theme['list-item__arrowed'])}>
{children({
number: currentPage + 1,
isActive: currentPage === numPages,
icon: <IconChevronRightMediumOutline />,
iconPlacement: 'right',
})}
</li>
</ul>
</Box>
);
Expand Down
28 changes: 20 additions & 8 deletions src/components/pagination/pagination.stories.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { addStoryInGroup, MID_LEVEL_BLOCKS } from '../../../.storybook/utils';
import { Pagination, Button } from '../../index';

Expand All @@ -7,13 +7,25 @@ export default {
title: addStoryInGroup(MID_LEVEL_BLOCKS, 'Pagination'),
};

export const DefaultStory = (args) => (
<Pagination {...args}>
{({ number, text, isActive, ...others }) => {
return <Button level="link" label={text} disabled={isActive} size="small" {...others} />;
}}
</Pagination>
);
export const DefaultStory = (args) => {
const [page, setPage] = useState(1);
return (
<Pagination {...args} currentPage={page}>
{({ number, text, isActive, ...others }) => {
return (
<Button
level="link"
label={text}
disabled={isActive}
size="small"
{...others}
onClick={() => setPage(number)}
/>
);
}}
</Pagination>
);
};

DefaultStory.args = {
currentPage: 3,
Expand Down
10 changes: 9 additions & 1 deletion src/components/pagination/theme.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@

.list-item {
margin: 0 var(--spacer-smallest);

min-width: 36px;
display: flex;
> * {
transition: none;
text-decoration: none;
flex: 1;
padding: 0!important;
}

&__arrowed {
width: 30px;
min-width: 0;
}
}

Expand Down

0 comments on commit 061a996

Please sign in to comment.