2021-08-25 10:38:33 +02:00
|
|
|
import '~/styles'
|
2023-08-21 09:32:49 +02:00
|
|
|
import type { Meta, Parameters, Preview } from '@storybook/react'
|
|
|
|
import { Title, Subtitle, Description, Primary, Controls, Stories } from '@storybook/blocks'
|
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 { withKea } from './decorators/withKea'
|
|
|
|
import { withMockDate } from './decorators/withMockDate'
|
2023-01-10 10:49:22 +01:00
|
|
|
import { defaultMocks } from '~/mocks/handlers'
|
2023-06-08 23:02:46 +02:00
|
|
|
import { withFeatureFlags } from './decorators/withFeatureFlags'
|
2023-10-26 13:27:17 +02:00
|
|
|
import { withTheme } from './decorators/withTheme'
|
2024-01-30 14:50:45 +01:00
|
|
|
import { apiHostOrigin } from 'lib/utils/apiHost'
|
2024-03-08 01:31:35 +01:00
|
|
|
import { getStorybookAppContext } from './app-context'
|
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,
|
2023-09-14 11:37:09 +02:00
|
|
|
onUnhandledRequest(request, print) {
|
|
|
|
// MSW warns on all unhandled requests, but we don't necessarily care
|
|
|
|
const pathAllowList = ['/images/']
|
|
|
|
|
|
|
|
if (pathAllowList.some((path) => request.url.pathname.startsWith(path))) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, default MSW warning behavior
|
|
|
|
print.warning()
|
|
|
|
},
|
2022-11-30 12:42:44 +01:00
|
|
|
})
|
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
|
2024-01-30 14:50:45 +01:00
|
|
|
window.JS_POSTHOG_HOST = apiHostOrigin()
|
2021-10-13 06:45:51 +02:00
|
|
|
|
|
|
|
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'] = [
|
|
|
|
// 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,
|
2023-06-08 23:02:46 +02:00
|
|
|
// Allow us to easily set feature flags in stories.
|
|
|
|
withFeatureFlags,
|
2023-10-26 13:27:17 +02:00
|
|
|
// Set theme from global context
|
|
|
|
withTheme,
|
2021-10-13 06:45:51 +02:00
|
|
|
]
|
2023-08-21 09:32:49 +02:00
|
|
|
|
|
|
|
const preview: Preview = {
|
|
|
|
parameters: {
|
|
|
|
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
|
|
controls: {
|
|
|
|
matchers: {
|
|
|
|
color: /(background|color)$/i,
|
|
|
|
date: /Date$/,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
docs: {
|
|
|
|
page: () => (
|
|
|
|
<>
|
|
|
|
<Title />
|
|
|
|
<Subtitle />
|
|
|
|
<Description />
|
|
|
|
<Primary />
|
|
|
|
<Controls />
|
|
|
|
<Stories />
|
|
|
|
</>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
2023-10-26 13:27:17 +02:00
|
|
|
globalTypes: {
|
|
|
|
theme: {
|
|
|
|
description: '',
|
2023-12-27 09:52:28 +01:00
|
|
|
defaultValue: 'light',
|
2023-10-26 13:27:17 +02:00
|
|
|
toolbar: {
|
|
|
|
title: 'Theme',
|
|
|
|
items: [
|
|
|
|
{ value: 'light', icon: 'sun', title: 'Light' },
|
|
|
|
{ value: 'dark', icon: 'moon', title: 'Dark' },
|
|
|
|
],
|
|
|
|
// change the title based on the selected value
|
|
|
|
dynamicTitle: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-21 09:32:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default preview
|