@1024pix/pix-ui 58.4.10 → 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.
@@ -36,7 +36,7 @@ export default class PixGauge extends Component {
36
36
  return this.args.hideValues ?? false;
37
37
  }
38
38
 
39
- get maxLevelPourcentage() {
39
+ get maxLevelPercentage() {
40
40
  return this.maxLevel / 8;
41
41
  }
42
42
  get viewBox() {
@@ -71,6 +71,41 @@ export default class PixGauge extends Component {
71
71
  return this.args.isSmall ? 18 : 26;
72
72
  }
73
73
 
74
+ get gaugeWidths() {
75
+ let reachedLevelWidth = this.gaugeWidthCSS(this.reachedLevelPercentage);
76
+ let maxLevelWidth = this.gaugeWidthCSS(this.maxLevelPercentage);
77
+
78
+ const levelDifference = Math.round((this.maxLevel - this.reachedLevel) * 10) / 10;
79
+
80
+ const isMaxLevelInteger = this.maxLevel % 1 === 0;
81
+ const spacingRem = isMaxLevelInteger ? 1.75 : 2.625;
82
+
83
+ const isSpaceBetweenLevelsNarrow = this.args.isSmall
84
+ ? levelDifference < 1.5
85
+ : levelDifference < 0.5;
86
+
87
+ if (!this.hideValues && levelDifference !== 0 && isSpaceBetweenLevelsNarrow) {
88
+ if (this.maxLevel >= 7.5) {
89
+ reachedLevelWidth = this.gaugeWidthCSS(this.maxLevelPercentage, `- ${spacingRem}rem`);
90
+ } else {
91
+ maxLevelWidth = this.gaugeWidthCSS(this.reachedLevelPercentage, `+ ${spacingRem}rem`);
92
+ }
93
+ }
94
+
95
+ const reachedLevelMinWidth = `3rem`;
96
+ const maxLevelMinWidth = `${reachedLevelMinWidth} + ${spacingRem}rem`;
97
+
98
+ return {
99
+ reachedLevel: this.gaugeAdaptativeWidthCSS(reachedLevelMinWidth, reachedLevelWidth),
100
+ maxLevel: this.gaugeAdaptativeWidthCSS(maxLevelMinWidth, maxLevelWidth),
101
+ };
102
+ }
103
+
104
+ gaugeWidthCSS = (levelPercentage, spacing = '') =>
105
+ `calc(calc(100% - 8px) * ${levelPercentage} ${spacing})`;
106
+
107
+ gaugeAdaptativeWidthCSS = (width, minWidth) => `max(${minWidth}, ${width})`;
108
+
74
109
  isLevelActive = (index) => {
75
110
  if (this.reachedLevel === 0 && index === 0) return true;
76
111
  const step = 8 / this.args.stepLabels.length;
@@ -127,13 +162,13 @@ export default class PixGauge extends Component {
127
162
  {{! gauge white max level}}
128
163
  <rect
129
164
  y={{26}}
130
- width="calc(calc(100% - 8px) * {{this.maxLevelPourcentage}})"
165
+ width={{this.gaugeWidths.maxLevel}}
131
166
  height={{this.whiteAndPurpleGaugesHeight}}
132
167
  rx={{this.whiteAndPurpleGaugeRx}}
133
168
  class="result-level-gauge__max-bar"
134
169
  />
135
170
  {{#unless this.hideValues}}
136
- <g style="transform: translate(calc(calc(100% - 8px) * {{this.maxLevelPourcentage}}))">
171
+ <g style="transform: translate({{this.gaugeWidths.maxLevel}})">
137
172
  <text
138
173
  y={{this.statsFontHeight}}
139
174
  x="0"
@@ -147,15 +182,13 @@ export default class PixGauge extends Component {
147
182
  {{! mean purple level }}
148
183
  <rect
149
184
  y={{26}}
150
- width="max(calc(calc(100% - 8px) * {{this.reachedLevelPercentage}}), 44px)"
185
+ width={{this.gaugeWidths.reachedLevel}}
151
186
  height={{this.whiteAndPurpleGaugesHeight}}
152
187
  rx={{this.whiteAndPurpleGaugeRx}}
153
188
  class="result-level-gauge__mean-bar"
154
189
  />
155
190
  {{#unless this.hideValues}}
156
- <g
157
- style="transform: translate(max(calc(calc(100% - 8px) * {{this.reachedLevelPercentage}}), 44px))"
158
- >
191
+ <g style="transform: translate({{this.gaugeWidths.reachedLevel}})">
159
192
  <text
160
193
  y={{this.statsFontHeight}}
161
194
  x="0"
@@ -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
- get id() {
6
- return guidFor(this);
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
- get value() {
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.value / 100).toLocaleString(navigator.language, { style: 'percent' });
24
+ return Number(this.clampValue).toLocaleString(this.args.locale, { style: 'percent' });
20
25
  }
21
26
 
22
27
  get label() {
23
- const thereIsNoLabel = !this.args.label || !this.args.label.trim();
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="100"
73
- value={{this.value}}
74
- >{{this.value}}%</progress>
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}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1024pix/pix-ui",
3
- "version": "58.4.10",
3
+ "version": "59.0.0",
4
4
  "description": "Pix-UI is the implementation of Pix design principles and guidelines for its products.",
5
5
  "keywords": [
6
6
  "ember-addon"