index.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. 'use client'
  2. import { RiCloseLine } from '@remixicon/react'
  3. import TagsFilter from './tags-filter'
  4. import ActionButton from '@/app/components/base/action-button'
  5. import cn from '@/utils/classnames'
  6. type SearchBoxProps = {
  7. search: string
  8. onSearchChange: (search: string) => void
  9. inputClassName?: string
  10. tags: string[]
  11. onTagsChange: (tags: string[]) => void
  12. size?: 'small' | 'large'
  13. placeholder?: string
  14. locale?: string
  15. }
  16. const SearchBox = ({
  17. search,
  18. onSearchChange,
  19. inputClassName,
  20. tags,
  21. onTagsChange,
  22. size = 'small',
  23. placeholder = '',
  24. locale,
  25. }: SearchBoxProps) => {
  26. return (
  27. <div
  28. className={cn(
  29. 'z-[11] flex items-center',
  30. size === 'large' && 'rounded-xl border border-components-chat-input-border bg-components-panel-bg-blur p-1.5 shadow-md',
  31. size === 'small' && 'rounded-lg bg-components-input-bg-normal p-0.5',
  32. inputClassName,
  33. )}
  34. >
  35. <TagsFilter
  36. tags={tags}
  37. onTagsChange={onTagsChange}
  38. size={size}
  39. locale={locale}
  40. />
  41. <div className='mx-1 h-3.5 w-[1px] bg-divider-regular'></div>
  42. <div className='relative flex grow items-center p-1 pl-2'>
  43. <div className='mr-2 flex w-full items-center'>
  44. <input
  45. className={cn(
  46. 'body-md-medium block grow appearance-none bg-transparent text-text-secondary outline-none',
  47. )}
  48. value={search}
  49. onChange={(e) => {
  50. onSearchChange(e.target.value)
  51. }}
  52. placeholder={placeholder}
  53. />
  54. {
  55. search && (
  56. <div className='absolute right-2 top-1/2 -translate-y-1/2'>
  57. <ActionButton onClick={() => onSearchChange('')}>
  58. <RiCloseLine className='h-4 w-4' />
  59. </ActionButton>
  60. </div>
  61. )
  62. }
  63. </div>
  64. </div>
  65. </div>
  66. )
  67. }
  68. export default SearchBox