/
preview.tsx
76 lines (72 loc) 路 1.75 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
74
75
76
import React from 'react'
import StoryLayout from './story-layout'
import '../src/styles.css'
import { DEFAULT_THEME, STORAGE_KEY, THEME_PICKER_LIST } from './theming'
import { docsTheme } from './theme.cjs'
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
previewTabs: {
'storybook/docs/panel': { hidden: true },
},
controls: {
matchers: {
date: /Date$/,
},
},
layout: 'fullscreen',
options: {
storySort: {
order: [
'Welcome',
'Actions',
'Data Display',
'Data Input',
'Layout',
'Navigation',
'Mockup',
'Utils',
],
},
},
themes: {
default: window.localStorage.getItem(STORAGE_KEY) || DEFAULT_THEME,
onChange: (theme) => {
// STORAGE_KEY does not work in onChange... not sure why
if (theme) {
window.localStorage.setItem(
'sb-react-daisyui-preview-theme',
theme.class
)
} else {
window.localStorage.removeItem('sb-react-daisyui-preview-theme')
}
},
list: THEME_PICKER_LIST,
},
docs: {
theme: docsTheme,
options: {
layout: 'fullscreen',
},
},
}
export const decorators = [
(Story, options) => (
<StoryLayout
title={options.title}
description={options.story}
source={
options.parameters.storySource.source.
/* TODO: clean up all this string formatting/regex */
/* Removes the args arrow function */
replace('(args) => {', '').
/* Removes leftover newline from previous replace */
replace('\n', '').
/* Removes the last occurence of a closing bracket (from the lambda) */
replace(/}([^}]*)$/, '$1')
}
>
<Story />
</StoryLayout>
),
]