File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import { Button } from '@/components/button' ;
2+ import { SpinLoading , ErrorShake , Complete } from '@/components/loading' ;
3+ import useDelayedLoading from '@/hooks/button/useDelayedLoading' ;
4+ import { cn } from '@/utils' ;
5+
6+ interface StatusButtonProps extends React . ButtonHTMLAttributes < HTMLButtonElement > {
7+ isLoading : boolean ;
8+ isSuccess : boolean ;
9+ isError : boolean ;
10+ text : string ;
11+ disabled ?: boolean ;
12+ }
13+
14+ const StatusButton = ( {
15+ isLoading,
16+ isSuccess,
17+ isError,
18+ text,
19+ disabled,
20+ className,
21+ ...props
22+ } : StatusButtonProps ) => {
23+ const showLoading = useDelayedLoading ( { isLoading } ) ;
24+
25+ const variant = disabled ? 'disabled' : 'primary' ;
26+
27+ const renderContent = ( ) => {
28+ if ( showLoading ) return < SpinLoading /> ;
29+ if ( isSuccess ) return < Complete /> ;
30+ if ( isError ) return < ErrorShake /> ;
31+ return < span > { text } </ span > ;
32+ } ;
33+
34+ return (
35+ < Button
36+ variant = { variant }
37+ disabled = { isLoading || disabled }
38+ className = { cn ( className , isError && 'bg-functional-danger' ) }
39+ { ...props }
40+ >
41+ { renderContent ( ) }
42+ </ Button >
43+ ) ;
44+ } ;
45+
46+ export default StatusButton ;
You can’t perform that action at this time.
0 commit comments