@@ -2,9 +2,10 @@ import {
22 Component ,
33 Input ,
44 ElementRef ,
5- AfterContentInit
5+ AfterViewInit ,
6+ ViewChild
67} from "@angular/core" ;
7- import { I18n , Overridable } from "carbon-components-angular/i18n" ;
8+ import { I18n } from "carbon-components-angular/i18n" ;
89import { merge } from "carbon-components-angular/utils" ;
910
1011export interface ExpandableTileTranslations {
@@ -16,39 +17,75 @@ export interface ExpandableTileTranslations {
1617 selector : "cds-expandable-tile, ibm-expandable-tile" ,
1718 template : `
1819 <button
20+ *ngIf="!interactive"
1921 class="cds--tile cds--tile--expandable"
2022 [ngClass]="{
2123 'cds--tile--is-expanded' : expanded,
2224 'cds--tile--light': theme === 'light'
2325 }"
2426 [ngStyle]="{'max-height': expandedHeight + 'px'}"
2527 type="button"
26- (click)="onClick()">
27- <div class="cds--tile__chevron">
28- <svg *ngIf="!expanded" width="12" height="7" viewBox="0 0 12 7" [attr.title]="expand.subject | async" role="img">
29- <title>{{expand.subject | async}}</title>
30- <path fill-rule="nonzero" d="M6.002 5.55L11.27 0l.726.685L6.003 7 0 .685.726 0z"/>
31- </svg>
32- <svg *ngIf="expanded" width="12" height="7" viewBox="0 0 12 7" [attr.title]="collapse.subject | async" role="img">
33- <title>{{collapse.subject | async}}</title>
34- <path fill-rule="nonzero" d="M6.002 5.55L11.27 0l.726.685L6.003 7 0 .685.726 0z"/>
35- </svg>
36- </div>
37- <div class="cds--tile-content">
38- <ng-content select=".cds--tile-content__above-the-fold"></ng-content>
39- <ng-content select=".cds--tile-content__below-the-fold"></ng-content>
40- </div>
28+ (click)="onClick()"
29+ [attr.aria-expanded]="expanded"
30+ [attr.title]="(expanded ? collapse.subject : expand.subject) | async">
31+ <ng-container *ngTemplateOutlet="expandableTileContent"></ng-container>
4132 </button>
33+
34+ <div
35+ *ngIf="interactive"
36+ class="cds--tile cds--tile--expandable cds--tile--expandable--interactive"
37+ [ngClass]="{
38+ 'cds--tile--is-expanded' : expanded,
39+ 'cds--tile--light': theme === 'light'
40+ }"
41+ [ngStyle]="{'max-height': expandedHeight + 'px'}"
42+ [attr.title]="(expanded ? collapse.subject : expand.subject) | async">
43+ <ng-container *ngTemplateOutlet="expandableTileContent"></ng-container>
44+ </div>
45+
46+ <ng-template #chevronIcon>
47+ <svg cdsIcon="chevron--down" size="16"></svg>
48+ </ng-template>
49+
50+ <ng-template #expandableTileContent>
51+ <div #container>
52+ <div class="cds--tile-content">
53+ <ng-content select="[cdsAboveFold],[ibmAboveFold],.cds--tile-content__above-the-fold"></ng-content>
54+ </div>
55+ <div *ngIf="!interactive" class="cds--tile__chevron">
56+ <ng-container *ngTemplateOutlet="chevronIcon"></ng-container>
57+ </div>
58+ <button
59+ *ngIf="interactive"
60+ class="cds--tile__chevron cds--tile__chevron--interactive"
61+ type="button"
62+ (click)="onClick()"
63+ [attr.aria-expanded]="expanded"
64+ [attr.aria-label]="(expanded ? collapse.subject : expand.subject) | async">
65+ <ng-container *ngTemplateOutlet="chevronIcon"></ng-container>
66+ </button>
67+ <div class="cds--tile-content">
68+ <ng-content select="[cdsBelowFold],[ibmBelowFold],.cds--tile-content__below-the-fold"></ng-content>
69+ </div>
70+ </div>
71+ </ng-template>
4272 `
4373} )
44- export class ExpandableTile implements AfterContentInit {
74+ export class ExpandableTile implements AfterViewInit {
4575 /**
4676 * @deprecated since v5 - Use `cdsLayer` directive instead
4777 * Set to `"light"` to apply the light style
4878 */
4979 @Input ( ) theme : "light" | "dark" = "dark" ;
5080
81+ /**
82+ * Controls the expanded state
83+ */
5184 @Input ( ) expanded = false ;
85+ /**
86+ * Controls the interactive state
87+ */
88+ @Input ( ) interactive = false ;
5289 /**
5390 * Expects an object that contains some or all of:
5491 * ```
@@ -65,21 +102,22 @@ export class ExpandableTile implements AfterContentInit {
65102 this . collapse . override ( valueWithDefaults . COLLAPSE ) ;
66103 }
67104
105+ @ViewChild ( "container" ) tileContainer : ElementRef ;
106+
68107 tileMaxHeight = 0 ;
69108 currentExpandedHeight = 0 ;
70- element = this . elementRef . nativeElement ;
71109
72110 expand = this . i18n . getOverridable ( "TILES.EXPAND" ) ;
73111 collapse = this . i18n . getOverridable ( "TILES.COLLAPSE" ) ;
74112
75- constructor ( protected i18n : I18n , protected elementRef : ElementRef ) { }
113+ constructor ( protected i18n : I18n , protected element : ElementRef ) { }
76114
77- ngAfterContentInit ( ) {
115+ ngAfterViewInit ( ) {
78116 this . updateMaxHeight ( ) ;
79117 }
80118
81119 get expandedHeight ( ) {
82- const tile = this . element . querySelector ( ".cds--tile" ) ;
120+ const tile = this . element . nativeElement . querySelector ( ".cds--tile" ) ;
83121 const tilePadding
84122 = parseInt ( getComputedStyle ( tile ) . paddingBottom , 10 ) + parseInt ( getComputedStyle ( tile ) . paddingTop , 10 ) ;
85123 const expandedHeight = this . tileMaxHeight + tilePadding ;
@@ -91,9 +129,9 @@ export class ExpandableTile implements AfterContentInit {
91129
92130 updateMaxHeight ( ) {
93131 if ( this . expanded ) {
94- this . tileMaxHeight = this . element . querySelector ( ".cds--tile-content" ) . getBoundingClientRect ( ) . height ;
132+ this . tileMaxHeight = this . tileContainer . nativeElement . getBoundingClientRect ( ) . height ;
95133 } else {
96- this . tileMaxHeight = this . element . querySelector ( ".cds--tile-content__above-the-fold" ) . getBoundingClientRect ( ) . height ;
134+ this . tileMaxHeight = this . element . nativeElement . querySelector ( ".cds--tile-content__above-the-fold" ) . getBoundingClientRect ( ) . height ;
97135 }
98136 }
99137
0 commit comments