11import { ReactNode } from 'react' ;
2+ import Link from 'next/link' ;
23
34type TButtonColors = 'red' | 'blue' ;
45
@@ -8,6 +9,8 @@ interface IButtonProps {
89 color ?: TButtonColors ;
910 children : ReactNode ;
1011 fullWidth ?: boolean ;
12+ isHero ?: boolean ;
13+ href ?: string ;
1114}
1215
1316/**
@@ -26,21 +29,41 @@ const Button = ({
2629 color = 'blue' ,
2730 children,
2831 fullWidth = false ,
29- } : IButtonProps ) => (
30- < button
31- onClick = { handleButtonClick }
32- disabled = { buttonDisabled }
33- className = { `px-2 lg:px-4 py-2 font-bold bg-blue-500 border border-gray-400 border-solid rounded text-white ease-in-out transition-all duration-300 disabled:opacity-50
34- ${
35- color === 'blue'
36- ? 'bg-blue-500 hover:bg-blue-600'
37- : 'bg-red-500 hover:bg-red-600'
38- }
39- ${ fullWidth ? 'w-full md:w-auto' : '' }
40- ` }
41- >
42- { children }
43- </ button >
44- ) ;
32+ isHero = false ,
33+ href,
34+ } : IButtonProps ) => {
35+ const getColorClasses = ( buttonColor : TButtonColors ) => {
36+ if ( buttonColor === 'blue' ) {
37+ return 'bg-blue-500 hover:bg-blue-600' ;
38+ }
39+ return 'bg-red-500 hover:bg-red-600' ;
40+ } ;
41+
42+ const buttonClasses = isHero
43+ ? 'inline-block px-8 py-4 text-sm tracking-wider uppercase bg-white bg-opacity-90 text-gray-900 hover:bg-gray-400 hover:bg-opacity-95 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 ${
47+ fullWidth ? 'w-full md:w-auto' : ''
48+ } `;
49+
50+ if ( href && isHero ) {
51+ return (
52+ < Link href = { href } className = { classes } >
53+ { children }
54+ </ Link >
55+ ) ;
56+ }
57+
58+ return (
59+ < button
60+ onClick = { handleButtonClick }
61+ disabled = { buttonDisabled }
62+ className = { classes }
63+ >
64+ { children }
65+ </ button >
66+ ) ;
67+ } ;
4568
4669export default Button ;
0 commit comments