@momentum-design/components 0.4.17 → 0.4.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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) {
@@ -180,7 +197,7 @@ class Badge extends Component {
180
197
  Badge.styles = [...Component.styles, ...styles];
181
198
  __decorate([
182
199
  property({ type: String, reflect: true }),
183
- __metadata("design:type", Object)
200
+ __metadata("design:type", String)
184
201
  ], Badge.prototype, "type", void 0);
185
202
  __decorate([
186
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);
@@ -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,13 +139,13 @@
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",
148
+ "description": "Type of the variant can be `primary` or `secondary`.\nIt defines the background and foreground color of the icon.",
146
149
  "attribute": "variant"
147
150
  },
148
151
  {
@@ -151,6 +154,7 @@
151
154
  "type": {
152
155
  "text": "number | undefined"
153
156
  },
157
+ "description": "Counter is the number which can be provided in the badge.",
154
158
  "attribute": "counter"
155
159
  },
156
160
  {
@@ -159,6 +163,7 @@
159
163
  "type": {
160
164
  "text": "number"
161
165
  },
166
+ "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`.",
162
167
  "attribute": "max-counter"
163
168
  },
164
169
  {
@@ -168,6 +173,7 @@
168
173
  "text": "boolean"
169
174
  },
170
175
  "default": "false",
176
+ "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
177
  "attribute": "overlay"
172
178
  },
173
179
  {
@@ -223,33 +229,32 @@
223
229
  "type": {
224
230
  "text": "string"
225
231
  },
226
- "description": "name of the icon to be used."
232
+ "description": "the name of the icon from the icon set"
227
233
  },
228
234
  {
229
235
  "name": "overlay",
230
236
  "type": {
231
237
  "text": "boolean"
232
- }
238
+ },
239
+ "description": "boolean indicating whether the badge should have an overlay."
233
240
  },
234
241
  {
235
242
  "name": "iconVariant",
236
243
  "type": {
237
244
  "text": "string"
238
- }
245
+ },
246
+ "description": "the variant of the icon badge."
239
247
  },
240
248
  {
241
249
  "name": "type",
242
250
  "optional": true,
243
251
  "type": {
244
252
  "text": "string"
245
- }
246
- },
247
- {
248
- "description": "variant of the badge.",
249
- "name": "variant"
253
+ },
254
+ "description": "the type of the badge."
250
255
  }
251
256
  ],
252
- "description": "Method to generate the badge icon template."
257
+ "description": "Method to generate the badge icon."
253
258
  },
254
259
  {
255
260
  "kind": "method",
@@ -367,7 +372,10 @@
367
372
  "attributes": [
368
373
  {
369
374
  "name": "type",
370
- "description": "Type of the badge\nCan be `dot` (notification) , `icon` and `counter`\n\nDefault: `dot`",
375
+ "type": {
376
+ "text": "string | undefined"
377
+ },
378
+ "description": "Type of the badge\nCan be `dot` (notification) , `icon`, `counter`, `success`, `warning` or `error`.",
371
379
  "fieldName": "type"
372
380
  },
373
381
  {
@@ -375,12 +383,12 @@
375
383
  "type": {
376
384
  "text": "string | undefined"
377
385
  },
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.",
386
+ "description": "Name of the icon (= filename).\n\nIf no `icon-name` is provided, no icon will be rendered.",
379
387
  "fieldName": "iconName"
380
388
  },
381
389
  {
382
390
  "name": "variant",
383
- "description": "badge variant",
391
+ "description": "Type of the variant can be `primary` or `secondary`.\nIt defines the background and foreground color of the icon.",
384
392
  "fieldName": "variant"
385
393
  },
386
394
  {
@@ -388,6 +396,7 @@
388
396
  "type": {
389
397
  "text": "number | undefined"
390
398
  },
399
+ "description": "Counter is the number which can be provided in the badge.",
391
400
  "fieldName": "counter"
392
401
  },
393
402
  {
@@ -395,6 +404,7 @@
395
404
  "type": {
396
405
  "text": "number"
397
406
  },
407
+ "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
408
  "fieldName": "maxCounter"
399
409
  },
400
410
  {
@@ -403,6 +413,7 @@
403
413
  "text": "boolean"
404
414
  },
405
415
  "default": "false",
416
+ "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
417
  "fieldName": "overlay"
407
418
  },
408
419
  {
@@ -420,7 +431,7 @@
420
431
  "module": "/src/models"
421
432
  },
422
433
  "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 */",
434
+ "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
435
  "customElement": true
425
436
  }
426
437
  ],
@@ -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.18"
41
41
  }