index.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { useCallback } from 'react'
  2. import type { ChangeEvent } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import s from './index.module.css'
  5. import cn from '@/utils/classnames'
  6. type SearchInputProps = {
  7. value: string
  8. onChange: (v: string) => void
  9. }
  10. const SearchInput = ({
  11. value,
  12. onChange,
  13. }: SearchInputProps) => {
  14. const { t } = useTranslation()
  15. const handleClear = useCallback(() => {
  16. onChange('')
  17. }, [onChange])
  18. return (
  19. <div className={cn(s['input-wrapper'], 'flex items-center px-2 h-7 rounded-md', `${value ? 'bg-white' : 'bg-gray-100'}`)}>
  20. <div className={cn(s['search-icon'], 'mr-[6px] w-4 h-4')} />
  21. <input
  22. className='grow text-[13px] bg-inherit border-0 outline-0 appearance-none'
  23. value={value}
  24. onChange={(e: ChangeEvent<HTMLInputElement>) => onChange(e.target.value)}
  25. placeholder={t('common.dataSource.notion.selector.searchPages') || ''}
  26. />
  27. {
  28. value && (
  29. <div
  30. className={cn(s['clear-icon'], 'ml-1 w-4 h-4 cursor-pointer')}
  31. onClick={handleClear}
  32. />
  33. )
  34. }
  35. </div>
  36. )
  37. }
  38. export default SearchInput