-
Notifications
You must be signed in to change notification settings - Fork 9
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
expander component #1706
Merged
Merged
expander component #1706
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
20 changes: 20 additions & 0 deletions
20
src/interface/src/styleguide/expander-item/expander-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,20 @@ | ||
<input | ||
type="radio" | ||
[value]="value" | ||
[id]="'layer-' + value" | ||
[name]="groupName" | ||
[checked]="checked" | ||
(click)="optionSelected.emit(value)" /> | ||
<label [for]="'layer-' + value">{{ label }}</label> | ||
<ng-container *ngIf="showTooltip"> | ||
<button mat-icon-button class="info" [matMenuTriggerFor]="tooltipMenu"> | ||
<mat-icon class="material-symbols-outlined info" color="primary"> | ||
info_outline | ||
</mat-icon> | ||
</button> | ||
<mat-menu #tooltipMenu="matMenu"> | ||
<div class="tooltip"> | ||
<ng-content></ng-content> | ||
</div> | ||
</mat-menu> | ||
</ng-container> |
35 changes: 35 additions & 0 deletions
35
src/interface/src/styleguide/expander-item/expander-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,35 @@ | ||
@import "mixins"; | ||
|
||
:host { | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
margin-bottom: 8px; | ||
text-transform: capitalize; | ||
} | ||
|
||
input { | ||
margin: 0; | ||
width: 20px; | ||
cursor: pointer; | ||
} | ||
|
||
label { | ||
@include small-paragraph(); | ||
cursor: pointer; | ||
} | ||
|
||
.info { | ||
width: 22px; | ||
height: 22px; | ||
font-size: 22px; | ||
line-height: 0; | ||
} | ||
|
||
button.info { | ||
margin-left: auto; | ||
} | ||
|
||
.tooltip { | ||
padding: 20px; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/interface/src/styleguide/expander-item/expander-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,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ExpanderItemComponent } from './expander-item.component'; | ||
|
||
describe('ExpanderItemComponent', () => { | ||
let component: ExpanderItemComponent; | ||
let fixture: ComponentFixture<ExpanderItemComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ExpanderItemComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ExpanderItemComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
src/interface/src/styleguide/expander-item/expander-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,50 @@ | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { MatIconModule } from '@angular/material/icon'; | ||
import { MatLegacyButtonModule } from '@angular/material/legacy-button'; | ||
import { MatLegacyMenuModule } from '@angular/material/legacy-menu'; | ||
import { NgIf, NgSwitchCase } from '@angular/common'; | ||
|
||
/** | ||
* This component is used in combination with `<sg-expander-section>`. | ||
* It shows a radio button with its label, and additionally a tooltip. | ||
* The markup provided in content projection will be used for the tooltip. | ||
*/ | ||
@Component({ | ||
selector: 'sg-expander-item', | ||
standalone: true, | ||
imports: [ | ||
MatIconModule, | ||
MatLegacyButtonModule, | ||
MatLegacyMenuModule, | ||
NgSwitchCase, | ||
NgIf, | ||
], | ||
templateUrl: './expander-item.component.html', | ||
styleUrl: './expander-item.component.scss', | ||
}) | ||
export class ExpanderItemComponent { | ||
/** | ||
* The label for the radio button | ||
*/ | ||
@Input() label: string = ''; | ||
/** | ||
* The value for the radio button | ||
*/ | ||
@Input() value: string | number = ''; | ||
/** | ||
* The name of the group (the input name) for the radio button | ||
*/ | ||
@Input() groupName: string = ''; | ||
/** | ||
* Whether the item is checked (selected) | ||
*/ | ||
@Input() checked = false; | ||
/** | ||
* Whether it shows the tooltip icon | ||
*/ | ||
@Input() showTooltip = false; | ||
/** | ||
* Emitted when the user changes the selected option | ||
*/ | ||
@Output() optionSelected = new EventEmitter<string | number>(); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/interface/src/styleguide/expander-section/expander-section.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,6 @@ | ||
<div class="title" [ngClass]="{ open: isOpen }" (click)="isOpen = !isOpen"> | ||
{{ title }} | ||
</div> | ||
<div class="base-options" *ngIf="isOpen"> | ||
<ng-content></ng-content> | ||
</div> |
30 changes: 30 additions & 0 deletions
30
src/interface/src/styleguide/expander-section/expander-section.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,30 @@ | ||
@import "mixins"; | ||
|
||
.title { | ||
@include xs-label(); | ||
border-bottom: 1px solid black; | ||
padding: 8px 8px 8px 14px; | ||
cursor: pointer; | ||
display: flex; | ||
align-items: center; | ||
|
||
&::before { | ||
display: block; | ||
width: 20px; | ||
height: 20px; | ||
content: ''; | ||
background: url('data:image/svg+xml,<svg width="5" height="10" viewBox="0 0 5 10" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0.333313 9.16683V0.833496L4.49998 5.00016L0.333313 9.16683Z" fill="black" /></svg>') no-repeat 50% 50%; | ||
background-size: 6px; | ||
} | ||
|
||
&.open { | ||
&::before { | ||
transform: rotate(90deg); | ||
} | ||
} | ||
} | ||
|
||
|
||
.base-options { | ||
padding: 16px 14px; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/interface/src/styleguide/expander-section/expander-section.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,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ExpanderSectionComponent } from './expander-section.component'; | ||
|
||
describe('ExpanderSectionComponent', () => { | ||
let component: ExpanderSectionComponent; | ||
let fixture: ComponentFixture<ExpanderSectionComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ExpanderSectionComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ExpanderSectionComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
src/interface/src/styleguide/expander-section/expander-section.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,22 @@ | ||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
import { NgClass, NgForOf, NgIf } from '@angular/common'; | ||
|
||
/** | ||
* The expander section component shows a title with a control to expand and collapse | ||
* inner content. | ||
* This component accepts html via content projection. | ||
* Its content can be any arbitrary html, or you can provide `<sg-expander-item>` to display | ||
* a list of radio buttons with optional tooltips. | ||
*/ | ||
@Component({ | ||
selector: 'sg-expander-section', | ||
standalone: true, | ||
imports: [NgForOf, NgIf, NgClass], | ||
templateUrl: './expander-section.component.html', | ||
styleUrl: './expander-section.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ExpanderSectionComponent { | ||
@Input() isOpen?: boolean; | ||
@Input() title: string = ''; | ||
} |
79 changes: 79 additions & 0 deletions
79
src/interface/src/styleguide/expander-section/expander-section.stories.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,79 @@ | ||
import type { Meta, StoryObj } from '@storybook/angular'; | ||
import { | ||
applicationConfig, | ||
argsToTemplate, | ||
moduleMetadata, | ||
} from '@storybook/angular'; | ||
import { ExpanderSectionComponent } from '@styleguide'; | ||
import { provideAnimations } from '@angular/platform-browser/animations'; | ||
import { ExpanderItemComponent } from '../expander-item/expander-item.component'; | ||
|
||
const meta: Meta<ExpanderSectionComponent> = { | ||
title: 'Components/Expander Section', | ||
component: ExpanderSectionComponent, | ||
decorators: [ | ||
applicationConfig({ | ||
providers: [provideAnimations()], | ||
}), | ||
moduleMetadata({ imports: [ExpanderItemComponent] }), | ||
], | ||
tags: ['autodocs'], | ||
render: (args) => ({ | ||
props: args, | ||
template: `<sg-expander-section ${argsToTemplate(args)}> | ||
<sg-expander-item label='Red' value='1' groupName='options' [checked]='true'></sg-expander-item> | ||
<sg-expander-item label='Green' value='2' groupName='options'></sg-expander-item> | ||
<sg-expander-item label='Blue' value='3' groupName='options'></sg-expander-item> | ||
</sg-expander-section>`, | ||
}), | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<ExpanderSectionComponent>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
title: 'Pick your color', | ||
}, | ||
}; | ||
|
||
export const Open: Story = { | ||
args: { | ||
title: 'Pick your color', | ||
isOpen: true, | ||
}, | ||
}; | ||
|
||
export const WithTooltips: Story = { | ||
args: { | ||
title: 'Pick your size', | ||
isOpen: true, | ||
}, | ||
render: (args) => ({ | ||
props: args, | ||
template: `<sg-expander-section ${argsToTemplate(args)}> | ||
<sg-expander-item label='Small' value='1' groupName='sizes' [showTooltip]='true'> | ||
Some tooltip content | ||
</sg-expander-item> | ||
<sg-expander-item label='Medium' value='2' groupName='sizes' [showTooltip]='true'> | ||
Another tooltip content | ||
</sg-expander-item> | ||
<sg-expander-item label='Large' value='3' groupName='sizes' [showTooltip]='true'> | ||
This can be <strong>html</strong> | ||
</sg-expander-item> | ||
</sg-expander-section>`, | ||
}), | ||
}; | ||
|
||
export const AnyContent: Story = { | ||
args: { | ||
title: 'Pick your size', | ||
isOpen: true, | ||
}, | ||
render: (args) => ({ | ||
props: args, | ||
template: `<sg-expander-section ${argsToTemplate(args)}> | ||
This can actually be whatever content we want. | ||
</sg-expander-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
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.
👍