Last active
May 5, 2022 20:39
-
-
Save andyhite/4a20bdb942900f0a90917b95c149d9b5 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
interface ButtonProps { | |
children: React.ReactNode; | |
disabled: boolean; | |
loading: boolean; | |
onClick: () => void; | |
variant?: keyof variants; | |
} | |
const variants = { | |
primary: { | |
backgroundColor: "blue", | |
color: "white", | |
":not(&.loading):disabled": { | |
backgroundColor: "light-blue", | |
}, | |
}, | |
secondary: { | |
backgroundColor: "red", | |
color: "yellow", | |
}, | |
}; | |
function Button({ children, variant = "primary", ...props }: ButtonProps) { | |
const styles = { | |
// Defaults go first | |
backgroundColor: "black", | |
color: "white", | |
":not(&.loading):disabled": { | |
backgroundColor: "gray", | |
}, | |
// Then spread in the variant overrides | |
...variants[variant], | |
}; | |
return ( | |
<button css={styles} className={cx({ loading })} {...props}> | |
{children} | |
</button> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment