search.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import cn from 'classnames'
  5. import {
  6. MagnifyingGlassIcon,
  7. } from '@heroicons/react/24/solid'
  8. import { useTranslation } from 'react-i18next'
  9. type Props = {
  10. className?: string
  11. value: string
  12. onChange: (v: string) => void
  13. }
  14. const Search: FC<Props> = ({
  15. className,
  16. value,
  17. onChange,
  18. }) => {
  19. const { t } = useTranslation()
  20. return (
  21. <div className={cn(className, 'flex relative')}>
  22. <div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
  23. <MagnifyingGlassIcon className="h-5 w-5 text-gray-400" aria-hidden="true" />
  24. </div>
  25. <input
  26. type="text"
  27. name="query"
  28. className="block w-0 grow bg-gray-200 shadow-sm rounded-md border-0 pl-10 text-gray-900 placeholder:text-gray-400 focus:ring-1 focus:ring-inset focus:ring-gray-200 focus-visible:outline-none sm:text-sm sm:leading-8"
  29. placeholder={t('common.operation.search')!}
  30. value={value}
  31. onChange={(e) => {
  32. onChange(e.target.value)
  33. }}
  34. />
  35. </div>
  36. )
  37. }
  38. export default React.memo(Search)