forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
70 lines (60 loc) · 2.4 KB
/
index.js
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
import { setAddon, storiesOf } from '@storybook/react';
import { withKnobs } from '@storybook/addon-knobs';
import JSXAddon from 'storybook-addon-jsx';
import categoricalD3 from '@superset-ui/color/esm/colorSchemes/categorical/d3';
import sequentialCommon from '@superset-ui/color/esm/colorSchemes/sequential/common';
import sequentialD3 from '@superset-ui/color/esm/colorSchemes/sequential/d3';
import { configure } from '@superset-ui/translation';
import { getCategoricalSchemeRegistry, getSequentialSchemeRegistry } from '@superset-ui/color';
import { getTimeFormatterRegistry, smartDateFormatter } from '@superset-ui/time-format';
setAddon(JSXAddon);
configure();
// Register color schemes
const categoricalSchemeRegistry = getCategoricalSchemeRegistry();
[categoricalD3].forEach(group => {
group.forEach(scheme => {
categoricalSchemeRegistry.registerValue(scheme.id, scheme);
});
});
categoricalSchemeRegistry.setDefaultKey('d3Category10');
const sequentialSchemeRegistry = getSequentialSchemeRegistry();
[sequentialCommon, sequentialD3].forEach(group => {
group.forEach(scheme => {
sequentialSchemeRegistry.registerValue(scheme.id, scheme);
});
});
getTimeFormatterRegistry()
.registerValue('smart_date', smartDateFormatter)
.setDefaultKey('smart_date');
const EMPTY_EXAMPLES = [
{
renderStory: () => 'Does your default export have an `examples` key?',
storyName: 'No examples found',
},
];
/*
* Below we crawl the dir + subdirs looking for index files of stories
* Each index is expected to have a default export with examples key containing
* an array of examples. Each example should have the shape:
* { storyPath: string, storyName: string, renderStory: fn() => node }
*
*/
const requireContext = require.context('./', /* subdirs= */ true, /index\.jsx?$/);
requireContext.keys().forEach(packageName => {
const packageExport = requireContext(packageName);
if (packageExport && packageExport.default && !Array.isArray(packageExport.default)) {
const { examples = EMPTY_EXAMPLES } = packageExport.default;
examples.forEach(example => {
const {
storyPath = 'Missing story path',
storyName = 'Missing name',
renderStory = () => 'Missing `renderStory`',
options = {},
} = example;
storiesOf(storyPath, module)
.addParameters({ options })
.addDecorator(withKnobs)
.addWithJSX(storyName, renderStory);
});
}
});