Last active
October 19, 2018 23:53
-
-
Save rafaelrinaldi/72ffe7de93393e3cb061699c61a9efb2 to your computer and use it in GitHub Desktop.
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
const ButtonWithPadding = ({ children, ...props }) => | |
<button style={{ padding: '15px 10px' }} {...props}>{children}</button> | |
const ButtonPrimary = ({ children, ...props }) => | |
<button style={{ color: 'white', backgroundColor: 'seagreen' }} {...props}>{children}</button> | |
const ButtonOutline = ({ children, ...props}) => | |
<button style={{ backgroundColor: 'transparent', border: '4px solid darkred' }} {...props}>{children}</button> | |
const ButtonBase = ({ children, ...props }) => <button {...props}>{children}</button>; | |
const Button = props => compose(ButtonBase /* or simply 'button' */, { | |
[ButtonWithPadding]: ['primary', 'outline'].includes(variant), | |
[ButtonPrimary]: props.variant === 'primary', | |
[ButtonOutline]: props.variant === 'outline' | |
}) | |
<Button variant="primary">Primary Button</Button> | |
// Equivalent of: | |
<ButtonWithPadding> | |
<ButtonPrimary>Primary Button</ButtonPrimary> | |
</ButtonWithPadding> | |
<Button variant="outline">Outline Button</Button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment