colors.stories.js 1.1 KB

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