-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add <tour-proxy-anchor>
component
#161
base: master
Are you sure you want to change the base?
Conversation
@phrei I thought a little bit about this and I think I came up with a better/simpler way to implement this feature. In the core library I would define a simple abstract base class like the following: import {AfterViewInit, Directive, ElementRef, inject, Input} from '@angular/core';
import {TourAnchorDirective} from './tour-anchor.directive';
import {DOCUMENT} from '@angular/common';
@Directive()
export abstract class BaseProxyAnchor implements AfterViewInit {
protected abstract readonly anchorDirective: TourAnchorDirective;
private readonly document = inject(DOCUMENT);
public abstract anchorEl: string | HTMLElement;
ngAfterViewInit(): void {
if (this.anchorEl instanceof HTMLElement) {
this.anchorDirective.element = new ElementRef<HTMLElement>(this.anchorEl);
return;
}
const htmlElement = this.document.querySelector<HTMLElement>(this.anchorEl);
if (!htmlElement) {
throw new Error(`Element with "${this.anchorEl}" CSS selector could not be found!`);
}
this.anchorDirective.element = new ElementRef<HTMLElement>(htmlElement);
}
} Then I would introduce a import {BaseProxyAnchor} from 'ngx-ui-tour-core';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {TourAnchorMatMenuDirective} from './tour-anchor.directive';
@Component({
selector: 'tour-proxy-anchor',
template: ``,
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
TourAnchorMatMenuDirective
],
hostDirectives: [{
directive: TourAnchorMatMenuDirective,
inputs: ['tourAnchor: anchorId']
}]
})
export class TourProxyAnchorComponent extends BaseProxyAnchor {
protected override readonly anchorDirective = inject(TourAnchorMatMenuDirective);
@Input({required: true})
public override anchorEl: string | HTMLElement;
} Finally, you can just use the component: <tour-proxy-anchor
anchorId="start.tour"
anchorEl="#TESTButton span.t-content"
></tour-proxy-anchor> Some of the advantages of this approach:
|
@hakimio Your solution definitely looks a lot neater! I'm totally fine with closing this pull request. |
@phrei It's still your PR. I only made a suggestion.
Whether you update this PR or create a new one is your choice. |
@hakimio Oh, okay. Sure, I'll take care of that as soon as possible. |
<tour-proxy-anchor>
component
In discussion #159 I had the following problem:
I'm using an external component (in this case a calendar component) that contains a button group to switch views. I'm not able to set the
tourAnchor
-Directive on this button group (as the code is not in my domain).My first solution was to create a
div
and position it absolutely over this button group and use thetourAnchor
-Directive on this newdiv
. If the layout changed somehow and these buttons were not in the same place anymore or changed in dimension, the absolutely positioneddiv
was wrong (especially visible, if backdrop is enabled).So instead of positioning this "artificial" tourAnchor-DIV I've created a directive which receives a CSS selector. This directive finds the element I want to overlay, gets it's bounding rect and sets the
div
's position and dimensions accordingly.In this branch you can see a demo of the directive. As a test I try to highlight the label of the button instead of the whole button (to showcase an element, that is not in my domain but in angular material's).
Additionally theres an Input for padding (which uses the technique from your docs to set padding and remove margin).