index.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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('flex h-8 w-[200px] items-center rounded-lg bg-components-input-bg-normal p-2')}>
  20. <RiSearchLine className={'mr-0.5 h-4 w-4 shrink-0 text-components-input-text-placeholder'} />
  21. <input
  22. className='min-w-0 grow appearance-none border-0 bg-transparent px-1 text-[13px] leading-[16px] text-components-input-text-filled outline-0 placeholder:text-components-input-text-placeholder'
  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={'h-4 w-4 shrink-0 cursor-pointer text-components-input-text-placeholder'}
  31. onClick={handleClear}
  32. />
  33. )
  34. }
  35. </div>
  36. )
  37. }
  38. export default SearchInput