Skip to content

Commit 8d371ac

Browse files
committed
fix: removing the color property is done using a css variable
1 parent 82e6f35 commit 8d371ac

File tree

14 files changed

+44
-54
lines changed

14 files changed

+44
-54
lines changed

migrate-from-v2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ plugins: [
666666
#### Badge
667667

668668
- 新增 `size` 属性,dot 尺寸,当 dot 等于 `true` 时生效
669+
- 移除 `徽标背景颜色`,通过css变量`--nutui-badge-background-color`实现
669670

670671
#### CircleProgress
671672

src/packages/badge/badge.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999
&-outline {
100100
background: $color-primary-text;
101-
color: $color-primary;
101+
color: $badge-outline-color;
102102
&::after {
103103
border: $badge-outline-border;
104104
}

src/packages/badge/badge.taro.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const defaultProps = {
2020
max: 99,
2121
top: 0,
2222
right: 0,
23-
color: '',
2423
fill: 'solid',
2524
size: 'large',
2625
} as BadgeProps
@@ -35,7 +34,6 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
3534
dot,
3635
top,
3736
right,
38-
color,
3937
fill,
4038
size,
4139
} = {
@@ -94,22 +92,6 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
9492
setContentStyle(style)
9593
}
9694

97-
const getCustomStyle = () => {
98-
const style: CSSProperties = {}
99-
if (color) {
100-
if (fill === 'outline') {
101-
style.color = color
102-
isHarmony
103-
? (style.backgroundColor = '#FFFFFF')
104-
: (style.background = '#FFFFFF')
105-
} else {
106-
style.color = '#fff'
107-
isHarmony ? (style.backgroundColor = color) : (style.background = color)
108-
}
109-
}
110-
return style
111-
}
112-
11395
return (
11496
<View className={classes} style={style} ref={badgeRef}>
11597
{isIcon() && (
@@ -125,10 +107,7 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
125107
)}
126108
{children}
127109
{!isIcon() && (
128-
<View
129-
className={contentClasses}
130-
style={{ ...contentStyle, ...getCustomStyle() }}
131-
>
110+
<View className={contentClasses} style={contentStyle}>
132111
{content()}
133112
</View>
134113
)}

src/packages/badge/badge.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const defaultProps = {
1111
max: 99,
1212
top: 0,
1313
right: 0,
14-
color: '',
1514
fill: 'solid',
1615
size: 'large',
1716
} as BadgeProps
@@ -26,7 +25,6 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
2625
dot,
2726
top,
2827
right,
29-
color,
3028
fill,
3129
size,
3230
} = {
@@ -102,10 +100,7 @@ export const Badge: FunctionComponent<Partial<BadgeProps>> = (props) => {
102100
)}
103101
{children}
104102
{!isIcon() && (
105-
<div
106-
className={contentClasses}
107-
style={{ ...getPositionStyle(), ...getCustomStyle() }}
108-
>
103+
<div className={contentClasses} style={getPositionStyle()}>
109104
{content()}
110105
</div>
111106
)}

src/packages/badge/demos/h5/demo3.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@ const Demo3 = () => {
77
<Cell style={{ justifyContent: 'space-around' }}>
88
<Badge
99
dot
10-
color="linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)"
10+
style={{
11+
'--nutui-badge-background-color':
12+
'linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)',
13+
}}
1114
>
1215
<Avatar icon={<User />} shape="square" />
1316
</Badge>
1417
<Badge
1518
value={8}
16-
color="linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)"
19+
style={{
20+
'--nutui-badge-background-color':
21+
'linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)',
22+
}}
1723
>
1824
<Avatar icon={<User />} shape="square" />
1925
</Badge>
2026
<Badge
2127
value="内容"
22-
color="linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)"
28+
style={{
29+
'--nutui-badge-background-color':
30+
'linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)',
31+
}}
2332
>
2433
<Avatar icon={<User />} shape="square" />
2534
</Badge>

src/packages/badge/demos/h5/demo8.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ const Demo8 = () => {
1313
</Badge>
1414
<Badge
1515
value="内容"
16-
color="blue"
1716
fill="outline"
1817
style={{
1918
'--nutui-badge-outline-border': '1px solid blue',
19+
'--nutui-badge-outline-color': 'blue',
2020
}}
2121
>
2222
<Avatar icon={<User />} shape="square" />

src/packages/badge/demos/taro/demo3.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,28 @@ const Demo3 = () => {
77
<Cell style={{ justifyContent: 'space-around' }}>
88
<Badge
99
dot
10-
color="linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)"
10+
style={{
11+
'--nutui-badge-background-color':
12+
'linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)',
13+
}}
1114
>
1215
<Avatar icon={<User />} shape="square" />
1316
</Badge>
1417
<Badge
1518
value={8}
16-
color="linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)"
19+
style={{
20+
'--nutui-badge-background-color':
21+
'linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)',
22+
}}
1723
>
1824
<Avatar icon={<User />} shape="square" />
1925
</Badge>
2026
<Badge
2127
value="内容"
22-
color="linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)"
28+
style={{
29+
'--nutui-badge-background-color':
30+
'linear-gradient(315deg, rgba(73,143,242,1) 0%,rgba(73,101,242,1) 100%)',
31+
}}
2332
>
2433
<Avatar icon={<User />} shape="square" />
2534
</Badge>

src/packages/badge/demos/taro/demo8.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
22
import { User } from '@nutui/icons-react-taro'
33
import { Avatar, Badge, Cell } from '@nutui/nutui-react-taro'
4-
import { harmony } from '@/utils/platform-taro'
54

65
const Demo8 = () => {
76
return (
@@ -12,18 +11,16 @@ const Demo8 = () => {
1211
<Badge value={8} fill="outline">
1312
<Avatar icon={<User />} shape="square" />
1413
</Badge>
15-
{harmony() ? null : (
16-
<Badge
17-
value="内容"
18-
color="blue"
19-
fill="outline"
20-
style={{
21-
'--nutui-badge-outline-border': '1px solid blue',
22-
}}
23-
>
24-
<Avatar icon={<User />} shape="square" />
25-
</Badge>
26-
)}
14+
<Badge
15+
value="内容"
16+
fill="outline"
17+
style={{
18+
'--nutui-badge-outline-border': '1px solid blue',
19+
'--nutui-badge-outline-color': 'blue',
20+
}}
21+
>
22+
<Avatar icon={<User />} shape="square" />
23+
</Badge>
2724
</Cell>
2825
)
2926
}

src/packages/badge/doc.en-US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ import { Badge } from '@nutui/nutui-react'
8787
| size | dot size, effective when dot is equal to `true` | `small` \| `normal` \| `large` | `large` |
8888
| top | Up and down offset, can be set to: "0" or 0, etc. | `string` \| `number` | `0` |
8989
| right | Left and right offset, can be set to: "0" or 0, etc. | `string` \| `number` | `0` |
90-
| color | background color,the default value is the theme primary color | `string` | `-` |
9190
| fill | Fill Mode | `solid` \| `outline` | `solid` |
9291

9392
## Theming
@@ -114,4 +113,5 @@ The component provides the following CSS variables, which can be used to customi
114113
| \--nutui-badge-dot-small-width | When badge is a dot, size is equal to the width and height of small | `4px` |
115114
| \--nutui-badge-dot-large-width | When the badge is a dot, size is equal to the width and height of large | `8px` |
116115
| \--nutui-badge-dot-border | The border when the badge is a dot | `1px solid $color-primary-text` |
116+
| \--nutui-badge-outline-color | The border when badge is outline text color value | `$color-primary` |
117117
| \--nutui-badge-outline-border | The border when badge is outline fill mode | `1px solid $color-primary-text` |

src/packages/badge/doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import { Badge } from '@nutui/nutui-react'
8686
| size | dot 尺寸,当 dot 等于 `true` 时生效 | `small` \| `normal` \| `large` | `large` |
8787
| top | 上下偏移量,可设置为:"0"或0 等 | `string` \| `number` | `0` |
8888
| right | 左右偏移量,可设置为:"0"或0 等 | `string` \| `number` | `0` |
89-
| color | 徽标背景颜色,默认值为当前主题色 | `string` | `-` |
9089
| fill | 填充模式 | `solid` \| `outline` | `solid` |
9190

9291
## 主题定制
@@ -113,4 +112,5 @@ import { Badge } from '@nutui/nutui-react'
113112
| \--nutui-badge-dot-small-width | badge 为圆点时,size 等于 small 的宽高 | `4px` |
114113
| \--nutui-badge-dot-large-width | badge 为圆点时,size 等于 large 的宽高 | `8px` |
115114
| \--nutui-badge-dot-border | badge 为圆点时的边框 | `1px solid $color-primary-text` |
115+
| \--nutui-badge-outline-color | badge 为 outline 文字色值 | `$color-primary` |
116116
| \--nutui-badge-outline-border | badge 为 outline 填充模式时的边框 | `1px solid $color-primary-text` |

0 commit comments

Comments
 (0)