0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-25 11:17:50 +01:00
posthog/.storybook/decorators/withMockDate.tsx
2023-10-27 22:47:36 +02:00

31 lines
681 B
TypeScript

import type { Decorator } from '@storybook/react'
import MockDate from 'mockdate'
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 />
}