Skip to content

Commit 2e3c490

Browse files
authored
refactor(badge): 支持禁用模式 (#3118)
* refactor(badge): 支持禁用模式 * fix: cr修改
1 parent c56941d commit 2e3c490

File tree

17 files changed

+117
-0
lines changed

17 files changed

+117
-0
lines changed

src/packages/badge/badge.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
z-index: 1;
5454
}
5555

56+
&-disabled {
57+
background: $badge-background-disabled-color;
58+
}
59+
5660
&-number {
5761
font-family: 'JD';
5862
}

src/packages/badge/badge.taro.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const defaultProps = {
2222
right: 0,
2323
fill: 'solid',
2424
size: 'large',
25+
disabled: false,
2526
} as TaroBadgeProps
2627
export const Badge: FunctionComponent<Partial<TaroBadgeProps>> = (props) => {
2728
const rtl = useRtl()
@@ -36,6 +37,7 @@ export const Badge: FunctionComponent<Partial<TaroBadgeProps>> = (props) => {
3637
right,
3738
fill,
3839
size,
40+
disabled,
3941
} = { ...defaultProps, ...props }
4042

4143
const classPrefix = 'nut-badge'
@@ -73,6 +75,7 @@ export const Badge: FunctionComponent<Partial<TaroBadgeProps>> = (props) => {
7375
[`${classPrefix}-dot-${size}`]: dot,
7476
[`${classPrefix}-${fill}`]: fill === 'outline',
7577
[`${classPrefix}-content`]: children,
78+
[`${classPrefix}-disabled`]: disabled,
7679
})
7780

