forked from storybookjs/storybook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddon-info.stories.js
306 lines (284 loc) · 9.09 KB
/
addon-info.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import { action } from '@storybook/addon-actions';
import DocgenButton from '../components/DocgenButton';
import FlowTypeButton from '../components/FlowTypeButton';
import BaseButton from '../components/BaseButton';
import { NamedExportButton } from '../components/NamedExportButton';
import TableComponent from '../components/TableComponent';
import externalMdDocs from './addon-info-resources/EXAMPLE.md';
storiesOf('Addons|Info.React Docgen', module)
.add(
'Comments from PropType declarations',
withInfo(
'Comments above the PropType declarations should be extracted from the React component file itself and rendered in the Info Addon prop table'
)(() => <DocgenButton onClick={action('clicked')} label="Docgen Button" />)
)
.add(
'Comments from Flow declarations',
withInfo(
'Comments above the Flow declarations should be extracted from the React component file itself and rendered in the Info Addon prop table'
)(() => <FlowTypeButton onClick={action('clicked')} label="Flow Typed Button" />)
)
.add(
'Comments from component declaration',
withInfo(
'Comments above the component declaration should be extracted from the React component file itself and rendered below the Info Addon heading'
)(() => <BaseButton onClick={action('clicked')} label="Button" />)
)
.add(
'Comments from named export component declaration',
withInfo(
'Comments above the component declaration should be extracted from the React component file itself and rendered below the Info Addon heading'
)(() => <NamedExportButton onClick={action('clicked')} label="Button" />)
);
const markdownDescription = `
#### You can use markdown in your withInfo() description.
Sometimes you might want to manually include some code examples:
~~~js
const Button = () => <button />;
~~~
Maybe include a [link](http://storybook.js.org) to your project as well.
`;
storiesOf('Addons|Info.Markdown', module)
.add(
'Displays Markdown in description',
withInfo(markdownDescription)(() => <BaseButton onClick={action('clicked')} label="Button" />)
)
.add(
'From internal Markdown file',
withInfo(`
# internal
## markdown
file
`)(() => <BaseButton onClick={action('clicked')} label="Button" />)
)
.add(
'From external Markdown file',
withInfo(externalMdDocs)(() => <BaseButton onClick={action('clicked')} label="Button" />)
);
const JSXDescription = (
<div>
<h2>This is a JSX info section</h2>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed ornare massa rutrum metus
commodo, a mattis velit dignissim. Fusce vestibulum turpis sed massa egestas pharetra. Sed at
libero nulla.
</p>
<p>
<a href="https://github.com/storybooks/react-storybook-addon-info">This is a link</a>
</p>
<p>
<img alt="350x150" src="http://placehold.it/350x150" />
</p>
</div>
);
storiesOf('Addons|Info.JSX', module).add(
'Displays JSX in description',
withInfo({ text: JSXDescription })(() => (
<BaseButton onClick={action('clicked')} label="Button" />
))
);
storiesOf('Addons|Info.Options.inline', module).add(
'Inlines component inside story',
withInfo({
text: 'Component should be inlined between description and PropType table',
inline: true, // Displays info inline vs click button to view
})(() => <BaseButton label="Button" />)
);
storiesOf('Addons|Info.Options.header', module).add(
'Shows or hides Info Addon header',
withInfo({
text: 'The Info Addon header should be hidden',
header: false, // Toggles display of header with component name and description
})(() => <BaseButton label="Button" />)
);
storiesOf('Addons|Info.Options.source', module).add(
'Shows or hides Info Addon source',
withInfo({
text: 'The Info Addon source section should be hidden',
source: false, // Displays the source of story Component
})(() => <BaseButton label="Button" />)
);
storiesOf('Addons|Info.Options.propTables', module).add(
'Shows additional component prop tables',
withInfo({
text: 'There should be a prop table added for a component not included in the story',
propTables: [FlowTypeButton],
})(() => <BaseButton label="Button" />)
);
storiesOf('Addons|Info.Options.propTablesExclude', module).add(
'Exclude component from prop tables',
withInfo({
text: 'This can exclude extraneous components from being displayed in prop tables.',
propTablesExclude: [FlowTypeButton],
})(() => (
<div>
<BaseButton label="Button" />
<FlowTypeButton label="Flow Typed Button" />
</div>
))
);
storiesOf('Addons|Info.Options.styles', module)
.add(
'Extend info styles with an object',
withInfo({
styles: {
button: {
base: {
background: 'purple',
},
},
header: {
h1: {
color: 'green',
},
},
},
})(() => <BaseButton label="Button" />)
)
.add(
'Full control over styles using a function',
withInfo({
styles: stylesheet => ({
...stylesheet,
header: {
...stylesheet.header,
h1: {
...stylesheet.header.h1,
color: 'red',
},
},
}),
})(() => <BaseButton label="Button" />)
);
storiesOf('Addons|Info.Options.TableComponent', module).add(
'Use a custom component for the table',
withInfo({
TableComponent,
})(() => <BaseButton label="Button" />)
);
storiesOf('Addons|Info.Decorator', module)
.addDecorator((story, context) =>
withInfo('Info could be used as a global or local decorator as well.')(story)(context)
)
.add('Use Info as story decorator', () => <BaseButton label="Button" />);
const hoc = WrapComponent => ({ ...props }) => <WrapComponent {...props} />;
const Input = hoc(() => <input type="text" />);
const TextArea = hoc(({ children }) => <textarea>{children}</textarea>);
storiesOf('Addons|Info.GitHub issues', module).add(
'#1814',
withInfo('Allow Duplicate DisplayNames for HOC #1814')(() => (
<div>
<Input />
<TextArea />
</div>
))
);
storiesOf('Addons|Info.Options.maxPropsIntoLine === 0', module).add(
'Object and array props are broken to lines',
withInfo({
text: 'Component should be inlined between description and PropType table',
inline: true,
maxPropsIntoLine: 0,
})(() => (
<BaseButton
label="Button"
object={{
one: 'Object and array properties',
two: 'will be broken to different lines',
three: 'if greater than `maxPropsIntoLine` option threshold.',
}}
array={['one', 'two', 'three', 'four']}
arrayOfObjects={[
{
one: 'Object and array properties will be broken to different lines',
two: 'if greater than `maxPropsIntoLine` option threshold.',
object: {
object1: {
one: 'one',
two: 'two',
three: 'three',
},
array: ['one', 'two', 'three'],
object2: {
object: {
one: 'one',
two: 'two',
three: 'three',
},
array: [
'one',
'two',
{
object: {
object: {
one: 'one',
two: 'two',
three: 'three',
},
array: ['one', 'two', 'three'],
},
},
],
},
},
},
]}
/>
))
);
storiesOf('Addons|Info.Options.maxPropsIntoLine === 3', module).add(
'Object and array props are broken to lines',
withInfo({
text: 'Component should be inlined between description and PropType table',
inline: true,
maxPropsIntoLine: 3,
})(() => (
<BaseButton
label="Button"
object={{
one: 'Object and array properties',
two: 'will be broken to different lines',
three: 'if greater than `maxPropsIntoLine` option threshold.',
}}
array={['one', 'two', 'three', 'four']}
arrayOfObjects={[
{
one: 'Object and array properties will be broken to different lines',
two: 'if greater than `maxPropsIntoLine` option threshold.',
object: {
object1: {
one: 'one',
two: 'two',
three: 'three',
},
array: ['one', 'two', 'three'],
object2: {
object: {
one: 'one',
two: 'two',
three: 'three',
},
array: [
'one',
'two',
{
object: {
object: {
one: 'one',
two: 'two',
three: 'three',
},
array: ['one', 'two', 'three'],
},
},
],
},
},
},
]}
/>
))
);