Skip to content

Commit

Permalink
feat(pagination): update story to Storybook v7 (carbon-design-system#…
Browse files Browse the repository at this point in the history
…11401)

* chore(pagination): update pagination stories to sb v7

* fix(pagination): fix backward-text control

* fix(pagination): specify page-input-disabled property as boolean

---------

Co-authored-by: kennylam <909118+kennylam@users.noreply.github.com>
  • Loading branch information
m4olivei and kennylam authored Jan 18, 2024
1 parent f857143 commit 1de2e1f
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const stories = glob.sync(
'../src/**/toast-notification.stories.ts',
'../src/**/overflow-menu.mdx',
'../src/**/overflow-menu.stories.ts',
'../src/**/pagination.mdx',
'../src/**/pagination.stories.ts',
'../src/**/progress-bar.mdx',
'../src/**/progress-bar.stories.ts',
'../src/**/progress-indicator.mdx',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Props, Description } from '@storybook/addon-docs/blocks';
import { ArgsTable, Meta, Markdown } from '@storybook/addon-docs/blocks';
import { cdnJs, cdnCss } from '../../globals/internal/storybook-cdn';
import * as PaginationStories from './pagination.stories';

<Meta of={PaginationStories} />

# Pagination

Expand All @@ -23,8 +26,8 @@ Here's a quick example to get you started.
import '@carbon/web-components/es/components/pagination/index.js';
```

<Description markdown={`${cdnJs({ components: ['pagination'] })}`} />
<Description markdown={`${cdnCss()}`} />
<Markdown>{`${cdnJs({ components: ['pagination'] })}`}</Markdown>
<Markdown>{`${cdnCss()}`}</Markdown>

### HTML

Expand All @@ -44,12 +47,12 @@ Note: For `boolean` attributes, `true` means simply setting the attribute (e.g.
`<cds-pagination at-last-page>`) and `false` means not setting the attribute
(e.g. `<cds-pagination>` without `at-last-page` attribute).

<Props of="cds-pagination" />
<ArgsTable of="cds-pagination" />

## `<cds-pages-select>` attributes, properties and events

<Props of="cds-pages-select" />
<ArgsTable of="cds-pages-select" />

## `<cds-page-sizes-select>` attributes, properties and events

<Props of="cds-page-sizes-select" />
<ArgsTable of="cds-page-sizes-select" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
/**
* @license
*
* Copyright IBM Corp. 2019, 2024
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { html } from 'lit';
import './index';
import '../select/index';
import storyDocs from './pagination.mdx';
import { prefix } from '../../globals/settings';
import { PAGINATION_SIZE } from './defs';

const sizes = {
[`Small size (${PAGINATION_SIZE.SMALL})`]: PAGINATION_SIZE.SMALL,
[`Medium size (${PAGINATION_SIZE.MEDIUM})`]: PAGINATION_SIZE.MEDIUM,
[`Large size (${PAGINATION_SIZE.LARGE})`]: PAGINATION_SIZE.LARGE,
};

const args = {
backwardText: 'Previous page',
disabled: false,
forwardText: 'Next page',
isLastPage: false,
itemsPerPageText: 'Items per page:',
page: 1,
pageSize: 10,
pageInputDisabled: false,
pageSizeInputDisabled: false,
pagesUnknown: false,
size: PAGINATION_SIZE.MEDIUM,
totalItems: 103,
};

const argTypes = {
backwardText: {
control: 'text',
description: 'The description for the backward icon.',
},
disabled: {
control: 'boolean',
description:
'<code>true</code> if the backward/forward buttons, as well as the page select elements, should be disabled.',
},
forwardText: {
control: 'text',
description: 'The description for the forward icon.',
},
isLastPage: {
control: 'boolean',
description:
'<code>true</code> if the current page should be the last page.',
},
itemsPerPageText: {
control: 'text',
description: 'The text indicating the number of items per page.',
},
page: {
control: 'number',
description: 'The current page.',
},
pageSize: {
control: 'number',
description: 'The number dictating how many items a page contains.',
},
pageInputDisabled: {
control: 'boolean',
description:
'<code>true</code> if the select box to change the page should be disabled.',
},
pageSizeInputDisabled: {
control: 'boolean',
description:
'<code>true</code> if the select box to change the items per page should be disabled.',
},
pagesUnknown: {
control: 'boolean',
description: '<code>true</code> if the total number of items is unknown.',
},
size: {
control: 'select',
description: 'Specify the size of the Pagination.',
options: sizes,
},
totalItems: {
control: 'number',
description: 'The total number of items.',
},
onChangedCurrent: {
action: `${prefix}-pagination-changed-current`,
},
onChangedPageSizesSelect: {
action: `${prefix}-page-sizes-select-changed`,
},
};

export const Default = {
render: () => {
return html`
<cds-pagination start="0" total-items="103">
<cds-select-item value="10">10</cds-select-item>
<cds-select-item value="20">20</cds-select-item>
<cds-select-item value="30">30</cds-select-item>
<cds-select-item value="40">40</cds-select-item>
<cds-select-item value="50">50</cds-select-item>
</cds-pagination>
`;
},
};

export const MultiplePaginationComponents = {
render: () => {
return html`
<cds-pagination start="0" total-items="103">
<cds-select-item value="10">10</cds-select-item>
<cds-select-item value="20">20</cds-select-item>
<cds-select-item value="30">30</cds-select-item>
<cds-select-item value="40">40</cds-select-item>
<cds-select-item value="50">50</cds-select-item>
</cds-pagination>
<cds-pagination start="0" total-items="103">
<cds-select-item value="10">10</cds-select-item>
<cds-select-item value="20">20</cds-select-item>
<cds-select-item value="30">30</cds-select-item>
<cds-select-item value="40">40</cds-select-item>
<cds-select-item value="50">50</cds-select-item>
</cds-pagination>
`;
},
};

export const PaginationWithCustomPageSizesLabel = {
render: () => {
return html`
<cds-pagination start="0" total-items="103">
<cds-select-item value="10">Ten</cds-select-item>
<cds-select-item value="20">Twenty</cds-select-item>
<cds-select-item value="30">Thirty</cds-select-item>
<cds-select-item value="40">Forty</cds-select-item>
<cds-select-item value="50">Fifty</cds-select-item>
</cds-pagination>
`;
},
};

export const Playground = {
args,
argTypes,
render: (args) => {
const {
backwardText,
onChangedCurrent,
onChangedPageSizesSelect,
disabled,
forwardText,
isLastPage,
itemsPerPageText,
page,
pageInputDisabled,
pageSize,
pageSizeInputDisabled,
pagesUnknown,
size,
totalItems,
} = args ?? {};
return html`
<cds-pagination
backward-text=${backwardText}
?disabled=${disabled}
forward-text=${forwardText}
?is-last-page=${isLastPage}
items-per-page-text=${itemsPerPageText}
page=${page}
page-size=${pageSize}
?page-input-disabled=${pageInputDisabled}
?page-size-input-disabled=${pageSizeInputDisabled}
size=${size}
?pages-unknown=${pagesUnknown}
total-items=${totalItems}
@cds-pagination-changed-current="${onChangedCurrent}"
@cds-page-sizes-select-changed="${onChangedPageSizesSelect}">
<cds-select-item value="10">10</cds-select-item>
<cds-select-item value="20">20</cds-select-item>
<cds-select-item value="30">30</cds-select-item>
<cds-select-item value="40">40</cds-select-item>
<cds-select-item value="50">50</cds-select-item>
</cds-pagination>
`;
},
};

const meta = {
title: 'Components/Pagination',
parameters: {
docs: {
page: storyDocs,
},
},
decorators: [(story) => html`<div style="max-width: 800px">${story()}</div>`],
};

export default meta;
Loading

0 comments on commit 1de2e1f

Please sign in to comment.