@brightspace-ui/core 3.201.0 → 3.202.0

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.
@@ -45,6 +45,8 @@
45
45
  <d2l-meter-linear value="3" max="6" text="Visited: {x/y}" percent text-hidden></d2l-meter-linear>
46
46
  <d2l-meter-linear value="3" max="6" text="Visited: {%}"></d2l-meter-linear>
47
47
  <d2l-meter-linear value="3" max="6" text="You're doing great!" percent></d2l-meter-linear>
48
+ <d2l-meter-linear value="1" max="3" text="Round up({x/y} => {%})" percent percent-rounding-mode="ceil"></d2l-meter-linear>
49
+ <d2l-meter-linear value="2" max="3" text="Round down({x/y} => {%})" percent percent-rounding-mode="floor"></d2l-meter-linear>
48
50
  </div>
49
51
  <div class="dark-background">
50
52
  <d2l-meter-linear value="2" max="15" foreground-light text-inline></d2l-meter-linear>
@@ -56,6 +58,8 @@
56
58
  <d2l-meter-linear value="3" max="6" foreground-light text="Visited: {x/y}" percent></d2l-meter-linear>
57
59
  <d2l-meter-linear value="3" max="6" foreground-light text="Visited: {%}"></d2l-meter-linear>
58
60
  <d2l-meter-linear value="3" max="6" foreground-light text="You're doing great!" percent></d2l-meter-linear>
61
+ <d2l-meter-linear value="1" max="3" foreground-light text="Round up({x/y} => {%})" percent percent-rounding-mode="ceil"></d2l-meter-linear>
62
+ <d2l-meter-linear value="2" max="3" foreground-light text="Round down({x/y} => {%})" percent percent-rounding-mode="floor"></d2l-meter-linear>
59
63
  </div>
60
64
  </template>
61
65
  </d2l-demo-snippet>
