1
1
import { ReactNode } from 'react' ;
2
2
import Link from 'next/link' ;
3
3
4
- type TButtonColors = 'red ' | 'blue ' ;
4
+ type TButtonVariant = 'primary ' | 'secondary' | 'hero' | 'filter' | 'reset ';
5
5
6
6
interface IButtonProps {
7
7
handleButtonClick ?: ( ) => void ;
8
8
buttonDisabled ?: boolean ;
9
- color ?: TButtonColors ;
10
- children : ReactNode ;
9
+ variant ?: TButtonVariant ;
10
+ children ? : ReactNode ;
11
11
fullWidth ?: boolean ;
12
- isHero ?: boolean ;
13
12
href ?: string ;
13
+ title ?: string ;
14
+ selected ?: boolean ;
14
15
}
15
16
16
17
/**
17
18
* Renders a clickable button
18
19
* @function Button
19
20
* @param {void } handleButtonClick - Handle button click
20
21
* @param {boolean? } buttonDisabled - Is button disabled?
21
- * @param {TButtonColors ? } color - Color for button, either red or blue
22
+ * @param {TButtonVariant ? } variant - Button variant
22
23
* @param {ReactNode } children - Children for button
23
24
* @param {boolean? } fullWidth - Whether the button should be full-width on mobile
25
+ * @param {boolean? } selected - Whether the button is in a selected state
24
26
* @returns {JSX.Element } - Rendered component
25
27
*/
26
28
const Button = ( {
27
29
handleButtonClick,
28
30
buttonDisabled,
29
- color = 'blue ' ,
31
+ variant = 'primary ' ,
30
32
children,
31
33
fullWidth = false ,
32
- isHero = false ,
33
34
href,
35
+ title,
36
+ selected = false ,
34
37
} : IButtonProps ) => {
35
- const getColorClasses = ( buttonColor : TButtonColors ) => {
36
- if ( buttonColor === 'blue' ) {
37
- return 'bg-blue-500 hover:bg-blue-600' ;
38
+ const getVariantClasses = ( variant : TButtonVariant = 'primary' ) => {
39
+ switch ( variant ) {
40
+ case 'hero' :
41
+ return 'inline-block px-8 py-4 text-sm tracking-wider uppercase bg-white text-gray-900 hover:bg-gray-400 hover:text-white hover:shadow-md' ;
42
+ case 'filter' :
43
+ return selected
44
+ ? 'px-3 py-1 border rounded bg-gray-900 text-white'
45
+ : 'px-3 py-1 border rounded hover:bg-gray-100 bg-white text-gray-900' ;
46
+ case 'reset' :
47
+ return 'w-full mt-8 py-2 px-4 bg-gray-100 text-gray-700 rounded hover:bg-gray-200 transition-colors' ;
48
+ case 'secondary' :
49
+ return 'px-2 lg:px-4 py-2 font-bold border border-gray-400 border-solid rounded text-white bg-red-500 hover:bg-red-600' ;
50
+ default : // primary
51
+ return 'px-2 lg:px-4 py-2 font-bold border border-gray-400 border-solid rounded text-white bg-blue-500 hover:bg-blue-600' ;
38
52
}
39
- return 'bg-red-500 hover:bg-red-600' ;
40
53
} ;
41
54
42
- const buttonClasses = isHero
43
- ? 'inline-block px-8 py-4 text-sm tracking-wider uppercase bg-white text-gray-900 hover:bg-gray-400 hover:text-white hover:shadow-md'
44
- : `px-2 lg:px-4 py-2 font-bold border border-gray-400 border-solid rounded text-white ${ getColorClasses ( color ) } ` ;
45
-
46
- const classes = `${ buttonClasses } ease-in-out transition-all duration-300 disabled:opacity-50 ${
55
+ const classes = `${ getVariantClasses ( variant ) } ease-in-out transition-all duration-300 disabled:opacity-50 ${
47
56
fullWidth ? 'w-full md:w-auto' : ''
48
57
} `;
49
58
50
- if ( href && isHero ) {
59
+ if ( href && variant === 'hero' ) {
51
60
return (
52
61
< Link href = { href } className = { classes } >
53
62
{ children }
@@ -60,6 +69,7 @@ const Button = ({
60
69
onClick = { handleButtonClick }
61
70
disabled = { buttonDisabled }
62
71
className = { classes }
72
+ title = { title }
63
73
>
64
74
{ children }
65
75
</ button >
0 commit comments