1
1
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" ;
2
2
import type { IconDefinition } from "@fortawesome/free-regular-svg-icons" ;
3
- import { default as Popover } from "antd/es/popover " ;
4
- import { ActionType } from ' @rc-component/trigger/lib/interface' ;
3
+ import { Popover } from "antd" ;
4
+ import { ActionType } from " @rc-component/trigger/lib/interface" ;
5
5
import { TacoInput } from "components/tacoInput" ;
6
6
import { Tooltip } from "components/toolTip" ;
7
7
import { trans } from "i18n/design" ;
8
8
import _ from "lodash" ;
9
- import { ReactNode , useEffect , useCallback , useMemo , useRef , useState } from "react" ;
9
+ import {
10
+ ReactNode ,
11
+ useEffect ,
12
+ useCallback ,
13
+ useMemo ,
14
+ useRef ,
15
+ useState ,
16
+ } from "react" ;
10
17
import Draggable from "react-draggable" ;
11
18
import { default as List , ListRowProps } from "react-virtualized/dist/es/List" ;
12
19
import styled from "styled-components" ;
13
20
import { CloseIcon , SearchIcon } from "icons" ;
21
+ import { ANTDICON } from "../../../../lowcoder/src/comps/comps/timelineComp/antIcon" ;
14
22
15
23
const PopupContainer = styled . div `
16
24
width: 408px;
@@ -110,11 +118,23 @@ const IconItemContainer = styled.div`
110
118
111
119
class Icon {
112
120
readonly title : string ;
113
- constructor ( readonly def : IconDefinition , readonly names : string [ ] ) {
114
- this . title = def . iconName . split ( "-" ) . map ( _ . upperFirst ) . join ( " " ) ;
121
+ constructor ( readonly def : IconDefinition | any , readonly names : string [ ] ) {
122
+ if ( def ?. iconName ) {
123
+ this . title = def . iconName . split ( "-" ) . map ( _ . upperFirst ) . join ( " " ) ;
124
+ } else {
125
+ this . title = names [ 0 ] . slice ( 5 ) ;
126
+ this . def = def ;
127
+ }
115
128
}
116
129
getView ( ) {
117
- return < FontAwesomeIcon icon = { this . def } style = { { width : "1em" , height : "1em" } } /> ;
130
+ if ( this . names [ 0 ] ?. startsWith ( "antd/" ) ) return this . def ;
131
+ else
132
+ return (
133
+ < FontAwesomeIcon
134
+ icon = { this . def }
135
+ style = { { width : "1em" , height : "1em" } }
136
+ />
137
+ ) ;
118
138
}
119
139
}
120
140
@@ -144,14 +164,25 @@ async function getAllIcons() {
144
164
}
145
165
}
146
166
}
167
+ //append ant icon
168
+ for ( let key of Object . keys ( ANTDICON ) ) {
169
+ ret [ "antd/" + key ] = new Icon (
170
+ ANTDICON [ key . toLowerCase ( ) as keyof typeof ANTDICON ] ,
171
+ [ "antd/" + key ]
172
+ ) ;
173
+ }
147
174
allIcons = ret ;
148
175
return ret ;
149
176
}
150
177
151
178
export const iconPrefix = "/icon:" ;
152
179
153
180
export function removeQuote ( value ?: string ) {
154
- return value ? ( value . startsWith ( '"' ) && value . endsWith ( '"' ) ? value . slice ( 1 , - 1 ) : value ) : "" ;
181
+ return value
182
+ ? value . startsWith ( '"' ) && value . endsWith ( '"' )
183
+ ? value . slice ( 1 , - 1 )
184
+ : value
185
+ : "" ;
155
186
}
156
187
157
188
function getIconKey ( value ?: string ) {
@@ -171,7 +202,8 @@ export function useIcon(value?: string) {
171
202
function search (
172
203
allIcons : Record < string , Icon > ,
173
204
searchText : string ,
174
- searchKeywords ?: Record < string , string >
205
+ searchKeywords ?: Record < string , string > ,
206
+ IconType ?: "OnlyAntd" | "All" | "default" | undefined
175
207
) {
176
208
const tokens = searchText
177
209
. toLowerCase ( )
@@ -182,6 +214,8 @@ function search(
182
214
if ( icon . names . length === 0 ) {
183
215
return false ;
184
216
}
217
+ if ( IconType === "OnlyAntd" && ! key . startsWith ( "antd/" ) ) return false ;
218
+ if ( IconType === "default" && key . startsWith ( "antd/" ) ) return false ;
185
219
let text = icon . names
186
220
. flatMap ( ( name ) => [ name , searchKeywords ?. [ name ] ] )
187
221
. filter ( ( t ) => t )
@@ -198,16 +232,20 @@ const IconPopup = (props: {
198
232
label ?: ReactNode ;
199
233
onClose : ( ) => void ;
200
234
searchKeywords ?: Record < string , string > ;
235
+ IconType ?: "OnlyAntd" | "All" | "default" | undefined ;
201
236
} ) => {
202
237
const [ searchText , setSearchText ] = useState ( "" ) ;
203
238
const [ allIcons , setAllIcons ] = useState < Record < string , Icon > > ( { } ) ;
204
239
const searchResults = useMemo (
205
- ( ) => search ( allIcons , searchText , props . searchKeywords ) ,
240
+ ( ) => search ( allIcons , searchText , props . searchKeywords , props . IconType ) ,
206
241
[ searchText , allIcons ]
207
242
) ;
208
243
const onChangeRef = useRef ( props . onChange ) ;
209
244
onChangeRef . current = props . onChange ;
210
- const onChangeIcon = useCallback ( ( key : string ) => onChangeRef . current ( iconPrefix + key ) , [ ] ) ;
245
+ const onChangeIcon = useCallback (
246
+ ( key : string ) => onChangeRef . current ( iconPrefix + key ) ,
247
+ [ ]
248
+ ) ;
211
249
const columnNum = 8 ;
212
250
213
251
useEffect ( ( ) => {
@@ -217,24 +255,26 @@ const IconPopup = (props: {
217
255
const rowRenderer = useCallback (
218
256
( p : ListRowProps ) => (
219
257
< IconRow key = { p . key } style = { p . style } >
220
- { searchResults . slice ( p . index * columnNum , ( p . index + 1 ) * columnNum ) . map ( ( [ key , icon ] ) => (
221
- < Tooltip
222
- key = { key }
223
- title = { icon . title }
224
- placement = "bottom"
225
- align = { { offset : [ 0 , - 7 , 0 , 0 ] } }
226
- destroyTooltipOnHide
227
- >
228
- < IconItemContainer
229
- tabIndex = { 0 }
230
- onClick = { ( ) => {
231
- onChangeIcon ( key ) ;
232
- } }
258
+ { searchResults
259
+ . slice ( p . index * columnNum , ( p . index + 1 ) * columnNum )
260
+ . map ( ( [ key , icon ] ) => (
261
+ < Tooltip
262
+ key = { key }
263
+ title = { icon . title }
264
+ placement = "bottom"
265
+ align = { { offset : [ 0 , - 7 , 0 , 0 ] } }
266
+ destroyTooltipOnHide
233
267
>
234
- { icon . getView ( ) }
235
- </ IconItemContainer >
236
- </ Tooltip >
237
- ) ) }
268
+ < IconItemContainer
269
+ tabIndex = { 0 }
270
+ onClick = { ( ) => {
271
+ onChangeIcon ( key ) ;
272
+ } }
273
+ >
274
+ { icon . getView ( ) }
275
+ </ IconItemContainer >
276
+ </ Tooltip >
277
+ ) ) }
238
278
</ IconRow >
239
279
) ,
240
280
[ searchResults , allIcons , onChangeIcon ]
@@ -279,6 +319,7 @@ export const IconSelectBase = (props: {
279
319
leftOffset ?: number ;
280
320
parent ?: HTMLElement | null ;
281
321
searchKeywords ?: Record < string , string > ;
322
+ IconType ?: "OnlyAntd" | "All" | "default" | undefined ;
282
323
} ) => {
283
324
const { setVisible, parent } = props ;
284
325
return (
@@ -290,7 +331,11 @@ export const IconSelectBase = (props: {
290
331
onOpenChange = { setVisible }
291
332
getPopupContainer = { parent ? ( ) => parent : undefined }
292
333
// hide the original background when dragging the popover is allowed
293
- overlayInnerStyle = { { border : "none" , boxShadow : "none" , background : "transparent" } }
334
+ overlayInnerStyle = { {
335
+ border : "none" ,
336
+ boxShadow : "none" ,
337
+ background : "transparent" ,
338
+ } }
294
339
// when dragging is allowed, always re-location to avoid the popover exceeds the screen
295
340
destroyTooltipOnHide
296
341
content = {
@@ -299,6 +344,7 @@ export const IconSelectBase = (props: {
299
344
label = { props . label }
300
345
onClose = { ( ) => setVisible ?.( false ) }
301
346
searchKeywords = { props . searchKeywords }
347
+ IconType = { props . IconType }
302
348
/>
303
349
}
304
350
>
@@ -312,6 +358,7 @@ export const IconSelect = (props: {
312
358
label ?: ReactNode ;
313
359
children ?: ReactNode ;
314
360
searchKeywords ?: Record < string , string > ;
361
+ IconType ?: "OnlyAntd" | "All" | "default" | undefined ;
315
362
} ) => {
316
363
const [ visible , setVisible ] = useState ( false ) ;
317
364
return (
0 commit comments