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

docs(DataTable): add playground story #6842

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 54 additions & 0 deletions packages/react/src/components/DataTable/DataTable-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import './stories/datatable-story.scss';

import { action } from '@storybook/addon-actions';
import React from 'react';
import { withKnobs, boolean, select } from '@storybook/addon-knobs';
import Button from '../Button';
import Checkbox from '../Checkbox';
import OverflowMenu from '../OverflowMenu';
Expand All @@ -31,6 +32,16 @@ import {
import mdx from './DataTable.mdx';
import { headers, rows } from './stories/shared';

const props = () => ({
useZebraStyles: boolean('Zebra row styles (useZebraStyles)', false),
size: select(
'Row height (size)',
{ compact: 'compact', short: 'short', tall: 'tall', none: null },
null
),
stickyHeader: boolean('Sticky header (experimental)', false),
});

export default {
title: 'DataTable',
component: DataTable,
Expand All @@ -43,6 +54,7 @@ export default {
TableBody,
TableCell,
},
decorators: [withKnobs],
parameters: {
docs: {
page: mdx,
Expand Down Expand Up @@ -356,3 +368,45 @@ export const WithCheckmarkColumns = () => {
</DataTable>
);
};

export const Playground = () => (
<DataTable
rows={rows}
headers={headers}
{...props()}
render={({
rows,
headers,
getHeaderProps,
getRowProps,
getTableProps,
getTableContainerProps,
}) => (
<TableContainer
title="DataTable"
description="With default options"
{...getTableContainerProps()}>
<Table {...getTableProps()}>
<TableHead>
<TableRow>
{headers.map((header, i) => (
<TableHeader key={i} {...getHeaderProps({ header })}>
{header.header}
</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{rows.map((row, i) => (
<TableRow key={i} {...getRowProps({ row })}>
{row.cells.map((cell) => (
<TableCell key={cell.id}>{cell.value}</TableCell>
))}
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)}
/>
);
63 changes: 0 additions & 63 deletions packages/react/src/components/DataTable/stories/default.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import DataTable, {
TableToolbarSearch,
TableToolbarMenu,
} from '../../../DataTable';
import { batchActionClick, initialRows, headers } from '../shared';
import { batchActionClick, rows, headers } from '../shared';

export default {
title: 'DataTable/Development',
Expand All @@ -48,7 +48,7 @@ export const Example = (props) => {

class DynamicRows extends React.Component {
state = {
rows: initialRows,
rows,
headers: headers,
id: 0,
};
Expand Down
57 changes: 0 additions & 57 deletions packages/react/src/components/DataTable/stories/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,63 +64,6 @@ export const rows = [
},
];

export const initialRows = [
{
id: 'a',
name: 'Load Balancer 3',
protocol: 'HTTP',
port: 3000,
rule: 'Round robin',
attached_groups: 'Kevin’s VM Groups',
status: 'Disabled',
},
{
id: 'b',
name: 'Load Balancer 1',
protocol: 'HTTP',
port: 443,
rule: 'Round robin',
attached_groups: 'Maureen’s VM Groups',
status: 'Starting',
},
{
id: 'c',
name: 'Load Balancer 2',
protocol: 'HTTP',
port: 80,
rule: 'DNS delegation',
attached_groups: 'Andrew’s VM Groups',
status: 'Active',
},
{
id: 'd',
name: 'Load Balancer 6',
protocol: 'HTTP',
port: 3000,
rule: 'Round robin',
attached_groups: 'Marc’s VM Groups',
status: 'Disabled',
},
{
id: 'e',
name: 'Load Balancer 4',
protocol: 'HTTP',
port: 443,
rule: 'Round robin',
attached_groups: 'Mel’s VM Groups',
status: 'Starting',
},
{
id: 'f',
name: 'Load Balancer 5',
protocol: 'HTTP',
port: 80,
rule: 'DNS delegation',
attached_groups: 'Ronja’s VM Groups',
status: 'Active',
},
];

export const headers = [
{
key: 'name',
Expand Down