-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate floating-ui with popover component (#2785)
Signed-off-by: Akshat Patel <[email protected]>
- Loading branch information
Showing
17 changed files
with
944 additions
and
343 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,40 @@ | ||
import { Component, HostBinding } from "@angular/core"; | ||
import { | ||
Component, | ||
HostBinding, | ||
ViewChild, | ||
ElementRef, | ||
AfterViewInit, | ||
ChangeDetectorRef | ||
} from "@angular/core"; | ||
|
||
/** | ||
* [See demo](../../?path=/story/components-popover--basic) | ||
*/ | ||
@Component({ | ||
selector: "cds-popover-content, ibm-popover-content", | ||
template: ` | ||
<span class="cds--popover-content"> | ||
<ng-content></ng-content> | ||
<span class="cds--popover-content" #content> | ||
<div> | ||
<ng-content></ng-content> | ||
</div> | ||
<span *ngIf="autoAlign" class="cds--popover-caret cds--popover--auto-align"></span> | ||
</span> | ||
<span class="cds--popover-caret"></span> | ||
<span *ngIf="!autoAlign" class="cds--popover-caret"></span> | ||
` | ||
}) | ||
export class PopoverContent { | ||
export class PopoverContent implements AfterViewInit { | ||
@HostBinding("class.cds--popover") popoverClass = true; | ||
@ViewChild("content") popoverContent: ElementRef; | ||
autoAlign = false; | ||
|
||
constructor(private changeDetectorRef: ChangeDetectorRef) {} | ||
|
||
ngAfterViewInit(): void { | ||
if (this.popoverContent) { | ||
// Check we are in a popover with autoAlign enabled | ||
this.autoAlign = !!this.popoverContent.nativeElement.closest(".cds--popover--auto-align"); | ||
// Run change detection manually to resolve ExpressionHasChanged | ||
this.changeDetectorRef.detectChanges(); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.