|
1 |
| -import { Component, HostBinding, Input } from '@angular/core'; |
2 |
| -import { BooleanInput, coerceBooleanProperty } from '@angular/cdk/coercion'; |
| 1 | +import { booleanAttribute, Component, HostBinding, inject, Input } from '@angular/core'; |
3 | 2 |
|
4 | 3 | import { AccordionService } from '../accordion.service';
|
5 | 4 |
|
6 | 5 | @Component({
|
7 | 6 | selector: 'c-accordion',
|
8 |
| - template: `<ng-content></ng-content>`, |
| 7 | + template: '<ng-content/>', |
9 | 8 | styleUrls: ['./accordion.component.scss'],
|
10 | 9 | exportAs: 'cAccordionItem',
|
11 | 10 | providers: [AccordionService],
|
12 | 11 | standalone: true
|
13 | 12 | })
|
14 | 13 | export class AccordionComponent {
|
15 | 14 |
|
16 |
| - static ngAcceptInputType_alwaysOpen: BooleanInput; |
| 15 | + #accordionService = inject(AccordionService); |
17 | 16 |
|
18 | 17 | /**
|
19 | 18 | * Removes the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container.
|
20 | 19 | * @type boolean
|
21 | 20 | */
|
22 |
| - @Input() flush?: boolean; |
| 21 | + @Input({ transform: booleanAttribute }) flush: boolean = false; |
| 22 | + |
23 | 23 | /**
|
24 | 24 | * Make accordion items stay open when another item is opened
|
25 | 25 | * @type boolean
|
26 | 26 | */
|
27 |
| - @Input() |
| 27 | + @Input({ transform: booleanAttribute }) |
28 | 28 | set alwaysOpen(value: boolean) {
|
29 |
| - this.accordionService.alwaysOpen = coerceBooleanProperty(value); |
| 29 | + this.#accordionService.alwaysOpen = value; |
30 | 30 | }
|
| 31 | + |
31 | 32 | get alwaysOpen(): boolean {
|
32 |
| - return this.accordionService.alwaysOpen; |
| 33 | + return this.#accordionService.alwaysOpen; |
33 | 34 | }
|
34 | 35 |
|
35 | 36 | @HostBinding('class')
|
36 | 37 | get hostClasses(): any {
|
37 | 38 | return {
|
38 | 39 | accordion: true,
|
39 |
| - 'accordion-flush': !!this.flush |
| 40 | + 'accordion-flush': this.flush |
40 | 41 | };
|
41 | 42 | }
|
42 | 43 |
|
43 |
| - constructor( |
44 |
| - private accordionService: AccordionService |
45 |
| - ) {} |
46 |
| - |
47 | 44 | }
|
0 commit comments