feat: search box

pull/12372/head
StyleZhang 2 years ago
parent 207b589458
commit 197f1b3957

@ -1,6 +1,5 @@
'use client' 'use client'
import { RiCloseLine } from '@remixicon/react' import { RiCloseLine } from '@remixicon/react'
import { useMarketplaceContext } from '../context'
import TagsFilter from './tags-filter' import TagsFilter from './tags-filter'
import ActionButton from '@/app/components/base/action-button' import ActionButton from '@/app/components/base/action-button'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
@ -11,6 +10,8 @@ type SearchBoxProps = {
inputClassName?: string inputClassName?: string
tags: string[] tags: string[]
onTagsChange: (tags: string[]) => void onTagsChange: (tags: string[]) => void
size?: 'small' | 'large'
placeholder?: string
} }
const SearchBox = ({ const SearchBox = ({
search, search,
@ -18,36 +19,39 @@ const SearchBox = ({
inputClassName, inputClassName,
tags, tags,
onTagsChange, onTagsChange,
size = 'small',
placeholder = 'Search tools...',
}: SearchBoxProps) => { }: SearchBoxProps) => {
const intersected = useMarketplaceContext(v => v.intersected)
const searchPluginText = useMarketplaceContext(v => v.searchPluginText)
const handleSearchPluginTextChange = useMarketplaceContext(v => v.handleSearchPluginTextChange)
return ( return (
<div <div
className={cn( className={cn(
'sticky top-3 flex items-center mx-auto p-1.5 w-[640px] h-11 border border-components-chat-input-border bg-components-panel-bg-blur rounded-xl shadow-md z-[11]', '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',
inputClassName, inputClassName,
!intersected && 'w-[508px] transition-[width] duration-300',
)} )}
> >
<TagsFilter <TagsFilter
tags={tags} tags={tags}
onTagsChange={onTagsChange} onTagsChange={onTagsChange}
size={size}
/> />
<div className='mx-1 w-[1px] h-3.5 bg-divider-regular'></div> <div className='mx-1 w-[1px] h-3.5 bg-divider-regular'></div>
<div className='grow flex items-center p-1 pl-2'> <div className='grow flex items-center p-1 pl-2'>
<div className='flex items-center mr-2 py-0.5 w-full'> <div className='flex items-center mr-2 py-0.5 w-full'>
<input <input
className='grow block outline-none appearance-none body-md-medium text-text-secondary' className={cn(
'grow block outline-none appearance-none body-md-medium text-text-secondary bg-transparent',
)}
value={search} value={search}
onChange={(e) => { onChange={(e) => {
onSearchChange(e.target.value) onSearchChange(e.target.value)
}} }}
placeholder={placeholder}
/> />
{ {
searchPluginText && ( search && (
<ActionButton onClick={() => handleSearchPluginTextChange('')}> <ActionButton onClick={() => onSearchChange('')}>
<RiCloseLine className='w-4 h-4' /> <RiCloseLine className='w-4 h-4' />
</ActionButton> </ActionButton>
) )

@ -12,11 +12,15 @@ const SearchBoxWrapper = () => {
return ( return (
<SearchBox <SearchBox
inputClassName={cn(!intersected && 'w-[508px] transition-[width] duration-300')} inputClassName={cn(
'sticky top-3 mx-auto w-[640px]',
!intersected && 'w-[508px] transition-[width] duration-300',
)}
search={searchPluginText} search={searchPluginText}
onSearchChange={handleSearchPluginTextChange} onSearchChange={handleSearchPluginTextChange}
tags={filterPluginTags} tags={filterPluginTags}
onTagsChange={handleFilterPluginTagsChange} onTagsChange={handleFilterPluginTagsChange}
size='large'
/> />
) )
} }

@ -18,10 +18,12 @@ import Input from '@/app/components/base/input'
type TagsFilterProps = { type TagsFilterProps = {
tags: string[] tags: string[]
onTagsChange: (tags: string[]) => void onTagsChange: (tags: string[]) => void
size: 'small' | 'large'
} }
const TagsFilter = ({ const TagsFilter = ({
tags, tags,
onTagsChange, onTagsChange,
size,
}: TagsFilterProps) => { }: TagsFilterProps) => {
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const [searchText, setSearchText] = useState('') const [searchText, setSearchText] = useState('')
@ -56,7 +58,9 @@ const TagsFilter = ({
> >
<PortalToFollowElemTrigger onClick={() => setOpen(v => !v)}> <PortalToFollowElemTrigger onClick={() => setOpen(v => !v)}>
<div className={cn( <div className={cn(
'flex items-center px-2 py-1 h-8 text-text-tertiary rounded-lg hover:bg-state-base-hover cursor-pointer', 'flex items-center text-text-tertiary rounded-lg hover:bg-state-base-hover cursor-pointer',
size === 'large' && 'px-2 py-1 h-8',
size === 'small' && 'pr-1.5 py-0.5 h-7 pl-1 ',
selectedTagsLength && 'text-text-secondary', selectedTagsLength && 'text-text-secondary',
open && 'bg-state-base-hover', open && 'bg-state-base-hover',
)}> )}>
@ -65,6 +69,8 @@ const TagsFilter = ({
</div> </div>
<div className={cn( <div className={cn(
'flex items-center p-1 system-sm-medium', 'flex items-center p-1 system-sm-medium',
size === 'large' && 'p-1',
size === 'small' && 'px-0.5 py-1',
)}> )}>
{ {
!selectedTagsLength && 'All Tags' !selectedTagsLength && 'All Tags'
@ -95,7 +101,7 @@ const TagsFilter = ({
} }
</div> </div>
</PortalToFollowElemTrigger> </PortalToFollowElemTrigger>
<PortalToFollowElemContent className='z-10'> <PortalToFollowElemContent className='z-[1000]'>
<div className='w-[240px] border-[0.5px] border-components-panel-border bg-components-panel-bg-blur rounded-xl shadow-lg'> <div className='w-[240px] border-[0.5px] border-components-panel-border bg-components-panel-bg-blur rounded-xl shadow-lg'>
<div className='p-2 pb-1'> <div className='p-2 pb-1'>
<Input <Input

@ -19,6 +19,7 @@ import {
fetchAllWorkflowTools, fetchAllWorkflowTools,
} from '@/service/tools' } from '@/service/tools'
import type { BlockEnum, ToolWithProvider } from '@/app/components/workflow/types' import type { BlockEnum, ToolWithProvider } from '@/app/components/workflow/types'
import SearchBox from '@/app/components/plugins/marketplace/search-box'
type Props = { type Props = {
disabled: boolean disabled: boolean
@ -83,7 +84,14 @@ const ToolPicker: FC<Props> = ({
<PortalToFollowElemContent className='z-[1000]'> <PortalToFollowElemContent className='z-[1000]'>
<div className="relative w-[320px] min-h-20 bg-white"> <div className="relative w-[320px] min-h-20 bg-white">
<input placeholder='search holder' value={searchText} onChange={e => setSearchText(e.target.value)} /> <SearchBox
search={searchText}
onSearchChange={setSearchText}
tags={[]}
onTagsChange={() => {}}
size='small'
placeholder='Search tools...'
/>
<AllTools <AllTools
className='mt-1' className='mt-1'
searchText={searchText} searchText={searchText}

Loading…
Cancel
Save