Skip to content

Commit 9a5c39c

Browse files
committed
fixed: uni-badge width bug, feat: uni-badge support custom style
1 parent b5be715 commit 9a5c39c

File tree

7 files changed

+38
-19
lines changed

7 files changed

+38
-19
lines changed

docs/components/badge.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ url : pages/vue/badge/badge
3030

3131
### Badge Props
3232

33-
|属性名 |类型 |默认值 |说明 |
34-
|:-: |:-: |:-: |:-: |
35-
|text |String |- |角标内容 |
36-
|type |String |default|颜色类型,可选值:default(灰色)、primary(蓝色)、success(绿色)、warning(黄色)、error(红色)|
37-
|size |String |normal|Badge 大小,可取值:normal、small|
38-
|inverted |Boolean |false |是否无需背景颜色,为 true 时,背景颜色将变为文字的字体颜色 |
33+
|属性名 |类型 |默认值 |说明 |
34+
|:-: |:-: |:-: |:-: |
35+
|text |String |- |角标内容 |
36+
|type |String |default|颜色类型,可选值:default(灰色)、primary(蓝色)、success(绿色)、warning(黄色)、error(红色)|
37+
|size |String |normal |Badge 大小,可取值:normal、small |
38+
|custom-style |String | |自定义 Badge 样式 |
39+
|inverted |Boolean|false |是否无需背景颜色,为 true 时,背景颜色将变为文字的字体颜色 |
3940

4041
### Badge Events
4142

pages/nvue/badge/badge.nvue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
<uni-badge class="uni-badge-left-margin" text="45" type="warning" size="small" />
2626
<uni-badge class="uni-badge-left-margin" text="123" type="error" size="small" />
2727
</view>
28+
<uni-section title="自定义样式" type="line"></uni-section>
29+
<view class="example-body">
30+
<uni-badge class="uni-badge-left-margin" text="2" type="primary" customStyle="background-color: #2C405A; color: #fff;" />
31+
<uni-badge class="uni-badge-left-margin" text="2" type="primary" customStyle="background-color: #2C405A; color: red;" />
32+
</view>
2833
</view>
2934
</template>
3035

pages/vue/badge/badge.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
<uni-badge class="uni-badge-left-margin" text="45" type="warning" size="small" />
2626
<uni-badge class="uni-badge-left-margin" text="123" type="error" size="small" />
2727
</view>
28+
<uni-section title="自定义样式" type="line"></uni-section>
29+
<view class="example-body">
30+
<uni-badge class="uni-badge-left-margin" text="2" type="primary" customStyle="background-color: #2C405A; color: #fff;" />
31+
<uni-badge class="uni-badge-left-margin" text="2" type="primary" customStyle="background-color: #2C405A; color: red;" />
32+
</view>
2833
</view>
2934
</template>
3035

uni_modules/uni-badge/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
## 1.0.7(2021-05-07)
2+
- 修复 uni-badge 在 App 端,数字小于10时不是圆形的bug
3+
- 修复 uni-badge 在父元素不是 flex 布局时,宽度缩小的bug
4+
- 新增 uni-badge 属性 custom-style, 支持自定义样式
15
## 1.0.6(2021-02-04)
26
- 调整为uni_modules目录规范

uni_modules/uni-badge/components/uni-badge/uni-badge.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
size: {
4141
type: String,
4242
default: 'normal'
43+
},
44+
customStyle: {
45+
type: String,
46+
default: ''
4347
}
4448
},
4549
data() {
@@ -57,7 +61,7 @@
5761
},
5862
methods: {
5963
setStyle() {
60-
this.badgeStyle = `width: ${String(this.text).length * 8 + 12}px`
64+
this.badgeStyle = `width: ${String(this.text).length * 8 + 12}px;` + this.customStyle
6165
},
6266
onClick() {
6367
this.$emit('click');
@@ -71,14 +75,14 @@
7175
$bage-small: scale(0.8);
7276
$bage-height: 20px;
7377
74-
.uni-badge {
75-
/* #ifndef APP-PLUS */
78+
.uni-badge {
79+
/* #ifndef APP-NVUE */
7680
display: flex;
81+
overflow: hidden;
7782
box-sizing: border-box;
78-
overflow: hidden;
7983
/* #endif */
8084
justify-content: center;
81-
flex-direction: row;
85+
flex-direction: row;
8286
height: $bage-height;
8387
line-height: $bage-height;
8488
color: $uni-text-color;
@@ -88,7 +92,6 @@
8892
text-align: center;
8993
font-family: 'Helvetica Neue', Helvetica, sans-serif;
9094
font-size: $bage-size;
91-
padding: 0px 6px;
9295
/* #ifdef H5 */
9396
cursor: pointer;
9497
/* #endif */

uni_modules/uni-badge/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "uni-badge",
33
"displayName": "uni-badge 数字角标",
4-
"version": "1.0.6",
4+
"version": "1.0.7",
55
"description": "数字角标(徽章)组件,在元素周围展示消息提醒,一般用于列表、九宫格、按钮等地方。",
66
"keywords": [
77
"",

uni_modules/uni-badge/readme.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
### Badge Props
3030

31-
|属性名 |类型 |默认值 |说明 |
32-
|:-: |:-: |:-: |:-: |
33-
|text |String |- |角标内容 |
34-
|type |String |default|颜色类型,可选值:default(灰色)、primary(蓝色)、success(绿色)、warning(黄色)、error(红色)|
35-
|size |String |normal|Badge 大小,可取值:normal、small|
36-
|inverted |Boolean |false |是否无需背景颜色,为 true 时,背景颜色将变为文字的字体颜色 |
31+
|属性名 |类型 |默认值 |说明 |
32+
|:-: |:-: |:-: |:-: |
33+
|text |String |- |角标内容 |
34+
|type |String |default|颜色类型,可选值:default(灰色)、primary(蓝色)、success(绿色)、warning(黄色)、error(红色)|
35+
|size |String |normal |Badge 大小,可取值:normal、small |
36+
|custom-style |String | |自定义 Badge 样式 |
37+
|inverted |Boolean|false |是否无需背景颜色,为 true 时,背景颜色将变为文字的字体颜色 |
3738

3839
### Badge Events
3940

0 commit comments

Comments
 (0)