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
|
|
|
|
|
|
|
|
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-02 19:37:00 +01:00
|
|
|
default: 'hover:bg-gray-200 text-black',
|
|
|
|
|
primary: 'hover:bg-blue-100 text-blue-900',
|
|
|
|
|
secondary: 'hover:bg-blue-100 text-blue-300',
|
2020-02-13 23:43:20 +01:00
|
|
|
},
|
|
|
|
|
outlined: {
|
2020-03-02 19:37:00 +01:00
|
|
|
default: 'border border-black text-black hover:bg-gray-200',
|
|
|
|
|
primary: 'border border-blue-900 text-blue-900 hover:bg-blue-100',
|
|
|
|
|
secondary: 'border border-blue-300 text-blue-300 hover:bg-blue-100',
|
2020-02-13 23:43:20 +01:00
|
|
|
},
|
|
|
|
|
contained: {
|
2020-03-02 19:37:00 +01:00
|
|
|
default: 'bg-black hover:bg-gray-800 text-white',
|
|
|
|
|
primary: 'bg-blue-900 hover:bg-blue-800 text-white',
|
|
|
|
|
secondary: 'bg-blue-300 hover:bg-blue-500 text-black',
|
2020-02-13 23:43:20 +01:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const sizeClasses = {
|
2020-03-02 19:37:00 +01:00
|
|
|
small: 'py-1 px-2 text-sm',
|
|
|
|
|
medium: 'py-2 px-4 text-base',
|
|
|
|
|
large: 'py-3 px-6 text-lg',
|
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-03-02 19:37:00 +01:00
|
|
|
const endIcon = endIconProp && <div className="ml-2">{endIconProp}</div>;
|
2020-02-19 23:45:17 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
className={classnames(
|
|
|
|
|
baseClasses,
|
|
|
|
|
variantClasses[variant][color],
|
2020-03-02 19:37:00 +01:00
|
|
|
radiusClasses[radius],
|
2020-02-19 23:45:17 +01:00
|
|
|
sizeClasses[size],
|
|
|
|
|
disabledClasses[disabled],
|
|
|
|
|
className
|
|
|
|
|
)}
|
|
|
|
|
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-02 19:37:00 +01:00
|
|
|
color: PropTypes.oneOf(['default', 'primary', 'secondary']),
|
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;
|