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

feat(Pagination): add support for sizes #9215

Merged
merged 5 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
43 changes: 38 additions & 5 deletions packages/components/src/components/pagination/_pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $css--helpers: true;
@import '../../globals/scss/typography';
@import '../../globals/scss/layout';
@import '../../globals/scss/css--helpers';
@import '../../globals/scss/vendor/@carbon/layout/scss/generated/size';
@import '../../globals/scss/vendor/@carbon/elements/scss/import-once/import-once';
@import '../select/select';
@import '../text-input/text-input';
Expand All @@ -31,7 +32,7 @@ $css--helpers: true;

display: flex;
width: calc(100% - 1px);
min-height: rem(48px);
min-height: $size-md;
align-items: center;
justify-content: space-between;
border-top: 1px solid $ui-03;
Expand Down Expand Up @@ -63,6 +64,14 @@ $css--helpers: true;
}
}

.#{$prefix}--pagination--sm {
min-height: $size-sm;
}

.#{$prefix}--pagination--lg {
min-height: $size-lg;
}

.#{$prefix}--pagination .#{$prefix}--select {
height: 100%;
align-items: center;
Expand All @@ -78,8 +87,17 @@ $css--helpers: true;

width: auto;
min-width: auto;
height: rem(48px);
height: 100%;
padding: 0 2.25rem 0 $spacing-05;
line-height: $size-md;
}

.#{$prefix}--pagination--sm .#{$prefix}--select-input {
line-height: $size-sm;
}

.#{$prefix}--pagination--lg .#{$prefix}--select-input {
line-height: $size-lg;
}

.#{$prefix}--pagination .#{$prefix}--select-input:hover {
Expand All @@ -106,7 +124,7 @@ $css--helpers: true;
.#{$prefix}--pagination__left,
.#{$prefix}--pagination__right {
display: flex;
height: rem(48px);
height: 100%;
align-items: center;
}

Expand Down Expand Up @@ -153,8 +171,9 @@ $css--helpers: true;
@include reset;

display: flex;
width: $carbon--spacing-09;
height: 100%;
width: $size-md;
height: $size-md;
min-height: $size-sm;
align-items: center;
justify-content: center;
border: none;
Expand All @@ -167,6 +186,20 @@ $css--helpers: true;
background-color $duration--fast-02 motion(standard, productive);
}

.#{$prefix}--pagination--sm .#{$prefix}--pagination__button,
.#{$prefix}--pagination--sm
.#{$prefix}--btn--ghost.#{$prefix}--pagination__button {
width: $size-sm;
height: $size-sm;
}

.#{$prefix}--pagination--lg .#{$prefix}--pagination__button,
.#{$prefix}--pagination--lg
.#{$prefix}--btn--ghost.#{$prefix}--pagination__button {
width: $size-lg;
height: $size-lg;
}

.#{$prefix}--pagination__button:focus,
.#{$prefix}--btn--ghost:focus.#{$prefix}--pagination__button {
@include focus-outline('outline');
Expand Down
10 changes: 10 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4299,6 +4299,16 @@ Map {
"pagesUnknown": Object {
"type": "bool",
},
"size": Object {
"args": Array [
Array [
"sm",
"md",
"lg",
],
],
"type": "oneOf",
},
"totalItems": Object {
"type": "number",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ import {
array,
boolean,
number,
select,
text,
} from '@storybook/addon-knobs';
import Pagination from '../Pagination';
import mdx from './Pagination.mdx';

const sizes = {
'Small (sm)': 'sm',
'Medium (md) - default': undefined,
'Large (lg)': 'lg',
};

const props = () => ({
disabled: boolean('Disable page inputs (disabled)', false),
size: select('Size (size)', sizes, undefined) || undefined,
page: number('The current page (page)', 1),
totalItems: number('Total number of items (totalItems)', 103),
pagesUnknown: boolean('Total number of items unknown (pagesUnknown)', false),
Expand Down
10 changes: 9 additions & 1 deletion packages/react/src/components/Pagination/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ export default class Pagination extends Component {
*/
pagesUnknown: PropTypes.bool,

/**
* Specify the size of the Pagination. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
*/
size: PropTypes.oneOf(['sm', 'md', 'lg']),

/**
* The total number of items.
*/
Expand Down Expand Up @@ -277,10 +282,13 @@ export default class Pagination extends Component {
totalItems,
onChange, // eslint-disable-line no-unused-vars
page: pageNumber, // eslint-disable-line no-unused-vars
size,
...other
} = this.props;

const classNames = classnames(`${prefix}--pagination`, className);
const classNames = classnames(`${prefix}--pagination`, className, {
[`${prefix}--pagination--${size}`]: size,
});
const inputId = id || this.uniqueId;
const { page: statePage, pageSize: statePageSize } = this.state;
const totalPages = Math.max(Math.ceil(totalItems / statePageSize), 1);
Expand Down