-
Notifications
You must be signed in to change notification settings - Fork 2
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 #34 from Reloadly/new-accordion-feature
New accordion component and created a new component called expandable-tile
- Loading branch information
Showing
14 changed files
with
360 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,26 @@ | ||
<div class="accordion" [class.open]="isOpen" [class.disabled]="disabled" [style]="{width: width}"> | ||
<div class="accordion-header" (click)="toggle()"> | ||
<h6>{{title}}</h6> | ||
<div class="toggler-wrapper"> | ||
<div class="toggler"> | ||
<ng-content select="[toggler]"></ng-content> | ||
<section class="accordion"> | ||
<div *ngFor="let item of items; index as i" class="accordion-item" [style]="{width: width}" | ||
[class.disabled]="item.disabled" [class.active]="expanded.has(i)" [class.open]="expanded.has(i)"> | ||
<ng-container> | ||
<div class="accordion-header" (click)="item.disabled ? {} :toggleState(i)"> | ||
<p class="accordion-title">{{item?.title}}</p> | ||
<div class="toggler-wrapper"> | ||
<div class="toggler"> | ||
<ng-content select="[toggler]"></ng-content> | ||
</div> | ||
<div class="toggle-icon"> | ||
<span class="chevron"> | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="toggle-icon"> | ||
<span class="chevron"> | ||
|
||
</span> | ||
<div class="accordion-content" [class.expanded]="expanded.has(i)"> | ||
<div class="content"> | ||
<div [@contentExpansion]="expanded.has(i) ? 'expanded':'collapsed'"> | ||
<ng-container *ngTemplateOutlet="item!.content!.templateRef"></ng-container> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</ng-container> | ||
</div> | ||
<div class="accordion-body"> | ||
<div class="content"> | ||
<ng-content></ng-content> | ||
</div> | ||
</div> | ||
</div> | ||
</section> |
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,22 +1,39 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { Component, ContentChildren, EventEmitter, Input, Output, QueryList } from '@angular/core'; | ||
import { ReloadlyAccordionItem } from './directives/accordion-item.directive'; | ||
import { animate, state, style, transition, trigger } from '@angular/animations'; | ||
|
||
@Component({ | ||
selector: 'reloadly-accordion', | ||
templateUrl: './accordion.component.html', | ||
styleUrls: ['./accordion.component.scss'] | ||
styleUrls: ['./accordion.component.scss'], | ||
animations: [ | ||
trigger('contentExpansion', [ | ||
state('expanded', style({ height: '*', opacity: 1, visibility: 'visible' })), | ||
state('collapsed', style({ height: '0px', opacity: 0, visibility: 'hidden' })), | ||
transition('expanded <=> collapsed', | ||
animate('200ms cubic-bezier(.37,1.04,.68,.98)')), | ||
]) | ||
] | ||
}) | ||
export class ReloadlyAccordionComponent { | ||
@Input() title?: string; | ||
@Input() disabled: boolean = false; | ||
@Input() width: string = '176px' | ||
@Output() onToggle: EventEmitter<boolean> = new EventEmitter(); | ||
expanded = new Set<number>(); | ||
@Input() collapsing = true; | ||
@Input() width: string = '176px'; | ||
@ContentChildren(ReloadlyAccordionItem) items: QueryList<ReloadlyAccordionItem> = new QueryList(); | ||
|
||
getToggleState = (index: number) => { | ||
return this.toggleState.bind(this, index); | ||
}; | ||
|
||
isOpen: boolean = false; | ||
|
||
toggle() { | ||
if (this.disabled) return; | ||
this.isOpen = !this.isOpen; | ||
this.onToggle.emit(this.isOpen); | ||
} | ||
toggleState = (index: number) => { | ||
if (this.expanded.has(index)) { | ||
this.expanded.delete(index); | ||
} else { | ||
if (this.collapsing) { | ||
this.expanded.clear(); | ||
} | ||
this.expanded.add(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,11 +1,29 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { ReloadlyAccordionComponent } from './accordion.component'; | ||
import { ReloadlyAccordionItem } from "./directives/accordion-item.directive"; | ||
import { ReloadlyAccordionItemContent } from "./directives/accordion-item-content.directive"; | ||
import { BrowserAnimationsModule } from '@angular/platform-browser/animations' | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
|
||
|
||
@NgModule({ | ||
imports: [], | ||
exports: [ReloadlyAccordionComponent], | ||
declarations: [ReloadlyAccordionComponent], | ||
providers: [], | ||
imports: [ | ||
CommonModule, | ||
BrowserModule, | ||
BrowserAnimationsModule], | ||
exports: [ | ||
ReloadlyAccordionComponent, | ||
ReloadlyAccordionItem, | ||
ReloadlyAccordionItemContent, | ||
|
||
], | ||
declarations: [ | ||
ReloadlyAccordionComponent, | ||
ReloadlyAccordionItem, | ||
ReloadlyAccordionItemContent, | ||
], | ||
providers: [], | ||
}) | ||
export class ReloadlyAccordionModule { } |
9 changes: 9 additions & 0 deletions
9
src/lib/components/accordion/directives/accordion-item-content.directive.ts
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Directive, TemplateRef } from "@angular/core"; | ||
|
||
@Directive({ | ||
selector: "[accordionContent]" | ||
}) | ||
export class ReloadlyAccordionItemContent { | ||
constructor(public templateRef: TemplateRef<any>) {} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/lib/components/accordion/directives/accordion-item.directive.ts
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ContentChild, Directive, Input } from "@angular/core"; | ||
import { ReloadlyAccordionItemContent } from "./accordion-item-content.directive"; | ||
|
||
@Directive({ | ||
selector: "reloadly-accordion-item" | ||
}) | ||
export class ReloadlyAccordionItem { | ||
@Input() title = ""; | ||
@Input() disabled = false; | ||
@Input() expanded = false; | ||
@ContentChild(ReloadlyAccordionItemContent) content?: ReloadlyAccordionItemContent; | ||
|
||
constructor() {} | ||
|
||
} |
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
21 changes: 21 additions & 0 deletions
21
src/lib/components/expandable-tile/expandable-tile.component.html
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<div class="expandable-tile" [class.open]="isOpen" [class.disabled]="disabled" [style]="{width: width}"> | ||
<div class="expandable-tile-header" (click)="toggle()"> | ||
<h6>{{title}}</h6> | ||
<div class="toggler-wrapper"> | ||
<div class="toggler"> | ||
<ng-content select="[toggler]"></ng-content> | ||
</div> | ||
<div class="toggle-icon"> | ||
<span class="chevron"> | ||
|
||
</span> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
<div class="expandable-tile-body"> | ||
<div class="content"> | ||
<ng-content></ng-content> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.