@brightspace-ui/core 1.220.3 → 1.220.4
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.
|
@@ -46,7 +46,7 @@ The `d2l-count-badge` element is a web component to display a number count, depe
|
|
|
46
46
|
| `number` | Number, required | The number to display on the badge. Must be a positive integer. |
|
|
47
47
|
| `size`, default: `small` | String | The size of the badge. Valid options are `"small"` and `"large"`. |
|
|
48
48
|
| `type`, default: `count` | String | The type of the badge. Valid options are `"notification"` and `"count"`. Notification badges are orange and count badges are grey. |
|
|
49
|
-
| `max-digits`, default: `2` when `type="notification"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and
|
|
49
|
+
| `max-digits`, default: `2` when `type="notification"`, `5` when `type="count"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and five for `"count"` type. Must be between 1-5.
|
|
50
50
|
| `hide-zero`, default: `false` | Boolean | Optionally choose not to show the count badge when the number is zero. |
|
|
51
51
|
| `text`, required | String | Descriptive text for the badge which will act as an accessible label and tooltip text when tooltips are enabled. |
|
|
52
52
|
| `tab-stop`, default: `false` | Boolean | Optionally choose to make the badge a tab stop. |
|
|
@@ -88,7 +88,7 @@ The `d2l-count-badge-icon` element is a web component to display a number count,
|
|
|
88
88
|
| `icon` | String | Required: [Preset icon key](../icons#preset-icons) (e.g. `tier1:gear`) |
|
|
89
89
|
| `size`, default: `small` | String | The size of the badge. Valid options are `"small"` and `"large"`. |
|
|
90
90
|
| `type`, default: `count` | String | The type of the badge. Valid options are `"notification"` and `"count"`. Notification badges are orange and count badges are grey. |
|
|
91
|
-
| `max-digits`, default: `2` when `type="notification"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and
|
|
91
|
+
| `max-digits`, default: `2` when `type="notification"`, `5` when `type="count"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and five for `"count"` type. Must be between 1-5.
|
|
92
92
|
| `hide-zero`, default: `false` | Boolean | Optionally choose not to show the count badge when the number is zero. |
|
|
93
93
|
| `text` | String | REQUIRED: Descriptive text for the badge which will act as an accessible label and tooltip text when tooltips are enabled. |
|
|
94
94
|
| `tab-stop`, default: `false` | Boolean | Optionally choose to make the badge a tab stop. |
|
|
@@ -9,6 +9,8 @@ import { RtlMixin } from '../../mixins/rtl-mixin.js';
|
|
|
9
9
|
import { SkeletonMixin } from '../skeleton/skeleton-mixin.js';
|
|
10
10
|
import { styleMap } from 'lit-html/directives/style-map.js';
|
|
11
11
|
|
|
12
|
+
const maxBadgeDigits = 5;
|
|
13
|
+
|
|
12
14
|
export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(SkeletonMixin(RtlMixin(superclass))) {
|
|
13
15
|
|
|
14
16
|
static get properties() {
|
|
@@ -47,7 +49,8 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
|
|
|
47
49
|
attribute: 'hide-zero'
|
|
48
50
|
},
|
|
49
51
|
/**
|
|
50
|
-
* Optionally specify a digit limit, after which numbers are truncated.
|
|
52
|
+
* Optionally specify a digit limit, after which numbers are truncated.
|
|
53
|
+
* Defaults to two for "notification" type and five for "count" type.
|
|
51
54
|
* @type {number}
|
|
52
55
|
*/
|
|
53
56
|
maxDigits: {
|
|
@@ -156,9 +159,20 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
|
|
|
156
159
|
|
|
157
160
|
connectedCallback() {
|
|
158
161
|
super.connectedCallback();
|
|
159
|
-
if (!this.maxDigits
|
|
160
|
-
// default to two digits for notification type
|
|
161
|
-
this.maxDigits = 2;
|
|
162
|
+
if (!this.maxDigits) {
|
|
163
|
+
// default to two digits for notification type, 5 for count
|
|
164
|
+
this.maxDigits = this.type === 'notification' ? 2 : maxBadgeDigits;
|
|
165
|
+
} else if (this.maxDigits > maxBadgeDigits) {
|
|
166
|
+
// limit all badges to 5 digits
|
|
167
|
+
this.maxDigits = maxBadgeDigits;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
updated(changedProperties) {
|
|
172
|
+
super.updated(changedProperties);
|
|
173
|
+
if (changedProperties.get('maxDigits') && this.maxDigits > maxBadgeDigits) {
|
|
174
|
+
// impose a 5 digit maximum to prevent overflows
|
|
175
|
+
this.maxDigits = maxBadgeDigits;
|
|
162
176
|
}
|
|
163
177
|
}
|
|
164
178
|
|
|
@@ -166,15 +180,8 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
|
|
|
166
180
|
return this.hasTooltip ? undefined : this._labelId;
|
|
167
181
|
}
|
|
168
182
|
|
|
169
|
-
|
|
183
|
+
getNumberString() {
|
|
170
184
|
let numberString = `${this.number}`;
|
|
171
|
-
const hideNumber = this.hideZero && this.number === 0;
|
|
172
|
-
if (!numberStyles || numberStyles.visibility !== 'hidden') {
|
|
173
|
-
numberStyles = {
|
|
174
|
-
...numberStyles,
|
|
175
|
-
visibility: hideNumber ? 'hidden' : 'visible'
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
185
|
if (this.maxDigits && this.number.toString().length > this.maxDigits) {
|
|
179
186
|
numberString = `${'9'.repeat(this.maxDigits)}`;
|
|
180
187
|
numberString = formatNumber(parseInt(numberString));
|
|
@@ -183,9 +190,20 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
|
|
|
183
190
|
numberString = formatNumber(numberString);
|
|
184
191
|
}
|
|
185
192
|
|
|
193
|
+
return numberString;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
renderCount(numberStyles) {
|
|
197
|
+
const hideNumber = this.hideZero && this.number === 0;
|
|
198
|
+
if (!numberStyles || numberStyles.visibility !== 'hidden') {
|
|
199
|
+
numberStyles = {
|
|
200
|
+
...numberStyles,
|
|
201
|
+
visibility: hideNumber ? 'hidden' : 'visible'
|
|
202
|
+
};
|
|
203
|
+
}
|
|
186
204
|
return html`
|
|
187
205
|
<div class="d2l-count-badge-number" style=${styleMap(numberStyles)}>
|
|
188
|
-
<div aria-hidden="true">${
|
|
206
|
+
<div aria-hidden="true">${this.getNumberString()}</div>
|
|
189
207
|
</div>
|
|
190
208
|
`;
|
|
191
209
|
}
|
package/custom-elements.json
CHANGED
|
@@ -1032,7 +1032,7 @@
|
|
|
1032
1032
|
},
|
|
1033
1033
|
{
|
|
1034
1034
|
"name": "max-digits",
|
|
1035
|
-
"description": "Optionally specify a digit limit, after which numbers are truncated
|
|
1035
|
+
"description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
|
|
1036
1036
|
"type": "number"
|
|
1037
1037
|
},
|
|
1038
1038
|
{
|
|
@@ -1105,7 +1105,7 @@
|
|
|
1105
1105
|
{
|
|
1106
1106
|
"name": "maxDigits",
|
|
1107
1107
|
"attribute": "max-digits",
|
|
1108
|
-
"description": "Optionally specify a digit limit, after which numbers are truncated
|
|
1108
|
+
"description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
|
|
1109
1109
|
"type": "number"
|
|
1110
1110
|
},
|
|
1111
1111
|
{
|
|
@@ -1185,7 +1185,7 @@
|
|
|
1185
1185
|
"attributes": [
|
|
1186
1186
|
{
|
|
1187
1187
|
"name": "max-digits",
|
|
1188
|
-
"description": "Optionally specify a digit limit, after which numbers are truncated
|
|
1188
|
+
"description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
|
|
1189
1189
|
"type": "number"
|
|
1190
1190
|
},
|
|
1191
1191
|
{
|
|
@@ -1252,7 +1252,7 @@
|
|
|
1252
1252
|
{
|
|
1253
1253
|
"name": "maxDigits",
|
|
1254
1254
|
"attribute": "max-digits",
|
|
1255
|
-
"description": "Optionally specify a digit limit, after which numbers are truncated
|
|
1255
|
+
"description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
|
|
1256
1256
|
"type": "number"
|
|
1257
1257
|
},
|
|
1258
1258
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brightspace-ui/core",
|
|
3
|
-
"version": "1.220.
|
|
3
|
+
"version": "1.220.4",
|
|
4
4
|
"description": "A collection of accessible, free, open-source web components for building Brightspace applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "https://github.com/BrightspaceUI/core.git",
|