1
1
import styled from "styled-components" ;
2
2
import React , { useContext } from "react" ;
3
- import { trans } from "i18n" ;
4
3
import { Tag } from "antd" ;
5
4
import { EditorContext } from "comps/editorState" ;
6
5
import { PresetStatusColorTypes } from "antd/es/_util/colors" ;
@@ -23,7 +22,9 @@ const colors = PresetStatusColorTypes;
23
22
function getTagColor ( tagText : any , tagOptions : any [ ] ) {
24
23
const foundOption = tagOptions . find ( ( option : { label : any ; } ) => option . label === tagText ) ;
25
24
if ( foundOption ) {
26
- if ( foundOption . colorType === "preset" ) {
25
+ if ( foundOption . colorType === "default" ) {
26
+ return undefined ;
27
+ } else if ( foundOption . colorType === "preset" ) {
27
28
return foundOption . presetColor ;
28
29
} else if ( foundOption . colorType === "custom" ) {
29
30
return undefined ;
@@ -36,20 +37,32 @@ function getTagColor(tagText : any, tagOptions: any[]) {
36
37
37
38
const getTagStyle = ( tagText : any , tagOptions : any [ ] , baseStyle : any = { } ) => {
38
39
const foundOption = tagOptions . find ( ( option : { label : any ; } ) => option . label === tagText ) ;
40
+
39
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
+
40
51
const style : any = { ...baseStyle } ;
41
52
42
53
if ( foundOption . colorType === "custom" ) {
43
54
style . backgroundColor = foundOption . color ;
44
55
style . color = foundOption . textColor ;
45
- style . border = `1px solid ${ foundOption . color } ` ;
46
56
}
47
57
48
- if ( foundOption . border ) {
49
- style . borderColor = foundOption . border ;
50
- if ( ! foundOption . colorType || foundOption . colorType !== "custom" ) {
51
- style . border = `1px solid ${ foundOption . border } ` ;
52
- }
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" ;
53
66
}
54
67
55
68
if ( foundOption . radius ) {
@@ -64,33 +77,36 @@ const getTagStyle = (tagText: any, tagOptions: any[], baseStyle: any = {}) => {
64
77
style . padding = foundOption . padding ;
65
78
}
66
79
80
+ if ( foundOption . width ) {
81
+ style . width = foundOption . width ;
82
+ }
83
+
67
84
return style ;
68
85
}
69
- return baseStyle ;
70
- } ;
71
86
72
- function getTagIcon ( tagText : any , tagOptions : any [ ] ) {
73
- const foundOption = tagOptions . find ( option => option . label === tagText ) ;
74
- return foundOption ? foundOption . icon : undefined ;
75
- }
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
+ } ;
76
93
77
94
const multiTags = ( function ( ) {
78
95
79
- const StyledTag = styled ( Tag ) < { $style : any , $bordered : boolean , $ customStyle : any } > `
96
+ const StyledTag = styled ( Tag ) < { $style : any , $customStyle : any } > `
80
97
display: flex;
81
98
justify-content: center;
82
99
align-items: center;
83
- width: 100%;
100
+ min-width: fit-content;
101
+ width: ${ ( props ) => props . $customStyle ?. width || 'auto' } ;
102
+ max-width: 100px;
84
103
background: ${ ( props ) => props . $customStyle ?. backgroundColor || props . $style ?. background } ;
85
104
color: ${ ( props ) => props . $customStyle ?. color || props . $style ?. text } ;
86
105
border-radius: ${ ( props ) => props . $customStyle ?. borderRadius || props . $style ?. borderRadius } ;
87
- border: ${ ( props ) => {
88
- if ( props . $customStyle ?. border ) return props . $customStyle . border ;
89
- return props . $bordered ? `${ props . $style ?. borderStyle } ${ props . $style ?. borderWidth } ${ props . $style ?. border } ` : 'none' ;
90
- } } ;
106
+ border: ${ ( props ) => props . $customStyle ?. border || props . $style ?. border || '1px solid #d9d9d9' } ;
91
107
padding: ${ ( props ) => props . $customStyle ?. padding || props . $style ?. padding } ;
92
108
margin: ${ ( props ) => props . $customStyle ?. margin || props . $style ?. margin } ;
93
- font-size: ${ ( props ) => props . $style ?. textSize } ;
109
+ font-size: ${ ( props ) => props . $style ?. textSize || '8px' } ;
94
110
font-weight: ${ ( props ) => props . $style ?. fontWeight } ;
95
111
cursor: pointer;
96
112
` ;
@@ -105,8 +121,6 @@ const multiTags = (function () {
105
121
options : TagsCompOptionsControl ,
106
122
style : styleControl ( InputLikeStyle , 'style' ) ,
107
123
onEvent : ButtonEventHandlerControl ,
108
- borderless : BoolCodeControl ,
109
- enableIndividualStyling : BoolCodeControl ,
110
124
} ;
111
125
112
126
return new UICompBuilder ( childrenMap , ( props ) => {
@@ -116,16 +130,14 @@ const multiTags = (function () {
116
130
< StyledTagContainer >
117
131
{ props . options . map ( ( tag , index ) => {
118
132
119
- // Use individual styling only if enableIndividualStyling is true
120
- const tagColor = props . enableIndividualStyling ? getTagColor ( tag . label , props . options ) : undefined ;
121
- const tagIcon = props . enableIndividualStyling ? getTagIcon ( tag . label , props . options ) : tag . icon ;
122
- 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 ) ;
123
136
124
137
return (
125
138
< StyledTag
126
139
key = { `tag-${ index } ` }
127
140
$style = { props . style }
128
- $bordered = { ! props . borderless }
129
141
$customStyle = { tagStyle }
130
142
icon = { tagIcon }
131
143
color = { tagColor }
@@ -157,11 +169,6 @@ const multiTags = (function () {
157
169
useContext ( EditorContext ) . editorModeStatus
158
170
) && (
159
171
< Section name = { sectionNames . style } >
160
- { children . enableIndividualStyling . propertyView ( {
161
- label : trans ( "style.individualStyling" ) ,
162
- tooltip : trans ( "style.individualStylingTooltip" )
163
- } ) }
164
- { children . borderless . propertyView ( { label : trans ( "style.borderless" ) } ) }
165
172
{ children . style . getPropertyView ( ) }
166
173
</ Section >
167
174
) }
0 commit comments