@@ -15,6 +15,7 @@ import { toJson } from "really-relaxed-json";
15
15
import { hashToNum } from "util/stringUtils" ;
16
16
import { CustomSelect , PackUpIcon } from "lowcoder-design" ;
17
17
import { ScrollBar } from "lowcoder-design" ;
18
+ import { ColoredTagOptionControl } from "comps/controls/optionsControl" ;
18
19
19
20
const colors = PresetStatusColorTypes ;
20
21
@@ -55,13 +56,22 @@ const TagsControl = codeControl<Array<string> | string>(
55
56
{ expectedType : "string | Array<string>" , codeType : "JSON" }
56
57
) ;
57
58
58
- function getTagColor ( text : string ) {
59
- const index = Math . abs ( hashToNum ( text ) ) % colors . length ;
60
- return colors [ index ] ;
59
+ function getTagColor ( tagText : any , tagOptions : any [ ] ) {
60
+ const foundOption = tagOptions . find ( ( option : { label : any ; } ) => option . label === tagText ) ;
61
+ return foundOption ? foundOption . color : ( function ( ) {
62
+ const index = Math . abs ( hashToNum ( tagText ) ) % colors . length ;
63
+ return colors [ index ] ;
64
+ } ) ( ) ;
65
+ }
66
+
67
+ function getTagIcon ( tagText : any , tagOptions : any [ ] ) {
68
+ const foundOption = tagOptions . find ( option => option . label === tagText ) ;
69
+ return foundOption ? foundOption . icon : undefined ;
61
70
}
62
71
63
72
const childrenMap = {
64
73
text : TagsControl ,
74
+ tagColors : ColoredTagOptionControl ,
65
75
} ;
66
76
67
77
const getBaseValue : ColumnTypeViewFn < typeof childrenMap , string | string [ ] , string | string [ ] > = (
@@ -135,6 +145,9 @@ export const Wrapper = styled.div`
135
145
}
136
146
}
137
147
}
148
+ .ant-tag svg {
149
+ margin-right: 4px;
150
+ }
138
151
` ;
139
152
140
153
export const DropdownStyled = styled . div `
@@ -152,6 +165,12 @@ export const DropdownStyled = styled.div`
152
165
}
153
166
` ;
154
167
168
+ export const TagStyled = styled ( Tag ) `
169
+ svg {
170
+ margin-right: 4px;
171
+ }
172
+ ` ;
173
+
155
174
const TagEdit = ( props : TagEditPropsType ) => {
156
175
const defaultTags = useContext ( TagsContext ) ;
157
176
const [ tags , setTags ] = useState ( ( ) => {
@@ -206,12 +225,12 @@ const TagEdit = (props: TagEditPropsType) => {
206
225
< CustomSelect . Option value = { value } key = { index } >
207
226
{ value . split ( "," ) [ 1 ] ? (
208
227
value . split ( "," ) . map ( ( item , i ) => (
209
- < Tag color = { getTagColor ( item ) } key = { i } style = { { marginRight : "8px" } } >
228
+ < Tag color = { getTagColor ( item , [ ] ) } key = { i } style = { { marginRight : "8px" } } >
210
229
{ item }
211
230
</ Tag >
212
231
) )
213
232
) : (
214
- < Tag color = { getTagColor ( value ) } key = { index } >
233
+ < Tag color = { getTagColor ( value , [ ] ) } key = { index } >
215
234
{ value }
216
235
</ Tag >
217
236
) }
@@ -226,16 +245,17 @@ export const ColumnTagsComp = (function () {
226
245
return new ColumnTypeCompBuilder (
227
246
childrenMap ,
228
247
( props , dispatch ) => {
248
+ const tagOptions = props . tagColors ;
229
249
let value = props . changeValue ?? getBaseValue ( props , dispatch ) ;
230
250
value = typeof value === "string" && value . split ( "," ) [ 1 ] ? value . split ( "," ) : value ;
231
251
const tags = _ . isArray ( value ) ? value : [ value ] ;
232
252
const view = tags . map ( ( tag , index ) => {
233
253
// The actual eval value is of type number or boolean
234
254
const tagText = String ( tag ) ;
235
255
return (
236
- < Tag color = { getTagColor ( tagText ) } key = { index } >
256
+ < TagStyled color = { getTagColor ( tagText , tagOptions ) } icon = { getTagIcon ( tagText , tagOptions ) } key = { index } >
237
257
{ tagText }
238
- </ Tag >
258
+ </ TagStyled >
239
259
) ;
240
260
} ) ;
241
261
return view ;
@@ -257,6 +277,9 @@ export const ColumnTagsComp = (function () {
257
277
label : trans ( "table.columnValue" ) ,
258
278
tooltip : ColumnValueTooltip ,
259
279
} ) }
280
+ { children . tagColors . propertyView ( {
281
+ title : "test" ,
282
+ } ) }
260
283
</ >
261
284
) )
262
285
. build ( ) ;
0 commit comments