-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wc): implement a general cdk overlay for all web components
This will work with any webcomponent by creating an overlay at the root of each webcomponent Changed the name of the custom OverlayContainer for clarity
- Loading branch information
Showing
6 changed files
with
55 additions
and
57 deletions.
There are no files selected for viewing
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
4 changes: 1 addition & 3 deletions
4
apps/webcomponents/src/app/components/gn-search-input/gn-search-input.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 |
---|---|---|
@@ -1,3 +1 @@ | ||
<div id="angular-app-root"> | ||
<gn-ui-fuzzy-search #searchInput class="text-[18px]"></gn-ui-fuzzy-search> | ||
</div> | ||
<gn-ui-fuzzy-search #searchInput class="text-[18px]"></gn-ui-fuzzy-search> |
32 changes: 32 additions & 0 deletions
32
apps/webcomponents/src/app/webcomponent-overlay-container.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 { OverlayContainer } from '@angular/cdk/overlay' | ||
import { Platform } from '@angular/cdk/platform' | ||
import { DOCUMENT } from '@angular/common' | ||
import { Inject, Injectable } from '@angular/core' | ||
|
||
@Injectable() | ||
export class WebcomponentOverlayContainer extends OverlayContainer { | ||
private componentRoot: HTMLElement | ||
|
||
constructor( | ||
@Inject(DOCUMENT) private document: Document, | ||
platform: Platform | ||
) { | ||
super(document, platform) | ||
} | ||
|
||
setRoot(componentRoot: HTMLElement) { | ||
this.componentRoot = componentRoot | ||
} | ||
|
||
protected _createContainer(): void { | ||
const container: HTMLDivElement = this.document.createElement('div') | ||
container.classList.add('gn-ui-overlay-container') | ||
if (!this.componentRoot) { | ||
throw new Error( | ||
'Angular CDK OverlayContainer was used without proper initialization.' | ||
) | ||
} | ||
this.componentRoot.appendChild(container) | ||
this._containerElement = container | ||
} | ||
} |
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