Skip to content

Instantly share code, notes, and snippets.

@renatorib
Last active March 27, 2017 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatorib/7861c210c8b45c501fa08e3e6aeceb21 to your computer and use it in GitHub Desktop.
Save renatorib/7861c210c8b45c501fa08e3e6aeceb21 to your computer and use it in GitHub Desktop.
Composable Button
import React from 'react';
type Props = {
type?: 'normal' | 'outline',
radius: 'square' | 'round' | 'circle',
size?: 'mini' | 'small' | 'normal' | 'large' | 'xlarge',
theme?: 'primary' | 'grey' | 'danger' | 'warning' | 'success' | 'info',
className?: string, // ever allow pass custom className
style?: string, // custom styles also
children: string,
};
const Button = (props: Props) => {
/* Button markup logic */
// pass restProps at the end of element.
// eg.:
//
// const { type, radius, size, theme, /* etc */, ...restProps } = props;
// return (
// <button ... {...restProps} />
// );
};
Button.defaultProps = {
type: 'normal',
radius: 'round',
size: 'normal',
theme: 'primary',
};
/* Composable Buttons */
export const PrimaryButton = (props: Props) => (
<Button theme="primary" radius="round" {...props} />
);
export const SecondaryButton = (props: Props) => (
<Button theme="grey" radius="round" type="outline" {...props} />
);
export const HeaderButton = (props: Props) => (
<Button theme="info" radius="circle" type="outline" size="mini" {...props} />
);
Button.Primary = PrimaryButton;
Button.Secondary = SecondaryButton;
Button.Header = HeaderButton;
export default Button;
/*
<PrimaryButton>Primary</PrimaryButton>
<SecondaryButton>Secondary</SecondaryButton>
<HeaderButton>Header Button</HeaderButton>
or
<Button.Primary>Primary</Button.Primary>
etc...
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment