https://www.npmjs.com/package/classnames - очень удобная библиотека
import styles from './Button.scss'
import cn from 'classnames'
const Button = (props) => {
const { theme, size, children } = props
const classList = cn(styles.button, {
[styles.buttonPrimary]: theme === 'primary',
[styles.buttonGhost]: theme === 'ghost',
[styles.buttonSmall]: size === 'small'
})
return <button className={classList}>{children}</button>
}
export default Button
Без css модулей:
import './Button.scss'
import cn from 'classnames'
const Button = (props) => {
const { theme, size, children } = props
const classList = cn('button', {
'button--primary': theme === 'primary',
'button--ghost': theme === 'ghost',
'button--small': size === 'small'
})
return (
<button className={classList}>{children}</button>
)
}
export default Button