Skip to content

Commit

Permalink
refactor(accordion): introducing signals signals
Browse files Browse the repository at this point in the history
  • Loading branch information
lexasq committed Nov 4, 2024
1 parent b606d45 commit a8c6fd4
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/accordion/accordion.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, input, OnChanges, SimpleChanges } from '@angular/core';
import { Component, effect, input } from '@angular/core';
import { AccordionPanelComponent } from './accordion-group.component';
import { AccordionConfig } from './accordion.config';

Expand All @@ -15,7 +15,7 @@ import { AccordionConfig } from './accordion.config';
},
standalone: true
})
export class AccordionComponent implements OnChanges {
export class AccordionComponent {
/** turn on/off animation */
isAnimated = input<boolean>(false);
_isAnimated = this.isAnimated();
Expand All @@ -28,17 +28,11 @@ export class AccordionComponent implements OnChanges {

constructor(config: AccordionConfig) {
Object.assign(this, config);
}

ngOnChanges(changes: SimpleChanges) {
if (changes['isAnimated'] && !changes['isAnimated'].firstChange) {
// Only update if foo has changed and isn't the initial setup
effect(() => {
this._isAnimated = this.isAnimated();
}
if (changes['closeOthers'] && !changes['closeOthers'].firstChange) {
// Only update if foo has changed and isn't the initial setup
this._closeOthers = this.closeOthers();
}

});
}

closeOtherPanels(openGroup: AccordionPanelComponent): void {
Expand Down

0 comments on commit a8c6fd4

Please sign in to comment.