-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas Pourchel
committed
Jan 22, 2024
1 parent
d94b475
commit 5c3ba9e
Showing
11 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.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,18 @@ | ||
#b1-listbox { | ||
padding: 0.4rem; | ||
position: absolute; | ||
list-style: none; | ||
background-color: white; | ||
border: 1px solid grey; | ||
min-width: 14.6rem; | ||
max-height: 14rem; | ||
overflow: scroll; | ||
overflow-x: hidden; | ||
font-size: 95%; | ||
cursor: pointer; | ||
} | ||
|
||
#b1-listbox li { | ||
padding: 10px; | ||
} | ||
|
35 changes: 35 additions & 0 deletions
35
projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.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,35 @@ | ||
<label for="b1-input">{{ label }}</label> | ||
<div class="box box-list" (focusout)="close()" (keydown)="escClose($event)"> | ||
<div class="group"> | ||
<input | ||
#acInput | ||
id="b1-input" | ||
class="b_edit" | ||
type="text" | ||
role="combobox" | ||
(focus)="toggleOpen()" | ||
(click)="onChange($event)" | ||
(keyup)="onChange($event)" | ||
aria-autocomplete="countries" | ||
[attr.aria-expanded]="isOpen" | ||
aria-controls="b1-listbox" /> | ||
<button | ||
id="b1-button" | ||
tabindex="-1" | ||
aria-label="Regions" | ||
[attr.aria-expanded]="isOpen" | ||
(click)="toggleOpen()" | ||
(close)="close()" | ||
aria-controls="b1-listbox"> | ||
<svg width="18" height="16" aria-hidden="true" focusable="false" style="forced-color-adjust: auto"> | ||
<polygon class="arrow" stroke-width="0" fill-opacity="0.75" fill="currentcolor" points="3,6 15,6 9,14"></polygon> | ||
</svg> | ||
</button> | ||
|
||
<ul id="b1-listbox" role="listbox" [hidden]="!isOpen" aria-label="Regions"> | ||
<p> | ||
<li *ngFor="let li of filteredCountriesList">{{ li }}</li> | ||
</p> | ||
</ul> | ||
</div> | ||
</div> |
23 changes: 23 additions & 0 deletions
23
projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.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,23 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { AutocompleteComponent } from './autocomplete.component'; | ||
|
||
describe('AutocompleteComponent', () => { | ||
let component: AutocompleteComponent; | ||
let fixture: ComponentFixture<AutocompleteComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ AutocompleteComponent ] | ||
Check failure on line 11 in projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.spec.ts GitHub Actions / Run linters
|
||
}) | ||
Check failure on line 12 in projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.component.spec.ts GitHub Actions / Run linters
|
||
.compileComponents(); | ||
|
||
fixture = TestBed.createComponent(AutocompleteComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
projects/ngx-cream-lib/src/lib/autocomplete/autocomplete.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,34 @@ | ||
import { Component, Input } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'c3m-autocomplete', | ||
templateUrl: './autocomplete.component.html', | ||
styleUrls: ['./autocomplete.component.css'], | ||
}) | ||
export class AutocompleteComponent { | ||
@Input() isOpen = false; | ||
@Input() label = ''; | ||
@Input() countries: Array<string> = []; | ||
@Input() acValue = ''; | ||
@Input() filteredCountriesList: Array<string> = []; | ||
|
||
toggleOpen(): void { | ||
this.isOpen = !this.isOpen; | ||
this.onChange; | ||
} | ||
|
||
close(): void { | ||
this.isOpen = false; | ||
} | ||
|
||
escClose(event: KeyboardEvent): void { | ||
if (event.code === 'Escape') { | ||
this.isOpen = false; | ||
} | ||
} | ||
|
||
onChange(e: any) { | ||
this.acValue = e.target.value; | ||
this.filteredCountriesList = this.countries.filter(country => country.toLowerCase().startsWith(this.acValue.toLowerCase())); | ||
} | ||
} |
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
Empty file.
12 changes: 12 additions & 0 deletions
12
src/app/pages/autocomplete-page/autocomplete-page.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,12 @@ | ||
<section id="autocomp"> | ||
<h3>Autocomplete</h3> | ||
|
||
<c3m-tabs class="block-style" label="Demo and Code"> | ||
<c3m-tab-panel class="block-style" tabTitle="Demo" [isActive]="true"> | ||
<c3m-autocomplete label="Label of autocomplete" [countries]="countries"></c3m-autocomplete> | ||
</c3m-tab-panel> | ||
<c3m-tab-panel class="block-style" tabTitle="Application"> | ||
<pre></pre> | ||
</c3m-tab-panel> | ||
</c3m-tabs> | ||
</section> |
32 changes: 32 additions & 0 deletions
32
src/app/pages/autocomplete-page/autocomplete-page.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,32 @@ | ||
import { Component } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'app-autocomplete-page', | ||
templateUrl: './autocomplete-page.component.html', | ||
styleUrls: ['./autocomplete-page.component.css'], | ||
}) | ||
export class AutocompletePageComponent { | ||
pageTitle = 'Autocomplete'; | ||
componentName = 'c3m-autocomplete'; | ||
resourceType = 'Component'; | ||
|
||
countries = [ | ||
'Hauts-de-France', | ||
'Normandie', | ||
'Grand Est', | ||
'Bretagne', | ||
'Ile-de-France', | ||
'Pays de la Loire', | ||
'Centre-Val de Loire', | ||
'Bourgogne-Franche-Comte', | ||
'Nouvelle Aquitaine', | ||
'Auvergne-Rhone-Alpes', | ||
'Occitanie', | ||
'Corse', | ||
'Mayotte', | ||
'La Reunion', | ||
'Guyane', | ||
'Martinique', | ||
'Guadeloupe', | ||
]; | ||
} |