11import { ReactNode } from 'react' ;
22import Link from 'next/link' ;
33
4- type TButtonColors = 'red ' | 'blue ' ;
4+ type TButtonVariant = 'primary ' | 'secondary' | 'hero' | 'filter' | 'reset ';
55
66interface IButtonProps {
77 handleButtonClick ?: ( ) => void ;
88 buttonDisabled ?: boolean ;
9- color ?: TButtonColors ;
10- children : ReactNode ;
9+ variant ?: TButtonVariant ;
10+ children ? : ReactNode ;
1111 fullWidth ?: boolean ;
12- isHero ?: boolean ;
1312 href ?: string ;
13+ title ?: string ;
14+ selected ?: boolean ;
1415}
1516
1617/**
1718 * Renders a clickable button
1819 * @function Button
1920 * @param {void } handleButtonClick - Handle button click
2021 * @param {boolean? } buttonDisabled - Is button disabled?
21- * @param {TButtonColors ? } color - Color for button, either red or blue
22+ * @param {TButtonVariant ? } variant - Button variant
2223 * @param {ReactNode } children - Children for button
2324 * @param {boolean? } fullWidth - Whether the button should be full-width on mobile
25+ * @param {boolean? } selected - Whether the button is in a selected state
2426 * @returns {JSX.Element } - Rendered component
2527 */
2628const Button = ( {
2729 handleButtonClick,
2830 buttonDisabled,
29- color = 'blue ' ,
31+ variant = 'primary ' ,
3032 children,
3133 fullWidth = false ,
32- isHero = false ,
3334 href,
35+ title,
36+ selected = false ,
3437} : 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' ;
3852 }
39- return 'bg-red-500 hover:bg-red-600' ;
4053 } ;
4154
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 ${
4756 fullWidth ? 'w-full md:w-auto' : ''
4857 } `;
4958
50- if ( href && isHero ) {
59+ if ( href && variant === 'hero' ) {
5160 return (
5261 < Link href = { href } className = { classes } >
5362 { children }
@@ -60,6 +69,7 @@ const Button = ({
6069 onClick = { handleButtonClick }
6170 disabled = { buttonDisabled }
6271 className = { classes }
72+ title = { title }
6373 >
6474 { children }
6575 </ button >
0 commit comments