Skip to content

Commit

Permalink
feat: upstream generic pagination component for tables
Browse files Browse the repository at this point in the history
Signed-off-by: Mason Hu <[email protected]>
  • Loading branch information
mas-who committed Jan 12, 2024
1 parent 80a8005 commit a49fbf7
Show file tree
Hide file tree
Showing 10 changed files with 525 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/components/TablePagination/TablePagination.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
@import "~vanilla-framework/scss/settings";

.pagination {
align-items: baseline;
display: flex;
margin-top: 1.2rem;

.description {
flex-grow: 1;
}

.back {
margin: 0 $spv--large;

.p-icon--chevron-down {
rotate: 90deg;
}
}

.next {
margin: 0 $spv--large;

.p-icon--chevron-down {
rotate: 270deg;
}
}

.pagination-input {
margin-right: $spv--small;
min-width: 0;
width: 3rem;
}

.pagination-select {
margin-bottom: 0;
margin-left: $spv--x-large;
min-width: 0;
width: 7rem;
}
}
214 changes: 214 additions & 0 deletions src/components/TablePagination/TablePagination.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import { ArgsTable, Canvas, Meta, Story } from "@storybook/addon-docs";

import TablePagination from "./TablePagination";
import MainTable from "../MainTable";

<Meta title="TablePagination" component={TablePagination} />

export const Template = (args) => <TablePagination {...args} />;

### TablePagination

This is an HOC [React](https://reactjs.org/) component for applying pagination to input data for direct child components.
This component is un-opinionated about the structure of the input data and can be used with any child component that displays
a list of data.

To use this component, simply wrap a child component with it and provide the data that you want to paginate to the ```data``` prop.
This component will then pass the paged data to all <bold>direct</bold> child components via a child prop specified by ```dataPropOverride```.

### Props

<ArgsTable of={TablePagination} />

### Default

<Canvas>
<Story
name="Default"
args={{
data: [{id: "row-1"}, {id: "row-2"}, {id: "row-3"}, {id: "row-4"}, {id: "row-5"}],
}}
>
{Template.bind({})}
</Story>
</Canvas>

### Custom page limit

<Canvas>
<Story
name="CustomPageLimit"
args={{
data: [{id: "row-1"}, {id: "row-2"}, {id: "row-3"}, {id: "row-4"}, {id: "row-5"}],
pageLimits: [1, 2, 3]
}}
>
{Template.bind({})}
</Story>
</Canvas>

### Custom display title

<Canvas>
<Story
name="CustomDisplayTitle"
args={{
data: [{id: "row-1"}, {id: "row-2"}, {id: "row-3"}, {id: "row-4"}, {id: "row-5"}],
displayTitle: <bold>Hello there</bold>
}}
>
{Template.bind({})}
</Story>
</Canvas>

### Render above

<Canvas>
<Story
name="RenderAbove"
>
{() => {
const data = [
{
columns: [
{ content: "Ready", role: "rowheader" },
{ content: 1, className: "u-align--right" },
{ content: "1 GiB", className: "u-align--right" },
{ content: 2, className: "u-align--right" },
{ content: 42, className: "u-align--right" },
],
sortData: {
status: "ready",
cores: 2,
ram: 1,
disks: 2,
},
},
{
columns: [
{ content: "Idle", role: "rowheader" },
{ content: 1, className: "u-align--right" },
{ content: "1 GiB", className: "u-align--right" },
{ content: 2, className: "u-align--right" },
{ content: 23, className: "u-align--right" },
],
sortData: {
status: "idle",
cores: 1,
ram: 1,
disks: 2,
},
},
{
columns: [
{ content: "Waiting", role: "rowheader" },
{ content: 8, className: "u-align--right" },
{ content: "3.9 GiB", className: "u-align--right" },
{ content: 3, className: "u-align--right" },
{ content: 0, className: "u-align--right" },
],
sortData: {
status: "waiting",
cores: 8,
ram: 3.9,
disks: 3,
},
},
];

const headers = [
{ content: "Status", sortKey: "status" },
{ content: "Cores", sortKey: "cores", className: "u-align--right" },
{ content: "RAM", sortKey: "ram", className: "u-align--right" },
{ content: "Disks", sortKey: "disks", className: "u-align--right" },
{ content: "Networks", className: "u-align--right" },
];

return (
<TablePagination data={data} pageLimits={[1, 2, 3]}>
<MainTable
headers={headers}
rows={data}
sortabl
/>
</TablePagination>
);
}}
</Story>
</Canvas>

### Render below

<Canvas>
<Story
name="RenderBelow"
>
{() => {
const data = [
{
columns: [
{ content: "Ready", role: "rowheader" },
{ content: 1, className: "u-align--right" },
{ content: "1 GiB", className: "u-align--right" },
{ content: 2, className: "u-align--right" },
{ content: 42, className: "u-align--right" },
],
sortData: {
status: "ready",
cores: 2,
ram: 1,
disks: 2,
},
},
{
columns: [
{ content: "Idle", role: "rowheader" },
{ content: 1, className: "u-align--right" },
{ content: "1 GiB", className: "u-align--right" },
{ content: 2, className: "u-align--right" },
{ content: 23, className: "u-align--right" },
],
sortData: {
status: "idle",
cores: 1,
ram: 1,
disks: 2,
},
},
{
columns: [
{ content: "Waiting", role: "rowheader" },
{ content: 8, className: "u-align--right" },
{ content: "3.9 GiB", className: "u-align--right" },
{ content: 3, className: "u-align--right" },
{ content: 0, className: "u-align--right" },
],
sortData: {
status: "waiting",
cores: 8,
ram: 3.9,
disks: 3,
},
},
];

const headers = [
{ content: "Status", sortKey: "status" },
{ content: "Cores", sortKey: "cores", className: "u-align--right" },
{ content: "RAM", sortKey: "ram", className: "u-align--right" },
{ content: "Disks", sortKey: "disks", className: "u-align--right" },
{ content: "Networks", className: "u-align--right" },
];

return (
<TablePagination data={data} pageLimits={[1, 2, 3]} renderBelow>
<MainTable
headers={headers}
rows={data}
sortabl
/>
</TablePagination>
);
}}
</Story>
</Canvas>
Empty file.
Loading

0 comments on commit a49fbf7

Please sign in to comment.