This repository has been archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #203 from storybooks/refactor/decorators
refactor(decorators): move Container to new component
- Loading branch information
Showing
2 changed files
with
58 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |