1
1
import * as React from 'react' ;
2
2
import { useState } from 'react' ;
3
3
import { IActionBarItemProps } from '../actionBar' ;
4
- import Input from './input' ;
4
+ import Input , { InfoTypeEnum } from './input' ;
5
5
import { classNames } from 'mo/common/className' ;
6
6
import {
7
7
baseInputClassName ,
@@ -16,6 +16,7 @@ export interface ISearchProps extends React.ComponentProps<any> {
16
16
values ?: ( string | undefined ) [ ] ;
17
17
placeholders ?: string [ ] ;
18
18
addons ?: ( IActionBarItemProps [ ] | undefined ) [ ] ;
19
+ validationInfo ?: string | { type : keyof typeof InfoTypeEnum ; text : string } ;
19
20
onAddonClick ?: ( addon ) => void ;
20
21
onButtonClick ?: ( status : boolean ) => void ;
21
22
/**
@@ -29,14 +30,15 @@ export interface ISearchProps extends React.ComponentProps<any> {
29
30
/**
30
31
* onSearch always be triggered behind onChange or onClick
31
32
*/
32
- onSearch ?: ( queryVal : string | undefined , replaceVal ?: string ) => void ;
33
+ onSearch ?: ( value ?: ( string | undefined ) [ ] ) => void ;
33
34
}
34
35
35
36
export function Search ( props : ISearchProps ) {
36
37
const {
37
38
className = '' ,
38
39
style,
39
40
placeholders = [ ] ,
41
+ validationInfo : rawInfo ,
40
42
addons = [ ] ,
41
43
values = [ ] ,
42
44
onAddonClick,
@@ -62,7 +64,7 @@ export function Search(props: ISearchProps) {
62
64
const onToggleReplaceBtn = ( ) => {
63
65
setShowReplace ( ! isShowReplace ) ;
64
66
onButtonClick ?.( ! isShowReplace ) ;
65
- onSearch ?.( searchVal , replaceVal ) ;
67
+ onSearch ?.( [ searchVal , replaceVal ] ) ;
66
68
} ;
67
69
68
70
const handleSearchChange = (
@@ -73,15 +75,26 @@ export function Search(props: ISearchProps) {
73
75
const values =
74
76
source === 'search' ? [ value , replaceVal ] : [ searchVal , value ] ;
75
77
onChange ( values ) ;
76
- onSearch ?.( searchVal , replaceVal ) ;
78
+ onSearch ?.( values ) ;
77
79
}
78
80
} ;
79
81
80
82
const handleToolbarClick = ( addon ) => {
81
83
onAddonClick ?.( addon ) ;
82
- onSearch ?.( searchVal , replaceVal ) ;
84
+ onSearch ?.( [ searchVal , replaceVal ] ) ;
83
85
} ;
84
86
87
+ const getInfoFromRaw = ( ) => {
88
+ if ( rawInfo ) {
89
+ if ( typeof rawInfo === 'string' ) {
90
+ return { type : InfoTypeEnum . info , text : rawInfo } ;
91
+ }
92
+ return rawInfo ;
93
+ }
94
+ return undefined ;
95
+ } ;
96
+
97
+ const validationInfo = getInfoFromRaw ( ) ;
85
98
return (
86
99
< div
87
100
style = { style }
@@ -98,6 +111,7 @@ export function Search(props: ISearchProps) {
98
111
baseInputClassName ,
99
112
searchTargetContainerClassName
100
113
) }
114
+ info = { validationInfo }
101
115
placeholder = { searchPlaceholder }
102
116
onChange = { ( v ) => handleSearchChange ( v , 'search' ) }
103
117
toolbarData = { searchAddons }
0 commit comments