/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

  1. /**
  2. * Copyright IBM Corp. 2016, 2018
  3. *
  4. * This source code is licensed under the Apache-2.0 license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. import React from 'react';
  8. import { action } from '@storybook/addon-actions';
  9. import Button from '../../Button';
  10. import DataTable, {
  11. Table,
  12. TableBody,
  13. TableCell,
  14. TableContainer,
  15. TableHead,
  16. TableHeader,
  17. TableRow,
  18. TableToolbar,
  19. TableToolbarAction,
  20. TableToolbarContent,
  21. TableToolbarSearch,
  22. TableToolbarMenu,
  23. } from '..';
  24. import { initialRows, headers } from './shared';
  25. export default props => (
  26. <DataTable
  27. rows={initialRows}
  28. headers={headers}
  29. {...props}
  30. render={({
  31. rows,
  32. headers,
  33. getHeaderProps,
  34. getRowProps,
  35. getTableProps,
  36. onInputChange,
  37. }) => (
  38. <TableContainer title="DataTable" description="With toolbar">
  39. <TableToolbar>
  40. <TableToolbarContent>
  41. <TableToolbarSearch onChange={onInputChange} />
  42. <TableToolbarMenu>
  43. <TableToolbarAction onClick={action('Action 1 Click')}>
  44. Action 1
  45. </TableToolbarAction>
  46. <TableToolbarAction onClick={action('Action 2 Click')}>
  47. Action 2
  48. </TableToolbarAction>
  49. <TableToolbarAction onClick={action('Action 3 Click')}>
  50. Action 3
  51. </TableToolbarAction>
  52. </TableToolbarMenu>
  53. <Button onClick={action('ButtonCLick')}>Primary Button</Button>
  54. </TableToolbarContent>
  55. </TableToolbar>
  56. <Table {...getTableProps()}>
  57. <TableHead>
  58. <TableRow>
  59. {headers.map(header => (
  60. <TableHeader {...getHeaderProps({ header })}>
  61. {header.header}
  62. </TableHeader>
  63. ))}
  64. </TableRow>
  65. </TableHead>
  66. <TableBody>
  67. {rows.map(row => (
  68. <TableRow {...getRowProps({ row })}>
  69. {row.cells.map(cell => (
  70. <TableCell key={cell.id}>{cell.value}</TableCell>
  71. ))}
  72. </TableRow>
  73. ))}
  74. </TableBody>
  75. </Table>
  76. </TableContainer>
  77. )}
  78. />
  79. );