-
Notifications
You must be signed in to change notification settings - Fork 16
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
863 feat accordion group #864
Merged
Merged
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
64bcd79
feat: accordion-group
deeved-hiuston-brisa 35788ee
docs: accordion group
deeved-hiuston-brisa 8cefe2e
refactor: accordion
deeved-hiuston-brisa 5738ee5
docs: refactor storybook accordion
deeved-hiuston-brisa 04ed5ef
test: changing safyany import path
deeved-hiuston-brisa f31a460
Merge branch 'main' into 863-feat-accordion-group
iurynogueira 1e02545
style: add borders
deeved-hiuston-brisa d741466
Merge branch '863-feat-accordion-group' of github.com:Brisanet/ion in…
deeved-hiuston-brisa cd851d6
Update projects/ion/src/lib/accordion/accordion-item/accordion-item.c…
deeved-hiuston-brisa 6e3e98c
Update projects/ion/src/lib/accordion/accordion.component.ts
deeved-hiuston-brisa 67b6660
refactor: indetation
deeved-hiuston-brisa 83d23b7
chore: merge 'main' into '863-feat-accordion-group'
deeved-hiuston-brisa cd3050c
test: adjust the error message
deeved-hiuston-brisa 0840df0
Merge branch 'main' into 863-feat-accordion-group
alysson-mascarenhas-brisa f964950
Merge branch 'main' into 863-feat-accordion-group
alysson-mascarenhas-brisa 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
19 changes: 19 additions & 0 deletions
19
projects/ion/src/lib/accordion/accordion-item/accordion-item.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,19 @@ | ||
<section | ||
data-testid="ion-accordion-item" | ||
[class.open]="show" | ||
[class.close]="!show" | ||
tabindex="0" | ||
> | ||
<header (click)="toggle()"> | ||
<div data-testid="ion-accordion-item__header"> | ||
<ng-container | ||
[ngTemplateOutlet]="templateHeader" | ||
[ngTemplateOutletContext]="{ $implicit: data }" | ||
></ng-container> | ||
</div> | ||
<ion-icon *ngIf="show" [type]="show ? 'semi-up' : 'semi-down'" [size]="iconSize"></ion-icon> | ||
</header> | ||
<main *ngIf="show" data-testid="ion-accordion-item__main"> | ||
<ng-content></ng-content> | ||
</main> | ||
</section> |
66 changes: 66 additions & 0 deletions
66
projects/ion/src/lib/accordion/accordion-item/accordion-item.component.scss
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,66 @@ | ||
@import '../../../styles/index.scss'; | ||
|
||
@mixin accordion-style($bgColor, $color) { | ||
header { | ||
color: $color; | ||
border-bottom: 1px solid $color; | ||
background-color: $bgColor; | ||
|
||
ion-icon { | ||
::ng-deep svg { | ||
fill: $color; | ||
} | ||
} | ||
} | ||
} | ||
|
||
section { | ||
@include accordion-style($neutral-1, $neutral-7); | ||
header, | ||
main { | ||
padding: 16px 20px; | ||
} | ||
|
||
header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
min-height: 64px; | ||
box-sizing: border-box; | ||
cursor: pointer; | ||
|
||
div { | ||
div { | ||
font-size: 16px; | ||
font-weight: 600; | ||
line-height: 24px; | ||
} | ||
} | ||
} | ||
|
||
main { | ||
background-color: $neutral-1; | ||
} | ||
|
||
&:hover { | ||
@include accordion-style($neutral-2, $primary-3); | ||
} | ||
|
||
&:active { | ||
@include accordion-style($primary-2, $primary-4); | ||
} | ||
|
||
&:focus-visible { | ||
outline: 2px solid $primary-4; | ||
} | ||
|
||
&.open { | ||
@include accordion-style($primary-1, $primary-4); | ||
} | ||
|
||
&.close { | ||
header { | ||
border-bottom: 1px solid $neutral-4; | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
projects/ion/src/lib/accordion/accordion-item/accordion-item.component.spec.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,94 @@ | ||
import { screen, fireEvent, render } from '@testing-library/angular'; | ||
import { Component, NgModule } from '@angular/core'; | ||
import { IonAccordionModule } from '../accordion.module'; | ||
import { TestBed, ComponentFixture } from '@angular/core/testing'; | ||
import { CommonModule } from '@angular/common'; | ||
import { IonIconModule } from '../../icon/icon.module'; | ||
import { IonAccordionItemComponent } from './accordion-item.component'; | ||
import { IonAccordionItemProps } from '../../core/types'; | ||
import { SafeAny } from '../../utils/safe-any'; | ||
|
||
@Component({ | ||
template: `<ion-accordion-item [templateHeader]="customHeader" [data]="data"> | ||
<p data-testid="ion-accordion-item__main-paragraph">Context Main</p> | ||
</ion-accordion-item> | ||
<ng-template #customHeader> {{ data.name }}</ng-template>`, | ||
}) | ||
class AccordionItemTestComponent { | ||
data = { name: 'Accordion header' }; | ||
} | ||
|
||
@NgModule({ | ||
declarations: [AccordionItemTestComponent], | ||
imports: [CommonModule, IonAccordionModule, IonIconModule], | ||
}) | ||
class AccordionTestModule {} | ||
|
||
describe('IonAccordionItem', () => { | ||
let accordionTestComponent!: AccordionItemTestComponent; | ||
let fixture!: ComponentFixture<AccordionItemTestComponent>; | ||
beforeEach(async () => { | ||
TestBed.configureTestingModule({ | ||
imports: [AccordionTestModule], | ||
}).compileComponents(); | ||
fixture = TestBed.createComponent(AccordionItemTestComponent); | ||
accordionTestComponent = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
afterEach(async () => { | ||
fixture.destroy(); | ||
}); | ||
|
||
it('should render ion-accordion-item', async () => { | ||
expect(screen.getByTestId('ion-accordion-item')).toBeTruthy(); | ||
}); | ||
|
||
it('should render the header with the name Brisanet', async () => { | ||
const accordionHeader = 'Brisanet'; | ||
accordionTestComponent.data.name = accordionHeader; | ||
fixture.detectChanges(); | ||
expect(screen.getByTestId('ion-accordion-item__header')).toHaveTextContent( | ||
accordionHeader | ||
); | ||
}); | ||
|
||
it('should render main when clicking on header', async () => { | ||
const header = screen.getByTestId('ion-accordion-item__header'); | ||
fireEvent.click(header); | ||
fixture.detectChanges(); | ||
expect(screen.getByTestId('ion-accordion-item__main')).toBeTruthy(); | ||
expect( | ||
screen.getByTestId('ion-accordion-item__main-paragraph') | ||
).toHaveTextContent('Context Main'); | ||
}); | ||
|
||
it('should not render main when clicking on header twice', async () => { | ||
const header = screen.getByTestId('ion-accordion-item__header'); | ||
fireEvent.click(header); | ||
fireEvent.click(header); | ||
fixture.detectChanges(); | ||
expect(screen.queryByTestId('ion-accordion-item__main')).not.toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('IonAccordionItem - throw an error', () => { | ||
const sut = async ( | ||
customProps: IonAccordionItemProps = {} as SafeAny | ||
): Promise<void> => { | ||
await render(IonAccordionItemComponent, { | ||
componentProperties: { ...customProps }, | ||
imports: [CommonModule, IonIconModule], | ||
}); | ||
}; | ||
|
||
it('should throw an error when templateHeader propertie do not exist', async () => { | ||
try { | ||
await sut(); | ||
} catch (error) { | ||
expect(error.message).toBe( | ||
'The name or templateHeader properties were not set correctly' | ||
); | ||
} | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
projects/ion/src/lib/accordion/accordion-item/accordion-item.component.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,37 @@ | ||
import { | ||
Component, | ||
Input, | ||
OnInit, | ||
Output, | ||
EventEmitter, | ||
TemplateRef, | ||
} from '@angular/core'; | ||
import { SafeAny } from '../../utils/safe-any'; | ||
|
||
@Component({ | ||
selector: 'ion-accordion-item', | ||
templateUrl: './accordion-item.component.html', | ||
styleUrls: ['./accordion-item.component.scss'], | ||
}) | ||
export class IonAccordionItemComponent implements OnInit { | ||
@Input() templateHeader: TemplateRef<HTMLElement>; | ||
@Input() show? = false; | ||
@Input() data?: SafeAny; | ||
@Output() activeChange? = new EventEmitter<void>(); | ||
|
||
iconSize = 24; | ||
|
||
ngOnInit(): void { | ||
if (!this.templateHeader) { | ||
throw new Error( | ||
'The name or templateHeader properties were not set correctly' | ||
); | ||
} | ||
} | ||
|
||
toggle(): void { | ||
this.show = !this.show; | ||
|
||
this.activeChange.emit(); | ||
} | ||
} |
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,26 +1,15 @@ | ||
<section | ||
data-testid="ion-accordion" | ||
[class.open]="show" | ||
[class.close]="!show" | ||
tabindex="0" | ||
> | ||
<header (click)="toggle()"> | ||
<div> | ||
<div | ||
*ngIf="!templateHeader; else headerCustom" | ||
data-testid="ion-accordion__header-name" | ||
> | ||
{{ name }} | ||
</div> | ||
<ng-template | ||
#headerCustom | ||
[ngTemplateOutlet]="templateHeader" | ||
></ng-template> | ||
</div> | ||
<ion-icon *ngIf="show" type="semi-up" [size]="iconSize"></ion-icon> | ||
<ion-icon *ngIf="!show" type="semi-down" [size]="iconSize"></ion-icon> | ||
</header> | ||
<main *ngIf="show" data-testid="ion-accordion__main"> | ||
<ng-content></ng-content> | ||
</main> | ||
<section data-testid="ion-accordion"> | ||
<ion-accordion-item | ||
*ngFor="let accordion of accordions; let i = index" | ||
[show]="accordion.show" | ||
[data]="accordion" | ||
[templateHeader]="templateHeader" | ||
(activeChange)="toggle(i)" | ||
> | ||
<ng-container | ||
*ngIf="templateBody" | ||
[ngTemplateOutlet]="templateBody" | ||
[ngTemplateOutletContext]="{ $implicit: accordion }" | ||
></ng-container> | ||
</ion-accordion-item> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,38 @@ | ||
@import '../../styles/index.scss'; | ||
|
||
@mixin accordion-style($bgColor, $color) { | ||
header { | ||
color: $color; | ||
border-bottom: 1px solid $color; | ||
background-color: $bgColor; | ||
|
||
ion-icon { | ||
::ng-deep svg { | ||
fill: $color; | ||
section { | ||
::ng-deep ion-accordion-item:first-child { | ||
section { | ||
header { | ||
border-radius: 8px 8px 0 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
section { | ||
@include accordion-style($neutral-1, $neutral-7); | ||
header, | ||
main { | ||
padding: 16px 20px; | ||
} | ||
|
||
header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
min-height: 64px; | ||
box-sizing: border-box; | ||
cursor: pointer; | ||
|
||
div { | ||
div { | ||
font-size: 16px; | ||
font-weight: 600; | ||
line-height: 24px; | ||
::ng-deep ion-accordion-item { | ||
section { | ||
header, | ||
main { | ||
border: 1px solid $neutral-4; | ||
} | ||
} | ||
} | ||
|
||
main { | ||
background-color: $neutral-1; | ||
} | ||
|
||
&:hover { | ||
@include accordion-style($neutral-2, $primary-3); | ||
} | ||
|
||
&:active { | ||
@include accordion-style($primary-2, $primary-4); | ||
} | ||
|
||
&:focus-visible { | ||
outline: 2px solid $primary-4; | ||
} | ||
::ng-deep ion-accordion-item:last-child { | ||
section { | ||
header { | ||
border-radius: 0 0 8px 8px; | ||
} | ||
} | ||
|
||
&.open { | ||
@include accordion-style($primary-1, $primary-4); | ||
} | ||
section.open { | ||
header { | ||
border-radius: 0; | ||
} | ||
|
||
&.close { | ||
header { | ||
border-bottom: 1px solid $neutral-4; | ||
main { | ||
border-radius: 0 0 8px 8px; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
good case 👏