dify/web/app/components/plugins/marketplace/search-box/index.tsx

69 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-10-08 17:57:46 +08:00
'use client'
import { RiCloseLine } from '@remixicon/react'
import TagsFilter from './tags-filter'
import ActionButton from '@/app/components/base/action-button'
2024-10-12 12:46:29 +08:00
import cn from '@/utils/classnames'
2024-10-08 17:57:46 +08:00
2024-10-31 18:54:13 +08:00
type SearchBoxProps = {
search: string
onSearchChange: (search: string) => void
inputClassName?: string
tags: string[]
onTagsChange: (tags: string[]) => void
2024-11-01 11:26:36 +08:00
size?: 'small' | 'large'
placeholder?: string
2024-11-06 11:55:19 +08:00
locale?: string
2024-10-31 18:54:13 +08:00
}
const SearchBox = ({
search,
onSearchChange,
inputClassName,
tags,
onTagsChange,
2024-11-01 11:26:36 +08:00
size = 'small',
2024-11-06 11:55:19 +08:00
placeholder = '',
locale,
2024-10-31 18:54:13 +08:00
}: SearchBoxProps) => {
2024-10-08 17:57:46 +08:00
return (
2024-10-12 12:46:29 +08:00
<div
className={cn(
2024-11-01 11:26:36 +08:00
'flex items-center z-[11]',
size === 'large' && 'p-1.5 bg-components-panel-bg-blur rounded-xl shadow-md border border-components-chat-input-border',
size === 'small' && 'p-0.5 bg-components-input-bg-normal rounded-lg',
2024-10-31 18:54:13 +08:00
inputClassName,
2024-10-12 12:46:29 +08:00
)}
>
2024-10-31 18:54:13 +08:00
<TagsFilter
tags={tags}
onTagsChange={onTagsChange}
2024-11-01 11:26:36 +08:00
size={size}
2024-11-06 11:55:19 +08:00
locale={locale}
2024-10-31 18:54:13 +08:00
/>
2024-10-08 17:57:46 +08:00
<div className='mx-1 w-[1px] h-3.5 bg-divider-regular'></div>
<div className='grow flex items-center p-1 pl-2'>
2024-11-07 15:37:22 +08:00
<div className='flex items-center mr-2 w-full'>
2024-10-08 17:57:46 +08:00
<input
2024-11-01 11:26:36 +08:00
className={cn(
'grow block outline-none appearance-none body-md-medium text-text-secondary bg-transparent',
)}
2024-10-31 18:54:13 +08:00
value={search}
2024-10-08 17:57:46 +08:00
onChange={(e) => {
2024-10-31 18:54:13 +08:00
onSearchChange(e.target.value)
2024-10-08 17:57:46 +08:00
}}
2024-11-01 11:26:36 +08:00
placeholder={placeholder}
2024-10-08 17:57:46 +08:00
/>
2024-10-09 15:06:09 +08:00
{
2024-11-01 11:26:36 +08:00
search && (
<ActionButton onClick={() => onSearchChange('')}>
2024-10-09 15:06:09 +08:00
<RiCloseLine className='w-4 h-4' />
</ActionButton>
)
}
2024-10-08 17:57:46 +08:00
</div>
</div>
</div>
)
}
export default SearchBox