@@ -2,6 +2,7 @@ import React, { useState } from 'react';
22import { Input , type InputProps , Tooltip } from 'antd' ;
33import classNames from 'classnames' ;
44
5+ import useLocale from '../locale/useLocale' ;
56import { CaseSensitiveIcon , FrontIcon , PreciseIcon , TailIcon } from './icons' ;
67import './match.scss' ;
78
@@ -29,30 +30,11 @@ interface IMatchProps extends Omit<InputProps, 'suffix'> {
2930 onSearch ?: ( value : string , searchType : SearchType ) => void ;
3031}
3132
32- const searchTypeList = [
33- {
34- key : 'caseSensitive' ,
35- tip : '区分大小写匹配' ,
36- } ,
37- {
38- key : 'precise' ,
39- tip : '精确匹配' ,
40- } ,
41- {
42- key : 'front' ,
43- tip : '头部匹配' ,
44- } ,
45- {
46- key : 'tail' ,
47- tip : '尾部匹配' ,
48- } ,
49- ] as const ;
50-
5133export default function Match ( {
5234 className,
5335 value,
5436 searchType,
55- filterOptions = searchTypeList . map ( ( i ) => i . key ) ,
37+ filterOptions : propFilterOptions ,
5638 onTypeChange,
5739 onSearch,
5840 onChange,
@@ -62,12 +44,35 @@ export default function Match({
6244 const [ internalValue , setValue ] = useState < string > ( '' ) ;
6345 const [ internalSearchType , setSearchType ] = useState < SearchType > ( 'fuzzy' ) ;
6446
47+ const locale = useLocale ( 'Input' ) ;
48+
6549 const handleTypeChange = ( key : SearchType ) => {
6650 const next = realSearchType === key ? 'fuzzy' : key ;
6751 onTypeChange ?.( next ) ;
6852 setSearchType ( next ) ;
6953 } ;
7054
55+ const searchTypeList = [
56+ {
57+ key : 'caseSensitive' ,
58+ tip : locale . case ,
59+ } ,
60+ {
61+ key : 'precise' ,
62+ tip : locale . precise ,
63+ } ,
64+ {
65+ key : 'front' ,
66+ tip : locale . front ,
67+ } ,
68+ {
69+ key : 'tail' ,
70+ tip : locale . tail ,
71+ } ,
72+ ] as const ;
73+
74+ const filterOptions = propFilterOptions || searchTypeList . map ( ( i ) => i . key ) ;
75+
7176 const options = searchTypeList . filter ( ( i ) => filterOptions . includes ( i . key ) ) ;
7277
7378 const realSearchType = searchType || internalSearchType ;
0 commit comments