0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 09:14:46 +01:00
posthog/.storybook/decorators/withMockDate.tsx

31 lines
681 B
TypeScript
Raw Normal View History

import type { Decorator } from '@storybook/react'
import MockDate from 'mockdate'
2023-10-27 22:47:36 +02:00
declare module '@storybook/types' {
interface Parameters {
mockDate?: string | number | Date
}
}
/** Global story decorator that allows mocking of dates.
*
* ```ts
* export default {
* title: 'My story',
* component: MyComponent,
* parameters: {
* mockDate: '2023-02-01', // add mock date here
* },
* } as ComponentMeta<typeof MyComponent>
* ```
*/
export const withMockDate: Decorator = (Story, { parameters }) => {
if (parameters.mockDate) {
MockDate.set(parameters.mockDate)
} else {
MockDate.reset()
}
return <Story />
}