-
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.
feat(list): add provider directive and remove collection component
- Loading branch information
patrickjahr
committed
Apr 16, 2024
1 parent
54b129b
commit c9e22fd
Showing
12 changed files
with
64 additions
and
68 deletions.
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
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
4 changes: 0 additions & 4 deletions
4
libs/sketch/src/lib/components/list/components/list-collection/list-collection.component.css
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
.../sketch/src/lib/components/list/components/list-collection/list-collection.component.html
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
...etch/src/lib/components/list/components/list-collection/list-collection.component.spec.ts
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
libs/sketch/src/lib/components/list/components/list-collection/list-collection.component.ts
This file was deleted.
Oops, something went wrong.
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
39 changes: 39 additions & 0 deletions
39
libs/sketch/src/lib/components/list/directives/list-provider.directive.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 { | ||
AfterViewInit, | ||
Directive, | ||
forwardRef, | ||
inject, | ||
OnInit, | ||
viewChild, | ||
} from '@angular/core'; | ||
import { ListService } from '../services/list.service'; | ||
import { ListComponent } from '../list.component'; | ||
|
||
@Directive({ | ||
selector: '[skListProvider]', | ||
standalone: true, | ||
providers: [ListService], | ||
}) | ||
export class ListProviderDirective implements OnInit, AfterViewInit { | ||
private readonly possibleParentList = inject(ListComponent, { | ||
optional: true, | ||
skipSelf: true, | ||
}); | ||
private readonly listComponent = viewChild(forwardRef(() => ListComponent)); | ||
|
||
ngOnInit(): void { | ||
if (this.possibleParentList) { | ||
throw new Error( | ||
'The ListProviderDirective must be set on root sk-list component.' | ||
); | ||
} | ||
} | ||
|
||
ngAfterViewInit(): void { | ||
if (!this.listComponent) { | ||
throw new Error( | ||
'The ListProviderDirective must be set on a sk-list component.' | ||
); | ||
} | ||
} | ||
} |
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,5 +1,5 @@ | ||
export * from './components/list-collection/list-collection.component'; | ||
export * from './components/list-item/list-item.component'; | ||
export * from './directives/list-item-active.directive'; | ||
export * from './directives/list-provider.directive'; | ||
export * from './services/list.service'; | ||
export * from './list.component'; |
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,4 @@ | ||
:host { | ||
display: flex; | ||
flex-direction: column; | ||
} |
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,13 +1,17 @@ | ||
import { Component } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { ListService } from './services/list.service'; | ||
import { Component, output, signal } from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'sk-list', | ||
standalone: true, | ||
imports: [CommonModule], | ||
providers: [ListService], | ||
templateUrl: './list.component.html', | ||
styleUrl: './list.component.css', | ||
}) | ||
export class ListComponent {} | ||
export class ListComponent { | ||
private readonly activeItemId = signal<string | undefined>(undefined); | ||
activeIdChanged = output<string>(); | ||
|
||
activateItem(id: string): void { | ||
this.activeItemId.update(() => id); | ||
this.activeIdChanged.emit(id); | ||
} | ||
} |