1
- import React , { useContext , useEffect , useState } from "react" ;
1
+ import { ReactNode , useEffect , useState } from "react" ;
2
2
import { Input , Section , sectionNames } from "lowcoder-design" ;
3
3
import { BoolControl } from "comps/controls/boolControl" ;
4
4
import { styleControl } from "comps/controls/styleControl" ;
5
5
import {
6
6
AnimationStyle ,
7
+ ChildrenMultiSelectStyle ,
8
+ ChildrenMultiSelectStyleType ,
7
9
InputFieldStyle ,
8
10
InputLikeStyle ,
9
11
InputLikeStyleType ,
@@ -16,7 +18,7 @@ import {
16
18
withExposingConfigs ,
17
19
} from "comps/generators/withExposing" ;
18
20
import styled , { css } from "styled-components" ;
19
- import { UICompBuilder , withDefault } from "../../generators" ;
21
+ import { UICompBuilder } from "../../generators" ;
20
22
import { FormDataPropertyView } from "../formComp/formDataConstants" ;
21
23
import { jsonControl } from "comps/controls/codeControl" ;
22
24
import { dropdownControl } from "comps/controls/dropdownControl" ;
@@ -37,7 +39,6 @@ import { trans } from "i18n";
37
39
import { IconControl } from "comps/controls/iconControl" ;
38
40
import { hasIcon } from "comps/utils" ;
39
41
import { InputRef } from "antd/es/input" ;
40
- import { default as ConfigProvider } from "antd/es/config-provider" ;
41
42
import { default as AutoComplete } from "antd/es/auto-complete" ;
42
43
import { RefControl } from "comps/controls/refControl" ;
43
44
import {
@@ -55,6 +56,7 @@ import {
55
56
autocompleteIconColor ,
56
57
componentSize ,
57
58
} from "./autoCompleteConstants" ;
59
+ import { DropdownStyled } from "../selectInputComp/selectCompConstants" ;
58
60
59
61
const InputStyle = styled ( Input ) < { $style : InputLikeStyleType } > `
60
62
box-shadow: ${ props => `${ props . $style ?. boxShadow } ${ props . $style ?. boxShadowColor } ` } ;
@@ -69,13 +71,10 @@ box-shadow: ${props=>`${props.$style?.boxShadow} ${props.$style?.boxShadowColor}
69
71
` }
70
72
` ;
71
73
72
-
73
74
const childrenMap = {
74
75
...textInputChildren ,
75
76
viewRef : RefControl < InputRef > ,
76
77
allowClear : BoolControl . DEFAULT_TRUE ,
77
- style : styleControl ( InputFieldStyle , 'style' ) ,
78
- labelStyle : styleControl ( LabelStyle , 'labelStyle' ) ,
79
78
prefixIcon : IconControl ,
80
79
suffixIcon : IconControl ,
81
80
items : jsonControl ( convertAutoCompleteData , autoCompleteDate ) ,
@@ -88,7 +87,10 @@ const childrenMap = {
88
87
autocompleteIconColor : dropdownControl ( autocompleteIconColor , "blue" ) ,
89
88
componentSize : dropdownControl ( componentSize , "small" ) ,
90
89
valueInItems : booleanExposingStateControl ( "valueInItems" ) ,
90
+ style : styleControl ( InputFieldStyle , 'style' ) ,
91
+ labelStyle : styleControl ( LabelStyle , 'labelStyle' ) ,
91
92
inputFieldStyle : styleControl ( InputLikeStyle , 'inputFieldStyle' ) ,
93
+ childrenInputFieldStyle : styleControl ( ChildrenMultiSelectStyle , 'childrenInputFieldStyle' ) ,
92
94
animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
93
95
} ;
94
96
@@ -155,59 +157,85 @@ let AutoCompleteCompBase = (function () {
155
157
required : props . required ,
156
158
children : (
157
159
< >
158
- < ConfigProvider
159
- theme = { {
160
- token : {
161
- colorBgContainer : props . inputFieldStyle . background ,
162
- colorBorder : props . inputFieldStyle . border ,
163
- borderRadius : parseInt ( props . inputFieldStyle . radius ) ,
164
- colorText : props . inputFieldStyle . text ,
165
- colorPrimary : props . inputFieldStyle . accent ,
166
- controlHeight : componentSize === "small" ? 30 : 38 ,
167
- } ,
160
+ < AutoComplete
161
+ disabled = { props . disabled }
162
+ value = { searchtext }
163
+ options = { items }
164
+ style = { { width : "100%" } }
165
+ onChange = { ( value : string , option ) => {
166
+ props . valueInItems . onChange ( false ) ;
167
+ setvalidateState ( textInputValidate ( getTextInputValidate ( ) ) ) ;
168
+ setsearchtext ( value ) ;
169
+ props . value . onChange ( value ) ;
170
+ props . onEvent ( "change" )
171
+ } }
172
+ onFocus = { ( ) => {
173
+ setActivationFlag ( true )
174
+ props . onEvent ( "focus" )
168
175
} }
169
- >
170
- < AutoComplete
171
- disabled = { props . disabled }
172
- value = { searchtext }
173
- options = { items }
174
- style = { { width : "100%" } }
175
- onChange = { ( value : string , option ) => {
176
- props . valueInItems . onChange ( false ) ;
177
- setvalidateState ( textInputValidate ( getTextInputValidate ( ) ) ) ;
178
- setsearchtext ( value ) ;
179
- props . value . onChange ( value ) ;
180
- props . onEvent ( "change" )
181
- } }
182
- onFocus = { ( ) => {
183
- setActivationFlag ( true )
184
- props . onEvent ( "focus" )
185
- } }
186
- onBlur = { ( ) => props . onEvent ( "blur" ) }
187
- onSelect = { ( data : string , option ) => {
188
- setsearchtext ( option [ valueOrLabel ] ) ;
189
- props . valueInItems . onChange ( true ) ;
190
- props . value . onChange ( option [ valueOrLabel ] ) ;
191
- props . onEvent ( "submit" ) ;
192
- } }
193
- filterOption = { ( inputValue : string , option ) => {
176
+ onBlur = { ( ) => props . onEvent ( "blur" ) }
177
+ onSelect = { ( data : string , option ) => {
178
+ setsearchtext ( option [ valueOrLabel ] ) ;
179
+ props . valueInItems . onChange ( true ) ;
180
+ props . value . onChange ( option [ valueOrLabel ] ) ;
181
+ props . onEvent ( "submit" ) ;
182
+ } }
183
+ filterOption = { ( inputValue : string , option ) => {
184
+ if ( ignoreCase ) {
185
+ if (
186
+ option ?. label &&
187
+ option ?. label
188
+ . toUpperCase ( )
189
+ . indexOf ( inputValue . toUpperCase ( ) ) !== - 1
190
+ )
191
+ return true ;
192
+ } else {
193
+ if ( option ?. label && option ?. label . indexOf ( inputValue ) !== - 1 )
194
+ return true ;
195
+ }
196
+ if (
197
+ chineseEnv &&
198
+ searchFirstPY &&
199
+ option ?. label &&
200
+ option . label
201
+ . spell ( "first" )
202
+ . toString ( )
203
+ . toLowerCase ( )
204
+ . indexOf ( inputValue . toLowerCase ( ) ) >= 0
205
+ )
206
+ return true ;
207
+ if (
208
+ chineseEnv &&
209
+ searchCompletePY &&
210
+ option ?. label &&
211
+ option . label
212
+ . spell ( )
213
+ . toString ( )
214
+ . toLowerCase ( )
215
+ . indexOf ( inputValue . toLowerCase ( ) ) >= 0
216
+ )
217
+ return true ;
218
+ if ( ! searchLabelOnly ) {
194
219
if ( ignoreCase ) {
195
220
if (
196
- option ?. label &&
197
- option ?. label
221
+ option ?. value &&
222
+ option ?. value
198
223
. toUpperCase ( )
199
224
. indexOf ( inputValue . toUpperCase ( ) ) !== - 1
200
225
)
201
226
return true ;
202
227
} else {
203
- if ( option ?. label && option ?. label . indexOf ( inputValue ) !== - 1 )
228
+ if (
229
+ option ?. value &&
230
+ option ?. value . indexOf ( inputValue ) !== - 1
231
+ )
204
232
return true ;
205
233
}
206
234
if (
207
235
chineseEnv &&
208
236
searchFirstPY &&
209
- option ?. label &&
210
- option . label
237
+ option ?. value &&
238
+ option . value
211
239
. spell ( "first" )
212
240
. toString ( )
213
241
. toLowerCase ( )
@@ -217,73 +245,40 @@ let AutoCompleteCompBase = (function () {
217
245
if (
218
246
chineseEnv &&
219
247
searchCompletePY &&
220
- option ?. label &&
221
- option . label
248
+ option ?. value &&
249
+ option . value
222
250
. spell ( )
223
251
. toString ( )
224
252
. toLowerCase ( )
225
253
. indexOf ( inputValue . toLowerCase ( ) ) >= 0
226
254
)
227
255
return true ;
228
- if ( ! searchLabelOnly ) {
229
- if ( ignoreCase ) {
230
- if (
231
- option ?. value &&
232
- option ?. value
233
- . toUpperCase ( )
234
- . indexOf ( inputValue . toUpperCase ( ) ) !== - 1
235
- )
236
- return true ;
237
- } else {
238
- if (
239
- option ?. value &&
240
- option ?. value . indexOf ( inputValue ) !== - 1
241
- )
242
- return true ;
243
- }
244
- if (
245
- chineseEnv &&
246
- searchFirstPY &&
247
- option ?. value &&
248
- option . value
249
- . spell ( "first" )
250
- . toString ( )
251
- . toLowerCase ( )
252
- . indexOf ( inputValue . toLowerCase ( ) ) >= 0
253
- )
254
- return true ;
255
- if (
256
- chineseEnv &&
257
- searchCompletePY &&
258
- option ?. value &&
259
- option . value
260
- . spell ( )
261
- . toString ( )
262
- . toLowerCase ( )
263
- . indexOf ( inputValue . toLowerCase ( ) ) >= 0
264
- )
265
- return true ;
266
- }
267
- return false ;
268
- } }
269
- >
270
- < InputStyle
271
- ref = { props . viewRef }
272
- placeholder = { placeholder }
273
- allowClear = { props . allowClear }
274
- $style = { props . inputFieldStyle }
275
- prefix = { hasIcon ( props . prefixIcon ) && props . prefixIcon }
276
- suffix = { hasIcon ( props . suffixIcon ) && props . suffixIcon }
277
- status = { getValidate ( validateState ) }
278
- onPressEnter = { undefined }
279
- />
280
- </ AutoComplete >
281
- </ ConfigProvider >
256
+ }
257
+ return false ;
258
+ } }
259
+ dropdownRender = { ( originNode : ReactNode ) => (
260
+ < DropdownStyled $style = { props . childrenInputFieldStyle as ChildrenMultiSelectStyleType } >
261
+ { originNode }
262
+ </ DropdownStyled >
263
+ ) }
264
+ >
265
+ < InputStyle
266
+ ref = { props . viewRef }
267
+ placeholder = { placeholder }
268
+ allowClear = { props . allowClear }
269
+ $style = { props . inputFieldStyle }
270
+ prefix = { hasIcon ( props . prefixIcon ) && props . prefixIcon }
271
+ suffix = { hasIcon ( props . suffixIcon ) && props . suffixIcon }
272
+ status = { getValidate ( validateState ) }
273
+ onPressEnter = { undefined }
274
+ />
275
+ </ AutoComplete >
282
276
</ >
283
277
) ,
284
278
style : props . style ,
285
279
labelStyle : props . labelStyle ,
286
- inputFieldStyle :props . inputFieldStyle ,
280
+ inputFieldStyle : props . inputFieldStyle ,
281
+ childrenInputFieldStyle : props . childrenInputFieldStyle ,
287
282
animationStyle : props . animationStyle ,
288
283
showValidationWhenEmpty : props . showValidationWhenEmpty ,
289
284
...validateState ,
@@ -350,6 +345,9 @@ let AutoCompleteCompBase = (function () {
350
345
< Section name = { sectionNames . inputFieldStyle } >
351
346
{ children . inputFieldStyle . getPropertyView ( ) }
352
347
</ Section >
348
+ < Section name = { sectionNames . childrenInputFieldStyle } >
349
+ { children . childrenInputFieldStyle . getPropertyView ( ) }
350
+ </ Section >
353
351
< Section
354
352
name = { sectionNames . animationStyle }
355
353
hasTooltip = { true }
0 commit comments