mirror of
				https://github.com/langgenius/dify.git
				synced 2025-10-31 02:42:59 +00:00 
			
		
		
		
	 d069c668f8
			
		
	
	
		d069c668f8
		
			
		
	
	
	
	
		
			
			Co-authored-by: StyleZhang <jasonapring2015@outlook.com> Co-authored-by: Garfield Dai <dai.hai@foxmail.com> Co-authored-by: chenhe <guchenhe@gmail.com> Co-authored-by: jyong <jyong@dify.ai> Co-authored-by: Joel <iamjoel007@gmail.com> Co-authored-by: Yeuoly <admin@srmxy.cn>
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import type { FC, MouseEventHandler } from 'react'
 | |
| import React from 'react'
 | |
| import Spinner from '../spinner'
 | |
| 
 | |
| export type IButtonProps = {
 | |
|   type?: string
 | |
|   className?: string
 | |
|   disabled?: boolean
 | |
|   loading?: boolean
 | |
|   tabIndex?: number
 | |
|   children: React.ReactNode
 | |
|   onClick?: MouseEventHandler<HTMLDivElement>
 | |
| }
 | |
| 
 | |
| const Button: FC<IButtonProps> = ({
 | |
|   type,
 | |
|   disabled,
 | |
|   children,
 | |
|   className,
 | |
|   onClick,
 | |
|   loading = false,
 | |
|   tabIndex,
 | |
| }) => {
 | |
|   let style = 'cursor-pointer'
 | |
|   switch (type) {
 | |
|     case 'primary':
 | |
|       style = (disabled || loading) ? 'btn-primary-disabled' : 'btn-primary'
 | |
|       break
 | |
|     case 'warning':
 | |
|       style = (disabled || loading) ? 'btn-warning-disabled' : 'btn-warning'
 | |
|       break
 | |
|     default:
 | |
|       style = disabled ? 'btn-default-disabled' : 'btn-default'
 | |
|       break
 | |
|   }
 | |
| 
 | |
|   return (
 | |
|     <div
 | |
|       className={`btn ${style} ${className && className}`}
 | |
|       tabIndex={tabIndex}
 | |
|       onClick={disabled ? undefined : onClick}
 | |
|     >
 | |
|       {children}
 | |
|       {/* Spinner is hidden when loading is false */}
 | |
|       <Spinner loading={loading} className='!text-white !h-3 !w-3 !border-2 !ml-1' />
 | |
|     </div>
 | |
|   )
 | |
| }
 | |
| 
 | |
| export default React.memo(Button)
 |