This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #681 from buildcom/663
resolves #663 applied animation to collapsed component
- Loading branch information
Showing
5 changed files
with
70 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
import {Component, Input, OnInit, SimpleChanges} from '@angular/core'; | ||
import {BossyCollapseConfig} from './collapse.config'; | ||
import { Component, Input, OnInit, SimpleChanges} from '@angular/core'; | ||
import { BossyCollapseConfig } from './collapse.config'; | ||
import { Console } from '@angular/core/src/console'; | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||
import { trigger, style, transition, animate, keyframes, query, stagger, state } from '@angular/animations'; | ||
|
||
@Component({ | ||
selector: 'bossy-collapse', | ||
templateUrl: './collapse.html', | ||
animations: [ | ||
trigger('collapseAnimation', [ | ||
state('true', style({ height: '*', fontSize: '14px' })), | ||
state('false', style({ height: '0px', fontSize: '0px' })), | ||
transition('1 => 0', animate('250ms ease-in')), | ||
transition('0 => 1', animate('250ms ease-out')) | ||
]) | ||
] | ||
}) | ||
|
||
|
||
export class BossyCollapseComponent implements OnInit { | ||
@Input() config: BossyCollapseConfig; | ||
isShowing = false; | ||
show = ''; | ||
buttonCollapsed = 'collapsed'; | ||
areItemsExpanded: Array<boolean> = []; | ||
buttonsCollapsed: Array<string> = []; | ||
|
||
ngOnInit() { | ||
this.isShowing = false; | ||
this.show = ''; | ||
this.buttonCollapsed = 'collapsed'; | ||
this.config.items.forEach(item => { | ||
this.areItemsExpanded.push(false); | ||
this.buttonsCollapsed.push('collapsed'); | ||
}); | ||
} | ||
|
||
isItemExpanded(index): boolean { | ||
return this.areItemsExpanded[index]; | ||
} | ||
|
||
onEventClick() { | ||
if (this.isShowing) { | ||
this.show = ''; | ||
this.isShowing = false; | ||
this.buttonCollapsed = 'collapsed'; | ||
} else { | ||
this.show = 'show'; | ||
this.isShowing = true; | ||
this.buttonCollapsed = ''; | ||
} | ||
onEventClick(index) { | ||
if (this.areItemsExpanded[index]) { | ||
this.areItemsExpanded[index] = false; | ||
this.buttonsCollapsed[index] = 'collapsed'; | ||
} else { | ||
this.areItemsExpanded[index] = true; | ||
this.buttonsCollapsed[index] = ''; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
interface CollapseItems { | ||
name: string; | ||
data: string; | ||
} | ||
|
||
export class BossyCollapseConfig { | ||
constructor(public name: string, | ||
public data: string, | ||
constructor(public items: Array<CollapseItems>, | ||
public isAccordionStyle?: boolean) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
<div *ngIf="!config?.isAccordionStyle"> | ||
<p> | ||
<button class="btn btn-primary {{buttonCollapsed}}" (click)="onEventClick()" type="button" data-toggle="collapse" data-target="#collapseExample" attr.aria-expanded="{{isShowing}}" aria-controls="collapseExample"> | ||
{{config.name}} | ||
</button> | ||
</p> | ||
|
||
<div class="collapse {{show}}" id="collapseExample"> | ||
<div class="card card-body"> | ||
{{config.data}} | ||
<div *ngFor="let item of config.items; let i = index"> | ||
<p> | ||
<button class="btn btn-primary {{buttonsCollapsed[i]}}" (click)="onEventClick(i)" type="button" data-toggle="collapse" data-target="#collapseExample" attr.aria-expanded="{{isItemExpanded(i)}}" aria-controls="collapseExample"> | ||
{{item.name}} | ||
</button> | ||
</p> | ||
|
||
<div class="veritcal-menu" id="collapseExample" [@collapseAnimation]="isItemExpanded(i)"> | ||
<div class="card vertical-menu" [@collapseAnimation]="isItemExpanded(i)"> | ||
{{item.data}} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div *ngIf="config?.isAccordionStyle"> | ||
<div id="accordion"> | ||
<div class="card"> | ||
<div class="card-header" id="headingOne"> | ||
<h5 class="mb-0"> | ||
<button class="btn btn-link {{buttonCollapsed}}" (click)="onEventClick()" data-toggle="collapse" data-target="#collapseOne" attr.aria-expanded="{{isShowing}}" aria-controls="collapseOne"> | ||
{{config.name}} | ||
</button> | ||
</h5> | ||
</div> | ||
|
||
<div id="collapseOne" class="collapse {{show}}" aria-labelledby="headingOne" data-parent="#accordion"> | ||
<div class="card-body"> | ||
{{config.data}} | ||
<div *ngFor="let item of config.items; let i = index"> | ||
<div class="card-header" id="headingOne"> | ||
<h5 class="mb-0"> | ||
<button class="btn btn-link {{buttonsCollapsed[i]}}" (click)="onEventClick(i)" data-toggle="collapse" data-target="#collapseOne" attr.aria-expanded="{{isItemExpanded(i)}}" aria-controls="collapseOne"> | ||
{{item.name}} | ||
</button> | ||
</h5> | ||
</div> | ||
|
||
<div > | ||
<div id="collapseOne" class="vertical-menu" aria-labelledby="headingOne" data-parent="#accordion" [@collapseAnimation]="isItemExpanded(i)"> | ||
<div class="vertical-menu" [@collapseAnimation]="isItemExpanded(i)"> | ||
{{item.data}} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |