Skip to content

Commit b32f34b

Browse files
feat: update Badge (#2419)
Co-authored-by: tangjinzhou <[email protected]>
1 parent 6cad9c3 commit b32f34b

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

components/_util/props-util.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import isPlainObject from 'lodash/isPlainObject';
22
import classNames from 'classnames';
3-
import { isVNode, Fragment, Comment, Text } from 'vue';
3+
import { isVNode, Fragment, Comment, Text, h } from 'vue';
44
import { camelize, hyphenate, isOn, resolvePropValue } from './util';
55
import isValid from './isValid';
66
// function getType(fn) {
@@ -187,7 +187,7 @@ const getComponent = (instance, prop = 'default', options = instance, execute =
187187
};
188188
const getComponentFromProp = (instance, prop, options = instance, execute = true) => {
189189
if (instance.$createElement) {
190-
const h = instance.$createElement;
190+
// const h = instance.$createElement;
191191
const temp = instance[prop];
192192
if (temp !== undefined) {
193193
return typeof temp === 'function' && execute ? temp(h, options) : temp;
@@ -199,7 +199,7 @@ const getComponentFromProp = (instance, prop, options = instance, execute = true
199199
undefined
200200
);
201201
} else {
202-
const h = instance.context.$createElement;
202+
// const h = instance.context.$createElement;
203203
const temp = getPropsData(instance)[prop];
204204
if (temp !== undefined) {
205205
return typeof temp === 'function' && execute ? temp(h, options) : temp;

components/badge/Badge.jsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { cloneElement } from '../_util/vnode';
1212
import getTransitionProps from '../_util/getTransitionProps';
1313
import isNumeric from '../_util/isNumeric';
1414
import { ConfigConsumerProps } from '../config-provider';
15+
import { inject } from 'vue';
1516

1617
const BadgeProps = {
1718
/** Number to show in badge */
@@ -40,8 +41,10 @@ export default {
4041
dot: false,
4142
overflowCount: 99,
4243
}),
43-
inject: {
44-
configProvider: { default: () => ConfigConsumerProps },
44+
setup() {
45+
return {
46+
configProvider: inject('configProvider', ConfigConsumerProps),
47+
};
4548
},
4649
methods: {
4750
getNumberedDispayCount() {
@@ -80,7 +83,7 @@ export default {
8083
: { ...numberStyle };
8184
},
8285
getBadgeClassName(prefixCls) {
83-
const children = filterEmpty(this.$slots.default);
86+
const children = filterEmpty(this.$slots.default && this.$slots.default());
8487
const hasStatus = this.hasStatus();
8588
return classNames(prefixCls, {
8689
[`${prefixCls}-status`]: hasStatus,
@@ -181,7 +184,7 @@ export default {
181184
const prefixCls = getPrefixCls('badge', customizePrefixCls);
182185
const scrollNumberPrefixCls = getPrefixCls('scroll-number', customizeScrollNumberPrefixCls);
183186

184-
const children = filterEmpty($slots.default);
187+
const children = filterEmpty($slots.default && $slots.default());
185188
let count = getComponentFromProp(this, 'count');
186189
if (Array.isArray(count)) {
187190
count = count[0];

components/badge/ScrollNumber.jsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getStyle } from '../_util/props-util';
55
import omit from 'omit.js';
66
import { cloneElement } from '../_util/vnode';
77
import { ConfigConsumerProps } from '../config-provider';
8+
import { inject } from 'vue';
89

910
function getNumberArray(num) {
1011
return num
@@ -31,8 +32,10 @@ const ScrollNumberProps = {
3132
export default {
3233
mixins: [BaseMixin],
3334
props: ScrollNumberProps,
34-
inject: {
35-
configProvider: { default: () => ConfigConsumerProps },
35+
setup() {
36+
return {
37+
configProvider: inject('configProvider', ConfigConsumerProps),
38+
};
3639
},
3740
data() {
3841
return {

components/badge/index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import Badge from './Badge';
2-
import Base from '../base';
32

43
/* istanbul ignore next */
5-
Badge.install = function(Vue) {
6-
Vue.use(Base);
7-
Vue.component(Badge.name, Badge);
4+
Badge.install = function(app) {
5+
app.component(Badge.name, Badge);
86
};
97

108
export default Badge;

examples/index.js

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import '@babel/polyfill';
22
import { createApp } from 'vue';
33
import App from './App.vue';
44
import {
5+
Badge,
56
AutoComplete,
67
Radio,
78
Spin,
@@ -23,6 +24,7 @@ import {
2324
notification,
2425
message,
2526
} from 'ant-design-vue';
27+
2628
import 'ant-design-vue/style.js';
2729

2830
const basic = {
@@ -51,6 +53,7 @@ app
5153
.use(Tooltip)
5254
.use(Col)
5355
.use(Row)
56+
.use(Badge)
5457
.use(Radio)
5558
.use(Switch)
5659
.use(Checkbox)

0 commit comments

Comments
 (0)