| 
									
										
										
										
											2024-06-26 04:51:00 -05:00
										 |  |  | import type { CSSProperties } from 'react' | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  | import React from 'react' | 
					
						
							|  |  |  | import { type VariantProps, cva } from 'class-variance-authority' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import Spinner from '../spinner' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import classNames from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  | const buttonVariants = cva( | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |   'btn disabled:btn-disabled', | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |   { | 
					
						
							|  |  |  |     variants: { | 
					
						
							|  |  |  |       variant: { | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |         'primary': 'btn-primary', | 
					
						
							|  |  |  |         'warning': 'btn-warning', | 
					
						
							|  |  |  |         'secondary': 'btn-secondary', | 
					
						
							|  |  |  |         'secondary-accent': 'btn-secondary-accent', | 
					
						
							|  |  |  |         'ghost': 'btn-ghost', | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  |         'ghost-accent': 'btn-ghost-accent', | 
					
						
							| 
									
										
										
										
											2024-07-10 18:20:13 +08:00
										 |  |  |         'tertiary': 'btn-tertiary', | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |       }, | 
					
						
							|  |  |  |       size: { | 
					
						
							|  |  |  |         small: 'btn-small', | 
					
						
							|  |  |  |         medium: 'btn-medium', | 
					
						
							|  |  |  |         large: 'btn-large', | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |       }, | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     defaultVariants: { | 
					
						
							| 
									
										
										
										
											2024-06-21 14:17:45 +08:00
										 |  |  |       variant: 'secondary', | 
					
						
							|  |  |  |       size: 'medium', | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |     }, | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  | export type ButtonProps = { | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  |   destructive?: boolean | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |   loading?: boolean | 
					
						
							| 
									
										
										
										
											2024-06-26 04:51:00 -05:00
										 |  |  |   styleCss?: CSSProperties | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  | } & React.ButtonHTMLAttributes<HTMLButtonElement> & VariantProps<typeof buttonVariants> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  | const Button = React.forwardRef<HTMLButtonElement, ButtonProps>( | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  |   ({ className, variant, size, destructive, loading, styleCss, children, ...props }, ref) => { | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |     return ( | 
					
						
							|  |  |  |       <button | 
					
						
							| 
									
										
										
										
											2024-06-20 12:44:27 +08:00
										 |  |  |         type='button' | 
					
						
							| 
									
										
										
										
											2024-07-24 12:50:48 +08:00
										 |  |  |         className={classNames( | 
					
						
							|  |  |  |           buttonVariants({ variant, size, className }), | 
					
						
							|  |  |  |           destructive && 'btn-destructive', | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |         ref={ref} | 
					
						
							| 
									
										
										
										
											2024-06-26 04:51:00 -05:00
										 |  |  |         style={styleCss} | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |         {...props} | 
					
						
							|  |  |  |       > | 
					
						
							|  |  |  |         {children} | 
					
						
							| 
									
										
										
										
											2024-07-18 17:35:10 +08:00
										 |  |  |         {loading && <Spinner loading={loading} className='!text-white !h-3 !w-3 !border-2 !ml-1' />} | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  |       </button> | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   }, | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | Button.displayName = 'Button' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-19 14:13:16 +08:00
										 |  |  | export default Button | 
					
						
							|  |  |  | export { Button, buttonVariants } |