index.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { useCallback } from 'react'
  2. import type { ChangeEvent } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import { RiCloseCircleFill, RiSearchLine } from '@remixicon/react'
  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('w-[200px] flex items-center p-2 h-8 rounded-lg bg-components-input-bg-normal')}>
  20. <RiSearchLine className={'w-4 h-4 mr-0.5 shrink-0 text-components-input-text-placeholder'} />
  21. <input
  22. className='min-w-0 grow px-1 text-[13px] leading-[16px] bg-transparent text-components-input-text-filled placeholder:text-components-input-text-placeholder 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. <RiCloseCircleFill
  30. className={'w-4 h-4 shrink-0 cursor-pointer text-components-input-text-placeholder'}
  31. onClick={handleClear}
  32. />
  33. )
  34. }
  35. </div>
  36. )
  37. }
  38. export default SearchInput