Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #203 from storybooks/refactor/decorators
Browse files Browse the repository at this point in the history
refactor(decorators): move Container to new component
  • Loading branch information
maximilianoforlenza authored May 2, 2019
2 parents 9ccc280 + 089096e commit 8206bc4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 56 deletions.
54 changes: 54 additions & 0 deletions src/components/Decorators/Container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {VelocityComponent} from 'velocity-react';

class Container extends PureComponent {
renderToggle() {
const {animations} = this.props;

if (!animations) {
return this.renderToggleDecorator();
}

return (
<VelocityComponent
animation={animations.toggle.animation}
duration={animations.toggle.duration}
>
{this.renderToggleDecorator()}
</VelocityComponent>
);
}

renderToggleDecorator() {
const {style, decorators} = this.props;
return <decorators.Toggle style={style.toggle}/>;
}

render() {
const {style, decorators, terminal, onClick, node} = this.props;
return (
<div
onClick={onClick}
style={node.active ? {...style.container} : {...style.link}}
>
{!terminal ? this.renderToggle() : null}
<decorators.Header node={node} style={style.header}/>
</div>
);
}
}

Container.propTypes = {
style: PropTypes.object.isRequired,
decorators: PropTypes.object.isRequired,
terminal: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired,
animations: PropTypes.oneOfType([
PropTypes.object,
PropTypes.bool
]).isRequired,
node: PropTypes.object.isRequired
};

export default Container;
60 changes: 4 additions & 56 deletions src/components/Decorators/index.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,11 @@
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {VelocityComponent} from 'velocity-react';

import Container from './Container';
import Header from './Header';
import Loading from './Loading';
import Toggle from './Toggle';

class Container extends PureComponent {
renderToggle() {
const {animations} = this.props;

if (!animations) {
return this.renderToggleDecorator();
}

return (
<VelocityComponent
animation={animations.toggle.animation}
duration={animations.toggle.duration}
>
{this.renderToggleDecorator()}
</VelocityComponent>
);
}

renderToggleDecorator() {
const {style, decorators} = this.props;
return <decorators.Toggle style={style.toggle}/>;
}

render() {
const {style, decorators, terminal, onClick, node} = this.props;
return (
<div
onClick={onClick}
style={node.active ? {...style.container} : {...style.link}}
>
{!terminal ? this.renderToggle() : null}
<decorators.Header node={node} style={style.header}/>
</div>
);
}
}

Container.propTypes = {
style: PropTypes.object.isRequired,
decorators: PropTypes.object.isRequired,
terminal: PropTypes.bool.isRequired,
onClick: PropTypes.func.isRequired,
animations: PropTypes.oneOfType([
PropTypes.object,
PropTypes.bool
]).isRequired,
node: PropTypes.object.isRequired
};

export default {
Loading,
Toggle,
Container,
Header,
Container
Loading,
Toggle
};

0 comments on commit 8206bc4

Please sign in to comment.