Skip to content

Instantly share code, notes, and snippets.

@andyhite
Last active May 5, 2022 20:39
Show Gist options
  • Save andyhite/4a20bdb942900f0a90917b95c149d9b5 to your computer and use it in GitHub Desktop.
Save andyhite/4a20bdb942900f0a90917b95c149d9b5 to your computer and use it in GitHub Desktop.
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