-
Notifications
You must be signed in to change notification settings - Fork 210
Expand file tree
/
Copy pathSolidButton.tsx
More file actions
73 lines (69 loc) · 2.03 KB
/
Copy pathSolidButton.tsx
File metadata and controls
73 lines (69 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { PropsWithChildren, ReactElement } from 'react';
interface ButtonProps {
type?: 'submit' | 'reset' | 'button';
color?: 'white' | 'primary' | 'accent' | 'green' | 'red' | 'gray'; // defaults to primary
bold?: boolean;
className?: string;
icon?: ReactElement;
}
export function SolidButton(
props: PropsWithChildren<ButtonProps & React.HTMLProps<HTMLButtonElement>>,
) {
const {
type,
onClick,
color: _color,
className,
bold,
icon,
disabled,
title,
...passThruProps
} = props;
const color = _color ?? 'primary';
const base =
'flex items-center justify-center rounded transition-all duration-500 active:scale-95';
let baseColors, onHover;
if (color === 'primary') {
baseColors = 'bg-primary-500 text-white';
onHover = 'hover:bg-primary-600';
} else if (color === 'accent') {
baseColors = 'bg-accent-gradient shadow-accent-glow';
onHover = 'hover:opacity-90';
} else if (color === 'green') {
baseColors = 'bg-green-500 text-white';
onHover = 'hover:bg-green-600';
} else if (color === 'red') {
baseColors = 'bg-error-gradient shadow-error-glow';
onHover = 'hover:opacity-90';
} else if (color === 'white') {
baseColors = 'bg-white text-black';
onHover = 'hover:bg-primary-100';
} else if (color === 'gray') {
baseColors = 'bg-gray-100 text-primary-500';
onHover = 'hover:bg-gray-200';
}
const onDisabled =
'disabled:bg-gray-300 disabled:text-gray-500 disabled:shadow-none disabled:bg-none';
const weight = bold ? 'font-semibold' : '';
const allClasses = `${base} ${baseColors} ${onHover} ${onDisabled} ${weight} ${className}`;
return (
<button
onClick={onClick}
type={type ?? 'button'}
disabled={disabled ?? false}
title={title}
className={allClasses}
{...passThruProps}
>
{icon ? (
<div className="flex items-center justify-center space-x-1">
{props.icon}
{props.children}
</div>
) : (
<>{props.children}</>
)}
</button>
);
}