Skip to content

Commit 0a3139f

Browse files
committed
Refine stories
1 parent 596e03a commit 0a3139f

File tree

3 files changed

+120
-41
lines changed

3 files changed

+120
-41
lines changed

stories/ball-spin-clockwise.min.css

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stories/index.js

+110-41
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,77 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { storiesOf } from '@storybook/react';
34
import { action } from '@storybook/addon-actions';
45
import { AsyncUnveil, Unveil } from '../src/';
6+
import './ball-spin-clockwise.min.css';
57
import './styles.css';
68

7-
const RichContent = props => {
8-
console.log('render rich content');
9-
console.log(props);
9+
class AsyncComponent extends React.Component {
10+
static propTypes = {
11+
notifyResize: PropTypes.func,
12+
};
13+
14+
state = {
15+
height: 100,
16+
complete: false,
17+
};
18+
19+
componentDidMount() {
20+
this.timeoutId = setTimeout(() => {
21+
this.setState(
22+
{
23+
height: 400,
24+
complete: true,
25+
},
26+
() => {
27+
this.props.notifyResize();
28+
}
29+
);
30+
}, 1000);
31+
}
32+
33+
componentWillUnmount() {
34+
clearTimeout(this.timeoutId);
35+
}
36+
37+
render() {
38+
return (
39+
<div
40+
style={{
41+
height: this.state.height,
42+
border: '1px solid #49d7cb',
43+
background: '#bffcee',
44+
display: 'flex',
45+
justifyContent: 'center',
46+
alignItems: 'center',
47+
}}
48+
>
49+
{this.state.complete ? (
50+
'done async stuff!'
51+
) : (
52+
<div className="la-ball-spin-clockwise la-2x">
53+
<div />
54+
<div />
55+
<div />
56+
<div />
57+
<div />
58+
<div />
59+
<div />
60+
<div />
61+
</div>
62+
)}
63+
</div>
64+
);
65+
}
66+
}
1067

68+
const RichContent = props => {
1169
return (
1270
<React.Fragment>
1371
<h1>An Essay I Wrote for Philosophy Class :)</h1>
14-
<img
15-
width="100%"
16-
onLoad={() => {
17-
console.log('done loading');
18-
console.log(props);
19-
props.notifyResize();
20-
}}
21-
src="https://placeimg.com/720/240/tech"
22-
/>
72+
{props.withImage ? (
73+
<img width="100%" src="https://placeimg.com/720/240/tech" />
74+
) : null}
2375
<p>
2476
One of the greatest philosophical questions is whether or not machines
2577
can “think”, brought up by Alan Turing almost a century ago. This
@@ -119,29 +171,46 @@ const RichContent = props => {
119171
};
120172

121173
storiesOf('React Unveil', module)
122-
.add('test', () => {
123-
// render async, no polling
124-
// some observer injected into it
174+
.add('with default configuration using ', () => {
125175
return (
126176
<AsyncUnveil>
177+
<RichContent withImage />
178+
</AsyncUnveil>
179+
);
180+
})
181+
.add('without Async wrapper', () => {
182+
return (
183+
<Unveil>
184+
<RichContent />
185+
</Unveil>
186+
);
187+
})
188+
.add('Async wrapper no img test', () => {
189+
return (
190+
<AsyncUnveil poll>
127191
<RichContent />
128192
</AsyncUnveil>
129193
);
130194
})
131-
.add('with default props', () => (
132-
<Unveil>
133-
<RichContent />
134-
</Unveil>
135-
))
195+
.add('img test', () => {
196+
return (
197+
<AsyncUnveil>
198+
<img
199+
onLoad={() => console.log('der')}
200+
src="https://placeimg.com/720/240/tech"
201+
/>
202+
</AsyncUnveil>
203+
);
204+
})
136205
.add('with async content with polling', () => (
137-
<Unveil>
138-
<AsyncComponent onComplete={undefined} />
139-
</Unveil>
206+
<AsyncUnveil poll>
207+
<AsyncComponent />
208+
</AsyncUnveil>
140209
))
141-
.add('with async content without polling', () => (
142-
<Unveil>
143-
<AsyncComponent onComplete={undefined} />
144-
</Unveil>
210+
.add('with async ', () => (
211+
<AsyncUnveil>
212+
<AsyncComponent />
213+
</AsyncUnveil>
145214
))
146215
.add('with children shorter than maxHeight', () => (
147216
<Unveil>
@@ -162,36 +231,36 @@ storiesOf('React Unveil', module)
162231
const More = expand => () => <div>Show More</div>;
163232
const Less = collapse => () => <div>Show More</div>;
164233
return (
165-
<Unveil>
166-
<RichContent />
167-
</Unveil>
234+
<AsyncUnveil>
235+
<RichContent withImage />
236+
</AsyncUnveil>
168237
);
169238
})
170239
.add('with custom styles', () => (
171-
<Unveil
240+
<AsyncUnveil
172241
style={{
173242
border: '1px solid blue',
174243
padding: 4,
175244
}}
176245
>
177246
<RichContent />
178-
</Unveil>
247+
</AsyncUnveil>
179248
))
180249
.add('with initially expanded state', () => (
181-
<Unveil expanded>
182-
<RichContent />
183-
</Unveil>
250+
<AsyncUnveil expanded>
251+
<RichContent withImage />
252+
</AsyncUnveil>
184253
))
185254
.add('with callbacks', () => (
186-
<Unveil
255+
<AsyncUnveil
187256
onMoreClick={() => alert('Clicked more!')}
188257
onLessClick={() => alert('Clicked less!')}
189258
>
190-
<RichContent />
191-
</Unveil>
259+
<RichContent withImage />
260+
</AsyncUnveil>
192261
))
193262
.add('without show less button', () => (
194-
<Unveil less={null}>
195-
<RichContent />
196-
</Unveil>
263+
<AsyncUnveil less={() => <div />}>
264+
<RichContent withImage />
265+
</AsyncUnveil>
197266
));

stories/styles.css

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
body {
1111
font-family: 'Open Sans', sans-serif;
1212
}
13+
14+
.la-ball-spin-clockwise {
15+
color: #49d7cb;
16+
}

0 commit comments

Comments
 (0)