diff --git a/packages/canon/src/components/DataTable/Pagination/DataTablePagination.stories.tsx b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.stories.tsx new file mode 100644 index 0000000000..54563cd98a --- /dev/null +++ b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.stories.tsx @@ -0,0 +1,39 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import type { Meta, StoryObj } from '@storybook/react'; +import { DataTablePagination } from './DataTablePagination'; + +const meta = { + title: 'Components/DataTable/Pagination', + component: DataTablePagination, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + args: { + pageIndex: 0, + pageSize: 10, + totalRows: 100, + onClickPrevious: () => {}, + onClickNext: () => {}, + canPrevious: true, + canNext: true, + setPageSize: () => {}, + }, +}; diff --git a/packages/canon/src/components/DataTable/Pagination/DataTablePagination.styles.css b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.styles.css new file mode 100644 index 0000000000..460a6a5874 --- /dev/null +++ b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.styles.css @@ -0,0 +1,21 @@ +.canon-TablePagination { + display: flex; + align-items: center; + justify-content: space-between; + padding-top: var(--canon-space-3); + border-top: 1px solid var(--canon-border); + margin-top: var(--canon-space-3); +} + +.canon-TablePagination--left { + display: flex; + align-items: center; + justify-content: space-between; +} + +.canon-TablePagination--right { + display: flex; + align-items: center; + justify-content: space-between; + gap: var(--canon-space-2); +} diff --git a/packages/canon/src/components/DataTable/Pagination/DataTablePagination.tsx b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.tsx new file mode 100644 index 0000000000..3a80ba3270 --- /dev/null +++ b/packages/canon/src/components/DataTable/Pagination/DataTablePagination.tsx @@ -0,0 +1,86 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as React from 'react'; +import { Text } from '../../Text'; +import { DataTablePaginationProps } from './types'; +import { IconButton } from '../../IconButton'; +import clsx from 'clsx'; +import { Select } from '../../Select'; + +/** @public */ +const DataTablePagination = React.forwardRef< + HTMLDivElement, + DataTablePaginationProps +>(({ className, ...props }, ref) => { + const { + pageIndex, + pageSize, + onClickPrevious, + onClickNext, + canPrevious, + canNext, + totalRows, + setPageSize, + } = props; + return ( +
+
+ { - setPageSize(Number(e.target.value)); - }} - > - {[10, 20, 30, 40, 50].map(pageSize => ( - - ))} - -
- {`${pageIndex * pageSize + 1} - ${ - (pageIndex + 1) * pageSize - } of ${totalRows}`} -
-
- - -
-
- ); - }, -); -TablePagination.displayName = 'TablePagination'; - -export { TablePagination }; diff --git a/packages/canon/src/css/components.css b/packages/canon/src/css/components.css index 2480baab14..f6b1db16c5 100644 --- a/packages/canon/src/css/components.css +++ b/packages/canon/src/css/components.css @@ -16,6 +16,8 @@ @import '../components/Box/styles.css'; @import '../components/Button/styles.css'; +@import '../components/DataTable/Root/DataTableRoot.styles.css'; +@import '../components/DataTable/Pagination/DataTablePagination.styles.css'; @import '../components/Flex/styles.css'; @import '../components/Grid/styles.css'; @import '../components/Container/styles.css'; diff --git a/packages/canon/src/index.ts b/packages/canon/src/index.ts index 7435b6dd60..a458ac0f4d 100644 --- a/packages/canon/src/index.ts +++ b/packages/canon/src/index.ts @@ -33,6 +33,7 @@ export * from './components/Heading'; // UI components export * from './components/Button'; +export * from './components/DataTable'; export * from './components/Icon'; export * from './components/IconButton'; export * from './components/Checkbox';