File size: 1,693 Bytes
1e92f2d |
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 |
import React from 'react';
import TransitionGroup from '../src/TransitionGroup';
import StoryFixture from './StoryFixture';
class CSSTransitionGroupFixture extends React.Component {
static defaultProps = {
items: [],
};
count = this.props.items.length;
state = {
items: this.props.items,
};
handleAddItem = () => {
this.setState(({ items }) => ({
items: [...items, `Item number: ${++this.count}`],
}));
};
handleRemoveItems = () => {
this.setState(({ items }) => {
items = items.slice();
items.splice(1, 3);
return { items };
});
};
handleRemoveItem = (item) => {
this.setState(({ items }) => ({
items: items.filter((i) => i !== item),
}));
};
render() {
const { items: _, description, children, ...rest } = this.props;
// e.g. `Fade`, see where `CSSTransitionGroupFixture` is used
const { type: TransitionType, props: transitionTypeProps } =
React.Children.only(children);
return (
<StoryFixture description={description}>
<div style={{ marginBottom: 10 }}>
<button onClick={this.handleAddItem}>Add Item</button>{' '}
<button onClick={this.handleRemoveItems}>Remove a few</button>
</div>
<TransitionGroup component="div" {...rest}>
{this.state.items.map((item) => (
<TransitionType {...transitionTypeProps} key={item}>
{item}
<button onClick={() => this.handleRemoveItem(item)}>
×
</button>
</TransitionType>
))}
</TransitionGroup>
</StoryFixture>
);
}
}
export default CSSTransitionGroupFixture;
|