/src/components/DataTable/stories/with-toolbar.js
https://github.com/carbon-design-system/carbon-components-react · JavaScript · 82 lines · 73 code · 3 blank · 6 comment · 0 complexity · bc5be2bebe93e6f237da0d55e0357ab6 MD5 · raw file
- /**
- * Copyright IBM Corp. 2016, 2018
- *
- * 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 React from 'react';
- import { action } from '@storybook/addon-actions';
- import Button from '../../Button';
- import DataTable, {
- Table,
- TableBody,
- TableCell,
- TableContainer,
- TableHead,
- TableHeader,
- TableRow,
- TableToolbar,
- TableToolbarAction,
- TableToolbarContent,
- TableToolbarSearch,
- TableToolbarMenu,
- } from '..';
- import { initialRows, headers } from './shared';
- export default props => (
- <DataTable
- rows={initialRows}
- headers={headers}
- {...props}
- render={({
- rows,
- headers,
- getHeaderProps,
- getRowProps,
- getTableProps,
- onInputChange,
- }) => (
- <TableContainer title="DataTable" description="With toolbar">
- <TableToolbar>
- <TableToolbarContent>
- <TableToolbarSearch onChange={onInputChange} />
- <TableToolbarMenu>
- <TableToolbarAction onClick={action('Action 1 Click')}>
- Action 1
- </TableToolbarAction>
- <TableToolbarAction onClick={action('Action 2 Click')}>
- Action 2
- </TableToolbarAction>
- <TableToolbarAction onClick={action('Action 3 Click')}>
- Action 3
- </TableToolbarAction>
- </TableToolbarMenu>
- <Button onClick={action('ButtonCLick')}>Primary Button</Button>
- </TableToolbarContent>
- </TableToolbar>
- <Table {...getTableProps()}>
- <TableHead>
- <TableRow>
- {headers.map(header => (
- <TableHeader {...getHeaderProps({ header })}>
- {header.header}
- </TableHeader>
- ))}
- </TableRow>
- </TableHead>
- <TableBody>
- {rows.map(row => (
- <TableRow {...getRowProps({ row })}>
- {row.cells.map(cell => (
- <TableCell key={cell.id}>{cell.value}</TableCell>
- ))}
- </TableRow>
- ))}
- </TableBody>
- </Table>
- </TableContainer>
- )}
- />
- );