@1024pix/pix-ui 58.4.11 → 59.0.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.
|
@@ -1,30 +1,36 @@
|
|
|
1
|
+
import { warn } from '@ember/debug';
|
|
1
2
|
import { guidFor } from '@ember/object/internals';
|
|
2
3
|
import Component from '@glimmer/component';
|
|
3
4
|
|
|
4
5
|
export default class PixProgressBar extends Component {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
constructor(...args) {
|
|
7
|
+
super(...args);
|
|
8
|
+
warn('PixProgressBar: you need to provide a locale', this.args.locale, {
|
|
9
|
+
id: 'pix-progress-bar.locale.required',
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
warn(
|
|
13
|
+
'PixProgressBar: you need to provide a number value between 0 and 1',
|
|
14
|
+
this.args.value >= 0 && this.args.value <= 1,
|
|
15
|
+
{
|
|
16
|
+
id: 'pix-progress-bar.value.type.incorrect',
|
|
17
|
+
},
|
|
18
|
+
);
|
|
8
19
|
|
|
9
|
-
|
|
10
|
-
if (Number(this.args.value) <= 0) return 0;
|
|
11
|
-
if (Number(this.args.value) > 100) return 100;
|
|
12
|
-
if (!this.args.value) {
|
|
13
|
-
throw new Error('ERROR in PixProgressBar component, @value param is not provided.');
|
|
14
|
-
}
|
|
15
|
-
return Number(this.args.value);
|
|
20
|
+
this.id = guidFor(this);
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
get percentageValue() {
|
|
19
|
-
return Number(this.
|
|
24
|
+
return Number(this.clampValue).toLocaleString(this.args.locale, { style: 'percent' });
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
get label() {
|
|
23
|
-
const
|
|
28
|
+
const hasLabel = this.args.label && this.args.label.trim().length > 0;
|
|
29
|
+
|
|
30
|
+
warn('PixProgressBar: you need to provide a valid label', hasLabel || this.args.isDecorative, {
|
|
31
|
+
id: 'pix-progress-bar.label.required',
|
|
32
|
+
});
|
|
24
33
|
|
|
25
|
-
if (thereIsNoLabel && !this.args.isDecorative) {
|
|
26
|
-
throw new Error('ERROR in PixProgressBar component, @label param is not provided.');
|
|
27
|
-
}
|
|
28
34
|
return this.args.label;
|
|
29
35
|
}
|
|
30
36
|
|
|
@@ -56,6 +62,10 @@ export default class PixProgressBar extends Component {
|
|
|
56
62
|
return `progress-bar--content-${color}`;
|
|
57
63
|
}
|
|
58
64
|
|
|
65
|
+
get clampValue() {
|
|
66
|
+
return Math.max(Math.min(this.args.value, 1), 0);
|
|
67
|
+
}
|
|
68
|
+
|
|
59
69
|
<template>
|
|
60
70
|
<div
|
|
61
71
|
class="progress-bar {{this.themeMode}} {{this.colorClass}}"
|
|
@@ -69,9 +79,10 @@ export default class PixProgressBar extends Component {
|
|
|
69
79
|
<progress
|
|
70
80
|
class="progress-bar__bar"
|
|
71
81
|
id={{this.id}}
|
|
72
|
-
max="
|
|
73
|
-
|
|
74
|
-
|
|
82
|
+
max="1"
|
|
83
|
+
min="0"
|
|
84
|
+
value={{this.clampValue}}
|
|
85
|
+
>{{this.percentageValue}}</progress>
|
|
75
86
|
{{#if @subtitle}}
|
|
76
87
|
<p class="progress-bar__sub-title">{{@subtitle}}</p>
|
|
77
88
|
{{/if}}
|