@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.
Files changed (62) hide show
  1. package/dist/browser/index.js +86 -31
  2. package/dist/browser/index.js.map +4 -4
  3. package/dist/components/avatar/avatar.component.js +38 -32
  4. package/dist/components/avatar/avatar.constants.js +3 -9
  5. package/dist/components/avatar/avatar.styles.js +3 -5
  6. package/dist/components/avatar/avatar.types.js +1 -2
  7. package/dist/components/avatar/index.js +4 -7
  8. package/dist/components/badge/badge.component.d.ts +74 -29
  9. package/dist/components/badge/badge.component.js +182 -88
  10. package/dist/components/badge/badge.constants.d.ts +28 -4
  11. package/dist/components/badge/badge.constants.js +30 -12
  12. package/dist/components/badge/badge.styles.js +59 -19
  13. package/dist/components/badge/index.d.ts +2 -0
  14. package/dist/components/badge/index.js +6 -7
  15. package/dist/components/icon/icon.component.js +46 -40
  16. package/dist/components/icon/icon.constants.js +3 -8
  17. package/dist/components/icon/icon.styles.js +5 -7
  18. package/dist/components/icon/icon.utils.js +1 -4
  19. package/dist/components/icon/index.js +4 -7
  20. package/dist/components/iconprovider/iconprovider.component.js +39 -33
  21. package/dist/components/iconprovider/iconprovider.constants.js +3 -10
  22. package/dist/components/iconprovider/iconprovider.context.js +4 -6
  23. package/dist/components/iconprovider/index.js +4 -7
  24. package/dist/components/text/fonts.styles.js +2 -5
  25. package/dist/components/text/index.js +4 -7
  26. package/dist/components/text/text.component.js +35 -29
  27. package/dist/components/text/text.constants.js +3 -9
  28. package/dist/components/text/text.styles.js +5 -7
  29. package/dist/components/text/text.types.js +1 -2
  30. package/dist/components/themeprovider/index.js +4 -7
  31. package/dist/components/themeprovider/themeprovider.component.js +27 -21
  32. package/dist/components/themeprovider/themeprovider.constants.js +3 -8
  33. package/dist/components/themeprovider/themeprovider.context.js +4 -6
  34. package/dist/components/themeprovider/themeprovider.styles.js +3 -5
  35. package/dist/custom-elements.json +230 -51
  36. package/dist/index.js +7 -16
  37. package/dist/models/component/component.component.js +5 -8
  38. package/dist/models/component/component.styles.js +2 -4
  39. package/dist/models/component/component.types.js +1 -2
  40. package/dist/models/component/index.js +2 -5
  41. package/dist/models/index.js +3 -8
  42. package/dist/models/provider/index.js +2 -5
  43. package/dist/models/provider/provider.component.js +9 -12
  44. package/dist/models/provider/provider.styles.js +3 -5
  45. package/dist/react/avatar/index.js +8 -11
  46. package/dist/react/badge/index.d.ts +6 -3
  47. package/dist/react/badge/index.js +14 -14
  48. package/dist/react/icon/index.js +8 -11
  49. package/dist/react/iconprovider/index.js +8 -11
  50. package/dist/react/index.js +6 -18
  51. package/dist/react/text/index.js +8 -11
  52. package/dist/react/themeprovider/index.js +8 -11
  53. package/dist/utils/mixins/DisabledMixin.js +14 -10
  54. package/dist/utils/mixins/TabIndexMixin.js +14 -10
  55. package/dist/utils/provider/index.js +3 -5
  56. package/dist/utils/styles/index.js +4 -8
  57. package/dist/utils/tag-name/constants.js +1 -3
  58. package/dist/utils/tag-name/index.js +3 -6
  59. package/dist/utils/types.js +1 -2
  60. package/package.json +1 -1
  61. package/dist/components/badge/badge.types.d.ts +0 -1
  62. package/dist/components/badge/badge.types.js +0 -2
