-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor expander-section to use expander-item to be more flexible an…
…d allow tooltips via content projection
- Loading branch information
Pablo Lopez
committed
Aug 30, 2024
1 parent
0a0c8f4
commit 7188980
Showing
9 changed files
with
190 additions
and
88 deletions.
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>(); | ||
} |
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
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
77 changes: 50 additions & 27 deletions
77
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 |
---|---|---|
@@ -1,56 +1,79 @@ | ||
import type { Meta, StoryObj } from '@storybook/angular'; | ||
import { argsToTemplate } from '@storybook/angular'; | ||
import { ExpanderSectionComponent, OptionType } from '@styleguide'; | ||
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<OptionType>> = { | ||
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-section>`, | ||
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<string>>; | ||
|
||
type StoryKeyValue = StoryObj< | ||
ExpanderSectionComponent<{ value: number; text: string }> | ||
>; | ||
type Story = StoryObj<ExpanderSectionComponent>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
title: 'Pick your color', | ||
options: ['black', 'red', 'blue', 'green'], | ||
defaultOption: 'red', | ||
groupName: 'options-colors', | ||
}, | ||
}; | ||
|
||
export const Open: Story = { | ||
args: { | ||
title: 'Pick your color', | ||
isOpen: true, | ||
title: 'Pick your size', | ||
options: ['small', 'medium', 'large', 'x-large'], | ||
defaultOption: 'small', | ||
groupName: 'options-pick-size', | ||
}, | ||
}; | ||
|
||
const options = [ | ||
{ value: 1, text: 'One' }, | ||
{ value: 2, text: 'Two' }, | ||
{ value: 3, text: 'Three' }, | ||
{ value: 4, text: 'Four' }, | ||
]; | ||
|
||
export const WithKeyValue: StoryKeyValue = { | ||
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', | ||
options: options, | ||
defaultOption: options[1], | ||
groupName: 'options-keyvalue', | ||
isOpen: true, | ||
}, | ||
render: (args) => ({ | ||
props: args, | ||
template: `<sg-expander-section ${argsToTemplate(args)}> | ||
This can actually be whatever content we want. | ||
</sg-expander-section>`, | ||
}), | ||
}; |