Skip to content

Commit

Permalink
Merge pull request #34 from Reloadly/new-accordion-feature
Browse files Browse the repository at this point in the history
New accordion component and created a new component called expandable-tile
  • Loading branch information
iSeremet-Reloadly authored Nov 2, 2023
2 parents 1cc6bf8 + 5ff738b commit 5eec1b9
Show file tree
Hide file tree
Showing 14 changed files with 360 additions and 59 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reloadly-ui",
"version": "0.0.1-beta.37",
"version": "0.0.1-beta.38",
"description": "Angular UI library",
"repository": {
"type": "git",
Expand Down Expand Up @@ -66,4 +66,4 @@
"url": "https://github.com/Reloadly/reloadly-ui/issues"
},
"homepage": "https://ui.reloadly.com/"
}
}
41 changes: 23 additions & 18 deletions src/lib/components/accordion/accordion.component.html
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>
80 changes: 60 additions & 20 deletions src/lib/components/accordion/accordion.component.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,61 @@
.accordion {
.toggle-icon {
transition: 300ms all ease-in-out;
transform-origin: center center;
height: 24px;
width: 24px;

.chevron {
box-sizing: border-box;
position: relative;
display: block;
transform: scale(var(--ggs, 1));
width: 22px;
height: 22px;
border: 2px solid transparent;
border-radius: 100px
}

.chevron::after {
content: "";
display: block;
box-sizing: border-box;
position: absolute;
width: 10px;
height: 10px;
border-bottom: 2px solid;
border-right: 2px solid;
transform: rotate(45deg);
left: 4px;
top: 2px
}

}

.accordion-header {
display: flex;

padding: 4px;
justify-content: space-between;
align-items: center;
border-radius: 4px;
cursor: pointer;

h6 {
margin: 4px 0px;
}

&:hover {
background: var(--palette-neutral-neutral-90, #E0E3E8);
}

h6 {
font-size: 16px;
font-style: normal;
font-weight: 450;
}
}

.accordion-item {
display: block;
padding: 4px;
overflow-y: hidden;
Expand Down Expand Up @@ -61,16 +118,9 @@

}

.accordion-body {
padding: 4px 0px;
margin: 1px 0px;
opacity: 1;
height: auto !important;
.accordion-content {
padding: 4px;
font-size: 14px;
transition: font-size .25s,
margin .25s,
padding .25s,
opacity .5s .25s;

.content {
padding: 4px;
Expand Down Expand Up @@ -102,14 +152,4 @@
}
}

.accordion-body {
font-size: 0;
margin: 0;
opacity: 0;
padding: 0;
transition: opacity .25s,
font-size .5s .25s,
margin .5s .25s,
padding .5s .25s;
}
}
43 changes: 30 additions & 13 deletions src/lib/components/accordion/accordion.component.ts
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);
}
};
}

26 changes: 22 additions & 4 deletions src/lib/components/accordion/accordion.module.ts
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 { }
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>) {}

}
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() {}

}
4 changes: 3 additions & 1 deletion src/lib/components/components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PaginationComponent } from './pagination/pagination.component';
import { BreadcrumbItemComponent } from './breadcrumb-group/breadcrumb-item/breadcrumb-item.component';
import { ReloadlyModalOutletComponent } from './modal/reloadly-modal-outlet/reloadly-modal-outlet.component';
import { ReloadlyBreadcrumbsComponent } from './breadcrumb-group/breadcrumbs/breadcrumbs.component';
import { ReloadlyExpandableTileModule } from './expandable-tile/expandable-tile.module';
import { InputLabelComponent } from './input-group/input-label/input-label.component';
import { InputGroupDirective } from './input-group/directives/input-group.directive';
import { FormGroupDirective } from './form-group/directives/form-group.directive';
Expand Down Expand Up @@ -39,7 +40,7 @@ import { MenuModule } from './menu/menu.module';
InputLabelComponent,
PreloaderComponent,
ReloadlyBreadcrumbsComponent,
BreadcrumbItemComponent
BreadcrumbItemComponent,
],
imports: [
CommonModule,
Expand Down Expand Up @@ -72,6 +73,7 @@ import { MenuModule } from './menu/menu.module';
TooltipModule,
ReloadlyBreadcrumbsComponent,
ReloadlyAccordionModule,
ReloadlyExpandableTileModule,
BreadcrumbItemComponent,
ReloadlyModalOutletComponent
]
Expand Down
21 changes: 21 additions & 0 deletions src/lib/components/expandable-tile/expandable-tile.component.html
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>
Loading

0 comments on commit 5eec1b9

Please sign in to comment.