@momentum-design/components 0.4.17 → 0.4.19

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;
@@ -16,10 +16,22 @@ import { FONT_TYPE, VALID_TEXT_TAGS } from '../text/text.constants';
16
16
  import { BADGE_TYPE, ICON_NAMES_LIST, DEFAULTS, ICON_VARIANT, ICON_STATE } from './badge.constants';
17
17
  import styles from './badge.styles';
18
18
  /**
19
- * A badge is a small, visually distinct element that provides additional information
20
- * or highlights the status of an item.
21
- * Badges are often used to display notification dot, counts, making them a useful tool for
22
- * 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
+ *
23
35
  * @dependency mdc-icon
24
36
  * @dependency mdc-text
25
37
  *
@@ -29,17 +41,20 @@ class Badge extends Component {
29
41
  constructor() {
30
42
  super(...arguments);
31
43
  /**
32
- * Type of the badge
33
- * Can be `dot` (notification) , `icon` and `counter`
34
- *
35
- * Default: `dot`
44
+ * Type of the variant can be `primary` or `secondary`.
45
+ * It defines the background and foreground color of the icon.
36
46
  */
37
- this.type = DEFAULTS.TYPE;
47
+ this.variant = DEFAULTS.VARIANT;
38
48
  /**
39
- * 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`.
40
51
  */
41
- this.variant = DEFAULTS.VARIANT;
42
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
+ */
43
58
  this.overlay = false;
44
59
  /**
45
60
  * Aria-label attribute to be set for accessibility
@@ -56,22 +71,24 @@ class Badge extends Component {
56
71
  * @returns the string representation of the counter
57
72
  */