@@ -16,6 +16,11 @@ export const MeterMixin = superclass => class extends LocalizeCoreElement(superc
16
16
  * @type {boolean}
17
17
  */
18
18
  percent: { type: Boolean },
19
+ /**
20
+ * Rounding mode for percentage text values
21
+ * @type {"round" | "ceil" | "floor"}
22
+ */
23
+ percentRoundingMode: { type: String, attribute: 'percent-rounding-mode' },
19
24
  /**
20
25
  * Context information for the meter. If the text contains {%} or {x/y}, they will be replaced with a percentage or fraction respectively.
21
26
  * @type {string}
@@ -41,6 +46,7 @@ export const MeterMixin = superclass => class extends LocalizeCoreElement(superc
41
46
  this.percent = false;
42
47
  this.textHidden = false;
43
48
  this.value = 0;
49
+ this.percentRoundingMode = 'round';
44
50
 
45
51
  this._namespace = 'components.meter-mixin';
46
52
  }
@@ -52,8 +58,17 @@ export const MeterMixin = superclass => class extends LocalizeCoreElement(superc
52
58
  return secondary ? this.localize(`${this._namespace}.commaSeperatedAria`, { term1: secondary, term2: mainLabel }) : mainLabel;
53
59
  }
54
60
 
61
+ _getPecentage() {
62
+ const value = this.max > 0 ? this.value / this.max : 0;
63
+ switch (this.percentRoundingMode) {
64
+ case 'ceil': return Math.ceil(value * 100) / 100;
65
+ case 'floor': return Math.floor(value * 100) / 100;
66
+ default: return Math.round(value * 100) / 100;
67
+ }
68
+ }
69
+
55
70
  _primary(value, max, aria = false) {
56
- const percentage = max > 0 ? value / max : 0;
71
+ const percentage = this._getPecentage();
57
72
  const key = aria ? 'fractionAria' : 'fraction';
58
73
 
59
74
  return this.percent
@@ -68,7 +83,7 @@ export const MeterMixin = superclass => class extends LocalizeCoreElement(superc
68
83
 
69
84
  const key = aria ? 'fractionAria' : 'fraction';
70
85
 
71
- const percentage = this.max > 0 ? value / max : 0;
86
+ const percentage = this._getPecentage();
72
87
  context = context.replace('{%}', formatPercent(percentage, { maximumFractionDigits: 0 }));
73
88
  context = context.replace('{x/y}', this.localize(`${this._namespace}.${key}`, { x: value, y: max }));
74
89
  context = context.replace('{x}', value);
@@ -11320,6 +11320,12 @@
11320
11320
  "description": "REQUIRED: Current number of completed units.\nValid values: A number between 0 and max",
11321
11321
  "type": "number",
11322
11322
  "default": "0"
11323
+ },
11324
+ {
11325
+ "name": "percent-rounding-mode",
11326
+ "description": "Rounding mode for percentage text values",
11327
+ "type": "\"round\" | \"ceil\" | \"floor\"",
11328
+ "default": "\"round\""
11323
11329
  }
11324
11330
  ],
11325
11331
  "properties": [
@@ -11356,6 +11362,13 @@
11356
11362
  "description": "REQUIRED: Current number of completed units.\nValid values: A number between 0 and max",
11357
11363
  "type": "number",
11358
11364
  "default": "0"
11365
+ },
11366
+ {
11367
+ "name": "percentRoundingMode",
11368
+ "attribute": "percent-rounding-mode",
11369
+ "description": "Rounding mode for percentage text values",
11370
+ "type": "\"round\" | \"ceil\" | \"floor\"",
11371
+ "default": "\"round\""
11359
11372
  }
11360
11373
  ]
11361
11374
  },
@@ -11398,6 +11411,12 @@
11398
11411
  "description": "REQUIRED: Current number of completed units.\nValid values: A number between 0 and max",
11399
11412
  "type": "number",
11400
11413
  "default": "0"
11414
+ },
11415
+ {
11416
+ "name": "percent-rounding-mode",
11417
+ "description": "Rounding mode for percentage text values",
11418
+ "type": "\"round\" | \"ceil\" | \"floor\"",
11419
+ "default": "\"round\""
11401
11420
  }
11402
11421
  ],
11403
11422
  "properties": [
@@ -11441,6 +11460,13 @@
11441
11460
  "description": "REQUIRED: Current number of completed units.\nValid values: A number between 0 and max",
11442
11461
  "type": "number",
11443
11462
  "default": "0"
11463
+ },
11464
+ {
11465
+ "name": "percentRoundingMode",
11466
+ "attribute": "percent-rounding-mode",
11467
+ "description": "Rounding mode for percentage text values",
11468
+ "type": "\"round\" | \"ceil\" | \"floor\"",
11469
+ "default": "\"round\""
11444
11470
  }
11445
11471
  ]
11446
11472
  },
@@ -11477,6 +11503,12 @@
11477
11503
  "description": "REQUIRED: Current number of completed units.\nValid values: A number between 0 and max",
11478
11504
  "type": "number",
11479
11505
  "default": "0"
11506
+ },
11507
+ {
11508
+ "name": "percent-rounding-mode",
11509
+ "description": "Rounding mode for percentage text values",
11510
+ "type": "\"round\" | \"ceil\" | \"floor\"",
11511
+ "default": "\"round\""
11480
11512
  }
11481
11513
  ],
11482
11514
  "properties": [
@@ -11513,6 +11545,13 @@
11513
11545
  "description": "REQUIRED: Current number of completed units.\nValid values: A number between 0 and max",
11514
11546
  "type": "number",
11515
11547
  "default": "0"
11548
+ },
11549
+ {
11550
+ "name": "percentRoundingMode",
11551
+ "attribute": "percent-rounding-mode",
11552
+ "description": "Rounding mode for percentage text values",
11553
+ "type": "\"round\" | \"ceil\" | \"floor\"",
11554
+ "default": "\"round\""
11516
11555
  }
11517
11556
  ]
11518
11557
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.201.0",
3
+ "version": "3.202.0",
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",