@momentum-design/components 0.4.16 → 0.4.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,22 @@
1
1
  import { CSSResult, PropertyValues, TemplateResult } from 'lit';
2
2
  import { Component } from '../../models';
3
3
  /**
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.
4
+ * The `mdc-badge` component is a versatile UI element used to
5
+ * display dot, icons, counters, success, warning and error type badge.
6
+ *
7
+ * Supported badge types:
8
+ * - `dot`: Displays a dot notification badge with a blue color.
9
+ * - `icon`: Displays a badge with a specified icon using the `icon-name` attribute.
10
+ * - `counter`: Displays a badge with a counter value. If the counter exceeds the `max-counter`,
11
+ * it shows `maxCounter+`. The maximum value of the counter is 999 and anything about that will be set to `999+`.
12
+ * - `success`: Displays a success badge with a check circle icon and green color.
13
+ * - `warning`: Displays a warning badge with a warning icon and yellow color.
14
+ * - `error`: Displays a error badge with a error legacy icon and red color.
15
+ *
16
+ * For `icon`, `success`, `warning` and `error` types, the `mdc-icon` component is used to render the icon.
17
+ *
18
+ * For the `counter` type, the `mdc-text` component is used to render the counter value.
19
+ *
8
20
  * @dependency mdc-icon
9
21
  * @dependency mdc-text
10
22
  *
@@ -13,24 +25,34 @@ import { Component } from '../../models';
13
25
  declare class Badge extends Component {
14
26
  /**
15
27
  * Type of the badge
16
- * Can be `dot` (notification) , `icon` and `counter`
17
- *
18
- * Default: `dot`
28
+ * Can be `dot` (notification) , `icon`, `counter`, `success`, `warning` or `error`.
19
29
  */
20
- type: string;
30
+ type?: string;
21
31
  /**
22
- * If `type` is set to `icon`, attribute `iconName` can
23
- * be used to choose which icon should be shown
32
+ * Name of the icon (= filename).
24
33
  *
25
- * If no `iconName` is provided, no icon will be rendered.
34
+ * If no `icon-name` is provided, no icon will be rendered.
26
35
  */
27
36
  iconName?: string;
28
37
  /**
29
- * badge variant
38
+ * Type of the variant can be `primary` or `secondary`.
39
+ * It defines the background and foreground color of the icon.
30
40
  */
31
41
  variant: string;
42
+ /**
43
+ * Counter is the number which can be provided in the badge.
44
+ */
32
45
  counter?: number;
46
+ /**
47
+ * The maximum number can be set up to 999, anything about that will be rendered as _999+_.
48
+ * The max counter can be `9`, `99` or `999`.
49
+ */
33
50
  maxCounter: number;
51
+ /**
52
+ * Overlay is to add a thin outline to the badge.
53
+ * This will help distinguish between the badge and the button,
54
+ * where the badge will be layered on top of a button.
55
+ */
34
56
  overlay: boolean;
35
57
  /**
36
58
  * Aria-label attribute to be set for accessibility
@@ -47,9 +69,11 @@ declare class Badge extends Component {
47
69
  */
48
70
  private getCounterText;
49
71
  /**
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.
72
+ * Method to generate the badge icon.
73
+ * @param iconName - the name of the icon from the icon set
74
+ * @param overlay - boolean indicating whether the badge should have an overlay.
75
+ * @param iconVariant - the variant of the icon badge.
76
+ * @param type - the type of the badge.
53
77
  * @returns the template result of the icon.
54
78
  */
55
79
  private getBadgeIcon;
@@ -12,13 +12,26 @@ import { classMap } from 'lit-html/directives/class-map.js';
12
12
  import { property } from 'lit/decorators.js';
13
13
  import { ifDefined } from 'lit/directives/if-defined.js';
14
14
  import { Component } from '../../models';
