3
3
import { cn } from "@/utils/classnames" ;
4
4
import { TrashIcon } from "@heroicons/react/24/outline" ;
5
5
import { useRouter } from "next/navigation" ;
6
- import React , {
7
- InputHTMLAttributes ,
8
- MouseEvent ,
9
- MouseEventHandler ,
10
- Ref ,
11
- forwardRef ,
12
- } from "react" ;
6
+ import React , { InputHTMLAttributes , MouseEvent , MouseEventHandler , Ref , forwardRef } from "react" ;
13
7
14
8
interface ButtonProps extends InputHTMLAttributes < HTMLButtonElement > {
15
9
onClick ?: MouseEventHandler < HTMLButtonElement > | ( ( ) => void ) ;
16
10
type ?: "button" | "submit" | "reset" ;
17
11
}
18
12
19
- export const Button : React . FC < ButtonProps & { ref ?: Ref < HTMLButtonElement > } > =
20
- forwardRef < HTMLButtonElement , ButtonProps > ( ( props , ref ) => {
21
- const {
22
- onClick,
23
- type = "button" ,
24
- className,
25
- children,
26
- ...remaining
27
- } = props ;
28
-
29
- const buttonStyle = cn (
30
- "text-white bg-blue-950 hover:bg-blue-900" ,
31
- "py-1 px-4 cursor-pointer font-semibold shadow-none rounded-md tracking-[1px] transition select-none" ,
32
- props . disabled &&
33
- "text-slate-600 bg-slate-300 hover:bg-slate-300 cursor-not-allowed" ,
34
- props . className
35
- ) ;
36
- return (
37
- < button
38
- className = { buttonStyle }
39
- type = { type }
40
- ref = { ref }
41
- onClick = { props . onClick }
42
- { ...remaining }
43
- >
44
- { props . children }
45
- </ button >
46
- ) ;
47
- } ) ;
13
+ export const Button : React . FC < ButtonProps & { ref ?: Ref < HTMLButtonElement > } > = forwardRef <
14
+ HTMLButtonElement ,
15
+ ButtonProps
16
+ > ( ( props , ref ) => {
17
+ const { onClick, type = "button" , className, children, ...remaining } = props ;
18
+
19
+ const buttonStyle = cn (
20
+ "text-white bg-blue-950 hover:bg-blue-900" ,
21
+ "py-1 px-4 cursor-pointer font-semibold shadow-none rounded-md tracking-[1px] transition select-none" ,
22
+ props . disabled && "text-slate-600 bg-slate-300 hover:bg-slate-300 cursor-not-allowed" ,
23
+ props . className ,
24
+ ) ;
25
+ return (
26
+ < button className = { buttonStyle } type = { type } ref = { ref } onClick = { props . onClick } { ...remaining } >
27
+ { props . children }
28
+ </ button >
29
+ ) ;
30
+ } ) ;
31
+
32
+ Button . displayName = "Button" ;
48
33
49
34
type LinkButtonProps = {
50
35
href : string ;
51
36
className ?: string ;
52
37
children : React . ReactNode ;
53
38
} ;
54
39
55
- export const LinkButton : React . FC < LinkButtonProps > = forwardRef <
56
- HTMLAnchorElement ,
57
- LinkButtonProps
58
- > ( ( props , ref ) => {
40
+ export const LinkButton : React . FC < LinkButtonProps > = forwardRef < HTMLAnchorElement , LinkButtonProps > ( ( props , ref ) => {
59
41
const { href, className, children, ...remaining } = props ;
60
42
61
43
const buttonStyle = cn (
62
44
"flex items-center justify-center text-white bg-blue-950 hover:bg-blue-900 tracking-[1px] py-1 px-4 cursor-pointer font-bold shadow-none rounded-md transition select-none" ,
63
- props . className
45
+ props . className ,
64
46
) ;
65
47
return (
66
48
< a className = { buttonStyle } ref = { ref } href = { props . href } { ...remaining } >
@@ -69,6 +51,8 @@ export const LinkButton: React.FC<LinkButtonProps> = forwardRef<
69
51
) ;
70
52
} ) ;
71
53
54
+ LinkButton . displayName = "LinkButton" ;
55
+
72
56
type FormButtonProps = {
73
57
className ?: string ;
74
58
children : React . ReactNode ;
@@ -77,7 +61,7 @@ type FormButtonProps = {
77
61
export const FormButton : React . FC < FormButtonProps > = ( props ) => {
78
62
const buttonStyle = cn (
79
63
"text-white bg-blue-950 hover:bg-blue-900 py-1 px-4 cursor-pointer font-bold shadow-none rounded-md tracking-[1px] transition select-none" ,
80
- props . className
64
+ props . className ,
81
65
) ;
82
66
return (
83
67
< button className = { buttonStyle } type = "submit" >
@@ -86,9 +70,7 @@ export const FormButton: React.FC<FormButtonProps> = (props) => {
86
70
) ;
87
71
} ;
88
72
89
- export const BackButton : React . FC < InputHTMLAttributes < HTMLDivElement > > = (
90
- props
91
- ) => {
73
+ export const BackButton : React . FC < InputHTMLAttributes < HTMLDivElement > > = ( props ) => {
92
74
const router = useRouter ( ) ;
93
75
94
76
const onClick = ( e : MouseEvent < HTMLDivElement > ) => {
@@ -101,10 +83,7 @@ export const BackButton: React.FC<InputHTMLAttributes<HTMLDivElement>> = (
101
83
102
84
return (
103
85
< div
104
- className = { cn (
105
- "cursor-pointer select-none text-sm font-[500] hover:text-slate-600 w-fit" ,
106
- props . className
107
- ) }
86
+ className = { cn ( "cursor-pointer select-none text-sm font-[500] hover:text-slate-600 w-fit" , props . className ) }
108
87
onClick = { onClick }
109
88
>
110
89
{ String . fromCharCode ( 8592 ) } Back
@@ -119,17 +98,14 @@ type IconButtonProps = {
119
98
children ?: React . ReactNode ;
120
99
disabled ?: boolean ;
121
100
} ;
122
- export const IconButton : React . FC < IconButtonProps > = forwardRef <
123
- HTMLButtonElement ,
124
- IconButtonProps
125
- > ( ( props , ref ) => {
101
+ export const IconButton : React . FC < IconButtonProps > = forwardRef < HTMLButtonElement , IconButtonProps > ( ( props , ref ) => {
126
102
const { onClick, className, children, ...remaining } = props ;
127
103
const buttonStyle = cn (
128
104
"font-semibold flex " ,
129
105
"py-1 px-4 cursor-pointer font-bold shadow-none rounded-md tracking-[1px] transition select-none" ,
130
106
! props . disabled && "hover:bg-slate-100" ,
131
107
props . disabled && "text-slate-400 cursor-not-allowed" ,
132
- props . className
108
+ props . className ,
133
109
) ;
134
110
return (
135
111
< button
@@ -146,6 +122,8 @@ export const IconButton: React.FC<IconButtonProps> = forwardRef<
146
122
) ;
147
123
} ) ;
148
124
125
+ IconButton . displayName = "IconButton" ;
126
+
149
127
export const DeleteButton = ( props : Omit < IconButtonProps , "icon" > ) => (
150
128
< IconButton { ...props } icon = { < TrashIcon className = "w-5 h-5" /> } />
151
129
) ;
0 commit comments