@@ -1,12 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const lit_1 = require("lit");
5
- const decorators_js_1 = require("lit/decorators.js");
6
- const if_defined_js_1 = require("lit/directives/if-defined.js");
7
- const avatar_styles_1 = tslib_1.__importDefault(require("./avatar.styles"));
8
- const models_1 = require("../../models");
9
- const avatar_constants_1 = require("./avatar.constants");
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 models_1.Component {
23
+ class Avatar extends Component {
18
24
  constructor() {
19
25
  super(...arguments);
20
- this.type = avatar_constants_1.DEFAULTS.TYPE;
26
+ this.type = DEFAULTS.TYPE;
21
27
  /**
22
28
  * Scale of the avatar
23
29
  */
24
- this.size = avatar_constants_1.DEFAULTS.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}${avatar_constants_1.LENGTH_UNIT}`;
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 (0, lit_1.html) `
49
+ return html `
44
50
  <img
45
- src="${(0, if_defined_js_1.ifDefined)(this.src)}"
46
- alt="${(0, if_defined_js_1.ifDefined)(this.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 = (0, lit_1.html) ``;
62
+ content = html ``;
57
63
  }
58
- return (0, lit_1.html) `${content}`;
64
+ return html `${content}`;
59
65
  }
60
66
  }
61
- Avatar.styles = [...models_1.Component.styles, ...avatar_styles_1.default];
62
- tslib_1.__decorate([
63
- (0, decorators_js_1.property)({ type: String, reflect: true }),
64
- tslib_1.__metadata("design:type", String)
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
- tslib_1.__decorate([
67
- (0, decorators_js_1.property)({ type: String }),
68
- tslib_1.__metadata("design:type", String)
72
+ __decorate([
73
+ property({ type: String }),
74
+ __metadata("design:type", String)
69
75
  ], Avatar.prototype, "alt", void 0);
70
- tslib_1.__decorate([
71
- (0, decorators_js_1.property)({ type: String }),
72
- tslib_1.__metadata("design:type", String)
76
+ __decorate([
77
+ property({ type: String }),
78
+ __metadata("design:type", String)
73
79
  ], Avatar.prototype, "src", void 0);
74
- tslib_1.__decorate([
75
- (0, decorators_js_1.property)({ type: Number }),
76
- tslib_1.__metadata("design:type", Number)
80
+ __decorate([
81
+ property({ type: Number }),
82
+ __metadata("design:type", Number)
77
83
  ], Avatar.prototype, "size", void 0);
78
- exports.default = Avatar;
84
+ export default Avatar;
@@ -1,14 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- exports.DEFAULTS = DEFAULTS;
8
+ export { TAG_NAME, DEFAULTS, LENGTH_UNIT };
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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
- exports.default = [styles];
18
+ export default [styles];
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const avatar_component_1 = tslib_1.__importDefault(require("./avatar.component"));
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
- * @slot - This is a default/unnamed slot
6
- *
7
- * @summary This is MyElement
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 `regular`, `icon`, `text` or `warning`
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: `rem`
18
+ * Default: `dot`
29
19
  */
30
- lengthUnit?: string;
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
- * If `type` is set to `text`, attribute `text` can
40
- * be used to pass in any text to be displayed in the badge.
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
- text?: string;
43
- private updateSize;
44
- updated(changedProperties: Map<string, any>): void;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const lit_1 = require("lit");
5
- const decorators_js_1 = require("lit/decorators.js");
6
- const if_defined_js_1 = require("lit/directives/if-defined.js");
7
- const style_map_js_1 = require("lit/directives/style-map.js");
8
- const models_1 = require("../../models");
9
- const badge_constants_1 = require("./badge.constants");
10
- const badge_styles_1 = tslib_1.__importDefault(require("./badge.styles"));
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
- * @slot - This is a default/unnamed slot
13
- *
14
- * @summary This is MyElement
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 models_1.Component {
27
+ class Badge extends Component {
19
28
  constructor() {
20
29
  super(...arguments);
21
30
  /**
22
31
  * Type of the badge
23
- * Can be `regular`, `icon`, `text` or `warning`
32
+ * Can be `dot` (notification) , `icon` and `counter`
24
33
  *
25
- * Default: `regular`
34
+ * Default: `dot`
26
35
  */
27
- this.type = badge_constants_1.DEFAULTS.TYPE;
36
+ this.type = DEFAULTS.TYPE;
28
37
  /**
29
- * Scale of the badge (works in combination with length unit)
30
- *
31
- * Default: `1`
38
+ * badge variant
32
39
  */
33
- this.size = badge_constants_1.DEFAULTS.SIZE;
40
+ this.variant = DEFAULTS.VARIANT;
41
+ this.maxCounter = DEFAULTS.MAX_COUNTER;
42
+ this.overlay = false;
34
43
  /**
35
- * Length unit attribute for scale
36
- *
37
- * Default: `rem`
44
+ * Aria-label attribute to be set for accessibility
38
45
  */
39
- this.lengthUnit = badge_constants_1.DEFAULTS.LENGTH_UNIT;
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
- updated(changedProperties) {
51
- super.updated(changedProperties);
52
- if (changedProperties.has('size') || changedProperties.has('lengthUnit')) {
53
- this.updateSize();
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
- iconTemplate() {
57
- return (0, lit_1.html) `<div class="mdc-badge-icon-container">
58
- <mdc-icon name=${(0, if_defined_js_1.ifDefined)(this.iconName)} size="100" length-unit="%"></mdc-icon>
59
- </div>`;
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
- textTemplate() {
62
- return (0, lit_1.html) `${this.text}`;
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
- warningTemplate() {
65
- return (0, lit_1.html) ` <mdc-icon name="${badge_constants_1.WARNING_ICON_NAME}" class="mdc-badge-warning"></mdc-icon> `;
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
- render() {
68
- let content;
69
- const size = `${this.size}${this.lengthUnit}`;
70
- let sizeStyles = { width: size, height: size };
71
- switch (this.type) {
72
- case 'regular':
73
- content = (0, lit_1.html) ``;
74
- break;
75
- case 'icon':
76
- content = this.iconTemplate();
77
- break;
78
- case 'text':
79
- content = this.textTemplate();
80
- // make width flexible when text -> only set the height:
81
- sizeStyles = { height: sizeStyles.height };
82
- break;
83
- case 'warning':
84
- content = this.warningTemplate();
85
- break;
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
- content = (0, lit_1.html) ``;
88
- break;
166
+ return html ``;
89
167
  }
90
- return (0, lit_1.html) `<div class="mdc-badge-container" style=${(0, style_map_js_1.styleMap)(sizeStyles)}>${content}</div>`;
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 = [...models_1.Component.styles, ...badge_styles_1.default];
94
- tslib_1.__decorate([
95
- (0, decorators_js_1.property)({ type: String, reflect: true }),
96
- tslib_1.__metadata("design:type", String)
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
- tslib_1.__decorate([
99
- (0, decorators_js_1.property)({ type: Number }),
100
- tslib_1.__metadata("design:type", Number)
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
- tslib_1.__decorate([
111
- (0, decorators_js_1.property)({ type: String }),
112
- tslib_1.__metadata("design:type", String)
113
- ], Badge.prototype, "text", void 0);
114
- exports.default = Badge;
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 WARNING_ICON_NAME = "warning-badge-filled";
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: "regular";
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, WARNING_ICON_NAME, };
32
+ export { TAG_NAME, DEFAULTS, BADGE_TYPE, ICON_STATE, ICON_VARIANT, ICON_NAMES_LIST, };