new examples buttonModules & buttonEmotion + refac
This commit is contained in:
1 parent
d03e3d3928
commit
b53d4528fb
16 files changed
+1347
-22089
No files matched your search
@@ -1,79 +1,18 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const Button = ({
|
||||
children,
|
||||
variant = defaults.variant,
|
||||
color = defaults.color,
|
||||
size = defaults.size,
|
||||
radius = defaults.radius,
|
||||
disabled = defaults.disabled,
|
||||
elevation,
|
||||
type = defaults.type,
|
||||
startIcon: startIconProp,
|
||||
endIcon: endIconProp,
|
||||
className,
|
||||
...rest
|
||||
}) => {
|
||||
const hasIcon = startIconProp || endIconProp;
|
||||
const getClasses = () => {
|
||||
const classes = [];
|
||||
let buttonElevation;
|
||||
|
||||
if (variant === 'text') {
|
||||
if (elevation) {
|
||||
buttonElevation = elevation;
|
||||
} else {
|
||||
buttonElevation = false;
|
||||
}
|
||||
} else {
|
||||
buttonElevation = defaults.elevation;
|
||||
}
|
||||
|
||||
classes.push(variantClasses[variant][color]);
|
||||
classes.push(radiusClasses[radius]);
|
||||
classes.push(sizeClasses[size]);
|
||||
classes.push(disabledClasses[disabled]);
|
||||
classes.push(elevationClasses[buttonElevation]);
|
||||
classes.push(className);
|
||||
|
||||
if (hasIcon) {
|
||||
classes.push(baseIconClasses);
|
||||
}
|
||||
|
||||
return classes.join(' ');
|
||||
};
|
||||
|
||||
const baseIconClasses = 'inline-flex items-center';
|
||||
const baseClasses =
|
||||
'outline-none transition duration-300 ease-in-out rounded font-bold focus:outline-none';
|
||||
|
||||
const startIcon = startIconProp && (
|
||||
<div className="mr-2">{startIconProp}</div>
|
||||
);
|
||||
|
||||
const endIcon = endIconProp && <div className="ml-2">{endIconProp}</div>;
|
||||
|
||||
return (
|
||||
<button className={`${baseClasses} ${getClasses()}`} type={type} {...rest}>
|
||||
{startIcon}
|
||||
{children}
|
||||
{endIcon}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
import classnames from 'classnames';
|
||||
|
||||
const defaults = {
|
||||
variant: 'outlined',
|
||||
variant: 'contained',
|
||||
color: 'default',
|
||||
size: 'medium',
|
||||
radius: 'medium',
|
||||
disabled: false,
|
||||
elevation: true,
|
||||
type: 'button',
|
||||
};
|
||||
|
||||
const radiusClasses = {
|
||||
none: '',
|
||||
small: 'rounded-sm',
|
||||
medium: 'rounded-md',
|
||||
large: 'rounded-lg',
|
||||
@@ -85,11 +24,6 @@ const disabledClasses = {
|
||||
false: '',
|
||||
};
|
||||
|
||||
const elevationClasses = {
|
||||
true: 'shadow',
|
||||
false: 'shadow-none',
|
||||
};
|
||||
|
||||
const variantClasses = {
|
||||
text: {
|
||||
default: 'hover:bg-gray-200 text-black',
|
||||
@@ -114,14 +48,55 @@ const sizeClasses = {
|
||||
large: 'py-3 px-6 text-lg',
|
||||
};
|
||||
|
||||
const Button = ({
|
||||
children,
|
||||
variant = defaults.variant,
|
||||
color = defaults.color,
|
||||
size = defaults.size,
|
||||
radius = defaults.radius,
|
||||
disabled = defaults.disabled,
|
||||
type = defaults.type,
|
||||
startIcon: startIconProp,
|
||||
endIcon: endIconProp,
|
||||
className,
|
||||
...rest
|
||||
}) => {
|
||||
const baseClasses =
|
||||
'inline-flex items-center outline-none transition duration-300 ease-in-out font-bold focus:outline-none';
|
||||
|
||||
const startIcon = startIconProp && (
|
||||
<div className="mr-2">{startIconProp}</div>
|
||||
);
|
||||
|
||||
const endIcon = endIconProp && <div className="ml-2">{endIconProp}</div>;
|
||||
|
||||
return (
|
||||
<button
|
||||
className={classnames(
|
||||
baseClasses,
|
||||
variantClasses[variant][color],
|
||||
radiusClasses[radius],
|
||||
sizeClasses[size],
|
||||
disabledClasses[disabled],
|
||||
className
|
||||
)}
|
||||
type={type}
|
||||
{...rest}
|
||||
>
|
||||
{startIcon}
|
||||
{children}
|
||||
{endIcon}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
Button.propTypes = {
|
||||
children: PropTypes.node,
|
||||
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
||||
radius: PropTypes.oneOf(['small', 'medium', 'large', 'full']),
|
||||
radius: PropTypes.oneOf(['none', 'small', 'medium', 'large', 'full']),
|
||||
variant: PropTypes.oneOf(['text', 'outlined', 'contained']),
|
||||
color: PropTypes.oneOf(['default', 'primary', 'secondary']),
|
||||
disabled: PropTypes.bool,
|
||||
elevation: PropTypes.bool,
|
||||
type: PropTypes.string,
|
||||
startIcon: PropTypes.node,
|
||||
endIcon: PropTypes.node,
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import styled from '@emotion/styled';
|
||||
import { fade } from '../../utils/colorManipulator';
|
||||
import capitalize from '../../utils/capitalize';
|
||||
import theme from '../../styles/theme';
|
||||
|
||||
const styles = {
|
||||
base: {
|
||||
'box-sizing': 'border-box',
|
||||
'min-width': '64px',
|
||||
padding: '6px 16px',
|
||||
'border-radius': '20px',
|
||||
color: theme.palette.primary.main,
|
||||
transition: 'all 300ms ease',
|
||||
'&:hover': {
|
||||
'text-decoration': 'none',
|
||||
'background-color': fade(
|
||||
theme.palette.default.main,
|
||||
theme.palette.action.hoverOpacity
|
||||
),
|
||||
},
|
||||
'&:active': {
|
||||
outline: 'none',
|
||||
},
|
||||
'&:focus': {
|
||||
outline: 'none',
|
||||
},
|
||||
'&:disabled': {
|
||||
color: theme.palette.action.disabled,
|
||||
cursor: 'not-allowed',
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="text"`. */
|
||||
text: {
|
||||
padding: '6px 8px',
|
||||
},
|
||||
/* Styles applied to the root element if `variant="text"` and `color="primary"`. */
|
||||
textPrimary: {
|
||||
color: theme.palette.primary.main,
|
||||
'&:hover': {
|
||||
'background-color': fade(
|
||||
theme.palette.primary.light,
|
||||
theme.palette.action.hoverOpacity
|
||||
),
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="text"` and `color="secondary"`. */
|
||||
textSecondary: {
|
||||
color: theme.palette.secondary.main,
|
||||
'&:hover': {
|
||||
'background-color': fade(
|
||||
theme.palette.secondary.light,
|
||||
theme.palette.action.hoverOpacity
|
||||
),
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="outlined"`. */
|
||||
outlined: {
|
||||
padding: '5px 15px',
|
||||
border: `1px solid ${
|
||||
theme.palette.type === 'light'
|
||||
? 'rgba(0, 0, 0, 0.23)'
|
||||
: 'rgba(255, 255, 255, 0.23)'
|
||||
}`,
|
||||
'&:disabled': {
|
||||
border: `1px solid ${theme.palette.default.main}`,
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="outlined"` and `color="primary"`. */
|
||||
outlinedPrimary: {
|
||||
color: theme.palette.primary.main,
|
||||
border: `1px solid ${fade(
|
||||
theme.palette.primary.light,
|
||||
theme.palette.action.hoverOpacity
|
||||
)}`,
|
||||
'&:hover': {
|
||||
border: `1px solid ${theme.palette.primary.main}`,
|
||||
'background-color': fade(
|
||||
theme.palette.primary.light,
|
||||
theme.palette.action.hoverOpacity
|
||||
),
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="outlined"` and `color="secondary"`. */
|
||||
outlinedSecondary: {
|
||||
color: theme.palette.secondary.main,
|
||||
border: `1px solid ${fade(
|
||||
theme.palette.secondary.main,
|
||||
theme.palette.action.hoverOpacity
|
||||
)}`,
|
||||
'&:hover': {
|
||||
border: `1px solid ${theme.palette.secondary.main}`,
|
||||
'background-color': fade(
|
||||
theme.palette.secondary.light,
|
||||
theme.palette.action.hoverOpacity
|
||||
),
|
||||
},
|
||||
'&$disabled': {
|
||||
border: `1px solid ${theme.palette.action.disabled}`,
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="contained"`. */
|
||||
contained: {
|
||||
color: '#000',
|
||||
'background-color': theme.palette.default.light,
|
||||
// 'box-shadow': theme.shadows[2],
|
||||
'&:hover': {
|
||||
'background-color': theme.palette.default.light,
|
||||
// 'box-shadow': theme.shadows[4],
|
||||
|
||||
'&$disabled': {
|
||||
'background-color': theme.palette.action.disabledBackground,
|
||||
},
|
||||
},
|
||||
'&:active': {
|
||||
// 'box-shadow': typographyows[8],
|
||||
},
|
||||
'&$disabled': {
|
||||
color: theme.palette.action.disabled,
|
||||
// 'box-shadow': theme.shadows[0],
|
||||
'background-color': theme.palette.action.disabledBackground,
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="contained"` and `color="primary"`. */
|
||||
containedPrimary: {
|
||||
color: 'white',
|
||||
'background-color': theme.palette.primary.main,
|
||||
'&:hover': {
|
||||
'background-color': fade(
|
||||
theme.palette.primary.light,
|
||||
theme.palette.action.hoverOpacity
|
||||
),
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `variant="contained"` and `color="secondary"`. */
|
||||
containedSecondary: {
|
||||
color: 'white',
|
||||
'background-color': theme.palette.secondary.main,
|
||||
'&:hover': {
|
||||
'background-color': fade(
|
||||
theme.palette.secondary.light,
|
||||
theme.palette.action.hoverOpacity
|
||||
),
|
||||
},
|
||||
},
|
||||
/* Styles applied to the root element if `size="small"` and `variant="text"`. */
|
||||
textSizeSmall: {
|
||||
padding: '4px 5px',
|
||||
fontSize: '13px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="medium"` and `variant="text"`. */
|
||||
textSizeMedium: {
|
||||
padding: '6px 9px',
|
||||
fontSize: '14px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="large"` and `variant="text"`. */
|
||||
textSizeLarge: {
|
||||
padding: '8px 11px',
|
||||
fontSize: '15px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="small"` and `variant="outlined"`. */
|
||||
outlinedSizeSmall: {
|
||||
padding: '3px 9px',
|
||||
fontSize: '13px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="medium"` and `variant="outlined"`. */
|
||||
outlinedSizeMedium: {
|
||||
padding: '5px 15px',
|
||||
fontSize: '14px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="large"` and `variant="outlined"`. */
|
||||
outlinedSizeLarge: {
|
||||
padding: '7px 21px',
|
||||
fontSize: '15px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="small"` and `variant="contained"`. */
|
||||
containedSizeSmall: {
|
||||
padding: '4px 10px',
|
||||
fontSize: '13px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="medium"` and `variant="contained"`. */
|
||||
containedSizeMedium: {
|
||||
padding: '6px 16px',
|
||||
fontSize: '13px',
|
||||
},
|
||||
/* Styles applied to the root element if `size="large"` and `variant="contained"`. */
|
||||
containedSizeLarge: {
|
||||
padding: '8px 22px',
|
||||
fontSize: '15px',
|
||||
},
|
||||
/* Styles applied to the startIcon element if supplied. */
|
||||
startIcon: {
|
||||
display: 'inherit',
|
||||
'margin-right': '8px',
|
||||
'margin-left': '-4px',
|
||||
},
|
||||
/* Styles applied to the endIcon element if supplied. */
|
||||
endIcon: {
|
||||
display: 'inherit',
|
||||
'margin-right': '-4px',
|
||||
'margin-left': '8px',
|
||||
},
|
||||
};
|
||||
|
||||
const BaseButton = styled.button`
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
background-color: transparent;
|
||||
outline: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
border-radius: 0;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
vertical-align: middle;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
`;
|
||||
|
||||
const ButtonIcon = styled.div`
|
||||
${props => ({
|
||||
...styles[`${props.icon}`],
|
||||
})}
|
||||
`;
|
||||
|
||||
const ButtonComponent = styled(BaseButton)`
|
||||
/* base styles */
|
||||
${props => ({
|
||||
...styles.base,
|
||||
})}
|
||||
|
||||
/* variant styles */
|
||||
${props => ({
|
||||
...styles[`${props.variant}`],
|
||||
})}
|
||||
|
||||
/* color */
|
||||
${props => ({
|
||||
...styles[`${props.variant}${capitalize(props.color)}`],
|
||||
})}
|
||||
|
||||
/* size styles */
|
||||
${props => ({
|
||||
...styles[`${props.variant}Size${capitalize(props.size)}`],
|
||||
})}
|
||||
`;
|
||||
|
||||
const Button = props => {
|
||||
const {
|
||||
children,
|
||||
variant = defaults.variant,
|
||||
color = defaults.color,
|
||||
size = defaults.size,
|
||||
radius = defaults.radius,
|
||||
disabled = defaults.disabled,
|
||||
elevation,
|
||||
type = defaults.type,
|
||||
startIcon: startIconProp,
|
||||
endIcon: endIconProp,
|
||||
className,
|
||||
...rest
|
||||
} = props;
|
||||
const startIcon = startIconProp && (
|
||||
<ButtonIcon icon="startIcon">{startIconProp}</ButtonIcon>
|
||||
);
|
||||
|
||||
const endIcon = endIconProp && (
|
||||
<ButtonIcon icon="endIcon">{endIconProp}</ButtonIcon>
|
||||
);
|
||||
|
||||
return (
|
||||
<ButtonComponent
|
||||
variant={variant}
|
||||
color={color}
|
||||
size={size}
|
||||
radius={radius}
|
||||
disabled={disabled}
|
||||
type={type}
|
||||
{...rest}
|
||||
>
|
||||
{startIcon}
|
||||
{children}
|
||||
{endIcon}
|
||||
</ButtonComponent>
|
||||
);
|
||||
};
|
||||
|
||||
const defaults = {
|
||||
variant: 'outlined',
|
||||
color: 'default',
|
||||
size: 'large',
|
||||
radius: 'medium',
|
||||
disabled: false,
|
||||
elevation: true,
|
||||
type: 'button',
|
||||
};
|
||||
|
||||
Button.propTypes = {
|
||||
children: PropTypes.node,
|
||||
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
||||
radius: PropTypes.oneOf(['small', 'medium', 'large', 'full']),
|
||||
variant: PropTypes.oneOf(['text', 'outlined', 'contained']),
|
||||
color: PropTypes.oneOf(['default', 'primary', 'secondary']),
|
||||
disabled: PropTypes.bool,
|
||||
elevation: PropTypes.bool,
|
||||
type: PropTypes.string,
|
||||
startIcon: PropTypes.node,
|
||||
endIcon: PropTypes.node,
|
||||
className: PropTypes.node,
|
||||
};
|
||||
|
||||
export default Button;
|
||||
@@ -0,0 +1,180 @@
|
||||
---
|
||||
name: ButtonEmotion
|
||||
menu: Components
|
||||
route: components/button-emotion
|
||||
---
|
||||
|
||||
import { Playground, Props } from 'docz';
|
||||
import Button from './';
|
||||
|
||||
# ButtonEmotion
|
||||
|
||||
Buttons are used to execute actions when users interacts with them.
|
||||
|
||||
## Properties
|
||||
|
||||
<Props of={Button} />
|
||||
|
||||
## Contained Buttons
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<Button variant="contained" style={{ margin: 5 }}>
|
||||
Default
|
||||
</Button>
|
||||
<Button variant="contained" color="primary" style={{ margin: 5 }}>
|
||||
Primary
|
||||
</Button>
|
||||
<Button variant="contained" color="secondary" style={{ margin: 5 }}>
|
||||
Secondary
|
||||
</Button>
|
||||
</>
|
||||
</Playground>
|
||||
|
||||
## Outlined Buttons
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<Button variant="outlined" style={{ margin: 5 }}>
|
||||
Default
|
||||
</Button>
|
||||
<Button variant="outlined" color="primary" style={{ margin: 5 }}>
|
||||
Primary
|
||||
</Button>
|
||||
<Button variant="outlined" color="secondary" style={{ margin: 5 }}>
|
||||
Secondary
|
||||
</Button>
|
||||
</>
|
||||
</Playground>
|
||||
|
||||
## Text Buttons
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<Button variant="text" style={{ margin: 5 }}>
|
||||
Default
|
||||
</Button>
|
||||
<Button variant="text" color="primary" style={{ margin: 5 }}>
|
||||
Primary
|
||||
</Button>
|
||||
<Button variant="text" color="secondary" style={{ margin: 5 }}>
|
||||
Secondary
|
||||
</Button>
|
||||
</>
|
||||
</Playground>
|
||||
|
||||
## Sizes
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<div>
|
||||
<Button variant="text" size="small" style={{ margin: 5 }}>
|
||||
Small
|
||||
</Button>
|
||||
<Button variant="contained" size="medium" style={{ margin: 5 }}>
|
||||
Medium
|
||||
</Button>
|
||||
<Button variant="outlined" size="large" style={{ margin: 5 }}>
|
||||
Large
|
||||
</Button>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
variant="text"
|
||||
size="small"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Small
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
size="medium"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Medium
|
||||
</Button>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
large
|
||||
</Button>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
variant="text"
|
||||
size="small"
|
||||
color="secondary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Small
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
size="medium"
|
||||
color="secondary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Medium
|
||||
</Button>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
color="secondary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Large
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
</>
|
||||
|
||||
</Playground>
|
||||
|
||||
## Buttons with icons
|
||||
|
||||
<Playground>
|
||||
{() => {
|
||||
return (
|
||||
<div className="flex">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
startIcon={
|
||||
<svg
|
||||
class="fill-current w-4 h-4"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path d="M13 8V2H7v6H2l8 8 8-8h-5zM0 18h20v2H0v-2z" />
|
||||
</svg>
|
||||
}
|
||||
>
|
||||
Download
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
endIcon={
|
||||
<svg
|
||||
class="fill-current w-4 h-4"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path d="M13 8V2H7v6H2l8 8 8-8h-5zM0 18h20v2H0v-2z" />
|
||||
</svg>
|
||||
}
|
||||
>
|
||||
Download
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
|
||||
</Playground>
|
||||
@@ -0,0 +1,2 @@
|
||||
import ButtonEmotion from './ButtonEmotion';
|
||||
export default ButtonEmotion;
|
||||
@@ -0,0 +1,68 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import classnames from 'classnames';
|
||||
import capitalize from '../../utils/capitalize';
|
||||
import styles from './ButtonModules.module.scss';
|
||||
|
||||
const Button = props => {
|
||||
const {
|
||||
children,
|
||||
variant = defaults.variant,
|
||||
color = defaults.color,
|
||||
size = defaults.size,
|
||||
type = defaults.type,
|
||||
startIcon: startIconProp,
|
||||
endIcon: endIconProp,
|
||||
className,
|
||||
...rest
|
||||
} = props;
|
||||
const startIcon = startIconProp && (
|
||||
<div className={styles.startIcon}>{startIconProp}</div>
|
||||
);
|
||||
|
||||
const endIcon = endIconProp && (
|
||||
<div className={styles.endIcon}>{endIconProp}</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<button
|
||||
className={classnames(
|
||||
styles.baseButton,
|
||||
styles[variant],
|
||||
styles[`${variant}${capitalize(color)}`],
|
||||
styles[`${variant}Size${capitalize(size)}`],
|
||||
className
|
||||
)}
|
||||
type={type}
|
||||
{...rest}
|
||||
>
|
||||
{startIcon}
|
||||
{children}
|
||||
{endIcon}
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
const defaults = {
|
||||
variant: 'outlined',
|
||||
color: 'default',
|
||||
size: 'large',
|
||||
radius: 'medium',
|
||||
disabled: false,
|
||||
type: 'button',
|
||||
};
|
||||
|
||||
Button.propTypes = {
|
||||
children: PropTypes.node,
|
||||
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
||||
radius: PropTypes.oneOf(['small', 'medium', 'large', 'full']),
|
||||
variant: PropTypes.oneOf(['text', 'outlined', 'contained']),
|
||||
color: PropTypes.oneOf(['default', 'primary', 'secondary']),
|
||||
disabled: PropTypes.bool,
|
||||
type: PropTypes.string,
|
||||
startIcon: PropTypes.node,
|
||||
endIcon: PropTypes.node,
|
||||
className: PropTypes.node,
|
||||
};
|
||||
|
||||
export default Button;
|
||||
@@ -0,0 +1,180 @@
|
||||
---
|
||||
name: ButtonModules
|
||||
menu: Components
|
||||
route: components/button-modules
|
||||
---
|
||||
|
||||
import { Playground, Props } from 'docz';
|
||||
import Button from './';
|
||||
|
||||
# ButtonModules
|
||||
|
||||
Buttons are used to execute actions when users interacts with them.
|
||||
|
||||
## Properties
|
||||
|
||||
<Props of={Button} />
|
||||
|
||||
## Contained Buttons
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<Button variant="contained" style={{ margin: 5 }}>
|
||||
Default
|
||||
</Button>
|
||||
<Button variant="contained" color="primary" style={{ margin: 5 }}>
|
||||
Primary
|
||||
</Button>
|
||||
<Button variant="contained" color="secondary" style={{ margin: 5 }}>
|
||||
Secondary
|
||||
</Button>
|
||||
</>
|
||||
</Playground>
|
||||
|
||||
## Outlined Buttons
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<Button variant="outlined" style={{ margin: 5 }}>
|
||||
Default
|
||||
</Button>
|
||||
<Button variant="outlined" color="primary" style={{ margin: 5 }}>
|
||||
Primary
|
||||
</Button>
|
||||
<Button variant="outlined" color="secondary" style={{ margin: 5 }}>
|
||||
Secondary
|
||||
</Button>
|
||||
</>
|
||||
</Playground>
|
||||
|
||||
## Text Buttons
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<Button variant="text" style={{ margin: 5 }}>
|
||||
Default
|
||||
</Button>
|
||||
<Button variant="text" color="primary" style={{ margin: 5 }}>
|
||||
Primary
|
||||
</Button>
|
||||
<Button variant="text" color="secondary" style={{ margin: 5 }}>
|
||||
Secondary
|
||||
</Button>
|
||||
</>
|
||||
</Playground>
|
||||
|
||||
## Sizes
|
||||
|
||||
<Playground>
|
||||
<>
|
||||
<div>
|
||||
<Button variant="text" size="small" style={{ margin: 5 }}>
|
||||
Small
|
||||
</Button>
|
||||
<Button variant="contained" size="medium" style={{ margin: 5 }}>
|
||||
Medium
|
||||
</Button>
|
||||
<Button variant="outlined" size="large" style={{ margin: 5 }}>
|
||||
Large
|
||||
</Button>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
variant="text"
|
||||
size="small"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Small
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
size="medium"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Medium
|
||||
</Button>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
large
|
||||
</Button>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
variant="text"
|
||||
size="small"
|
||||
color="secondary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Small
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
size="medium"
|
||||
color="secondary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Medium
|
||||
</Button>
|
||||
<Button
|
||||
variant="outlined"
|
||||
size="large"
|
||||
color="secondary"
|
||||
style={{ margin: 5 }}
|
||||
>
|
||||
Large
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
</>
|
||||
|
||||
</Playground>
|
||||
|
||||
## Buttons with icons
|
||||
|
||||
<Playground>
|
||||
{() => {
|
||||
return (
|
||||
<div className="flex">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
startIcon={
|
||||
<svg
|
||||
className="fill-current w-4 h-4"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path d="M13 8V2H7v6H2l8 8 8-8h-5zM0 18h20v2H0v-2z" />
|
||||
</svg>
|
||||
}
|
||||
>
|
||||
Download
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
style={{ margin: 5 }}
|
||||
endIcon={
|
||||
<svg
|
||||
className="fill-current w-4 h-4"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path d="M13 8V2H7v6H2l8 8 8-8h-5zM0 18h20v2H0v-2z" />
|
||||
</svg>
|
||||
}
|
||||
>
|
||||
Download
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}}
|
||||
|
||||
</Playground>
|
||||
@@ -0,0 +1,213 @@
|
||||
$default: #aaa;
|
||||
$primary: #00a;
|
||||
$secondary: #a00;
|
||||
$hoverOpacity: 40%;
|
||||
|
||||
.baseButton {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
position: relative;
|
||||
background-color: transparent;
|
||||
outline: 0;
|
||||
border: 0;
|
||||
margin: 0;
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
vertical-align: middle;
|
||||
-moz-appearance: none;
|
||||
appearance: none;
|
||||
text-decoration: none;
|
||||
box-sizing: border-box;
|
||||
min-width: 64px;
|
||||
padding: 6px 16px;
|
||||
border-radius: 20px;
|
||||
color: inherit;
|
||||
transition: all 300ms ease;
|
||||
|
||||
&:hover {
|
||||
text-decoration: none;
|
||||
background-color: lighten($default, $hoverOpacity / 2);
|
||||
}
|
||||
|
||||
&:active,
|
||||
&:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
color: $default;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="text"`. */
|
||||
.text {
|
||||
padding: 6px 8px;
|
||||
|
||||
&:hover {
|
||||
background-color: lighten($default, $hoverOpacity / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="text"` and `color="primary"`. */
|
||||
.textPrimary {
|
||||
color: $primary;
|
||||
|
||||
&:hover {
|
||||
background-color: lighten($primary, $hoverOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="text"` and `color="secondary"`. */
|
||||
.textSecondary {
|
||||
color: $secondary;
|
||||
|
||||
&:hover {
|
||||
background-color: lighten($secondary, $hoverOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="outlined"`. */
|
||||
.outlined {
|
||||
padding: 5px 15px;
|
||||
border: 1px solid $default;
|
||||
|
||||
&:disabled {
|
||||
border: 1px solid $default;
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="outlined"` and `color="primary"`. */
|
||||
.outlinedPrimary {
|
||||
color: $primary;
|
||||
border: 1px solid lighten($primary, $hoverOpacity);
|
||||
|
||||
&:hover {
|
||||
border: 1px solid $primary;
|
||||
background-color: lighten($primary, $hoverOpacity);
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="outlined"` and `color="secondary"`. */
|
||||
.outlinedSecondary {
|
||||
color: $secondary;
|
||||
border: 1px solid lighten($secondary, $hoverOpacity);
|
||||
|
||||
&:hover {
|
||||
border: 1px solid $secondary;
|
||||
background-color: lighten($secondary, $hoverOpacity);
|
||||
}
|
||||
|
||||
&:disabled {
|
||||
border: 1px solid $default;
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="contained"`. */
|
||||
.contained {
|
||||
color: #fff;
|
||||
background-color: $default;
|
||||
|
||||
&:disabled {
|
||||
color: lighten($default, $hoverOpacity);
|
||||
background-color: $default;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: darken($default, $hoverOpacity / 2);
|
||||
|
||||
&:disabled {
|
||||
color: lighten($default, $hoverOpacity);
|
||||
background-color: $default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="contained"` and `color="primary"`. */
|
||||
.containedPrimary {
|
||||
color: white;
|
||||
background-color: $primary;
|
||||
|
||||
&:hover {
|
||||
background-color: darken($primary, $hoverOpacity / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `variant="contained"` and `color="secondary"`. */
|
||||
.containedSecondary {
|
||||
color: white;
|
||||
background-color: $secondary;
|
||||
|
||||
&:hover {
|
||||
background-color: darken($secondary, $hoverOpacity / 2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="small"` and `variant="text"`. */
|
||||
.textSizeSmall {
|
||||
padding: 4px 5px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="medium"` and `variant="text"`. */
|
||||
.textSizeMedium {
|
||||
padding: 6px 9px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="large"` and `variant="text"`. */
|
||||
.textSizeLarge {
|
||||
padding: 8px 11px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="small"` and `variant="outlined"`. */
|
||||
.outlinedSizeSmall {
|
||||
padding: 3px 9px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="medium"` and `variant="outlined"`. */
|
||||
.outlinedSizeMedium {
|
||||
padding: 5px 15px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="large"` and `variant="outlined"`. */
|
||||
.outlinedSizeLarge {
|
||||
padding: 7px 21px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="small"` and `variant="contained"`. */
|
||||
.containedSizeSmall {
|
||||
padding: 4px 10px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="medium"` and `variant="contained"`. */
|
||||
.containedSizeMedium {
|
||||
padding: 6px 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Styles applied to the root element if `size="large"` and `variant="contained"`. */
|
||||
.containedSizeLarge {
|
||||
padding: 8px 22px;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
/* Styles applied to the startIcon element if supplied. */
|
||||
.startIcon {
|
||||
display: inherit;
|
||||
margin-right: 8px;
|
||||
margin-left: -4px;
|
||||
}
|
||||
|
||||
/* Styles applied to the endIcon element if supplied. */
|
||||
.endIcon {
|
||||
display: inherit;
|
||||
margin-right: -4px;
|
||||
margin-left: 8px;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
import ButtonModules from './ButtonModules';
|
||||
export default ButtonModules;
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import t from 'prop-types';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const Label = ({ children, spacing, className, text, ...rest }) => {
|
||||
const baseClasses = 'flex flex-1 flex-col text-gray-700 text-sm font-bold';
|
||||
@@ -12,7 +12,7 @@ const Label = ({ children, spacing, className, text, ...rest }) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<label className={getClasses()}>
|
||||
<label className={getClasses()} {...rest}>
|
||||
{text}
|
||||
{children}
|
||||
</label>
|
||||
@@ -27,6 +27,8 @@ const spacing = {
|
||||
|
||||
Label.defaultProps = {};
|
||||
|
||||
Label.prototypes = {};
|
||||
Label.propTypes = {
|
||||
children: PropTypes.node,
|
||||
};
|
||||
|
||||
export default Label;
|
||||
Reference in new issue
Block a user