261023_03_ENH: 자동완성 검색 일치 방식(fuzzy/contains) 옵션 추가
This commit is contained in:
@@ -3,14 +3,25 @@
|
||||
import * as React from 'react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { MultiSelect } from '@/components/common/multi-select'
|
||||
import type { MultiSelectOption, MultiSelectOptionTooltip, MultiSelectRef } from '@/components/common/multi-select'
|
||||
import type {
|
||||
MultiSelectOption,
|
||||
MultiSelectOptionTooltip,
|
||||
MultiSelectRef,
|
||||
MultiSelectSearchMatch,
|
||||
} from '@/components/common/multi-select'
|
||||
|
||||
export type { MultiSelectOption, MultiSelectOptionTooltip, MultiSelectRef } from '@/components/common/multi-select'
|
||||
export type {
|
||||
MultiSelectOption,
|
||||
MultiSelectOptionTooltip,
|
||||
MultiSelectRef,
|
||||
MultiSelectSearchMatch,
|
||||
} from '@/components/common/multi-select'
|
||||
|
||||
export interface KriAutoCompleteBaseProps<T> {
|
||||
items: T[]
|
||||
searchable?: boolean
|
||||
searchMode?: 'filter' | 'inputOnly'
|
||||
searchMatch?: MultiSelectSearchMatch
|
||||
resetScrollOnSearch?: boolean
|
||||
defaultSearchValue?: string
|
||||
onSearchValueChange?: (value: string) => void
|
||||
@@ -59,6 +70,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
searchMatch = 'fuzzy',
|
||||
resetScrollOnSearch = false,
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
@@ -102,6 +114,7 @@ export function KriMultiSelect<T = unknown>({
|
||||
badgeClassName={badgeClassName}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
searchMatch={searchMatch}
|
||||
resetScrollOnSearch={resetScrollOnSearch}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
@@ -140,6 +153,7 @@ function KriSingleSelectInner<T>({
|
||||
onChange,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
searchMatch = 'fuzzy',
|
||||
resetScrollOnSearch = false,
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
@@ -220,6 +234,7 @@ function KriSingleSelectInner<T>({
|
||||
badgeClassName={badgeClassName}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
searchMatch={searchMatch}
|
||||
resetScrollOnSearch={resetScrollOnSearch}
|
||||
defaultSearchValue={defaultSearchValue}
|
||||
onSearchValueChange={onSearchValueChange}
|
||||
|
||||
@@ -30,6 +30,7 @@ function MultiSelectInner<T>(
|
||||
hideSelectAll = false,
|
||||
searchable = true,
|
||||
searchMode = 'filter',
|
||||
searchMatch = 'fuzzy',
|
||||
resetScrollOnSearch = false,
|
||||
defaultSearchValue = '',
|
||||
onSearchValueChange,
|
||||
@@ -202,6 +203,7 @@ function MultiSelectInner<T>(
|
||||
selectedValues={selectedValues}
|
||||
searchable={searchable}
|
||||
searchMode={searchMode}
|
||||
searchMatch={searchMatch}
|
||||
resetScrollOnSearch={resetScrollOnSearch}
|
||||
searchValue={searchValue}
|
||||
onSearchValueChange={handleSearchChange}
|
||||
|
||||
@@ -13,14 +13,26 @@ import {
|
||||
} from '@/components/ui/command'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { cn } from '@/lib/utils'
|
||||
import type { MultiSelectGroup, MultiSelectOption, MultiSelectOptionTooltip, MultiSelectOptions } from './types'
|
||||
import type {
|
||||
MultiSelectGroup,
|
||||
MultiSelectOption,
|
||||
MultiSelectOptionTooltip,
|
||||
MultiSelectOptions,
|
||||
MultiSelectSearchMatch,
|
||||
} from './types'
|
||||
import { isGroupedOptions } from './utils'
|
||||
|
||||
// Case-insensitive substring match; equal scores keep the original option order.
|
||||
function containsFilter(value: string, search: string) {
|
||||
return value.toLowerCase().includes(search.toLowerCase()) ? 1 : 0
|
||||
}
|
||||
|
||||
interface MultiSelectContentProps<T> {
|
||||
options: MultiSelectOptions<T>
|
||||
selectedValues: string[]
|
||||
searchable: boolean
|
||||
searchMode: 'filter' | 'inputOnly'
|
||||
searchMatch?: MultiSelectSearchMatch
|
||||
searchValue: string
|
||||
resetScrollOnSearch?: boolean
|
||||
onSearchValueChange: (value: string) => void
|
||||
@@ -134,6 +146,7 @@ export function MultiSelectContent<T>({
|
||||
selectedValues,
|
||||
searchable,
|
||||
searchMode,
|
||||
searchMatch = 'fuzzy',
|
||||
searchValue,
|
||||
resetScrollOnSearch = false,
|
||||
onSearchValueChange,
|
||||
@@ -164,7 +177,10 @@ export function MultiSelectContent<T>({
|
||||
const tooltip = optionTooltip ? { mode: optionTooltip, className: optionTooltipClassName } : undefined
|
||||
|
||||
const content = (
|
||||
<Command shouldFilter={searchMode === 'filter'}>
|
||||
<Command
|
||||
shouldFilter={searchMode === 'filter'}
|
||||
filter={searchMatch === 'contains' ? containsFilter : undefined}
|
||||
>
|
||||
{searchable ? (
|
||||
<CommandInput
|
||||
value={searchValue}
|
||||
|
||||
@@ -9,6 +9,7 @@ export type {
|
||||
MultiSelectRef,
|
||||
MultiSelectResponsiveConfig,
|
||||
MultiSelectResponsiveSettings,
|
||||
MultiSelectSearchMatch,
|
||||
MultiSelectSelectionMode,
|
||||
MultiSelectVariant,
|
||||
} from './types'
|
||||
|
||||
@@ -30,6 +30,7 @@ export type MultiSelectOptions<T = unknown> = MultiSelectOption<T>[] | MultiSele
|
||||
export type MultiSelectSelectionMode = 'single' | 'multiple'
|
||||
export type MultiSelectVariant = 'default' | 'secondary' | 'destructive' | 'inverted'
|
||||
export type MultiSelectOptionTooltip = 'singleLine' | 'wrap'
|
||||
export type MultiSelectSearchMatch = 'fuzzy' | 'contains'
|
||||
|
||||
export interface MultiSelectResponsiveSettings {
|
||||
maxCount?: number
|
||||
@@ -65,6 +66,7 @@ export interface MultiSelectProps<T = unknown>
|
||||
hideSelectAll?: boolean
|
||||
searchable?: boolean
|
||||
searchMode?: 'filter' | 'inputOnly'
|
||||
searchMatch?: MultiSelectSearchMatch
|
||||
resetScrollOnSearch?: boolean
|
||||
defaultSearchValue?: string
|
||||
onSearchValueChange?: (value: string) => void
|
||||
|
||||
Reference in New Issue
Block a user