colors.stories.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import {storiesOf} from '@storybook/react';
  3. import {withInfo} from '@storybook/addon-info';
  4. import styled from 'react-emotion';
  5. import {Flex} from 'grid-emotion';
  6. import theme from 'app/utils/theme';
  7. storiesOf('Style|Colors', module).add(
  8. 'default',
  9. withInfo('Top level colors')(() => {
  10. const colorsToDisplay = Object.entries(theme).filter(([_name, val]) => {
  11. return typeof val === 'string' && val.match(/^\#[0-9a-fA-F]{6}$/);
  12. });
  13. return (
  14. <Flex wrap="wrap">
  15. {colorsToDisplay.map(([name, color]) => (
  16. <Swatch key={name} color={color} align="center" justify="center">
  17. {name}
  18. </Swatch>
  19. ))}
  20. </Flex>
  21. );
  22. })
  23. );
  24. const Swatch = styled(Flex)`
  25. background-color: ${p => p.color};
  26. color: ${p => (p.color[1].match(/[0-8]{1}/) ? p.theme.offWhite : p.theme.gray5)};
  27. font-size: ${p => p.theme.fontSizeSmall};
  28. width: 80px;
  29. height: 80px;
  30. margin: 8px;
  31. padding: 8px;
  32. text-align: center;
  33. word-break: break-all;
  34. line-height: 1.4em;
  35. `;