2021-08-25 10:38:33 +02:00
|
|
|
import '~/styles'
|
2022-06-14 17:14:44 +02:00
|
|
|
import './storybook.scss'
|
2023-02-03 13:06:21 +01:00
|
|
|
import type { Meta, Parameters } from '@storybook/react'
|
2022-03-15 17:36:51 +01:00
|
|
|
import { worker } from '~/mocks/browser'
|
2021-10-13 06:45:51 +02:00
|
|
|
import { loadPostHogJS } from '~/loadPostHogJS'
|
2022-12-07 11:40:56 +01:00
|
|
|
import { getStorybookAppContext } from './app-context'
|
|
|
|
import { withKea } from './decorators/withKea'
|
|
|
|
import { withMockDate } from './decorators/withMockDate'
|
2023-01-10 10:49:22 +01:00
|
|
|
import { defaultMocks } from '~/mocks/handlers'
|
2023-01-27 15:51:35 +01:00
|
|
|
import { withSnapshotsDisabled } from './decorators/withSnapshotsDisabled'
|
2021-08-25 10:38:33 +02:00
|
|
|
|
2021-10-13 06:45:51 +02:00
|
|
|
const setupMsw = () => {
|
2022-03-15 17:36:51 +01:00
|
|
|
// Make sure the msw worker is started
|
2022-11-30 12:42:44 +01:00
|
|
|
worker.start({
|
|
|
|
quiet: true,
|
|
|
|
})
|
2022-03-15 17:36:51 +01:00
|
|
|
;(window as any).__mockServiceWorker = worker
|
2022-03-21 13:45:10 +01:00
|
|
|
;(window as any).POSTHOG_APP_CONTEXT = getStorybookAppContext()
|
2021-10-13 06:45:51 +02:00
|
|
|
}
|
|
|
|
setupMsw()
|
|
|
|
|
|
|
|
const setupPosthogJs = () => {
|
|
|
|
// Make sure we don't hit production posthog. We want to control requests to,
|
|
|
|
// e.g. `/decide/` for feature flags
|
|
|
|
window.JS_POSTHOG_HOST = window.location.origin
|
|
|
|
|
|
|
|
loadPostHogJS()
|
|
|
|
}
|
|
|
|
setupPosthogJs()
|
|
|
|
|
2023-01-27 15:51:35 +01:00
|
|
|
/** Storybook global parameters. See https://storybook.js.org/docs/react/writing-stories/parameters#global-parameters */
|
2023-02-03 13:06:21 +01:00
|
|
|
export const parameters: Parameters = {
|
2022-03-17 08:45:47 +01:00
|
|
|
actions: { argTypesRegex: '^on[A-Z].*', disabled: true },
|
2021-08-25 10:38:33 +02:00
|
|
|
controls: {
|
|
|
|
matchers: {
|
|
|
|
color: /(background|color)$/i,
|
|
|
|
date: /Date$/,
|
|
|
|
},
|
|
|
|
},
|
2021-09-07 14:00:44 +02:00
|
|
|
options: {
|
2022-03-17 08:45:47 +01:00
|
|
|
// automatically show code panel
|
2022-08-08 08:27:00 +02:00
|
|
|
showPanel: false,
|
2022-04-27 12:20:52 +02:00
|
|
|
storySort: {
|
|
|
|
method: 'alphabetical',
|
2022-08-01 16:09:44 +02:00
|
|
|
order: [
|
|
|
|
'Lemon UI',
|
|
|
|
['Overview', 'Utilities', 'Icons'],
|
|
|
|
'Components',
|
|
|
|
'Forms',
|
|
|
|
['Field'],
|
|
|
|
'Filters',
|
|
|
|
'Layout',
|
|
|
|
],
|
2022-03-16 17:42:07 +01:00
|
|
|
},
|
2021-09-07 14:00:44 +02:00
|
|
|
},
|
2022-03-17 08:45:47 +01:00
|
|
|
viewMode: 'docs',
|
|
|
|
// auto-expand code blocks in docs
|
|
|
|
docs: {
|
2022-08-08 08:27:00 +02:00
|
|
|
source: { state: 'closed' },
|
2022-03-17 08:45:47 +01:00
|
|
|
},
|
2023-01-10 10:49:22 +01:00
|
|
|
msw: {
|
|
|
|
mocks: defaultMocks,
|
|
|
|
},
|
2021-08-25 10:38:33 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 06:45:51 +02:00
|
|
|
// Setup storybook global decorators. See https://storybook.js.org/docs/react/writing-stories/decorators#global-decorators
|
2022-12-07 11:40:56 +01:00
|
|
|
export const decorators: Meta['decorators'] = [
|
2023-01-27 15:51:35 +01:00
|
|
|
withSnapshotsDisabled,
|
2022-12-07 11:40:56 +01:00
|
|
|
// Make sure the msw service worker is started, and reset the handlers to defaults.
|
|
|
|
withKea,
|
|
|
|
// Allow us to time travel to ensure our stories don't change over time.
|
|
|
|
// To mock a date for a story, set the `mockDate` parameter.
|
|
|
|
withMockDate,
|
2021-10-13 06:45:51 +02:00
|
|
|
]
|