backgrounds.stories.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import React from 'react';
  2. import centered from '@storybook/addon-centered/react';
  3. import { storiesOf } from '@storybook/react';
  4. import importAll from '../../src/utils/importAll';
  5. import parsePathToName from '../../src/utils/parsePathToName';
  6. import ColumnsLayout from '../../src/components/ColumnsLayout';
  7. const backgroundsList = require.context('../../src/assets/background', false, /\.(png|jpe?g|svg)$/);
  8. const backgrounds = importAll(backgroundsList);
  9. const stories = storiesOf('Assets|Backgrounds', module);
  10. stories.addDecorator(centered);
  11. stories.addParameters({
  12. backgrounds: [{ name: 'silver', value: '#cacaca', default: true }],
  13. });
  14. stories.add('_all', () => {
  15. return (
  16. <ColumnsLayout columnsCount={4} style={{ padding: '20px' }}>
  17. {backgrounds.map((background, i) => {
  18. return (
  19. <div
  20. key={backgroundsList.keys()[i]}
  21. style={{
  22. display: 'flex',
  23. flexDirection: 'column',
  24. justifyContent: 'center',
  25. alignItems: 'center',
  26. textAlign: 'center',
  27. }}
  28. >
  29. <img src={background} alt={parsePathToName(backgroundsList.keys()[i])} />
  30. <p style={{ marginTop: '12px' }}>{parsePathToName(backgroundsList.keys()[i])}</p>
  31. </div>
  32. );
  33. })}
  34. </ColumnsLayout>
  35. );
  36. });
  37. backgrounds.forEach((background, i) => {
  38. stories.add(`${parsePathToName(backgroundsList.keys()[i])}`, () => (
  39. <img src={background} alt={parsePathToName(backgroundsList.keys()[i])} />
  40. ));
  41. });