@1024pix/pix-ui 62.2.0 → 62.3.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,3 +1,4 @@
1
+ import { warn } from '@ember/debug';
1
2
  import { on } from '@ember/modifier';
2
3
  import { action } from '@ember/object';
3
4
  import { guidFor } from '@ember/object/internals';
@@ -11,21 +12,49 @@ export default class PixAccordions extends Component {
11
12
  text = 'pix-accordions';
12
13
  contentId = 'pix-accordions-' + guidFor(this);
13
14
 
14
- @tracked isCollapsed = true;
15
- @tracked hasUnCollapsedOnce = false;
15
+ @tracked isCollapsedWhenUncontrolled = true;
16
+ hasBeenExpandedOnce = false;
16
17
 
17
- get isUnCollapsed() {
18
- return !this.isCollapsed;
18
+ constructor(...args) {
19
+ super(...args);
20
+
21
+ warn(
22
+ 'PixAccordions: uncontrolled mode is deprecated, use @isExpanded and @onToggle instead',
23
+ Boolean(this.args.onToggle),
24
+ {
25
+ id: 'pix-ui.pix-accordions.uncontrolled.deprecated',
26
+ },
27
+ );
28
+ }
29
+
30
+ get isControlled() {
31
+ return this.args.isExpanded !== undefined && this.args.isExpanded !== null;
32
+ }
33
+
34
+ get isExpanded() {
35
+ return this.isControlled ? Boolean(this.args.isExpanded) : !this.isCollapsedWhenUncontrolled;
19
36
  }
20
37
 
21
38
  get isContentRendered() {
22
- return this.hasUnCollapsedOnce;
39
+ if (this.isExpanded) {
40
+ // eslint-disable-next-line ember/no-side-effects
41
+ this.hasBeenExpandedOnce = true;
42
+ }
43
+
44
+ return this.hasBeenExpandedOnce;
23
45
  }
24
46
 
25
47
  @action
26
48
  toggleAccordions() {
27
- this.isCollapsed = !this.isCollapsed;
28
- this.hasUnCollapsedOnce = true;
49
+ const nextIsExpanded = !this.isExpanded;
50
+
51
+ if (!this.isControlled) {
52
+ this.isCollapsedWhenUncontrolled = !nextIsExpanded;
53
+ }
54
+
55
+ if (this.args.onToggle) {
56
+ this.args.onToggle(nextIsExpanded);
57
+ }
29
58
  }
30
59
 
31
60
  get isV2Version() {
@@ -40,7 +69,7 @@ export default class PixAccordions extends Component {
40
69
  type="button"
41
70
  {{on "click" this.toggleAccordions}}
42
71
  aria-controls={{this.contentId}}
43
- aria-expanded={{if this.isUnCollapsed "true" "false"}}
72
+ aria-expanded={{if this.isExpanded "true" "false"}}
44
73
  ...attributes
45
74
  >
46
75
 
@@ -66,7 +95,7 @@ export default class PixAccordions extends Component {
66
95
  <PixIcon
67
96
  class="pix-accordions{{this.isV2Version}}-title-container__toggle-icon"
68
97
  @ariaHidden={{true}}
69
- @name="{{if this.isCollapsed 'chevronBottom' 'chevronTop'}}"
98
+ @name="{{if this.isExpanded 'chevronTop' 'chevronBottom'}}"
70
99
  />
71
100
  </span>
72
101
  </button>
@@ -74,7 +103,7 @@ export default class PixAccordions extends Component {
74
103
  <div
75
104
  id={{this.contentId}}
76
105
  class="pix-accordions{{this.isV2Version}}__content"
77
- aria-hidden={{if this.isCollapsed "true" "false"}}
106
+ aria-hidden={{if this.isExpanded "false" "true"}}
78
107
  >
79
108
  {{#if this.isContentRendered}}
80
109
  {{yield to="content"}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1024pix/pix-ui",
3
- "version": "62.2.0",
3
+ "version": "62.3.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"