config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import React from 'react';
  2. import { configure } from '@storybook/react';
  3. import { addDecorator, addParameters } from '@storybook/react';
  4. import { INITIAL_VIEWPORTS } from '@storybook/addon-viewport';
  5. import { withInfo } from '@storybook/addon-info';
  6. import 'intersection-observer';
  7. import smoothscroll from 'smoothscroll-polyfill';
  8. import '../src/styles/global.scss';
  9. smoothscroll.polyfill();
  10. addParameters({ viewport: { viewports: { ...INITIAL_VIEWPORTS } } });
  11. addDecorator(withInfo);
  12. // automatically import all files ending in *.stories.js
  13. const src = require.context('../src', true, /.stories.js$/);
  14. const common = require.context('../__stories__', true, /.stories.js$/);
  15. function loadStories() {
  16. src.keys().forEach(filename => src(filename));
  17. common.keys().forEach(filename => common(filename));
  18. }
  19. // Gatsby's Link overrides:
  20. // Gatsby defines a global called ___loader to prevent its method calls from creating console errors you override it here
  21. global.___loader = {
  22. enqueue: () => {},
  23. hovering: () => {},
  24. };
  25. // Gatsby internal mocking to prevent unnecessary errors in storybook testing environment
  26. global.__PATH_PREFIX__ = '';
  27. // This is to utilized to override the window.___navigate method Gatsby defines and uses to report what path a Link would be taking us to if it wasn't inside a storybook
  28. window.___navigate = pathname => {
  29. action('NavigateTo:')(pathname);
  30. };
  31. configure(loadStories, module);