@@ -22,6 +22,9 @@ import { debounce } from "lodash";
22
22
import Spin from "antd/es/spin" ;
23
23
import { ControlParams } from "./controlParams" ;
24
24
import { getBase64 } from "@lowcoder-ee/util/fileUtils" ;
25
+ import Flex from "antd/es/flex" ;
26
+ import Typography from "antd/es/typography" ;
27
+ import LoadingOutlined from "@ant-design/icons/LoadingOutlined" ;
25
28
26
29
const ButtonWrapper = styled . div `
27
30
width: 100%;
@@ -32,15 +35,7 @@ const ButtonIconWrapper = styled.div`
32
35
display: flex;
33
36
width: 18px;
34
37
` ;
35
- const ButtonText = styled . div `
36
- margin: 0 4px;
37
- flex: 1;
38
- width: 0px;
39
- line-height: 20px;
40
- overflow: hidden;
41
- text-overflow: ellipsis;
42
- text-align: left;
43
- ` ;
38
+
44
39
const StyledDeleteInputIcon = styled ( DeleteInputIcon ) `
45
40
margin-left: auto;
46
41
cursor: pointer;
@@ -61,7 +56,10 @@ const Wrapper = styled.div`
61
56
}
62
57
` ;
63
58
const PopupContainer = styled . div `
59
+ display: flex;
60
+ flex-direction: column;
64
61
width: 580px;
62
+ min-height: 480px;
65
63
background: #ffffff;
66
64
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
67
65
border-radius: 8px;
@@ -167,15 +165,6 @@ const IconWrapper = styled.div`
167
165
justify-content: center;
168
166
` ;
169
167
170
- const IconKeyDisplay = styled . div `
171
- font-size: 8px;
172
- color: #8b8fa3;
173
- margin-top: 4px; /* Space between the icon and the text */
174
- text-align: center;
175
- word-wrap: break-word; /* Ensure text wraps */
176
- width: 100%; /* Ensure the container can grow */
177
- ` ;
178
-
179
168
export enum AssetType {
180
169
ICON = "icon" ,
181
170
ILLUSTRATION = "illustration" ,
@@ -212,6 +201,7 @@ export const IconPicker = (props: {
212
201
} ) => {
213
202
const [ visible , setVisible ] = useState ( false )
214
203
const [ loading , setLoading ] = useState ( false )
204
+ const [ searchText , setSearchText ] = useState < string > ( '' )
215
205
const [ searchResults , setSearchResults ] = useState < Array < any > > ( [ ] ) ;
216
206
217
207
const onChangeRef = useRef ( props . onChange ) ;
@@ -252,14 +242,14 @@ export const IconPicker = (props: {
252
242
}
253
243
}
254
244
255
- const fetchDownloadUrl = async ( uuid : string ) => {
245
+ const fetchDownloadUrl = async ( uuid : string , preview : string ) => {
256
246
try {
257
247
const result = await IconscoutApi . download ( uuid , {
258
248
format : props . assetType === AssetType . LOTTIE ? 'lottie' : 'svg' ,
259
249
} ) ;
260
250
261
251
downloadAsset ( uuid , result . download_url , ( assetUrl : string ) => {
262
- onChangeIcon ( uuid , assetUrl , result . url ) ;
252
+ onChangeIcon ( uuid , assetUrl , preview ) ;
263
253
} ) ;
264
254
} catch ( error ) {
265
255
console . error ( error ) ;
@@ -268,6 +258,7 @@ export const IconPicker = (props: {
268
258
269
259
const handleChange = debounce ( ( e ) => {
270
260
fetchResults ( e . target . value ) ;
261
+ setSearchText ( e . target . value ) ;
271
262
} , 500 ) ;
272
263
273
264
const rowRenderer = useCallback (
@@ -280,7 +271,10 @@ export const IconPicker = (props: {
280
271
key = { icon . uuid }
281
272
tabIndex = { 0 }
282
273
onClick = { ( ) => {
283
- fetchDownloadUrl ( icon . uuid ) ;
274
+ fetchDownloadUrl (
275
+ icon . uuid ,
276
+ props . assetType === AssetType . ICON ? icon . urls . png_64 : icon . urls . thumb ,
277
+ ) ;
284
278
} }
285
279
>
286
280
< IconWrapper >
@@ -310,12 +304,8 @@ export const IconPicker = (props: {
310
304
< Popover
311
305
trigger = { 'click' }
312
306
placement = "left"
313
- // align={{ offset: [props.leftOffset ?? 0, 0, 0, 0] }}
314
307
open = { visible }
315
308
onOpenChange = { setVisible }
316
- // getPopupContainer={parent ? () => parent : undefined}
317
- // hide the original background when dragging the popover is allowed
318
- // when dragging is allowed, always re-location to avoid the popover exceeds the screen
319
309
styles = { {
320
310
body : {
321
311
border : "none" ,
@@ -339,20 +329,29 @@ export const IconPicker = (props: {
339
329
/>
340
330
< StyledSearchIcon />
341
331
</ SearchDiv >
342
- < IconListWrapper >
343
- { loading && (
344
- < Spin />
345
- ) }
346
- { ! loading && (
332
+ { loading && (
333
+ < Flex align = "center" justify = "center" style = { { flex : 1 } } >
334
+ < Spin indicator = { < LoadingOutlined style = { { fontSize : 25 } } spin /> } />
335
+ </ Flex >
336
+ ) }
337
+ { ! loading && Boolean ( searchText ) && ! searchResults ?. length && (
338
+ < Flex align = "center" justify = "center" style = { { flex : 1 } } >
339
+ < Typography . Text type = "secondary" >
340
+ No results found.
341
+ </ Typography . Text >
342
+ </ Flex >
343
+ ) }
344
+ { ! loading && Boolean ( searchText ) && searchResults ?. length && (
345
+ < IconListWrapper >
347
346
< IconList
348
347
width = { 550 }
349
348
height = { 400 }
350
349
rowHeight = { 80 }
351
350
rowCount = { Math . ceil ( searchResults . length / columnNum ) }
352
351
rowRenderer = { rowRenderer }
353
352
/>
354
- ) }
355
- </ IconListWrapper >
353
+ </ IconListWrapper >
354
+ ) }
356
355
</ PopupContainer >
357
356
</ Draggable >
358
357
}
@@ -365,7 +364,7 @@ export const IconPicker = (props: {
365
364
< video style = { { 'width' : '100%' } } src = { props . preview } autoPlay />
366
365
) }
367
366
{ props . assetType !== AssetType . LOTTIE && (
368
- < IconControlView value = { props . preview } uuid = { props . uuid } />
367
+ < IconControlView value = { props . value } uuid = { props . uuid } />
369
368
) }
370
369
</ ButtonIconWrapper >
371
370
< StyledDeleteInputIcon
0 commit comments