2020-03-02 19:37:00 +01:00
|
|
|
import React from 'react';
|
2020-02-13 23:43:20 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2020-02-19 23:45:17 +01:00
|
|
|
import classnames from 'classnames';
|
2020-02-13 23:43:20 +01:00
|
|
|
|
2020-03-04 23:16:51 +01:00
|
|
|
const baseClasses =
|
2020-03-05 22:13:38 +01:00
|
|
|
'min-w-md leading-none font-sans text-center justify-center items-center outline-none transition duration-300 ease-in-out focus:outline-none';
|
2020-03-04 23:16:51 +01:00
|
|
|
|
2020-02-13 23:43:20 +01:00
|
|
|
const defaults = {
|
2020-03-02 19:37:00 +01:00
|
|
|
variant: 'contained',
|
2020-02-13 23:43:20 +01:00
|
|
|
color: 'default',
|
2020-02-28 19:31:42 +01:00
|
|
|
size: 'medium',
|
2020-03-02 19:37:00 +01:00
|
|
|
radius: 'medium',
|
|
|
|
|
disabled: false,
|
2020-02-13 23:43:20 +01:00
|
|
|
type: 'button',
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-02 19:37:00 +01:00
|
|
|
const radiusClasses = {
|
2020-02-19 23:45:17 +01:00
|
|
|
none: '',
|
2020-03-02 19:37:00 +01:00
|
|
|
small: 'rounded-sm',
|
2020-02-13 23:43:20 +01:00
|
|
|
medium: 'rounded-md',
|
|
|
|
|
large: 'rounded-lg',
|
|
|
|
|
full: 'rounded-full',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const disabledClasses = {
|
|
|
|
|
true: 'cursor-not-allowed',
|
|
|
|
|
false: '',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const variantClasses = {
|
|
|
|
|
text: {
|
2020-03-04 23:16:51 +01:00
|
|
|
default:
|
2020-04-02 20:52:41 +02:00
|
|
|
'text-primary-light hover:bg-primary-light hover:text-white active:opacity-80 focus:bg-primary-light focus:text-white',
|
2020-03-04 23:16:51 +01:00
|
|
|
primary:
|
2020-04-02 20:52:41 +02:00
|
|
|
'text-primary-main hover:bg-primary-main hover:text-white active:opacity-80 focus:bg-primary-main focus:text-white',
|
2020-03-04 23:16:51 +01:00
|
|
|
secondary:
|
2020-04-02 20:52:41 +02:00
|
|
|
'text-secondary-light hover:bg-secondary-light hover:text-white active:opacity-80 focus:bg-secondary-light focus:text-white',
|
2020-03-04 23:16:51 +01:00
|
|
|
white:
|
|
|
|
|
'text-white hover:bg-white hover:text-black active:opacity-80 focus:bg-white focus:text-black',
|
2020-02-13 23:43:20 +01:00
|
|
|
},
|
|
|
|
|
outlined: {
|
2020-03-04 23:16:51 +01:00
|
|
|
default:
|
2020-04-02 20:52:41 +02:00
|
|
|
'border bg-trasparent border-primary-light text-primary-light hover:bg-primary-light hover:text-black focus:text-black focus:bg-primary-light active:opacity-80',
|
2020-03-04 23:16:51 +01:00
|
|
|
primary:
|
2020-04-02 20:52:41 +02:00
|
|
|
'border bg-transparent border-primary-main text-primary-main hover:opacity-80 active:opacity-100 focus:opacity-80',
|
2020-03-04 23:16:51 +01:00
|
|
|
secondary:
|
2020-04-02 20:52:41 +02:00
|
|
|
'border bg-transparent border-secondary-light text-secondary-light hover:opacity-80 active:opacity-100 focus:opacity-80',
|
2020-03-04 23:16:51 +01:00
|
|
|
white:
|
|
|
|
|
'border bg-transparent border-white text-white hover:opacity-80 active:opacity-100 focus:opacity-80',
|
2020-02-13 23:43:20 +01:00
|
|
|
},
|
|
|
|
|
contained: {
|
2020-03-04 23:16:51 +01:00
|
|
|
default:
|
2020-04-02 20:52:41 +02:00
|
|
|
'bg-primary-light text-black hover:opacity-80 active:opacity-100 focus:opacity-80',
|
2020-03-04 23:16:51 +01:00
|
|
|
primary:
|
2020-04-02 20:52:41 +02:00
|
|
|
'bg-primary-main text-white hover:opacity-80 active:opacity-100 focus:opacity-80',
|
2020-03-04 23:16:51 +01:00
|
|
|
secondary:
|
2020-04-02 20:52:41 +02:00
|
|
|
'bg-secondary-light text-white hover:opacity-80 active:opacity-100 focus:opacity-80',
|
2020-03-04 23:16:51 +01:00
|
|
|
white:
|
|
|
|
|
'bg-white text-black hover:opacity-80 active:opacity-100 focus:opacity-80',
|
2020-02-13 23:43:20 +01:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const sizeClasses = {
|
2020-03-12 17:26:31 +01:00
|
|
|
small: 'py-2 px-2 text-sm',
|
2020-03-04 23:16:51 +01:00
|
|
|
medium: 'py-2 px-2 text-lg',
|
|
|
|
|
large: 'py-2 px-6 text-xl',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fullWidthClasses = {
|
|
|
|
|
true: 'flex w-full',
|
|
|
|
|
false: 'inline-flex',
|
2020-02-13 23:43:20 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-19 23:45:17 +01:00
|
|
|
const Button = ({
|
|
|
|
|
children,
|
|
|
|
|
variant = defaults.variant,
|
|
|
|
|
color = defaults.color,
|
|
|
|
|
size = defaults.size,
|
2020-03-02 19:37:00 +01:00
|
|
|
radius = defaults.radius,
|
2020-02-19 23:45:17 +01:00
|
|
|
disabled = defaults.disabled,
|
|
|
|
|
type = defaults.type,
|
2020-03-02 20:10:51 +01:00
|
|
|
fullWidth = defaults.fullWidth,
|
2020-02-19 23:45:17 +01:00
|
|
|
startIcon: startIconProp,
|
|
|
|
|
endIcon: endIconProp,
|
|
|
|
|
className,
|
|
|
|
|
...rest
|
|
|
|
|
}) => {
|
2020-03-02 19:37:00 +01:00
|
|
|
const baseClasses =
|
|
|
|
|
'inline-flex items-center outline-none transition duration-300 ease-in-out font-bold focus:outline-none';
|
2020-02-28 19:31:42 +01:00
|
|
|
|
2020-03-02 19:37:00 +01:00
|
|
|
const startIcon = startIconProp && (
|
|
|
|
|
<div className="mr-2">{startIconProp}</div>
|
2020-02-19 23:45:17 +01:00
|
|
|
);
|
|
|
|
|
|
2020-04-02 20:52:41 +02:00
|
|
|
const handleOnClick = e => {
|
|
|
|
|
buttonElement.current.blur();
|
|
|
|
|
if (rest.onClick) {
|
|
|
|
|
rest.onClick(e);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-02-19 23:45:17 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
className={classnames(
|
2020-03-12 17:26:31 +01:00
|
|
|
className,
|
2020-02-19 23:45:17 +01:00
|
|
|
baseClasses,
|
|
|
|
|
variantClasses[variant][color],
|
2020-03-02 19:37:00 +01:00
|
|
|
radiusClasses[radius],
|
2020-02-19 23:45:17 +01:00
|
|
|
sizeClasses[size],
|
2020-03-12 17:26:31 +01:00
|
|
|
fullWidthClasses[fullWidth],
|
|
|
|
|
disabledClasses[disabled]
|
2020-02-19 23:45:17 +01:00
|
|
|
)}
|
|
|
|
|
type={type}
|
|
|
|
|
{...rest}
|
|
|
|
|
>
|
|
|
|
|
{startIcon}
|
|
|
|
|
{children}
|
|
|
|
|
{endIcon}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-13 23:43:20 +01:00
|
|
|
Button.propTypes = {
|
2020-02-14 23:46:27 +01:00
|
|
|
children: PropTypes.node,
|
2020-02-13 23:43:20 +01:00
|
|
|
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
2020-03-02 19:37:00 +01:00
|
|
|
radius: PropTypes.oneOf(['none', 'small', 'medium', 'large', 'full']),
|
2020-02-13 23:43:20 +01:00
|
|
|
variant: PropTypes.oneOf(['text', 'outlined', 'contained']),
|
2020-03-12 17:26:31 +01:00
|
|
|
color: PropTypes.oneOf([
|
|
|
|
|
'default',
|
|
|
|
|
'primary',
|
|
|
|
|
'secondary',
|
|
|
|
|
'white',
|
|
|
|
|
'inherit',
|
|
|
|
|
]),
|
|
|
|
|
fullWidth: PropTypes.bool,
|
2020-02-14 23:46:27 +01:00
|
|
|
disabled: PropTypes.bool,
|
|
|
|
|
type: PropTypes.string,
|
|
|
|
|
startIcon: PropTypes.node,
|
|
|
|
|
endIcon: PropTypes.node,
|
2020-03-03 23:36:22 +01:00
|
|
|
className: PropTypes.string,
|
2020-02-13 23:43:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Button;
|