-
Notifications
You must be signed in to change notification settings - Fork 15
/
stories.js
119 lines (105 loc) · 2.51 KB
/
stories.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { storiesOf } from '@storybook/html';
import { withLinks } from '@storybook/addon-links';
import { basename } from 'path';
import marked from 'marked';
import {
renderMain, renderOverview, renderItems, importAll,
} from './helpers';
import readme from '../readme.md';
import docs from '../.data/docs.json';
const elements = {};
importAll(require.context('./elements/', true, /\.js$/), elements);
const components = {};
importAll(require.context('./components/', true, /\.js$/), components);
const templates = {};
importAll(require.context('./templates/', true, /\.js$/), templates);
const utilities = {};
importAll(require.context('./utilities/', true, /\.js$/), utilities);
const filteredItems = [
'carousel',
'code',
'figures',
'images',
'jumbotron',
'popovers',
'spinners',
'toasts',
'tooltips',
'borders',
'close-icon',
'display',
'embed',
'flex',
'float',
'image-replacement',
'position',
'shadows',
'sizing',
'text',
'vertical-alignment',
];
function generatePage(story) {
// Render overview
storiesOf(story.kind, module)
.addDecorator(withLinks)
.add(
'Overview',
() => renderOverview({
title: 'Overview',
kind: story.kind,
description: 'Select a page to see examples and get more information.',
items: Object.keys(story.source)
.filter(file => filteredItems.indexOf(basename(file, '.js')) === -1)
.map(key => story.source[key].default),
}),
);
// Render stories
Object.entries(story.source)
.filter(([file]) => filteredItems.indexOf(basename(file, '.js')) === -1)
.map(entry => {
const [file, module] = entry;
const name = basename(file, '.js');
const doc = docs.components.find(item => item.tag === name);
const item = {
...module.default,
name,
doc,
kind: story.kind,
};
storiesOf(story.kind, module)
.addDecorator(withLinks)
.add(
item.title,
() => (item.method || renderItems)(item),
);
});
}
// Render Info page
storiesOf('Info', module)
.add(
'Corporate UI',
() => renderMain({
title: 'Corporate UI',
content: `
<section>
<div>${marked(readme)}</div>
</section>
`,
}),
);
generatePage({
source: elements,
kind: 'Elements',
});
generatePage({
source: components,
kind: 'Components',
});
generatePage({
source: utilities,
kind: 'Utilities',
});
generatePage({
source: templates,
kind: 'Templates',
});