| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | 'use client' | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | import type { SVGProps } from 'react' | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  | import React, { useState } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import s from './style.module.css' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type InputProps = { | 
					
						
							|  |  |  |   placeholder?: string | 
					
						
							|  |  |  |   value?: string | 
					
						
							|  |  |  |   defaultValue?: string | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  |   onChange?: (v: string) => void | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   className?: string | 
					
						
							|  |  |  |   wrapperClassName?: string | 
					
						
							|  |  |  |   type?: string | 
					
						
							|  |  |  |   showPrefix?: React.ReactNode | 
					
						
							|  |  |  |   prefixIcon?: React.ReactNode | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | const GlassIcon = ({ className }: SVGProps<SVGElement>) => ( | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   <svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg" className={className ?? ''}> | 
					
						
							| 
									
										
										
										
											2023-05-30 15:26:26 +08:00
										 |  |  |     <path d="M12.25 12.25L10.2084 10.2083M11.6667 6.70833C11.6667 9.44675 9.44675 11.6667 6.70833 11.6667C3.96992 11.6667 1.75 9.44675 1.75 6.70833C1.75 3.96992 3.96992 1.75 6.70833 1.75C9.44675 1.75 11.6667 3.96992 11.6667 6.70833Z" stroke="#344054" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round" /> | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   </svg> | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  | const Input = ({ value, defaultValue, onChange, className = '', wrapperClassName = '', placeholder, type, showPrefix, prefixIcon }: InputProps) => { | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |   const [localValue, setLocalValue] = useState(value ?? defaultValue) | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div className={`relative inline-flex w-full ${wrapperClassName}`}> | 
					
						
							|  |  |  |       {showPrefix && <span className={s.prefix}>{prefixIcon ?? <GlassIcon className='h-3.5 w-3.5 stroke-current text-gray-700 stroke-2' />}</span>} | 
					
						
							|  |  |  |       <input | 
					
						
							|  |  |  |         type={type ?? 'text'} | 
					
						
							|  |  |  |         className={`${s.input} ${showPrefix ? '!pl-7' : ''} ${className}`} | 
					
						
							| 
									
										
										
										
											2023-08-28 19:48:53 +08:00
										 |  |  |         placeholder={placeholder ?? (showPrefix ? t('common.operation.search') ?? '' : 'please input')} | 
					
						
							| 
									
										
										
										
											2023-05-15 08:51:32 +08:00
										 |  |  |         value={localValue} | 
					
						
							|  |  |  |         onChange={(e) => { | 
					
						
							|  |  |  |           setLocalValue(e.target.value) | 
					
						
							|  |  |  |           onChange && onChange(e.target.value) | 
					
						
							|  |  |  |         }} | 
					
						
							|  |  |  |       /> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default Input |