forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.stories.tsx
More file actions
103 lines (98 loc) · 3.01 KB
/
index.stories.tsx
File metadata and controls
103 lines (98 loc) · 3.01 KB
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
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { text, select, number, array, boolean } from '@storybook/addon-knobs';
import SandboxCard, { Props, Sandbox } from '.';
import * as fixtures from './fixtures';
const authorWithKnobs = (
group: string,
author: Sandbox['author'] = null
): Sandbox['author'] => {
const knobs = {
username: text('author.username', author && author.username, group),
avatar_url: text('author.avatar_url', author && author.avatar_url, group),
};
if (knobs.username !== null || knobs.avatar_url !== null) {
return knobs;
}
return author;
};
const sandboxWithKnobs = (group: string, sandbox: Sandbox): Sandbox => ({
id: text('id', sandbox.id, group),
title: text('title', sandbox.title, group),
author: authorWithKnobs(group, sandbox.author),
description: text('description', sandbox.description, group),
screenshot_url: text('screenshot_url', sandbox.screenshot_url, group),
view_count: number('view_count', sandbox.view_count, {}, group),
fork_count: number('fork_count', sandbox.fork_count, {}, group),
like_count: number('like_count', sandbox.like_count, {}, group),
template: select(
'template',
fixtures.templateOptions,
sandbox.template,
group
),
tags: array('tags', sandbox.tags, ',', group),
});
const createSandboxStory = ({
sandbox = fixtures.sandbox(),
selectSandbox = action('selectSandbox'),
small,
noHeight,
defaultHeight,
noMargin,
}: Partial<Props>) => () => (
<SandboxCard
sandbox={sandboxWithKnobs('sandbox', sandbox)}
selectSandbox={selectSandbox}
small={boolean('small', small)}
noHeight={boolean('noHeight', noHeight)}
defaultHeight={number('defaultHeight', defaultHeight)}
noMargin={boolean('noMargin', noMargin)}
/>
);
storiesOf('components/SandboxCard', module)
.add('basic', createSandboxStory({}))
.add('small', createSandboxStory({ small: true }))
.add('no height', createSandboxStory({ noHeight: true }))
.add('default height', createSandboxStory({ defaultHeight: 500 }))
.add('no margin', createSandboxStory({ noMargin: true }))
.add('popular', createSandboxStory({ sandbox: fixtures.popularSandbox() }))
.add(
'many tags',
createSandboxStory({ sandbox: fixtures.sandboxWithManyTags() })
)
.add(
'long title',
createSandboxStory({ sandbox: fixtures.sandboxWithLongTitle() })
)
.add(
'long description',
createSandboxStory({
sandbox: fixtures.sandboxWithLongDescription(),
})
)
.add(
'null author',
createSandboxStory({
sandbox: fixtures.sandboxWithNullAuthor(),
})
)
.add(
'undefined author',
createSandboxStory({
sandbox: fixtures.sandboxWithUndefinedAuthor(),
})
)
.add(
'null screenshot url',
createSandboxStory({
sandbox: fixtures.sandboxWithNullScreenshotUrl(),
})
)
.add(
'undefined screenshot url',
createSandboxStory({
sandbox: fixtures.sandboxWithUndefinedScreenshotUrl(),
})
);