58
73
  getCounterText(maxCounter, counter) {
59
- if (counter === undefined || typeof counter !== 'number') {
74
+ if (counter === undefined || typeof counter !== 'number' || maxCounter === 0) {
60
75
  return '';
61
76
  }
62
- // At any given time, the max limit should not cross 999.
63
- if (counter > DEFAULTS.MAX_COUNTER_LIMIT) {
64
- return `${DEFAULTS.MAX_COUNTER_LIMIT}+`;
65
- }
66
77
  if (counter > maxCounter) {
67
78
  return `${maxCounter}+`;
68
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
+ }
69
84
  return counter.toString();
70
85
  }
71
86
  /**
72
- * Method to generate the badge icon template.
73
- * @param iconName - name of the icon to be used.
74
- * @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.
75
92
  * @returns the template result of the icon.
76
93
  */
77
94
  getBadgeIcon(iconName, overlay, iconVariant, type) {
@@ -102,8 +119,7 @@ class Badge extends Component {
102
119
  getIconClasses(overlay, iconVariant, type) {
103
120
  const overLayClass = { 'mdc-badge-overlay': overlay };
104
121
  const variantTypes = type === BADGE_TYPE.ICON ? ICON_VARIANT : ICON_STATE;
105
- const iconVariantType = Object.values(variantTypes).includes(iconVariant)
106
- ? iconVariant : DEFAULTS.VARIANT;
122
+ const iconVariantType = Object.values(variantTypes).includes(iconVariant) ? iconVariant : DEFAULTS.VARIANT;
107
123
  const backgroundClass = { [`mdc-badge-icon__${iconVariantType}`]: true };
108
124
  return {
109
125
  ...overLayClass,
@@ -149,10 +165,11 @@ class Badge extends Component {
149
165
  * @returns the TemplateResult for the current badge type.
150
166
  */
151
167
  getBadgeContentBasedOnType() {
168
+ if (this.variant && !Object.values(ICON_VARIANT).includes(this.variant)) {
169
+ this.variant = ICON_VARIANT.PRIMARY;
170
+ }
152
171
  const { counter, iconName, maxCounter, overlay, type, variant } = this;
153
172
  switch (type) {
154
- case BADGE_TYPE.DOT:
155
- return this.getBadgeDot(overlay);
156
173
  case BADGE_TYPE.ICON:
157
174
  return this.getBadgeIcon(iconName || '', overlay, variant, type);
158
175
  case BADGE_TYPE.COUNTER:
@@ -163,8 +180,10 @@ class Badge extends Component {
163
180
  return this.getBadgeIcon(ICON_NAMES_LIST.WARNING_ICON_NAME, overlay, ICON_STATE.WARNING);
164
181
  case BADGE_TYPE.ERROR:
165
182
  return this.getBadgeIcon(ICON_NAMES_LIST.ERROR_ICON_NAME, overlay, ICON_STATE.ERROR);
183
+ case BADGE_TYPE.DOT:
166
184
  default:
167
- return html ``;
185
+ this.type = BADGE_TYPE.DOT;
186
+ return this.getBadgeDot(overlay);
168
187
  }
169
188
  }
170
189
  update(changedProperties) {
@@ -180,14 +199,14 @@ class Badge extends Component {
180
199
  Badge.styles = [...Component.styles, ...styles];
181
200
  __decorate([
182
201
  property({ type: String, reflect: true }),
183
- __metadata("design:type", Object)
202
+ __metadata("design:type", String)
184
203
  ], Badge.prototype, "type", void 0);
185
204
  __decorate([
186
205
  property({ type: String, attribute: 'icon-name' }),
187
206
  __metadata("design:type", String)
188
207
  ], Badge.prototype, "iconName", void 0);
189
208
  __decorate([
190
- property({ type: String }),
209
+ property({ type: String, reflect: true }),
191
210
  __metadata("design:type", Object)
192
211
  ], Badge.prototype, "variant", void 0);
193
212
  __decorate([
@@ -195,7 +214,7 @@ __decorate([
195
214
  __metadata("design:type", Number)
196
215
  ], Badge.prototype, "counter", void 0);
197
216
  __decorate([
198
- property({ type: Number, attribute: 'max-counter' }),
217
+ property({ type: Number, attribute: 'max-counter', reflect: true }),
199
218
  __metadata("design:type", Number)
200
219
  ], Badge.prototype, "maxCounter", void 0);
201
220
  __decorate([
@@ -29,4 +29,4 @@ declare const DEFAULTS: {
29
29
  VARIANT: string;
30
30
  ICON_SIZE: number;
31
31
  };
32
- export { TAG_NAME, DEFAULTS, BADGE_TYPE, ICON_STATE, ICON_VARIANT, ICON_NAMES_LIST, };
32
+ export { TAG_NAME, DEFAULTS, BADGE_TYPE, ICON_STATE, ICON_VARIANT, ICON_NAMES_LIST };
@@ -30,4 +30,4 @@ const DEFAULTS = {
30
30
  VARIANT: ICON_VARIANT.PRIMARY,
31
31
  ICON_SIZE: 1,
32
32
  };
33
- export { TAG_NAME, DEFAULTS, BADGE_TYPE, ICON_STATE, ICON_VARIANT, ICON_NAMES_LIST, };
33
+ export { TAG_NAME, DEFAULTS, BADGE_TYPE, ICON_STATE, ICON_VARIANT, ICON_NAMES_LIST };
@@ -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);
@@ -120,13 +120,16 @@
120
120
  "declarations": [
121
121
  {
122
122
  "kind": "class",
123
- "description": "A badge is a small, visually distinct element that provides additional information\nor highlights the status of an item.\nBadges are often used to display notification dot, counts, making them a useful tool for\nconveying information quickly without taking up much space.",
123
+ "description": "The `mdc-badge` component is a versatile UI element used to\ndisplay dot, icons, counters, success, warning and error type badge.\n\nSupported badge types:\n- `dot`: Displays a dot notification badge with a blue color.\n- `icon`: Displays a badge with a specified icon using the `icon-name` attribute.\n- `counter`: Displays a badge with a counter value. If the counter exceeds the `max-counter`,\nit shows `maxCounter+`. The maximum value of the counter is 999 and anything about that will be set to `999+`.\n- `success`: Displays a success badge with a check circle icon and green color.\n- `warning`: Displays a warning badge with a warning icon and yellow color.\n- `error`: Displays a error badge with a error legacy icon and red color.\n\nFor `icon`, `success`, `warning` and `error` types, the `mdc-icon` component is used to render the icon.\n\nFor the `counter` type, the `mdc-text` component is used to render the counter value.",
124
124
  "name": "Badge",
125
125
  "members": [
126
126
  {
127
127
  "kind": "field",
128
128
  "name": "type",
129
- "description": "Type of the badge\nCan be `dot` (notification) , `icon` and `counter`\n\nDefault: `dot`",
129
+ "type": {
130
+ "text": "string | undefined"
131
+ },
132
+ "description": "Type of the badge\nCan be `dot` (notification) , `icon`, `counter`, `success`, `warning` or `error`.",
130
133
  "attribute": "type",
131
134
  "reflects": true
132
135
  },
@@ -136,14 +139,15 @@
136
139
  "type": {
137
140
  "text": "string | undefined"
138
141
  },
139
- "description": "If `type` is set to `icon`, attribute `iconName` can\nbe used to choose which icon should be shown\n\nIf no `iconName` is provided, no icon will be rendered.",
142
+ "description": "Name of the icon (= filename).\n\nIf no `icon-name` is provided, no icon will be rendered.",
140
143
  "attribute": "icon-name"
141
144
  },
142
145
  {
143
146
  "kind": "field",
144
147
  "name": "variant",
145
- "description": "badge variant",
146
- "attribute": "variant"
148
+ "description": "Type of the variant can be `primary` or `secondary`.\nIt defines the background and foreground color of the icon.",
149
+ "attribute": "variant",
150
+ "reflects": true
147
151
  },
148
152
  {
149
153
  "kind": "field",
@@ -151,6 +155,7 @@
151
155
  "type": {
152
156
  "text": "number | undefined"
153
157
  },
158
+ "description": "Counter is the number which can be provided in the badge.",
154
159
  "attribute": "counter"
155
160
  },
156
161
  {
@@ -159,7 +164,9 @@
159
164
  "type": {
160
165
  "text": "number"
161
166
  },
162
- "attribute": "max-counter"
167
+ "description": "The maximum number can be set up to 999, anything about that will be rendered as _999+_.\nThe max counter can be `9`, `99` or `999`.",
168
+ "attribute": "max-counter",
169
+ "reflects": true
163
170
  },
164
171
  {
165
172
  "kind": "field",
@@ -168,6 +175,7 @@
168
175
  "text": "boolean"
169
176
  },
170
177
  "default": "false",
178
+ "description": "Overlay is to add a thin outline to the badge.\nThis will help distinguish between the badge and the button,\nwhere the badge will be layered on top of a button.",
171
179
  "attribute": "overlay"
172
180
  },
173
181
  {
@@ -223,33 +231,32 @@
223
231
  "type": {
224
232
  "text": "string"
225
233
  },
226
- "description": "name of the icon to be used."
234
+ "description": "the name of the icon from the icon set"
227
235
  },
228
236
  {
229
237
  "name": "overlay",
230
238
  "type": {
231
239
  "text": "boolean"
232
- }
240
+ },
241
+ "description": "boolean indicating whether the badge should have an overlay."
233
242
  },
234
243
  {
235
244
  "name": "iconVariant",
236
245
  "type": {
237
246
  "text": "string"
238
- }
247
+ },
248
+ "description": "the variant of the icon badge."
239
249
  },
240
250
  {
241
251
  "name": "type",
242
252
  "optional": true,
243
253
  "type": {
244
254
  "text": "string"
245
- }
246
- },
247
- {
248
- "description": "variant of the badge.",
249
- "name": "variant"
255
+ },
256
+ "description": "the type of the badge."
250
257
  }
251
258
  ],
252
- "description": "Method to generate the badge icon template."
259
+ "description": "Method to generate the badge icon."
253
260
  },
254
261
  {
255
262
  "kind": "method",
@@ -367,7 +374,10 @@
367
374
  "attributes": [
368
375
  {
369
376
  "name": "type",
370
- "description": "Type of the badge\nCan be `dot` (notification) , `icon` and `counter`\n\nDefault: `dot`",
377
+ "type": {
378
+ "text": "string | undefined"
379
+ },
380
+ "description": "Type of the badge\nCan be `dot` (notification) , `icon`, `counter`, `success`, `warning` or `error`.",
371
381
  "fieldName": "type"
372
382
  },
373
383
  {
@@ -375,12 +385,12 @@
375
385
  "type": {
376
386
  "text": "string | undefined"
377
387
  },
378
- "description": "If `type` is set to `icon`, attribute `iconName` can\nbe used to choose which icon should be shown\n\nIf no `iconName` is provided, no icon will be rendered.",
388
+ "description": "Name of the icon (= filename).\n\nIf no `icon-name` is provided, no icon will be rendered.",
379
389
  "fieldName": "iconName"
380
390
  },
381
391
  {
382
392
  "name": "variant",
383
- "description": "badge variant",
393
+ "description": "Type of the variant can be `primary` or `secondary`.\nIt defines the background and foreground color of the icon.",
384
394
  "fieldName": "variant"
385
395
  },
386
396
  {
@@ -388,6 +398,7 @@
388
398
  "type": {
389
399
  "text": "number | undefined"
390
400
  },
401
+ "description": "Counter is the number which can be provided in the badge.",
391
402
  "fieldName": "counter"
392
403
  },
393
404
  {
@@ -395,6 +406,7 @@
395
406
  "type": {
396
407
  "text": "number"
397
408
  },
409
+ "description": "The maximum number can be set up to 999, anything about that will be rendered as _999+_.\nThe max counter can be `9`, `99` or `999`.",
398
410
  "fieldName": "maxCounter"
399
411
  },
400
412
  {
@@ -403,6 +415,7 @@
403
415
  "text": "boolean"
404
416
  },
405
417
  "default": "false",
418
+ "description": "Overlay is to add a thin outline to the badge.\nThis will help distinguish between the badge and the button,\nwhere the badge will be layered on top of a button.",
406
419
  "fieldName": "overlay"
407
420
  },
408
421
  {
@@ -420,7 +433,7 @@
420
433
  "module": "/src/models"
421
434
  },
422
435
  "tagName": "mdc-badge",
423
- "jsDoc": "/**\n * A badge is a small, visually distinct element that provides additional information\n * or highlights the status of an item.\n * Badges are often used to display notification dot, counts, making them a useful tool for\n * conveying information quickly without taking up much space.\n * @dependency mdc-icon\n * @dependency mdc-text\n *\n * @tagname mdc-badge\n */",
436
+ "jsDoc": "/**\n * The `mdc-badge` component is a versatile UI element used to\n * display dot, icons, counters, success, warning and error type badge.\n *\n * Supported badge types:\n * - `dot`: Displays a dot notification badge with a blue color.\n * - `icon`: Displays a badge with a specified icon using the `icon-name` attribute.\n * - `counter`: Displays a badge with a counter value. If the counter exceeds the `max-counter`,\n * it shows `maxCounter+`. The maximum value of the counter is 999 and anything about that will be set to `999+`.\n * - `success`: Displays a success badge with a check circle icon and green color.\n * - `warning`: Displays a warning badge with a warning icon and yellow color.\n * - `error`: Displays a error badge with a error legacy icon and red color.\n *\n * For `icon`, `success`, `warning` and `error` types, the `mdc-icon` component is used to render the icon.\n *\n * For the `counter` type, the `mdc-text` component is used to render the counter value.\n *\n * @dependency mdc-icon\n * @dependency mdc-text\n *\n * @tagname mdc-badge\n */",
424
437
  "customElement": true
425
438
  }
426
439
  ],
@@ -1,9 +1,21 @@
1
1
  import Component from '../../components/badge';
2
2
  /**
3
- * A badge is a small, visually distinct element that provides additional information
4
- * or highlights the status of an item.
5
- * Badges are often used to display notification dot, counts, making them a useful tool for
6
- * conveying information quickly without taking up much space.
3
+ * The `mdc-badge` component is a versatile UI element used to
4
+ * display dot, icons, counters, success, warning and error type badge.
5
+ *
6
+ * Supported badge types:
7
+ * - `dot`: Displays a dot notification badge with a blue color.
8
+ * - `icon`: Displays a badge with a specified icon using the `icon-name` attribute.
9
+ * - `counter`: Displays a badge with a counter value. If the counter exceeds the `max-counter`,
10
+ * it shows `maxCounter+`. The maximum value of the counter is 999 and anything about that will be set to `999+`.
11
+ * - `success`: Displays a success badge with a check circle icon and green color.
12
+ * - `warning`: Displays a warning badge with a warning icon and yellow color.
13
+ * - `error`: Displays a error badge with a error legacy icon and red color.
14
+ *
15
+ * For `icon`, `success`, `warning` and `error` types, the `mdc-icon` component is used to render the icon.
16
+ *
17
+ * For the `counter` type, the `mdc-text` component is used to render the counter value.
18
+ *
7
19
  * @dependency mdc-icon
8
20
  * @dependency mdc-text
9
21
  *
@@ -3,10 +3,22 @@ import { createComponent } from '@lit/react';
3
3
  import Component from '../../components/badge';
4
4
  import { TAG_NAME } from '../../components/badge/badge.constants';
5
5
  /**
6
- * A badge is a small, visually distinct element that provides additional information
7
- * or highlights the status of an item.
8
- * Badges are often used to display notification dot, counts, making them a useful tool for
9
- * conveying information quickly without taking up much space.
6
+ * The `mdc-badge` component is a versatile UI element used to
7
+ * display dot, icons, counters, success, warning and error type badge.
8
+ *
9
+ * Supported badge types:
10
+ * - `dot`: Displays a dot notification badge with a blue color.
11
+ * - `icon`: Displays a badge with a specified icon using the `icon-name` attribute.
12
+ * - `counter`: Displays a badge with a counter value. If the counter exceeds the `max-counter`,
13
+ * it shows `maxCounter+`. The maximum value of the counter is 999 and anything about that will be set to `999+`.
14
+ * - `success`: Displays a success badge with a check circle icon and green color.
15
+ * - `warning`: Displays a warning badge with a warning icon and yellow color.
16
+ * - `error`: Displays a error badge with a error legacy icon and red color.
17
+ *
18
+ * For `icon`, `success`, `warning` and `error` types, the `mdc-icon` component is used to render the icon.
19
+ *
20
+ * For the `counter` type, the `mdc-text` component is used to render the counter value.
21
+ *
10
22
  * @dependency mdc-icon
11
23
  * @dependency mdc-text
12
24
  *
package/package.json CHANGED
@@ -37,5 +37,5 @@
37
37
  "@momentum-design/icons": "*",
38
38
  "@momentum-design/tokens": "*"
39
39
  },
40
- "version": "0.4.17"
40
+ "version": "0.4.19"
41
41
  }