Skip to content

Instantly share code, notes, and snippets.

@grantglidewell
Created July 31, 2018 22:00
Show Gist options
  • Save grantglidewell/fbf64f9eafed4dcedd16a0b0adbc3efe to your computer and use it in GitHub Desktop.
Save grantglidewell/fbf64f9eafed4dcedd16a0b0adbc3efe to your computer and use it in GitHub Desktop.
Zesty.io Button
export function Button(props) {
return (
<button
{...props}
className={cx(styles.button, props.className, styles[props.type])}
>
{props.text}
{React.Children.map(
React.Children.toArray(props.children),
(child, i) => {
// If the first child is an element
// assume it's an icon
if (child.props && i === 0) {
return React.cloneElement(child, {
className: cx(styles.icon, child.props.className)
});
} else {
// probably just a text node
return child;
}
}
)}
</button>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment