You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. 'use client'
  2. import { RiCloseLine, RiSearchLine } 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. import { RiAddLine } from '@remixicon/react'
  7. type SearchBoxProps = {
  8. search: string
  9. onSearchChange: (search: string) => void
  10. wrapperClassName?: string
  11. inputClassName?: string
  12. tags: string[]
  13. onTagsChange: (tags: string[]) => void
  14. size?: 'small' | 'large'
  15. placeholder?: string
  16. locale?: string
  17. supportAddCustomTool?: boolean
  18. onShowAddCustomCollectionModal?: () => void
  19. onAddedCustomTool?: () => void
  20. }
  21. const SearchBox = ({
  22. search,
  23. onSearchChange,
  24. wrapperClassName,
  25. inputClassName,
  26. tags,
  27. onTagsChange,
  28. size = 'small',
  29. placeholder = '',
  30. locale,
  31. supportAddCustomTool,
  32. onShowAddCustomCollectionModal,
  33. }: SearchBoxProps) => {
  34. return (
  35. <div
  36. className={cn('z-[11] flex items-center', wrapperClassName)}
  37. >
  38. <div className={
  39. cn('flex items-center',
  40. size === 'large' && 'rounded-xl border border-components-chat-input-border bg-components-panel-bg-blur p-1.5 shadow-md',
  41. size === 'small' && 'rounded-lg bg-components-input-bg-normal p-0.5',
  42. inputClassName,
  43. )
  44. }>
  45. <div className='relative flex grow items-center p-1 pl-2'>
  46. <div className='mr-2 flex w-full items-center'>
  47. <RiSearchLine className='mr-1.5 size-4 text-text-placeholder' />
  48. <input
  49. className={cn(
  50. 'body-md-medium block grow appearance-none bg-transparent text-text-secondary outline-none',
  51. )}
  52. value={search}
  53. onChange={(e) => {
  54. onSearchChange(e.target.value)
  55. }}
  56. placeholder={placeholder}
  57. />
  58. {
  59. search && (
  60. <div className='absolute right-2 top-1/2 -translate-y-1/2'>
  61. <ActionButton onClick={() => onSearchChange('')}>
  62. <RiCloseLine className='h-4 w-4' />
  63. </ActionButton>
  64. </div>
  65. )
  66. }
  67. </div>
  68. </div>
  69. <div className='mx-1 h-3.5 w-[1px] bg-divider-regular'></div>
  70. <TagsFilter
  71. tags={tags}
  72. onTagsChange={onTagsChange}
  73. size={size}
  74. locale={locale}
  75. />
  76. </div>
  77. {supportAddCustomTool && (
  78. <div className='flex shrink-0 items-center'>
  79. <ActionButton
  80. className='ml-2 rounded-full bg-components-button-primary-bg text-components-button-primary-text hover:bg-components-button-primary-bg hover:text-components-button-primary-text'
  81. onClick={onShowAddCustomCollectionModal}
  82. >
  83. <RiAddLine className='h-4 w-4' />
  84. </ActionButton>
  85. </div>
  86. )}
  87. </div>
  88. )
  89. }
  90. export default SearchBox