15
+ import { FONT_TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
15
16
  import { BADGE_TYPE, ICON_NAMES_LIST, DEFAULTS, ICON_VARIANT, ICON_STATE } from './badge.constants';
16
17
  import styles from './badge.styles';
17
18
  /**
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.
19
+ * The `mdc-badge` component is a versatile UI element used to
20
+ * display dot, icons, counters, success, warning and error type badge.
21
+ *
22
+ * Supported badge types:
23
+ * - `dot`: Displays a dot notification badge with a blue color.
24
+ * - `icon`: Displays a badge with a specified icon using the `icon-name` attribute.
25
+ * - `counter`: Displays a badge with a counter value. If the counter exceeds the `max-counter`,
26
+ * it shows `maxCounter+`. The maximum value of the counter is 999 and anything about that will be set to `999+`.
27
+ * - `success`: Displays a success badge with a check circle icon and green color.
28
+ * - `warning`: Displays a warning badge with a warning icon and yellow color.
29
+ * - `error`: Displays a error badge with a error legacy icon and red color.
30
+ *
31
+ * For `icon`, `success`, `warning` and `error` types, the `mdc-icon` component is used to render the icon.
32
+ *
33
+ * For the `counter` type, the `mdc-text` component is used to render the counter value.
34
+ *
22
35
  * @dependency mdc-icon
23
36
  * @dependency mdc-text
24
37
  *
@@ -28,17 +41,20 @@ class Badge extends Component {
28
41
  constructor() {
29
42
  super(...arguments);
30
43
  /**
31
- * Type of the badge
32
- * Can be `dot` (notification) , `icon` and `counter`
33
- *
34
- * Default: `dot`
44
+ * Type of the variant can be `primary` or `secondary`.
45
+ * It defines the background and foreground color of the icon.
35
46
  */
36
- this.type = DEFAULTS.TYPE;
47
+ this.variant = DEFAULTS.VARIANT;
37
48
  /**
38
- * badge variant
49
+ * The maximum number can be set up to 999, anything about that will be rendered as _999+_.
50
+ * The max counter can be `9`, `99` or `999`.
39
51
  */
40
- this.variant = DEFAULTS.VARIANT;
41
52
  this.maxCounter = DEFAULTS.MAX_COUNTER;
53
+ /**
54
+ * Overlay is to add a thin outline to the badge.
55
+ * This will help distinguish between the badge and the button,
56
+ * where the badge will be layered on top of a button.
57
+ */
42
58
  this.overlay = false;
43
59
  /**
44
60
  * Aria-label attribute to be set for accessibility
@@ -55,22 +71,24 @@ class Badge extends Component {
55
71
  * @returns the string representation of the counter
56
72
  */
57
73
  getCounterText(maxCounter, counter) {
58
- if (counter === undefined || typeof counter !== 'number') {
74
+ if (counter === undefined || typeof counter !== 'number' || maxCounter === 0) {
59
75
  return '';
60
76
  }
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
77
  if (counter > maxCounter) {
66
78
  return `${maxCounter}+`;
67
79
  }
80
+ // At any given time, the max limit should not cross 999.
81
+ if (maxCounter > DEFAULTS.MAX_COUNTER_LIMIT || counter > DEFAULTS.MAX_COUNTER_LIMIT) {
82
+ return `${DEFAULTS.MAX_COUNTER_LIMIT}+`;
83
+ }
68
84
  return counter.toString();
69
85
  }
70
86
  /**
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.
87
+ * Method to generate the badge icon.
88
+ * @param iconName - the name of the icon from the icon set
89
+ * @param overlay - boolean indicating whether the badge should have an overlay.
90
+ * @param iconVariant - the variant of the icon badge.
91
+ * @param type - the type of the badge.
74
92
  * @returns the template result of the icon.
75
93
  */
76
94
  getBadgeIcon(iconName, overlay, iconVariant, type) {
@@ -119,8 +137,8 @@ class Badge extends Component {
119
137
  getBadgeCounterText(maxCounter, overlay, counter) {
120
138
  return html `
121
139
  <mdc-text
122
- type="body-small-medium"
123
- tagname="div"
140
+ type="${FONT_TYPE.BODY_SMALL_MEDIUM}"
141
+ tagname="${VALID_TEXT_TAGS.DIV}"
124
142
  class="mdc-badge-text ${classMap({ 'mdc-badge-overlay': overlay })}"
125
143
  >
126
144
  ${this.getCounterText(maxCounter, counter)}
@@ -179,7 +197,7 @@ class Badge extends Component {
179
197
  Badge.styles = [...Component.styles, ...styles];
180
198
  __decorate([
181
199
  property({ type: String, reflect: true }),
182
- __metadata("design:type", Object)
200
+ __metadata("design:type", String)
183
201
  ], Badge.prototype, "type", void 0);
184
202
  __decorate([
185
203
  property({ type: String, attribute: 'icon-name' }),
@@ -46,6 +46,7 @@ const styles = [
46
46
  }
47
47
  .mdc-badge-icon__primary {
48
48
  background-color: var(--mdc-badge-primary-background-color);
49
+ color: var(--mdc-badge-primary-foreground-color);
49
50
  }
50
51
  .mdc-badge-icon__success {
51
52
  background-color: var(--mdc-badge-success-background-color);
@@ -1,6 +1,5 @@
1
1
  import { CSSResult } from 'lit';
2
2
  import { Component } from '../../models';
3
- import type { FontType, ValidTextTags } from './text.types';
4
3
  /**
5
4
  * Text component for creating styled text elements.
6
5
  * It has to be mounted within the ThemeProvider to access color and font tokens.
@@ -55,7 +54,7 @@ declare class Text extends Component {
55
54
  * - 'headline-small-light'
56
55
  * - 'headline-small-regular'
57
56
  */
58
- type: FontType;
57
+ type: string;
59
58
  /**
60
59
  * Specifies the HTML tag name for the text element. The default tag name is `p`.
61
60
  * This attribute is optional. When set, it changes the tag name of the text element.
@@ -76,7 +75,7 @@ declare class Text extends Component {
76
75
  * For instance, setting this attribute to `h2` will render the text element as an `h2` element.
77
76
  * Note that the styling is determined by the `type` attribute.
78
77
  */
79
- tagname?: ValidTextTags;
78
+ tagname?: string | undefined;
80
79
  render(): import("lit-html").TemplateResult<1>;
81
80
  static styles: Array<CSSResult>;
82
81
  }
@@ -11,7 +11,7 @@ import { html } from 'lit';
11
11
  import { property } from 'lit/decorators.js';
12
12
  import styles from './text.styles';
13
13
  import { Component } from '../../models';
14
- import { DEFAULTS } from './text.constants';
14
+ import { DEFAULTS, VALID_TEXT_TAGS } from './text.constants';
15
15
  /**
16
16
  * Text component for creating styled text elements.
17
17
  * It has to be mounted within the ThemeProvider to access color and font tokens.
@@ -95,16 +95,16 @@ class Text extends Component {
95
95
  // Lit does not support dynamically changing values for the tag name of a custom element.
96
96
  // Read more: https://lit.dev/docs/templates/expressions/#invalid-locations
97
97
  switch (this.tagname) {
98
- case 'h1': return html `<h1 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h1>`;
99
- case 'h2': return html `<h2 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h2>`;
100
- case 'h3': return html `<h3 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h3>`;
101
- case 'h4': return html `<h4 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h4>`;
102
- case 'h5': return html `<h5 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h5>`;
103
- case 'h6': return html `<h6 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h6>`;
104
- case 'div': return html `<div part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></div>`;
105
- case 'span': return html `<span part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></span>`;
106
- case 'small': return html `<small part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></small>`;
107
- case 'p':
98
+ case VALID_TEXT_TAGS.H1: return html `<h1 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h1>`;
99
+ case VALID_TEXT_TAGS.H2: return html `<h2 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h2>`;
100
+ case VALID_TEXT_TAGS.H3: return html `<h3 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h3>`;
101
+ case VALID_TEXT_TAGS.H4: return html `<h4 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h4>`;
102
+ case VALID_TEXT_TAGS.H5: return html `<h5 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h5>`;
103
+ case VALID_TEXT_TAGS.H6: return html `<h6 part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></h6>`;
104
+ case VALID_TEXT_TAGS.DIV: return html `<div part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></div>`;
105
+ case VALID_TEXT_TAGS.SPAN: return html `<span part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></span>`;
106
+ case VALID_TEXT_TAGS.SMALL: return html `<small part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></small>`;
107
+ case VALID_TEXT_TAGS.P:
108
108
  default: return html `<p part=${DEFAULTS.CSS_PART_TEXT}><slot></slot></p>`;
109
109
  }
110
110
  }
@@ -112,10 +112,10 @@ class Text extends Component {
112
112
  Text.styles = [...Component.styles, ...styles];
113
113
  __decorate([
114
114
  property({ attribute: 'type', reflect: true, type: String }),
115
- __metadata("design:type", String)
115
+ __metadata("design:type", Object)
116
116
  ], Text.prototype, "type", void 0);
117
117
  __decorate([
118
118
  property({ attribute: 'tagname', reflect: true, type: String }),
119
- __metadata("design:type", String)
119
+ __metadata("design:type", Object)
120
120
  ], Text.prototype, "tagname", void 0);
121
121
  export default Text;
@@ -1,12 +1,51 @@
1
- import type { FontType, ValidTextTags } from './text.types';
2
1
  declare const TAG_NAME: "mdc-text";
3
- declare const VALUES: {
4
- TYPE: Array<FontType>;
5
- TAGNAME: Array<ValidTextTags>;
2
+ declare const FONT_TYPE: {
3
+ BODY_SMALL_REGULAR: string;
4
+ BODY_SMALL_MEDIUM: string;
5
+ BODY_SMALL_BOLD: string;
6
+ BODY_MIDSIZE_REGULAR: string;
7
+ BODY_MIDSIZE_MEDIUM: string;
8
+ BODY_MIDSIZE_BOLD: string;
9
+ BODY_LARGE_REGULAR: string;
10
+ BODY_LARGE_MEDIUM: string;
11
+ BODY_LARGE_BOLD: string;
12
+ BODY_SMALL_REGULAR_UNDERLINE: string;
13
+ BODY_SMALL_MEDIUM_UNDERLINE: string;
14
+ BODY_MIDSIZE_REGULAR_UNDERLINE: string;
15
+ BODY_MIDSIZE_MEDIUM_UNDERLINE: string;
16
+ BODY_LARGE_REGULAR_UNDERLINE: string;
17
+ BODY_LARGE_MEDIUM_UNDERLINE: string;
18
+ HEADING_SMALL_REGULAR: string;
19
+ HEADING_SMALL_MEDIUM: string;
20
+ HEADING_SMALL_BOLD: string;
21
+ HEADING_MIDSIZE_REGULAR: string;
22
+ HEADING_MIDSIZE_MEDIUM: string;
23
+ HEADING_MIDSIZE_BOLD: string;
24
+ HEADING_LARGE_REGULAR: string;
25
+ HEADING_LARGE_MEDIUM: string;
26
+ HEADING_LARGE_BOLD: string;
27
+ HEADING_XLARGE_REGULAR: string;
28
+ HEADING_XLARGE_MEDIUM: string;
29
+ HEADING_XLARGE_BOLD: string;
30
+ HEADLINE_SMALL_LIGHT: string;
31
+ HEADLINE_SMALL_REGULAR: string;
32
+ };
33
+ declare const VALID_TEXT_TAGS: {
34
+ H1: string;
35
+ H2: string;
36
+ H3: string;
37
+ H4: string;
38
+ H5: string;
39
+ H6: string;
40
+ P: string;
41
+ SMALL: string;
42
+ SPAN: string;
43
+ DIV: string;
6
44
  };
7
45
  declare const DEFAULTS: {
8
- TYPE: FontType;
9
- TEXT_ELEMENT_TAGNAME: ValidTextTags;
46
+ TYPE: string;
47
+ TEXT_ELEMENT_TAGNAME: string;
10
48
  CSS_PART_TEXT: string;
49
+ CHILDREN: string;
11
50
  };
12
- export { TAG_NAME, DEFAULTS, VALUES };
51
+ export { TAG_NAME, DEFAULTS, FONT_TYPE, VALID_TEXT_TAGS };
@@ -1,53 +1,52 @@
1
1
  import utils from '../../utils/tag-name';
2
2
  const TAG_NAME = utils.constructTagName('text');
3
- const VALUES = {
4
- TYPE: [
5
- 'body-small-regular',
6
- 'body-small-medium',
7
- 'body-small-bold',
8
- 'body-midsize-regular',
9
- 'body-midsize-medium',
10
- 'body-midsize-bold',
11
- 'body-large-regular',
12
- 'body-large-medium',
13
- 'body-large-bold',
14
- 'body-small-regular-underline',
15
- 'body-small-medium-underline',
16
- 'body-midsize-regular-underline',
17
- 'body-midsize-medium-underline',
18
- 'body-large-regular-underline',
19
- 'body-large-medium-underline',
20
- 'heading-small-regular',
21
- 'heading-small-medium',
22
- 'heading-small-bold',
23
- 'heading-midsize-regular',
24
- 'heading-midsize-medium',
25
- 'heading-midsize-bold',
26
- 'heading-large-regular',
27
- 'heading-large-medium',
28
- 'heading-large-bold',
29
- 'heading-xlarge-regular',
30
- 'heading-xlarge-medium',
31
- 'heading-xlarge-bold',
32
- 'headline-small-light',
33
- 'headline-small-regular',
34
- ],
35
- TAGNAME: [
36
- 'h1',
37
- 'h2',
38
- 'h3',
39
- 'h4',
40
- 'h5',
41
- 'h6',
42
- 'p',
43
- 'small',
44
- 'span',
45
- 'div',
46
- ],
3
+ const FONT_TYPE = {
4
+ BODY_SMALL_REGULAR: 'body-small-regular',
5
+ BODY_SMALL_MEDIUM: 'body-small-medium',
6
+ BODY_SMALL_BOLD: 'body-small-bold',
7
+ BODY_MIDSIZE_REGULAR: 'body-midsize-regular',
8
+ BODY_MIDSIZE_MEDIUM: 'body-midsize-medium',
9
+ BODY_MIDSIZE_BOLD: 'body-midsize-bold',
10
+ BODY_LARGE_REGULAR: 'body-large-regular',
11
+ BODY_LARGE_MEDIUM: 'body-large-medium',
12
+ BODY_LARGE_BOLD: 'body-large-bold',
13
+ BODY_SMALL_REGULAR_UNDERLINE: 'body-small-regular-underline',
14
+ BODY_SMALL_MEDIUM_UNDERLINE: 'body-small-medium-underline',
15
+ BODY_MIDSIZE_REGULAR_UNDERLINE: 'body-midsize-regular-underline',
16
+ BODY_MIDSIZE_MEDIUM_UNDERLINE: 'body-midsize-medium-underline',
17
+ BODY_LARGE_REGULAR_UNDERLINE: 'body-large-regular-underline',
18
+ BODY_LARGE_MEDIUM_UNDERLINE: 'body-large-medium-underline',
19
+ HEADING_SMALL_REGULAR: 'heading-small-regular',
20
+ HEADING_SMALL_MEDIUM: 'heading-small-medium',
21
+ HEADING_SMALL_BOLD: 'heading-small-bold',
22
+ HEADING_MIDSIZE_REGULAR: 'heading-midsize-regular',
23
+ HEADING_MIDSIZE_MEDIUM: 'heading-midsize-medium',
24
+ HEADING_MIDSIZE_BOLD: 'heading-midsize-bold',
25
+ HEADING_LARGE_REGULAR: 'heading-large-regular',
26
+ HEADING_LARGE_MEDIUM: 'heading-large-medium',
27
+ HEADING_LARGE_BOLD: 'heading-large-bold',
28
+ HEADING_XLARGE_REGULAR: 'heading-xlarge-regular',
29
+ HEADING_XLARGE_MEDIUM: 'heading-xlarge-medium',
30
+ HEADING_XLARGE_BOLD: 'heading-xlarge-bold',
31
+ HEADLINE_SMALL_LIGHT: 'headline-small-light',
32
+ HEADLINE_SMALL_REGULAR: 'headline-small-regular',
33
+ };
34
+ const VALID_TEXT_TAGS = {
35
+ H1: 'h1',
36
+ H2: 'h2',
37
+ H3: 'h3',
38
+ H4: 'h4',
39
+ H5: 'h5',
40
+ H6: 'h6',
41
+ P: 'p',
42
+ SMALL: 'small',
43
+ SPAN: 'span',
44
+ DIV: 'div',
47
45
  };
48
46
  const DEFAULTS = {
49
- TYPE: 'body-midsize-regular',
50
- TEXT_ELEMENT_TAGNAME: 'p',
47
+ TYPE: FONT_TYPE.BODY_LARGE_REGULAR,
48
+ TEXT_ELEMENT_TAGNAME: VALID_TEXT_TAGS.P,
51
49
  CSS_PART_TEXT: 'text',
50
+ CHILDREN: 'The quick brown fox jumps over the lazy dog',
52
51
  };
53
- export { TAG_NAME, DEFAULTS, VALUES };
52
+ export { TAG_NAME, DEFAULTS, FONT_TYPE, VALID_TEXT_TAGS };