-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/select component #23
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
553771a
feat(select): add inital select component with sample page
9b166cf
feat(select): update sample
4e82303
feat(select): add animation to select sample
55b1c04
wip(select): focus test
0a9d8d0
feat(select): move select component to correct folder
9781e5c
feat(select): add focustrap to options container
d520c98
feat(select): add key event functionality
4e33ade
feat(select): add sample and default style
e976994
feat(select): add story for select component
36af251
feat(select): close on escape
af92c80
feat(lib): add style file for users
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
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,12 @@ | ||
import { animate, AnimationMetadata, style } from '@angular/animations'; | ||
|
||
export const fadeFactory = ( | ||
from: number, | ||
to: number, | ||
duration = '200ms' | ||
): AnimationMetadata[] => { | ||
return [ | ||
style({ opacity: from }), | ||
animate(`${duration} ease`, style({ opacity: to })), | ||
]; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { animate, AnimationMetadata, style } from '@angular/animations'; | ||
|
||
export const zoomFactory = ( | ||
from: number, | ||
to: number, | ||
duration = '500ms' | ||
): AnimationMetadata[] => { | ||
return [ | ||
style({ opacity: from, scale: from }), | ||
animate( | ||
`${duration} cubic-bezier(0.05, 0.7, 0.1, 1)`, | ||
style({ opacity: to, scale: to }) | ||
), | ||
]; | ||
}; |
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
9 changes: 9 additions & 0 deletions
9
apps/demo-app/src/app/pages/select-sample/select-default/select-default.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,9 @@ | ||
<sk-select [(ngModel)]="selectedValue"> | ||
<span skSelectPlaceholder>Select option</span> | ||
<span skSelectLabel>{{ selectedValue?.label }}</span> | ||
@for (option of options; track option.value) { | ||
<sk-select-option [value]="option"> | ||
{{ option.label }} | ||
</sk-select-option> | ||
} | ||
</sk-select> | ||
39 changes: 39 additions & 0 deletions
39
apps/demo-app/src/app/pages/select-sample/select-default/select-default.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,39 @@ | ||
import { Component } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { SelectDemoOption } from '../select-sample.component'; | ||
import { | ||
faBell, | ||
faCog, | ||
faEnvelope, | ||
faGlobe, | ||
faHeart, | ||
faHome, | ||
faKey, | ||
faLock, | ||
faStar, | ||
faUser, | ||
} from '@fortawesome/free-solid-svg-icons'; | ||
import { SelectComponent, SelectOptionComponent } from '@qupaya/sketch'; | ||
import { FormsModule } from '@angular/forms'; | ||
|
||
@Component({ | ||
selector: 'app-select-default', | ||
standalone: true, | ||
imports: [CommonModule, SelectComponent, SelectOptionComponent, FormsModule], | ||
templateUrl: './select-default.component.html', | ||
}) | ||
export class SelectDefaultComponent { | ||
readonly options: SelectDemoOption[] = [ | ||
{ label: 'Option 1', icon: faHome, value: 1 }, | ||
{ label: 'Option 2', icon: faUser, value: 2 }, | ||
{ label: 'Option 3', icon: faCog, value: 3 }, | ||
{ label: 'Option 4', icon: faHeart, value: 4 }, | ||
{ label: 'Option 5', icon: faStar, value: 5 }, | ||
{ label: 'Option 6', icon: faBell, value: 6 }, | ||
{ label: 'Option 7', icon: faEnvelope, value: 7 }, | ||
{ label: 'Option 8', icon: faGlobe, value: 8 }, | ||
{ label: 'Option 9', icon: faLock, value: 9 }, | ||
{ label: 'Option 10', icon: faKey, value: 10 }, | ||
]; | ||
selectedValue?: SelectDemoOption; | ||
} |
1 change: 1 addition & 0 deletions
1
apps/demo-app/src/app/pages/select-sample/select-sample.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 @@ | ||
<router-outlet></router-outlet> |
22 changes: 22 additions & 0 deletions
22
apps/demo-app/src/app/pages/select-sample/select-sample.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 { SelectSampleComponent } from './select-sample.component'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
describe('SelectSampleComponent', () => { | ||
let component: SelectSampleComponent; | ||
let fixture: ComponentFixture<SelectSampleComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [SelectSampleComponent, NoopAnimationsModule], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(SelectSampleComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
apps/demo-app/src/app/pages/select-sample/select-sample.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,18 @@ | ||
import { Component } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { IconProp } from '@fortawesome/fontawesome-svg-core'; | ||
import { RouterOutlet } from '@angular/router'; | ||
|
||
export interface SelectDemoOption { | ||
label: string; | ||
icon: IconProp; | ||
value: number; | ||
} | ||
|
||
@Component({ | ||
selector: 'app-select-sample', | ||
standalone: true, | ||
imports: [CommonModule, RouterOutlet], | ||
templateUrl: './select-sample.component.html', | ||
}) | ||
export class SelectSampleComponent {} |
41 changes: 41 additions & 0 deletions
41
...select-sample/select-with-style/select-options-sample/select-options-sample.component.css
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,41 @@ | ||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
width: 100%; | ||
max-height: 200px; | ||
margin-top: 0.5rem; | ||
overflow-x: auto; | ||
} | ||
|
||
sk-select-option { | ||
display: flex; | ||
gap: 0.5rem; | ||
background-color: #fff; | ||
color: #000; | ||
padding: 0.5rem 1rem; | ||
cursor: pointer; | ||
transition: color 0.3s ease-in-out, font-weight 0.3s ease-in-out; | ||
} | ||
|
||
sk-select-option:first-child { | ||
border-top-left-radius: 0.25rem; | ||
border-top-right-radius: 0.25rem; | ||
} | ||
|
||
sk-select-option:last-child { | ||
border-bottom-left-radius: 0.25rem; | ||
border-bottom-right-radius: 0.25rem; | ||
} | ||
|
||
@media (hover) { | ||
sk-select-option:hover { | ||
color: var(--sk-primary-color); | ||
font-weight: bold; | ||
} | ||
} | ||
|
||
sk-select-option:focus { | ||
border: none; | ||
color: var(--sk-primary-color); | ||
font-weight: bold; | ||
} |
6 changes: 6 additions & 0 deletions
6
...elect-sample/select-with-style/select-options-sample/select-options-sample.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 @@ | ||
@for (option of options(); track option.value) { | ||
<sk-select-option [value]="option.value"> | ||
<fa-icon [icon]="option.icon"></fa-icon> | ||
<span>{{ option.label }}</span> | ||
</sk-select-option> | ||
} |
25 changes: 25 additions & 0 deletions
25
...ct-sample/select-with-style/select-options-sample/select-options-sample.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,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { SelectOptionsSampleComponent } from './select-options-sample.component'; | ||
import { NoopAnimationsModule } from '@angular/platform-browser/animations'; | ||
|
||
describe('SelectOptionsSampleComponent', () => { | ||
let component: SelectOptionsSampleComponent; | ||
let fixture: ComponentFixture<SelectOptionsSampleComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [SelectOptionsSampleComponent, NoopAnimationsModule], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(SelectOptionsSampleComponent); | ||
component = fixture.componentInstance; | ||
const componentRef = fixture.componentRef; | ||
componentRef.setInput('show', true); | ||
componentRef.setInput('options', []); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
.../select-sample/select-with-style/select-options-sample/select-options-sample.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,48 @@ | ||
import { Component, effect, HostBinding, input } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { query, transition, trigger } from '@angular/animations'; | ||
import { SelectOptionComponent } from '@qupaya/sketch'; | ||
import { slideFadeAnimationFactory } from '../../../../animations/slide.animation'; | ||
import { fadeFactory } from '../../../../animations/fade.animations'; | ||
import { FaIconComponent } from '@fortawesome/angular-fontawesome'; | ||
import { SelectDemoOption } from '../../select-sample.component'; | ||
|
||
@Component({ | ||
selector: 'app-select-options-sample', | ||
standalone: true, | ||
imports: [CommonModule, SelectOptionComponent, FaIconComponent], | ||
templateUrl: './select-options-sample.component.html', | ||
styleUrl: './select-options-sample.component.css', | ||
animations: [ | ||
trigger('animation', [ | ||
transition( | ||
'* => visible', | ||
query('sk-select-option', slideFadeAnimationFactory(), { | ||
optional: true, | ||
}) | ||
), | ||
transition( | ||
'* => hidden', | ||
query('sk-select-option', fadeFactory(1, 0, '350ms'), { | ||
optional: true, | ||
}) | ||
), | ||
transition( | ||
'visible => void', | ||
query('sk-select-option', fadeFactory(1, 0, '350ms'), { | ||
optional: true, | ||
}) | ||
), | ||
]), | ||
], | ||
}) | ||
export class SelectOptionsSampleComponent { | ||
options = input.required<SelectDemoOption[]>(); | ||
@HostBinding('@animation') animateOptions = 'hidden'; | ||
|
||
show = input.required<boolean>(); | ||
|
||
protected readonly toggleShow = effect(() => { | ||
this.animateOptions = this.show() ? 'visible' : 'hidden'; | ||
}); | ||
} |
Oops, something went wrong.
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.
Beautiful <3