-
Notifications
You must be signed in to change notification settings - Fork 8
add Accordion component #950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jferrer1W
wants to merge
10
commits into
master
Choose a base branch
from
949-new-accordion-component
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aa6da95
add Accordion component
jferrer1W f06a8cc
add test coveraging
jferrer1W dcc76e8
fix name of scss class removing mlab prefix
jferrer1W b047f2d
Add readme of accordion component
jferrer1W c1f87ab
replace prefix for suffix in preferencesName
jferrer1W d00310c
Update minor to from 18.0.1 to 18.1.1
jferrer1W 378bc16
fix Update version to 18.1.0
jferrer1W 9d97a25
fix accordion showcase
jferrer1W acbcdf4
fix tests
jferrer1W 9c06a92
Merge branch 'master' into 949-new-accordion-component
jferrer1W File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
projects/showcase/src/app/components/accordion/showcase-accordion.component.html
This file contains hidden or 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,3 @@ | ||
| <systelab-accordion [headerTitle]="'Accordion header'"> | ||
| <showcase-progress-bar></showcase-progress-bar> | ||
| </systelab-accordion> |
10 changes: 10 additions & 0 deletions
10
projects/showcase/src/app/components/accordion/showcase-accordion.component.ts
This file contains hidden or 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,10 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'showcase-accordion', | ||
| templateUrl: 'showcase-accordion.component.html' | ||
| }) | ||
| export class ShowcaseAccordion { | ||
| constructor() { | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
10 changes: 10 additions & 0 deletions
10
projects/systelab-components/src/lib/accordion/accordion.component.html
This file contains hidden or 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,10 @@ | ||
| <div class="slab-flex-1 d-flex flex-column"> | ||
| <div class="mlab-accordion-header d-flex align-items-center font-weight-bold px-3" [ngStyle]="{'backgroundColor': headerColor}" (click)="isCollapsed = !isCollapsed"> | ||
|
||
| <i class="d-flex justify-content-center align-items-center position-relative" [class.icon-chevron-circle-up]="!isCollapsed" [class.icon-chevron-circle-down]="isCollapsed" [ngClass]="{'text-primary': !iconColor}" [ngStyle]="{'color': iconColor}"></i> | ||
| <span class="d-block ml-3">{{ headerTitle }}</span> | ||
| </div> | ||
| <div class="collapsible-content d-flex" [class.collapsed]="isCollapsed" [class.p-3]="!isCollapsed" | ||
| [ngStyle]="{'max-height.px': isCollapsed ? '0' : contentMaxHeight, 'overflow': withOverflow ? 'auto' : 'hidden'}"> | ||
| <ng-content /> | ||
| </div> | ||
| </div> | ||
32 changes: 32 additions & 0 deletions
32
projects/systelab-components/src/lib/accordion/accordion.component.scss
This file contains hidden or 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,32 @@ | ||
| .mlab-accordion-header { | ||
| background-color: lightgrey; | ||
| border-radius: 4px 4px 0 0; | ||
| height: 40px; | ||
| i { | ||
| &:after { | ||
| content: ''; | ||
| background-color: white; | ||
| width: 15px; | ||
| height: 15px; | ||
| z-index: 1; | ||
| position: absolute; | ||
| } | ||
| &:before { | ||
| z-index: 2; | ||
| } | ||
| font-size: 25px; | ||
| &:hover { | ||
| cursor: pointer; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .collapsible-content { | ||
| transition: max-height 0.3s ease-out, opacity 0.3s ease-out; | ||
| opacity: 1; | ||
| border: 1px solid var(--slab_table_border_color) !important; | ||
| } | ||
|
|
||
| .collapsed { | ||
| opacity: 0; | ||
| } |
83 changes: 83 additions & 0 deletions
83
projects/systelab-components/src/lib/accordion/accordion.component.spec.ts
This file contains hidden or 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,83 @@ | ||
| import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
| import { BrowserModule, By } from '@angular/platform-browser'; | ||
| import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
| import { Accordion } from './accordion.component'; | ||
| import { PreferencesService } from 'systelab-preferences'; | ||
|
|
||
| describe('Systelab Accordion', () => { | ||
| let fixture: ComponentFixture<Accordion>; | ||
| let component: Accordion; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| declarations: [], | ||
| imports: [BrowserModule], | ||
| providers: [ | ||
| PreferencesService, | ||
| provideHttpClient(withInterceptorsFromDi()) | ||
| ] | ||
| }).compileComponents(); | ||
|
|
||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| fixture = TestBed.createComponent(Accordion); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should be instantiate', () => { | ||
| expect(fixture.componentInstance).toBeDefined(); | ||
| }); | ||
|
|
||
| it('should be height 0 when isCollapse is true', async () => { | ||
| component.isCollapsed = true; | ||
| fixture.detectChanges(); | ||
| await fixture.whenStable(); | ||
| const collapsibleContent = fixture.debugElement.query(By.css('.collapsible-content')); | ||
| const maxHeight = parseInt(getComputedStyle(collapsibleContent.nativeElement).maxHeight, 10); | ||
| expect(maxHeight).toEqual(0); | ||
| }); | ||
|
|
||
| it('should be height contentMaxHeight when isCollapse is false', async () => { | ||
| component.isCollapsed = false; | ||
| fixture.detectChanges(); | ||
| await fixture.whenStable(); | ||
| const collapsibleContent = fixture.debugElement.query(By.css('.collapsible-content')); | ||
| const maxHeight = parseInt(getComputedStyle(collapsibleContent.nativeElement).maxHeight, 10); | ||
| expect(maxHeight).toEqual(component.contentMaxHeight); | ||
| }); | ||
|
|
||
| it('should be collapsed if is expanded and clicks icon button', async () => { | ||
| component.isCollapsed = false; | ||
| const collapseExpandIcon = fixture.debugElement.query(By.css('.mlab-accordion-header')); | ||
| collapseExpandIcon.triggerEventHandler('click', null); | ||
| fixture.detectChanges(); | ||
| await fixture.whenStable(); | ||
| expect(component.isCollapsed).toBeTrue(); | ||
| }); | ||
|
|
||
| it('should be expanded if is collapsed and clicks icon button', async () => { | ||
| component.isCollapsed = true; | ||
| const collapseExpandIcon = fixture.debugElement.query(By.css('.mlab-accordion-header')); | ||
| collapseExpandIcon.triggerEventHandler('click', null); | ||
| fixture.detectChanges(); | ||
| await fixture.whenStable(); | ||
| expect(component.isCollapsed).toBeFalse(); | ||
| }); | ||
|
|
||
| it('should be get isCollapsed value from preferences id flag preferenceName exists', async () => { | ||
| const valueReturned: boolean = true; | ||
| const initianPreferenceName = 'testName'; | ||
| component.isCollapsed = false; | ||
| component.preferenceName = initianPreferenceName; | ||
| const preferenceServiceGetSpy = spyOn<any>(component['preferenceService'], 'get').and.returnValue(valueReturned); | ||
| const preferenceServicePutSpy = spyOn<any>(component['preferenceService'], 'put').and.callThrough(); | ||
| component.ngOnInit(); | ||
| await fixture.whenStable(); | ||
| expect(component.preferenceName).toEqual(`${component['preferencePrefix']}.${initianPreferenceName}`); | ||
| expect(preferenceServiceGetSpy).toHaveBeenCalledWith(component.preferenceName, false); | ||
| expect(component.isCollapsed).toEqual(valueReturned); | ||
| expect(preferenceServicePutSpy).toHaveBeenCalledWith(component.preferenceName, valueReturned); | ||
| }); | ||
| }); |
30 changes: 30 additions & 0 deletions
30
projects/systelab-components/src/lib/accordion/accordion.component.ts
This file contains hidden or 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,30 @@ | ||
| import { Component, Input, OnInit } from '@angular/core'; | ||
| import { PreferencesService } from 'systelab-preferences'; | ||
|
|
||
| @Component({ | ||
| selector: 'systelab-accordion', | ||
| templateUrl: './accordion.component.html', | ||
| styleUrls: ['./accordion.component.scss'] | ||
| }) | ||
| // eslint-disable-next-line @angular-eslint/component-class-suffix | ||
| export class Accordion implements OnInit { | ||
| @Input() headerTitle: string = ''; | ||
| @Input() preferenceName: string; | ||
| @Input() contentMaxHeight: number = 300; | ||
| @Input() withOverflow: boolean = false; | ||
| @Input() headerColor: string; | ||
| @Input() iconColor: string; | ||
| public isCollapsed: boolean = false; | ||
| private preferencePrefix: string = 'accordionStatus'; | ||
|
|
||
| constructor(private readonly preferenceService: PreferencesService) { | ||
| } | ||
|
|
||
| public ngOnInit() { | ||
| if(this.preferenceName) { | ||
| this.preferenceName = `${this.preferencePrefix}.${this.preferenceName}`; | ||
| this.isCollapsed = this.preferenceService.get(this.preferenceName, false); | ||
| this.preferenceService.put(this.preferenceName, this.isCollapsed); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty constructor. Unnecessary?