Last active
January 30, 2019 10:55
-
-
Save kdichev/fdc709f39c5c912b8c068cc98198b039 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// bad | |
<div | |
className={`miniBook__tab miniBook__tabOneWay${oneWay ? ' miniBook__tab--active' : ''}`} | |
onClick={() => this.tabOnClick(oneWay)} | |
> | |
{children} | |
</div> | |
// better | |
<div | |
className={classNames( | |
`${miniBookBaseClass}__tab`, | |
`${miniBookBaseClass}__tabOneWay`, | |
{ [`${miniBookBaseClass}__tab--active`]: oneWay } | |
)} | |
onClick={() => this.tabOnClick(oneWay)} | |
> | |
{children} | |
</div> | |
// best | |
const Tab = ({ isActive, baseClass, tabType, children, ...restProps }) => ( | |
<div | |
className={classNames( | |
`${baseClass}__tab`, | |
`${baseClass}__${tabType}`, | |
{ [`${baseClass}__tab--active`]: isActive } | |
)} | |
{...restProps} | |
> | |
{children} | |
</div> | |
) | |
// use | |
<Tab | |
isActive={oneWay} | |
baseClass='miniBook' | |
tabType='tabOneWay' | |
onClick={() => this.tabOnClick(oneWay)} | |
> | |
tab text | |
</Tab> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment