1
- import {
2
- BoolCodeControl ,
3
- ButtonEventHandlerControl ,
4
- InputLikeStyle ,
5
- NameConfig ,
6
- Section ,
7
- UICompBuilder ,
8
- hiddenPropertyView ,
9
- sectionNames ,
10
- showDataLoadingIndicatorsPropertyView ,
11
- styleControl ,
12
- withExposingConfigs
13
- } from "@lowcoder-ee/index.sdk" ;
14
1
import styled from "styled-components" ;
15
2
import React , { useContext } from "react" ;
16
- import { trans } from "i18n" ;
17
3
import { Tag } from "antd" ;
18
4
import { EditorContext } from "comps/editorState" ;
19
5
import { PresetStatusColorTypes } from "antd/es/_util/colors" ;
20
6
import { hashToNum } from "util/stringUtils" ;
21
7
import { TagsCompOptionsControl } from "comps/controls/optionsControl" ;
22
8
import { useCompClickEventHandler } from "@lowcoder-ee/comps/utils/useCompClickEventHandler" ;
9
+ import { styleControl } from "@lowcoder-ee/comps/controls/styleControl" ;
10
+ import { ButtonEventHandlerControl } from "@lowcoder-ee/comps/controls/eventHandlerControl" ;
11
+ import { InputLikeStyle } from "@lowcoder-ee/comps/controls/styleControlConstants" ;
12
+ import { BoolCodeControl } from "@lowcoder-ee/comps/controls/codeControl" ;
13
+ import { UICompBuilder } from "@lowcoder-ee/comps/generators/uiCompBuilder" ;
14
+ import { Section , sectionNames } from "lowcoder-design" ;
15
+ import { NameConfig } from "@lowcoder-ee/comps/generators/withExposing" ;
16
+ import { hiddenPropertyView , showDataLoadingIndicatorsPropertyView } from "@lowcoder-ee/comps/utils/propertyUtils" ;
17
+ import { withExposingConfigs } from "@lowcoder-ee/comps/generators/withExposing" ;
23
18
24
19
const colors = PresetStatusColorTypes ;
25
20
26
21
// These functions are used for individual tag styling
27
22
function getTagColor ( tagText : any , tagOptions : any [ ] ) {
28
23
const foundOption = tagOptions . find ( ( option : { label : any ; } ) => option . label === tagText ) ;
29
24
if ( foundOption ) {
30
- if ( foundOption . colorType === "preset" ) {
25
+ if ( foundOption . colorType === "default" ) {
26
+ return undefined ;
27
+ } else if ( foundOption . colorType === "preset" ) {
31
28
return foundOption . presetColor ;
32
29
} else if ( foundOption . colorType === "custom" ) {
33
30
return undefined ;
@@ -40,20 +37,32 @@ function getTagColor(tagText : any, tagOptions: any[]) {
40
37
41
38
const getTagStyle = ( tagText : any , tagOptions : any [ ] , baseStyle : any = { } ) => {
42
39
const foundOption = tagOptions . find ( ( option : { label : any ; } ) => option . label === tagText ) ;
40
+
43
41
if ( foundOption ) {
42
+ // If colorType is "default", use ONLY component styles
43
+ if ( foundOption . colorType === "default" ) {
44
+ const style : any = { ...baseStyle } ;
45
+ if ( baseStyle . borderWidth && baseStyle . border && baseStyle . borderStyle ) {
46
+ style . border = `${ baseStyle . borderWidth } ${ baseStyle . borderStyle } ${ baseStyle . border } ` ;
47
+ }
48
+ return style ;
49
+ }
50
+
44
51
const style : any = { ...baseStyle } ;
45
52
46
53
if ( foundOption . colorType === "custom" ) {
47
54
style . backgroundColor = foundOption . color ;
48
55
style . color = foundOption . textColor ;
49
- style . border = `1px solid ${ foundOption . color } ` ;
50
56
}
51
57
52
- if ( foundOption . border ) {
53
- style . borderColor = foundOption . border ;
54
- if ( ! foundOption . colorType || foundOption . colorType !== "custom" ) {
55
- style . border = `1px solid ${ foundOption . border } ` ;
56
- }
58
+ let borderStyle = foundOption . borderStyle || "none" ;
59
+ let borderWidth = foundOption . borderWidth || "0px" ;
60
+ let borderColor = foundOption . border || "none" ;
61
+
62
+ if ( borderStyle !== "none" ) {
63
+ style . border = `${ borderWidth } ${ borderStyle } ${ borderColor } ` ;
64
+ } else {
65
+ style . border = "none" ;
57
66
}
58
67
59
68
if ( foundOption . radius ) {
@@ -68,33 +77,36 @@ const getTagStyle = (tagText: any, tagOptions: any[], baseStyle: any = {}) => {
68
77
style . padding = foundOption . padding ;
69
78
}
70
79
80
+ if ( foundOption . width ) {
81
+ style . width = foundOption . width ;
82
+ }
83
+
71
84
return style ;
72
85
}
73
- return baseStyle ;
74
- } ;
75
86
76
- function getTagIcon ( tagText : any , tagOptions : any [ ] ) {
77
- const foundOption = tagOptions . find ( option => option . label === tagText ) ;
78
- return foundOption ? foundOption . icon : undefined ;
79
- }
87
+ const style : any = { ...baseStyle } ;
88
+ if ( baseStyle . borderWidth && baseStyle . border && baseStyle . borderStyle ) {
89
+ style . border = `${ baseStyle . borderWidth } ${ baseStyle . borderStyle } ${ baseStyle . border } ` ;
90
+ }
91
+ return style ;
92
+ } ;
80
93
81
94
const multiTags = ( function ( ) {
82
95
83
- const StyledTag = styled ( Tag ) < { $style : any , $bordered : boolean , $ customStyle : any } > `
96
+ const StyledTag = styled ( Tag ) < { $style : any , $customStyle : any } > `
84
97
display: flex;
85
98
justify-content: center;
86
99
align-items: center;
87
- width: 100%;
100
+ min-width: fit-content;
101
+ width: ${ ( props ) => props . $customStyle ?. width || 'auto' } ;
102
+ max-width: 100px;
88
103
background: ${ ( props ) => props . $customStyle ?. backgroundColor || props . $style ?. background } ;
89
104
color: ${ ( props ) => props . $customStyle ?. color || props . $style ?. text } ;
90
105
border-radius: ${ ( props ) => props . $customStyle ?. borderRadius || props . $style ?. borderRadius } ;
91
- border: ${ ( props ) => {
92
- if ( props . $customStyle ?. border ) return props . $customStyle . border ;
93
- return props . $bordered ? `${ props . $style ?. borderStyle } ${ props . $style ?. borderWidth } ${ props . $style ?. border } ` : 'none' ;
94
- } } ;
106
+ border: ${ ( props ) => props . $customStyle ?. border || props . $style ?. border || '1px solid #d9d9d9' } ;
95
107
padding: ${ ( props ) => props . $customStyle ?. padding || props . $style ?. padding } ;
96
108
margin: ${ ( props ) => props . $customStyle ?. margin || props . $style ?. margin } ;
97
- font-size: ${ ( props ) => props . $style ?. textSize } ;
109
+ font-size: ${ ( props ) => props . $style ?. textSize || '8px' } ;
98
110
font-weight: ${ ( props ) => props . $style ?. fontWeight } ;
99
111
cursor: pointer;
100
112
` ;
@@ -109,8 +121,6 @@ const multiTags = (function () {
109
121
options : TagsCompOptionsControl ,
110
122
style : styleControl ( InputLikeStyle , 'style' ) ,
111
123
onEvent : ButtonEventHandlerControl ,
112
- borderless : BoolCodeControl ,
113
- enableIndividualStyling : BoolCodeControl ,
114
124
} ;
115
125
116
126
return new UICompBuilder ( childrenMap , ( props ) => {
@@ -120,20 +130,18 @@ const multiTags = (function () {
120
130
< StyledTagContainer >
121
131
{ props . options . map ( ( tag , index ) => {
122
132
123
- // Use individual styling only if enableIndividualStyling is true
124
- const tagColor = props . enableIndividualStyling ? getTagColor ( tag . label , props . options ) : undefined ;
125
- const tagIcon = props . enableIndividualStyling ? getTagIcon ( tag . label , props . options ) : tag . icon ;
126
- const tagStyle = props . enableIndividualStyling ? getTagStyle ( tag . label , props . options , props . style ) : { } ;
133
+ const tagColor = getTagColor ( tag . label , props . options ) ;
134
+ const tagIcon = tag . icon ;
135
+ const tagStyle = getTagStyle ( tag . label , props . options , props . style ) ;
127
136
128
137
return (
129
138
< StyledTag
130
139
key = { `tag-${ index } ` }
131
140
$style = { props . style }
132
- $bordered = { ! props . borderless }
133
141
$customStyle = { tagStyle }
134
142
icon = { tagIcon }
135
143
color = { tagColor }
136
- onClick = { ( ) => handleClickEvent ( ) }
144
+ onClick = { handleClickEvent }
137
145
>
138
146
{ tag . label }
139
147
</ StyledTag >
@@ -145,7 +153,7 @@ const multiTags = (function () {
145
153
. setPropertyViewFn ( ( children : any ) => {
146
154
return (
147
155
< >
148
- < Section name = "Basic" >
156
+ < Section name = { sectionNames . basic } >
149
157
{ children . options . propertyView ( { } ) }
150
158
</ Section >
151
159
@@ -161,11 +169,6 @@ const multiTags = (function () {
161
169
useContext ( EditorContext ) . editorModeStatus
162
170
) && (
163
171
< Section name = { sectionNames . style } >
164
- { children . enableIndividualStyling . propertyView ( {
165
- label : trans ( "style.individualStyling" ) ,
166
- tooltip : trans ( "style.individualStylingTooltip" )
167
- } ) }
168
- { children . borderless . propertyView ( { label : trans ( "style.borderless" ) } ) }
169
172
{ children . style . getPropertyView ( ) }
170
173
</ Section >
171
174
) }
0 commit comments