@momentum-design/components 0.4.13 → 0.4.15
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/browser/index.js +86 -31
- package/dist/browser/index.js.map +4 -4
- package/dist/components/avatar/avatar.component.js +38 -32
- package/dist/components/avatar/avatar.constants.js +3 -9
- package/dist/components/avatar/avatar.styles.js +3 -5
- package/dist/components/avatar/avatar.types.js +1 -2
- package/dist/components/avatar/index.js +4 -7
- package/dist/components/badge/badge.component.d.ts +74 -29
- package/dist/components/badge/badge.component.js +182 -88
- package/dist/components/badge/badge.constants.d.ts +28 -4
- package/dist/components/badge/badge.constants.js +30 -12
- package/dist/components/badge/badge.styles.js +59 -19
- package/dist/components/badge/index.d.ts +2 -0
- package/dist/components/badge/index.js +6 -7
- package/dist/components/icon/icon.component.js +46 -40
- package/dist/components/icon/icon.constants.js +3 -8
- package/dist/components/icon/icon.styles.js +5 -7
- package/dist/components/icon/icon.utils.js +1 -4
- package/dist/components/icon/index.js +4 -7
- package/dist/components/iconprovider/iconprovider.component.js +39 -33
- package/dist/components/iconprovider/iconprovider.constants.js +3 -10
- package/dist/components/iconprovider/iconprovider.context.js +4 -6
- package/dist/components/iconprovider/index.js +4 -7
- package/dist/components/text/fonts.styles.js +2 -5
- package/dist/components/text/index.js +4 -7
- package/dist/components/text/text.component.js +35 -29
- package/dist/components/text/text.constants.js +3 -9
- package/dist/components/text/text.styles.js +5 -7
- package/dist/components/text/text.types.js +1 -2
- package/dist/components/themeprovider/index.js +4 -7
- package/dist/components/themeprovider/themeprovider.component.js +27 -21
- package/dist/components/themeprovider/themeprovider.constants.js +3 -8
- package/dist/components/themeprovider/themeprovider.context.js +4 -6
- package/dist/components/themeprovider/themeprovider.styles.js +3 -5
- package/dist/custom-elements.json +230 -51
- package/dist/index.js +7 -16
- package/dist/models/component/component.component.js +5 -8
- package/dist/models/component/component.styles.js +2 -4
- package/dist/models/component/component.types.js +1 -2
- package/dist/models/component/index.js +2 -5
- package/dist/models/index.js +3 -8
- package/dist/models/provider/index.js +2 -5
- package/dist/models/provider/provider.component.js +9 -12
- package/dist/models/provider/provider.styles.js +3 -5
- package/dist/react/avatar/index.js +8 -11
- package/dist/react/badge/index.d.ts +6 -3
- package/dist/react/badge/index.js +14 -14
- package/dist/react/icon/index.js +8 -11
- package/dist/react/iconprovider/index.js +8 -11
- package/dist/react/index.js +6 -18
- package/dist/react/text/index.js +8 -11
- package/dist/react/themeprovider/index.js +8 -11
- package/dist/utils/mixins/DisabledMixin.js +14 -10
- package/dist/utils/mixins/TabIndexMixin.js +14 -10
- package/dist/utils/provider/index.js +3 -5
- package/dist/utils/styles/index.js +4 -8
- package/dist/utils/tag-name/constants.js +1 -3
- package/dist/utils/tag-name/index.js +3 -6
- package/dist/utils/types.js +1 -2
- package/package.json +1 -1
- package/dist/components/badge/badge.types.d.ts +0 -1
- package/dist/components/badge/badge.types.js +0 -2
@@ -1,12 +1,18 @@
|
|
1
|
-
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html } from 'lit';
|
11
|
+
import { property } from 'lit/decorators.js';
|
12
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
13
|
+
import styles from './avatar.styles';
|
14
|
+
import { Component } from '../../models';
|
15
|
+
import { DEFAULTS, LENGTH_UNIT } from './avatar.constants';
|
10
16
|
/**
|
11
17
|
* @slot - This is a default/unnamed slot
|
12
18
|
*
|
@@ -14,21 +20,21 @@ const avatar_constants_1 = require("./avatar.constants");
|
|
14
20
|
*
|
15
21
|
* @tagname mdc-avatar
|
16
22
|
*/
|
17
|
-
class Avatar extends
|
23
|
+
class Avatar extends Component {
|
18
24
|
constructor() {
|
19
25
|
super(...arguments);
|
20
|
-
this.type =
|
26
|
+
this.type = DEFAULTS.TYPE;
|
21
27
|
/**
|
22
28
|
* Scale of the avatar
|
23
29
|
*/
|
24
|
-
this.size =
|
30
|
+
this.size = DEFAULTS.SIZE;
|
25
31
|
}
|
26
32
|
/**
|
27
33
|
* Updates the size by setting the width and height
|
28
34
|
*/
|
29
35
|
updateSize() {
|
30
36
|
if (this.size) {
|
31
|
-
const value = `${this.size}${
|
37
|
+
const value = `${this.size}${LENGTH_UNIT}`;
|
32
38
|
this.style.width = value;
|
33
39
|
this.style.height = value;
|
34
40
|
}
|
@@ -40,10 +46,10 @@ class Avatar extends models_1.Component {
|
|
40
46
|
}
|
41
47
|
}
|
42
48
|
photoTemplate() {
|
43
|
-
return
|
49
|
+
return html `
|
44
50
|
<img
|
45
|
-
src="${
|
46
|
-
alt="${
|
51
|
+
src="${ifDefined(this.src)}"
|
52
|
+
alt="${ifDefined(this.alt)}"
|
47
53
|
/>
|
48
54
|
`;
|
49
55
|
}
|
@@ -53,26 +59,26 @@ class Avatar extends models_1.Component {
|
|
53
59
|
content = this.photoTemplate();
|
54
60
|
}
|
55
61
|
else {
|
56
|
-
content =
|
62
|
+
content = html ``;
|
57
63
|
}
|
58
|
-
return
|
64
|
+
return html `${content}`;
|
59
65
|
}
|
60
66
|
}
|
61
|
-
Avatar.styles = [...
|
62
|
-
|
63
|
-
|
64
|
-
|
67
|
+
Avatar.styles = [...Component.styles, ...styles];
|
68
|
+
__decorate([
|
69
|
+
property({ type: String, reflect: true }),
|
70
|
+
__metadata("design:type", String)
|
65
71
|
], Avatar.prototype, "type", void 0);
|
66
|
-
|
67
|
-
|
68
|
-
|
72
|
+
__decorate([
|
73
|
+
property({ type: String }),
|
74
|
+
__metadata("design:type", String)
|
69
75
|
], Avatar.prototype, "alt", void 0);
|
70
|
-
|
71
|
-
|
72
|
-
|
76
|
+
__decorate([
|
77
|
+
property({ type: String }),
|
78
|
+
__metadata("design:type", String)
|
73
79
|
], Avatar.prototype, "src", void 0);
|
74
|
-
|
75
|
-
|
76
|
-
|
80
|
+
__decorate([
|
81
|
+
property({ type: Number }),
|
82
|
+
__metadata("design:type", Number)
|
77
83
|
], Avatar.prototype, "size", void 0);
|
78
|
-
|
84
|
+
export default Avatar;
|
@@ -1,14 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
exports.LENGTH_UNIT = exports.DEFAULTS = exports.TAG_NAME = void 0;
|
4
|
-
const tslib_1 = require("tslib");
|
5
|
-
const tag_name_1 = tslib_1.__importDefault(require("../../utils/tag-name"));
|
6
|
-
const TAG_NAME = tag_name_1.default.constructTagName('avatar');
|
7
|
-
exports.TAG_NAME = TAG_NAME;
|
1
|
+
import utils from '../../utils/tag-name';
|
2
|
+
const TAG_NAME = utils.constructTagName('avatar');
|
8
3
|
const LENGTH_UNIT = 'rem';
|
9
|
-
exports.LENGTH_UNIT = LENGTH_UNIT;
|
10
4
|
const DEFAULTS = {
|
11
5
|
TYPE: 'photo',
|
12
6
|
SIZE: 1.5,
|
13
7
|
};
|
14
|
-
|
8
|
+
export { TAG_NAME, DEFAULTS, LENGTH_UNIT };
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
const lit_1 = require("lit");
|
4
|
-
const styles = (0, lit_1.css) `
|
1
|
+
import { css } from 'lit';
|
2
|
+
const styles = css `
|
5
3
|
:host {
|
6
4
|
display: flex;
|
7
5
|
justify-content: center;
|
@@ -17,4 +15,4 @@ const styles = (0, lit_1.css) `
|
|
17
15
|
object-fit: cover;
|
18
16
|
}
|
19
17
|
`;
|
20
|
-
|
18
|
+
export default [styles];
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
1
|
+
export {};
|
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
const avatar_constants_1 = require("./avatar.constants");
|
6
|
-
avatar_component_1.default.register(avatar_constants_1.TAG_NAME);
|
7
|
-
exports.default = avatar_component_1.default;
|
1
|
+
import Avatar from './avatar.component';
|
2
|
+
import { TAG_NAME } from './avatar.constants';
|
3
|
+
Avatar.register(TAG_NAME);
|
4
|
+
export default Avatar;
|
@@ -1,33 +1,23 @@
|
|
1
|
-
import { CSSResult } from 'lit';
|
1
|
+
import { CSSResult, PropertyValues, TemplateResult } from 'lit';
|
2
2
|
import { Component } from '../../models';
|
3
|
-
import type { BadgeType } from './badge.types';
|
4
3
|
/**
|
5
|
-
*
|
6
|
-
*
|
7
|
-
*
|
4
|
+
* A badge is a small, visually distinct element that provides additional information
|
5
|
+
* or highlights the status of an item.
|
6
|
+
* Badges are often used to display notification dot, counts, making them a useful tool for
|
7
|
+
* conveying information quickly without taking up much space.
|
8
|
+
* @dependency mdc-icon
|
9
|
+
* @dependency mdc-text
|
8
10
|
*
|
9
11
|
* @tagname mdc-badge
|
10
12
|
*/
|
11
13
|
declare class Badge extends Component {
|
12
14
|
/**
|
13
15
|
* Type of the badge
|
14
|
-
* Can be `
|
15
|
-
*
|
16
|
-
* Default: `regular`
|
17
|
-
*/
|
18
|
-
type?: BadgeType;
|
19
|
-
/**
|
20
|
-
* Scale of the badge (works in combination with length unit)
|
21
|
-
*
|
22
|
-
* Default: `1`
|
23
|
-
*/
|
24
|
-
size?: number;
|
25
|
-
/**
|
26
|
-
* Length unit attribute for scale
|
16
|
+
* Can be `dot` (notification) , `icon` and `counter`
|
27
17
|
*
|
28
|
-
* Default: `
|
18
|
+
* Default: `dot`
|
29
19
|
*/
|
30
|
-
|
20
|
+
type: string;
|
31
21
|
/**
|
32
22
|
* If `type` is set to `icon`, attribute `iconName` can
|
33
23
|
* be used to choose which icon should be shown
|
@@ -36,16 +26,71 @@ declare class Badge extends Component {
|
|
36
26
|
*/
|
37
27
|
iconName?: string;
|
38
28
|
/**
|
39
|
-
*
|
40
|
-
|
29
|
+
* badge variant
|
30
|
+
*/
|
31
|
+
variant: string;
|
32
|
+
counter?: number;
|
33
|
+
maxCounter: number;
|
34
|
+
overlay: boolean;
|
35
|
+
/**
|
36
|
+
* Aria-label attribute to be set for accessibility
|
37
|
+
*/
|
38
|
+
ariaLabel: string | null;
|
39
|
+
/**
|
40
|
+
* If `type` is set to `counter` and if `counter` is greater than `maxCounter`,
|
41
|
+
* then it will return a string the maxCounter value as string.
|
42
|
+
* Otherwise, it will return a string representation of `counter`.
|
43
|
+
* If `counter` is not a number, it will return an empty string.
|
44
|
+
* @param maxCounter - the maximum limit which can be displayed on the badge
|
45
|
+
* @param counter - the number to be displayed on the badge
|
46
|
+
* @returns the string representation of the counter
|
47
|
+
*/
|
48
|
+
private getCounterText;
|
49
|
+
/**
|
50
|
+
* Method to generate the badge icon template.
|
51
|
+
* @param iconName - name of the icon to be used.
|
52
|
+
* @param variant - variant of the badge.
|
53
|
+
* @returns the template result of the icon.
|
54
|
+
*/
|
55
|
+
private getBadgeIcon;
|
56
|
+
/**
|
57
|
+
* Method to generate the badge dot template.
|
58
|
+
* @param overlay - boolean indicating whether the badge should have an overlay.
|
59
|
+
* @returns the template result of the dot with mdc-badge-dot class.
|
60
|
+
*/
|
61
|
+
private getBadgeDot;
|
62
|
+
/**
|
63
|
+
* This method generates the CSS classes for the badge icon.
|
64
|
+
* @param overlay - boolean indicating whether the badge should have an overlay.
|
65
|
+
* @param iconVariant - the variant of the icon badge.
|
66
|
+
* @param type - the type of the badge.
|
67
|
+
* @returns - an object containing the CSS classes for the icon.
|
68
|
+
*/
|
69
|
+
private getIconClasses;
|
70
|
+
/**
|
71
|
+
* Method to generate the badge text and counter template.
|
72
|
+
* @param maxCounter - the maximum limit which can be displayed on the badge
|
73
|
+
* @param overlay - whether the badge should have an overlay.
|
74
|
+
* @param counter - the number to be displayed on the badge
|
75
|
+
* @returns the template result of the text.
|
76
|
+
*/
|
77
|
+
private getBadgeCounterText;
|
78
|
+
/**
|
79
|
+
* Method to set the role based on the aria-label provided.
|
80
|
+
* If the aria-label is provided, the role of the element will be 'img'.
|
81
|
+
* Otherwise, the role will be null.
|
82
|
+
*/
|
83
|
+
private setRoleByAriaLabel;
|
84
|
+
/**
|
85
|
+
* Generates the badge content based on the badge type.
|
86
|
+
* Utilizes various helper methods to create the appropriate badge template based on the
|
87
|
+
* current badge type. Supports 'dot', 'icon', 'counter', 'success', 'warning', and 'error'
|
88
|
+
* types, returning the corresponding template result for each type.
|
89
|
+
* @returns the TemplateResult for the current badge type.
|
41
90
|
*/
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
iconTemplate(): import("lit-html").TemplateResult<1>;
|
46
|
-
textTemplate(): import("lit-html").TemplateResult<1>;
|
47
|
-
warningTemplate(): import("lit-html").TemplateResult<1>;
|
48
|
-
render(): import("lit-html").TemplateResult<1>;
|
91
|
+
private getBadgeContentBasedOnType;
|
92
|
+
update(changedProperties: PropertyValues): void;
|
93
|
+
render(): TemplateResult<1 | 2 | 3>;
|
49
94
|
static styles: Array<CSSResult>;
|
50
95
|
}
|
51
96
|
export default Badge;
|
@@ -1,114 +1,208 @@
|
|
1
|
-
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
9
|
+
};
|
10
|
+
import { html } from 'lit';
|
11
|
+
import { classMap } from 'lit-html/directives/class-map.js';
|
12
|
+
import { property } from 'lit/decorators.js';
|
13
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
14
|
+
import { Component } from '../../models';
|
15
|
+
import { BADGE_TYPE, ICON_NAMES_LIST, DEFAULTS, ICON_VARIANT, ICON_STATE } from './badge.constants';
|
16
|
+
import styles from './badge.styles';
|
11
17
|
/**
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
18
|
+
* A badge is a small, visually distinct element that provides additional information
|
19
|
+
* or highlights the status of an item.
|
20
|
+
* Badges are often used to display notification dot, counts, making them a useful tool for
|
21
|
+
* conveying information quickly without taking up much space.
|
22
|
+
* @dependency mdc-icon
|
23
|
+
* @dependency mdc-text
|
15
24
|
*
|
16
25
|
* @tagname mdc-badge
|
17
26
|
*/
|
18
|
-
class Badge extends
|
27
|
+
class Badge extends Component {
|
19
28
|
constructor() {
|
20
29
|
super(...arguments);
|
21
30
|
/**
|
22
31
|
* Type of the badge
|
23
|
-
* Can be `
|
32
|
+
* Can be `dot` (notification) , `icon` and `counter`
|
24
33
|
*
|
25
|
-
* Default: `
|
34
|
+
* Default: `dot`
|
26
35
|
*/
|
27
|
-
this.type =
|
36
|
+
this.type = DEFAULTS.TYPE;
|
28
37
|
/**
|
29
|
-
*
|
30
|
-
*
|
31
|
-
* Default: `1`
|
38
|
+
* badge variant
|
32
39
|
*/
|
33
|
-
this.
|
40
|
+
this.variant = DEFAULTS.VARIANT;
|
41
|
+
this.maxCounter = DEFAULTS.MAX_COUNTER;
|
42
|
+
this.overlay = false;
|
34
43
|
/**
|
35
|
-
*
|
36
|
-
*
|
37
|
-
* Default: `rem`
|
44
|
+
* Aria-label attribute to be set for accessibility
|
38
45
|
*/
|
39
|
-
this.
|
40
|
-
}
|
41
|
-
updateSize() {
|
42
|
-
// if (this.scale && this.lengthUnit) {
|
43
|
-
// const value = `${this.scale}${this.lengthUnit}`;
|
44
|
-
// this.style.height = value;
|
45
|
-
// if (this.type !== 'text') {
|
46
|
-
// this.style.width = value;
|
47
|
-
// }
|
48
|
-
// }
|
46
|
+
this.ariaLabel = null;
|
49
47
|
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
/**
|
49
|
+
* If `type` is set to `counter` and if `counter` is greater than `maxCounter`,
|
50
|
+
* then it will return a string the maxCounter value as string.
|
51
|
+
* Otherwise, it will return a string representation of `counter`.
|
52
|
+
* If `counter` is not a number, it will return an empty string.
|
53
|
+
* @param maxCounter - the maximum limit which can be displayed on the badge
|
54
|
+
* @param counter - the number to be displayed on the badge
|
55
|
+
* @returns the string representation of the counter
|
56
|
+
*/
|
57
|
+
getCounterText(maxCounter, counter) {
|
58
|
+
if (counter === undefined || typeof counter !== 'number') {
|
59
|
+
return '';
|
54
60
|
}
|
61
|
+
// At any given time, the max limit should not cross 999.
|
62
|
+
if (counter > DEFAULTS.MAX_COUNTER_LIMIT) {
|
63
|
+
return `${DEFAULTS.MAX_COUNTER_LIMIT}+`;
|
64
|
+
}
|
65
|
+
if (counter > maxCounter) {
|
66
|
+
return `${maxCounter}+`;
|
67
|
+
}
|
68
|
+
return counter.toString();
|
55
69
|
}
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
70
|
+
/**
|
71
|
+
* Method to generate the badge icon template.
|
72
|
+
* @param iconName - name of the icon to be used.
|
73
|
+
* @param variant - variant of the badge.
|
74
|
+
* @returns the template result of the icon.
|
75
|
+
*/
|
76
|
+
getBadgeIcon(iconName, overlay, iconVariant, type) {
|
77
|
+
return html `
|
78
|
+
<mdc-icon
|
79
|
+
class="mdc-badge-icon ${classMap(this.getIconClasses(overlay, iconVariant, type))}"
|
80
|
+
name="${ifDefined(iconName)}"
|
81
|
+
length-unit="${DEFAULTS.LENGTH_UNIT}"
|
82
|
+
size="${DEFAULTS.ICON_SIZE}"
|
83
|
+
></mdc-icon>
|
84
|
+
`;
|
60
85
|
}
|
61
|
-
|
62
|
-
|
86
|
+
/**
|
87
|
+
* Method to generate the badge dot template.
|
88
|
+
* @param overlay - boolean indicating whether the badge should have an overlay.
|
89
|
+
* @returns the template result of the dot with mdc-badge-dot class.
|
90
|
+
*/
|
91
|
+
getBadgeDot(overlay) {
|
92
|
+
return html `<div class="mdc-badge-dot ${classMap({ 'mdc-badge-overlay': overlay })}"></div>`;
|
63
93
|
}
|
64
|
-
|
65
|
-
|
94
|
+
/**
|
95
|
+
* This method generates the CSS classes for the badge icon.
|
96
|
+
* @param overlay - boolean indicating whether the badge should have an overlay.
|
97
|
+
* @param iconVariant - the variant of the icon badge.
|
98
|
+
* @param type - the type of the badge.
|
99
|
+
* @returns - an object containing the CSS classes for the icon.
|
100
|
+
*/
|
101
|
+
getIconClasses(overlay, iconVariant, type) {
|
102
|
+
const overLayClass = { 'mdc-badge-overlay': overlay };
|
103
|
+
const variantTypes = type === BADGE_TYPE.ICON ? ICON_VARIANT : ICON_STATE;
|
104
|
+
const iconVariantType = Object.values(variantTypes).includes(iconVariant)
|
105
|
+
? iconVariant : DEFAULTS.VARIANT;
|
106
|
+
const backgroundClass = { [`mdc-badge-icon__${iconVariantType}`]: true };
|
107
|
+
return {
|
108
|
+
...overLayClass,
|
109
|
+
...backgroundClass,
|
110
|
+
};
|
66
111
|
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
112
|
+
/**
|
113
|
+
* Method to generate the badge text and counter template.
|
114
|
+
* @param maxCounter - the maximum limit which can be displayed on the badge
|
115
|
+
* @param overlay - whether the badge should have an overlay.
|
116
|
+
* @param counter - the number to be displayed on the badge
|
117
|
+
* @returns the template result of the text.
|
118
|
+
*/
|
119
|
+
getBadgeCounterText(maxCounter, overlay, counter) {
|
120
|
+
return html `
|
121
|
+
<mdc-text
|
122
|
+
type="body-small-medium"
|
123
|
+
tagname="div"
|
124
|
+
class="mdc-badge-text ${classMap({ 'mdc-badge-overlay': overlay })}"
|
125
|
+
>
|
126
|
+
${this.getCounterText(maxCounter, counter)}
|
127
|
+
</mdc-text>
|
128
|
+
`;
|
129
|
+
}
|
130
|
+
/**
|
131
|
+
* Method to set the role based on the aria-label provided.
|
132
|
+
* If the aria-label is provided, the role of the element will be 'img'.
|
133
|
+
* Otherwise, the role will be null.
|
134
|
+
*/
|
135
|
+
setRoleByAriaLabel() {
|
136
|
+
if (this.ariaLabel) {
|
137
|
+
this.role = 'img';
|
138
|
+
}
|
139
|
+
else {
|
140
|
+
this.role = null;
|
141
|
+
}
|
142
|
+
}
|
143
|
+
/**
|
144
|
+
* Generates the badge content based on the badge type.
|
145
|
+
* Utilizes various helper methods to create the appropriate badge template based on the
|
146
|
+
* current badge type. Supports 'dot', 'icon', 'counter', 'success', 'warning', and 'error'
|
147
|
+
* types, returning the corresponding template result for each type.
|
148
|
+
* @returns the TemplateResult for the current badge type.
|
149
|
+
*/
|
150
|
+
getBadgeContentBasedOnType() {
|
151
|
+
const { counter, iconName, maxCounter, overlay, type, variant } = this;
|
152
|
+
switch (type) {
|
153
|
+
case BADGE_TYPE.DOT:
|
154
|
+
return this.getBadgeDot(overlay);
|
155
|
+
case BADGE_TYPE.ICON:
|
156
|
+
return this.getBadgeIcon(iconName || '', overlay, variant, type);
|
157
|
+
case BADGE_TYPE.COUNTER:
|
158
|
+
return this.getBadgeCounterText(maxCounter, overlay, counter);
|
159
|
+
case BADGE_TYPE.SUCCESS:
|
160
|
+
return this.getBadgeIcon(ICON_NAMES_LIST.SUCCESS_ICON_NAME, overlay, ICON_STATE.SUCCESS);
|
161
|
+
case BADGE_TYPE.WARNING:
|
162
|
+
return this.getBadgeIcon(ICON_NAMES_LIST.WARNING_ICON_NAME, overlay, ICON_STATE.WARNING);
|
163
|
+
case BADGE_TYPE.ERROR:
|
164
|
+
return this.getBadgeIcon(ICON_NAMES_LIST.ERROR_ICON_NAME, overlay, ICON_STATE.ERROR);
|
86
165
|
default:
|
87
|
-
|
88
|
-
break;
|
166
|
+
return html ``;
|
89
167
|
}
|
90
|
-
|
168
|
+
}
|
169
|
+
update(changedProperties) {
|
170
|
+
super.update(changedProperties);
|
171
|
+
if (changedProperties.has('ariaLabel')) {
|
172
|
+
this.setRoleByAriaLabel();
|
173
|
+
}
|
174
|
+
}
|
175
|
+
render() {
|
176
|
+
return this.getBadgeContentBasedOnType();
|
91
177
|
}
|
92
178
|
}
|
93
|
-
Badge.styles = [...
|
94
|
-
|
95
|
-
|
96
|
-
|
179
|
+
Badge.styles = [...Component.styles, ...styles];
|
180
|
+
__decorate([
|
181
|
+
property({ type: String, reflect: true }),
|
182
|
+
__metadata("design:type", Object)
|
97
183
|
], Badge.prototype, "type", void 0);
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
], Badge.prototype, "size", void 0);
|
102
|
-
tslib_1.__decorate([
|
103
|
-
(0, decorators_js_1.property)({ type: String, attribute: 'length-unit' }),
|
104
|
-
tslib_1.__metadata("design:type", String)
|
105
|
-
], Badge.prototype, "lengthUnit", void 0);
|
106
|
-
tslib_1.__decorate([
|
107
|
-
(0, decorators_js_1.property)({ type: String, attribute: 'icon-name' }),
|
108
|
-
tslib_1.__metadata("design:type", String)
|
184
|
+
__decorate([
|
185
|
+
property({ type: String, attribute: 'icon-name' }),
|
186
|
+
__metadata("design:type", String)
|
109
187
|
], Badge.prototype, "iconName", void 0);
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
], Badge.prototype, "
|
114
|
-
|
188
|
+
__decorate([
|
189
|
+
property({ type: String }),
|
190
|
+
__metadata("design:type", Object)
|
191
|
+
], Badge.prototype, "variant", void 0);
|
192
|
+
__decorate([
|
193
|
+
property({ type: Number }),
|
194
|
+
__metadata("design:type", Number)
|
195
|
+
], Badge.prototype, "counter", void 0);
|
196
|
+
__decorate([
|
197
|
+
property({ type: Number, attribute: 'max-counter' }),
|
198
|
+
__metadata("design:type", Number)
|
199
|
+
], Badge.prototype, "maxCounter", void 0);
|
200
|
+
__decorate([
|
201
|
+
property({ type: Boolean }),
|
202
|
+
__metadata("design:type", Object)
|
203
|
+
], Badge.prototype, "overlay", void 0);
|
204
|
+
__decorate([
|
205
|
+
property({ type: String, attribute: 'aria-label' }),
|
206
|
+
__metadata("design:type", Object)
|
207
|
+
], Badge.prototype, "ariaLabel", void 0);
|
208
|
+
export default Badge;
|
@@ -1,8 +1,32 @@
|
|
1
1
|
declare const TAG_NAME: "mdc-badge";
|
2
|
-
declare const
|
2
|
+
declare const BADGE_TYPE: {
|
3
|
+
DOT: string;
|
4
|
+
ICON: string;
|
5
|
+
COUNTER: string;
|
6
|
+
SUCCESS: string;
|
7
|
+
WARNING: string;
|
8
|
+
ERROR: string;
|
9
|
+
};
|
10
|
+
declare const ICON_NAMES_LIST: {
|
11
|
+
SUCCESS_ICON_NAME: string;
|
12
|
+
WARNING_ICON_NAME: string;
|
13
|
+
ERROR_ICON_NAME: string;
|
14
|
+
};
|
15
|
+
declare const ICON_VARIANT: {
|
16
|
+
PRIMARY: string;
|
17
|
+
SECONDARY: string;
|
18
|
+
};
|
19
|
+
declare const ICON_STATE: {
|
20
|
+
SUCCESS: string;
|
21
|
+
WARNING: string;
|
22
|
+
ERROR: string;
|
23
|
+
};
|
3
24
|
declare const DEFAULTS: {
|
4
|
-
TYPE:
|
5
|
-
SIZE: number;
|
25
|
+
TYPE: string;
|
6
26
|
LENGTH_UNIT: string;
|
27
|
+
MAX_COUNTER: number;
|
28
|
+
MAX_COUNTER_LIMIT: number;
|
29
|
+
VARIANT: string;
|
30
|
+
ICON_SIZE: number;
|
7
31
|
};
|
8
|
-
export { TAG_NAME, DEFAULTS,
|
32
|
+
export { TAG_NAME, DEFAULTS, BADGE_TYPE, ICON_STATE, ICON_VARIANT, ICON_NAMES_LIST, };
|