Skip to content

Commit 1a3e53c

Browse files
committed
feat: update Badge
1 parent 75e1661 commit 1a3e53c

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-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
// function getType(fn) {
66
// const match = fn && fn.toString().match(/^\s*function (\w+)/);
@@ -129,7 +129,7 @@ const getComponent = (instance, prop, options = instance, execute = true) => {
129129
};
130130
const getComponentFromProp = (instance, prop, options = instance, execute = true) => {
131131
if (instance.$createElement) {
132-
const h = instance.$createElement;
132+
// const h = instance.$createElement;
133133
const temp = instance[prop];
134134
if (temp !== undefined) {
135135
return typeof temp === 'function' && execute ? temp(h, options) : temp;
@@ -141,7 +141,7 @@ const getComponentFromProp = (instance, prop, options = instance, execute = true
141141
undefined
142142
);
143143
} else {
144-
const h = instance.context.$createElement;
144+
// const h = instance.context.$createElement;
145145
const temp = getPropsData(instance)[prop];
146146
if (temp !== undefined) {
147147
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

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Popover from 'ant-design-vue/popover';
2929
import notification from 'ant-design-vue/notification';
3030
import message from 'ant-design-vue/message';
3131
import Modal from 'ant-design-vue/modal';
32+
import Badge from 'ant-design-vue/badge';
3233
import 'ant-design-vue/style.js';
3334

3435
const app = createApp(App);
@@ -61,4 +62,5 @@ app
6162
.use(Popconfirm)
6263
.use(Popover)
6364
.use(Modal)
65+
.use(Badge)
6466
.mount('#app');

0 commit comments

Comments
 (0)