-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathbadge.ts
More file actions
59 lines (48 loc) · 1.47 KB
/
badge.ts
File metadata and controls
59 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { SuperComponent, wxComponent } from '../common/src/index';
import config from '../common/config';
import props from './props';
import type { TdBadgeProps } from './type';
import { uniqueFactory, getRect } from '../common/utils';
const { prefix } = config;
const name = `${prefix}-badge`;
const getUniqueID = uniqueFactory('badge');
export interface BadgeProps extends TdBadgeProps {}
@wxComponent()
export default class Badge extends SuperComponent {
options = {
multipleSlots: true,
};
externalClasses = [`${prefix}-class`, `${prefix}-class-count`, `${prefix}-class-content`];
properties = props;
data = {
prefix,
classPrefix: name,
value: '',
labelID: '',
descriptionID: '',
useOuterClass: false,
};
lifetimes = {
ready() {
const uniqueID = getUniqueID();
this.setData({
labelID: `${uniqueID}_label`,
descriptionID: `${uniqueID}_description`,
});
this.checkForActualContent();
},
};
methods = {
checkForActualContent() {
const target = ['ribbon', 'ribbon-right', 'ribbon-left', 'triangle-right', 'triangle-left'];
if (this.properties.content || !target.includes(this.properties.shape)) {
this.setData({ useOuterClass: false });
return;
}
return getRect(this, `.${name}__content`).then((rect) => {
const hasSlotContent = rect.width > 0 || rect.height > 0;
this.setData({ useOuterClass: !hasSlotContent });
});
},
};
}