forked from MODX-Club/modxclub.ru
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpreview.tsx
73 lines (66 loc) · 2.02 KB
/
preview.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { addDecorator } from '@storybook/react';
import theme from 'src/theme'
import { ThemeProvider } from 'styled-components'
import { makeDecorator } from '@storybook/addons';
import { linkTo } from '@storybook/addon-links'
import { RouterContext } from 'next/dist/next-server/lib/router-context'
import '../src/styles/styles.scss';
import { MittEmitter } from 'next/dist/next-server/lib/mitt';
export const parameters = {
options: {
storySort: (a: any, b: any) => {
// We want the Welcome story at the top
if (b[1].kind === 'Welcome') {
return 1
}
// Sort the other stories by ID
// https://github.com/storybookjs/storybook/issues/548#issuecomment-530305279
return a[1].kind === b[1].kind
? 0
: a[1].id.localeCompare(b[1].id, { numeric: true })
},
},
}
const startCase = (str: string) => {
return str.charAt(0).toUpperCase() + str.slice(1);
}
addDecorator(makeDecorator({
name: 'withSomething',
parameterName: 'something',
wrapper: (storyFn, context) => {
return <ThemeProvider theme={theme}>
{/*
https://github.com/vercel/next.js/issues/15543#issuecomment-664955766
*/}
<RouterContext.Provider
value={{
route: "/",
pathname: '/',
asPath: '/',
query: {},
basePath: '',
push: (_url, as) => {
if (as) {
linkTo('Routes', as !== '/' ? startCase(as.toString()) : 'Index')()
}
return Promise.resolve(true)
},
replace: (_url, as) => {
if (as) {
linkTo('Routes', as !== '/' ? startCase(as.toString()) : 'Index')()
}
return Promise.resolve(true)
},
reload: () => { },
prefetch: async () => { },
back: () => { },
beforePopState: () => { },
isFallback: false,
events: {} as MittEmitter,
}}
>
{storyFn(context)}
</RouterContext.Provider>
</ThemeProvider>
}
}));