7881
useEffect(() => {

src/packages/badge/badge.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const defaultProps = {
1313
right: 0,
1414
fill: 'solid',
1515
size: 'large',
16+
disabled: false,
1617
} as WebBadgeProps
1718

1819
export const Badge: FunctionComponent<Partial<WebBadgeProps>> = (props) => {
@@ -28,6 +29,7 @@ export const Badge: FunctionComponent<Partial<WebBadgeProps>> = (props) => {
2829
right,
2930
fill,
3031
size,
32+
disabled,
3133
} = { ...defaultProps, ...props }
3234

3335
const classPrefix = 'nut-badge'
@@ -62,6 +64,7 @@ export const Badge: FunctionComponent<Partial<WebBadgeProps>> = (props) => {
6264
[`${classPrefix}-dot-${size}`]: dot,
6365
[`${classPrefix}-${fill}`]: fill === 'outline',
6466
[`${classPrefix}-content`]: children,
67+
[`${classPrefix}-disabled`]: disabled,
6568
})
6669

6770
const getPositionStyle = (): CSSProperties => ({

src/packages/badge/demo.taro.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Demo5 from './demos/taro/demo5'
1111
import Demo6 from './demos/taro/demo6'
1212
import Demo7 from './demos/taro/demo7'
1313
import Demo8 from './demos/taro/demo8'
14+
import Demo9 from './demos/taro/demo9'
1415

1516
const BadgeDemo = () => {
1617
const [translated] = useTranslate({
@@ -23,6 +24,7 @@ const BadgeDemo = () => {
2324
'915d7b01': '自定义位置',
2425
f1089312: '独立展示',
2526
a8237653: '填充模式',
27+
disabled: '禁用',
2628
},
2729
'zh-TW': {
2830
'8ab98966': '默认用法',
@@ -33,6 +35,7 @@ const BadgeDemo = () => {
3335
'915d7b01': '自定义位置',
3436
f1089312: '独立展示',
3537
a8237653: '填充模式',
38+
disabled: '禁用',
3639
},
3740
'en-US': {
3841
'8ab98966': 'Basic usage',
@@ -43,6 +46,7 @@ const BadgeDemo = () => {
4346
'915d7b01': 'Custom Position',
4447
f1089312: 'Display Alone',
4548
a8237653: 'Fill Mode',
49+
disabled: 'Disabled',
4650
},
4751
})
4852
return (
@@ -53,6 +57,8 @@ const BadgeDemo = () => {
5357
<Demo1 />
5458
<View className="h2">{translated['1e7a2282']}</View>
5559
<Demo2 />
60+
<View className="h2">{translated.disabled}</View>
61+
<Demo9 />
5662
<View className="h2">{translated.customColor}</View>
5763
<Demo3 />
5864
<View className="h2">{translated['1c730245']}</View>

src/packages/badge/demo.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Demo5 from './demos/h5/demo5'
88
import Demo6 from './demos/h5/demo6'
99
import Demo7 from './demos/h5/demo7'
1010
import Demo8 from './demos/h5/demo8'
11+
import Demo9 from './demos/h5/demo9'
1112

1213
const BadgeDemo = () => {
1314
const [translated] = useTranslate({
@@ -20,6 +21,7 @@ const BadgeDemo = () => {
2021
'915d7b01': '自定义位置',
2122
f1089312: '独立展示',
2223
a8237653: '填充模式',
24+
disabled: '禁用',
2325
},
2426
'zh-TW': {
2527
'8ab98966': '默认用法',
@@ -30,6 +32,7 @@ const BadgeDemo = () => {
3032
'915d7b01': '自定义位置',
3133
f1089312: '独立展示',
3234
a8237653: '填充模式',
35+
disabled: '禁用',
3336
},
3437
'en-US': {
3538
'8ab98966': 'Basic usage',
@@ -40,6 +43,7 @@ const BadgeDemo = () => {
4043
'915d7b01': 'Custom Position',
4144
f1089312: 'Display Alone',
4245
a8237653: 'Fill Mode',
46+
disabled: 'Disabled',
4347
},
4448
})
4549

@@ -48,6 +52,8 @@ const BadgeDemo = () => {
4852
<div className="demo">
4953
<h2>{translated['8ab98966']}</h2>
5054
<Demo1 />
55+
<h2>{translated.disabled}</h2>
56+
<Demo9 />
5157
<h2>{translated['1e7a2282']}</h2>
5258
<Demo2 />
5359
<h2>{translated.customColor}</h2>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import { User } from '@nutui/icons-react'
3+
import { Avatar, Badge, Cell } from '@nutui/nutui-react'
4+
5+
const Demo9 = () => {
6+
return (
7+
<Cell style={{ justifyContent: 'space-around' }}>
8+
<Badge dot disabled>
9+
<Avatar icon={<User />} shape="square" />
10+
</Badge>
11+
<Badge value={8} disabled>
12+
<Avatar icon={<User />} shape="square" />
13+
</Badge>
14+
<Badge value="内容" disabled>
15+
<Avatar icon={<User />} shape="square" />
16+
</Badge>
17+
</Cell>
18+
)
19+
}
20+
export default Demo9
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react'
2+
import { User } from '@nutui/icons-react-taro'
3+
import { Avatar, Badge, Cell } from '@nutui/nutui-react-taro'
4+
5+
const Demo9 = () => {
6+
return (
7+
<Cell style={{ justifyContent: 'space-around' }}>
8+
<Badge dot disabled>
9+
<Avatar icon={<User />} shape="square" />
10+
</Badge>
11+
<Badge value={8} disabled>
12+
<Avatar icon={<User />} shape="square" />
13+
</Badge>
14+
<Badge value="内容" disabled>
15+
<Avatar icon={<User />} shape="square" />
16+
</Badge>
17+
</Cell>
18+
)
19+
}
20+
export default Demo9

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ import { Badge } from '@nutui/nutui-react'
1818

1919
:::
2020

21+
### Disabled
22+
23+
:::demo
24+
25+
<CodeBlock src='h5/demo9.tsx'></CodeBlock>
26+
27+
:::
28+
2129
### Max Size
2230

2331
:::demo
@@ -88,6 +96,7 @@ import { Badge } from '@nutui/nutui-react'
8896
| top | Up and down offset, can be set to: "0" or 0, etc. | `string` \| `number` | `0` |
8997
| right | Left and right offset, can be set to: "0" or 0, etc. | `string` \| `number` | `0` |
9098
| fill | Fill Mode | `solid` \| `outline` | `solid` |
99+
| disabled | Whether to disable | `boolean` | `false` |
91100

92101
## Theming
93102

@@ -99,6 +108,7 @@ The component provides the following CSS variables, which can be used to customi
99108
| --- | --- | --- |
100109
| \--nutui-badge-height | The height of the badge | `14px` |
101110
| \--nutui-badge-background-color | badge background color | `$color-primary` |
111+
| \--nutui-badge-background-disabled-color | badge disables background color | `$color-text-disabled` |
102112
| \--nutui-badge-color | badge content color value | `$color-primary-text)` |
103113
| \--nutui-badge-font-size | badge content font size | `$font-size-xxs` |
104114
| \--nutui-badge-border | badge border | `1px solid $color-primary-text` |

src/packages/badge/doc.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ import { Badge } from '@nutui/nutui-react'
1818

1919
:::
2020

21+
### 禁用
22+
23+
:::demo
24+
25+
<CodeBlock src='h5/demo9.tsx'></CodeBlock>
26+
27+
:::
28+
2129
### 最大值
2230

2331
:::demo
@@ -87,6 +95,7 @@ import { Badge } from '@nutui/nutui-react'
8795
| top | 上下偏移量,可设置为:"0"或0 等 | `string` \| `number` | `0` |
8896
| right | 左右偏移量,可设置为:"0"或0 等 | `string` \| `number` | `0` |
8997
| fill | 填充模式 | `solid` \| `outline` | `solid` |
98+
| disabled | 是否禁用 | `boolean` | `false` |
9099

91100
## 主题定制
92101

@@ -98,6 +107,7 @@ import { Badge } from '@nutui/nutui-react'
98107
| --- | --- | --- |
99108
| \--nutui-badge-height | badge 的高度 | `14px` |
100109
| \--nutui-badge-background-color | badge 背景色 | `$color-primary` |
110+
| \--nutui-badge-background-disabled-color | badge 禁用背景色 | `$color-text-disabled` |
101111
| \--nutui-badge-color | badge 内容色值 | `$color-primary-text` |
102112
| \--nutui-badge-font-size | badge 内容字号 | `$font-size-xxs` |
103113
| \--nutui-badge-border | badge 边框 | `1px solid $color-primary-text` |

src/packages/badge/doc.taro.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ import { Badge } from '@nutui/nutui-react-taro'
1818

1919
:::
2020

21+
### 禁用
22+
23+
:::demo
24+
25+
<CodeBlock src='taro/demo9.tsx'></CodeBlock>
26+
27+
:::
28+
2129
### 最大值
2230

2331
:::demo
@@ -87,6 +95,7 @@ import { Badge } from '@nutui/nutui-react-taro'
8795
| top | 上下偏移量,可设置为:"0"或0 等 | `string` \| `number` | `"0"` |
8896
| right | 左右偏移量,可设置为:"0"或0 等 | `string` \| `number` | `"0"` |
8997
| fill | 填充模式 | `solid` \| `outline` | `solid` |
98+
| disabled | 是否禁用 | `boolean` | `false` |
9099

91100
## 主题定制
92101

@@ -98,6 +107,7 @@ import { Badge } from '@nutui/nutui-react-taro'
98107
| --- | --- | --- |
99108
| \--nutui-badge-height | badge 的高度 | `14px` |
100109
| \--nutui-badge-background-color | badge 背景色 | `$color-primary` |
110+
| \--nutui-badge-background-disabled-color | badge 禁用背景色 | `$color-text-disabled` |
101111
| \--nutui-badge-color | badge 内容色值 | `$color-primary-text` |
102112
| \--nutui-badge-font-size | badge 内容字号 | `$font-size-xxs` |
103113
| \--nutui-badge-border | badge 边框 | `1px solid $color-primary-text` |

0 commit comments

Comments
 (0)