Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | 1x 3x 3x 3x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 2x 3x 3x 3x 2x 2x 2x 2x 2x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 2x 2x 2x 3x 3x 1x 2x 1x 1x 1x | /** * Copyright (c) Siemens 2016 - 2025 * SPDX-License-Identifier: MIT */ import { Overlay, OverlayRef } from '@angular/cdk/overlay'; import { ComponentPortal } from '@angular/cdk/portal'; import { booleanAttribute, ComponentRef, computed, Directive, ElementRef, HostListener, inject, input, OnDestroy, OnInit, output, TemplateRef } from '@angular/core'; import { getOverlay, getPositionStrategy, hasTrigger, positions } from '@siemens/element-ng/common'; import { Subject, takeUntil } from 'rxjs'; import { PopoverComponent } from './si-popover.component'; /** * @deprecated Use {@link SiPopoverDirective} instead. */ @Directive({ selector: '[siPopoverLegacy]', exportAs: 'si-popover' }) export class SiPopoverLegacyDirective implements OnInit, OnDestroy { /** * The popover text to be displayed */ readonly siPopoverLegacy = input<string | TemplateRef<any>>(); /** * The placement of the popover. One of 'top', 'start', end', 'bottom' * * @defaultValue 'auto' */ readonly placement = input<keyof typeof positions>('auto'); readonly placementInternal = computed(() => { if ( this.placement() !== 'top' && this.placement() !== 'bottom' && this.placement() !== 'start' && this.placement() !== 'end' ) { return 'auto'; } else E{ return this.placement(); } }); /** * The trigger event(s) on which the popover shall be displayed. * Applications can pass multiple triggers separated by space. * Supported events are 'click', 'hover' and 'focus'. * * **Limitations:** * Safari browsers do not raise a 'focus' event on host element click and 'focus' * on tab key has to be enabled in the advanced browser settings. * * @defaultValue 'click' */ readonly triggers = input('click'); /** * The title to be displayed on top for the popover * * @defaultValue '' */ readonly popoverTitle = input(''); /** * The class that will be applied to container of the popover * * @defaultValue '' */ readonly containerClass = input(''); /** * The flag determines whether to close popover on clicking outside * * @defaultValue true */ readonly outsideClick = input(true, { transform: booleanAttribute }); /** * The icon to be displayed besides popover title */ readonly icon = input<string>(); /** * Specify whether or not the popover is currently shown * * @defaultValue false */ readonly isOpen = input<boolean | undefined, unknown>(false, { transform: booleanAttribute }); /** * The context for the attached template */ readonly popoverContext = input<unknown>(); /** * Emits an event when the popover is shown */ readonly shown = output<void>(); /** * Emits an event when the popover is hidden */ readonly hidden = output<void>(); private overlayref?: OverlayRef; private overlay = inject(Overlay); private elementRef = inject(ElementRef); private destroyer = new Subject<void>(); ngOnInit(): void { Iif (this.isOpen()) { this.show(); } } ngOnDestroy(): void { this.overlayref?.dispose(); this.destroyer.next(); this.destroyer.complete(); } /** * Displays popover and emits 'shown' event. */ show(): void { if (!this.overlayref?.hasAttached()) { const triggers = this.triggers(); const backdrop = this.outsideClick() && !hasTrigger('focus', triggers) && !hasTrigger('hover', triggers); this.overlayref = getOverlay( this.elementRef, this.overlay, backdrop, this.placementInternal() ); if (backdrop) { this.overlayref .backdropClick() .pipe(takeUntil(this.destroyer)) .subscribe(() => this.hide()); } } Iif (this.overlayref.hasAttached()) { return; } const popoverPortal = new ComponentPortal(PopoverComponent); const popoverRef: ComponentRef<PopoverComponent> = this.overlayref.attach(popoverPortal); popoverRef.setInput('popover', this.siPopoverLegacy()); popoverRef.setInput('popoverTitle', this.popoverTitle()); popoverRef.setInput('icon', this.icon()); popoverRef.setInput('containerClass', this.containerClass()); popoverRef.setInput('popoverContext', this.popoverContext()); const positionStrategy = getPositionStrategy(this.overlayref); positionStrategy?.positionChanges .pipe(takeUntil(this.destroyer)) .subscribe(change => popoverRef.instance.updateArrow(change, this.elementRef)); this.shown.emit(); } /** * Hides the popover and emits 'hidden' event. */ hide(): void { if (this.overlayref?.hasAttached()) { this.overlayref?.detach(); this.hidden.emit(); this.destroyer.next(); } } /** * Updates the position of the popover based on the position strategy. */ updatePosition(): void { this.overlayref?.updatePosition(); } @HostListener('mouseenter', ['"hover"']) @HostListener('mouseleave', ['"hover"']) @HostListener('focus', ['"focus"']) @HostListener('click', ['"click"']) protected onTrigger(trigger: string): void { if (hasTrigger(trigger, this.triggers())) { if (this.overlayref?.hasAttached()) { this.hide(); } else { this.show(); } } } @HostListener('touchstart') @HostListener('focusout') protected focusOut(): void { if (hasTrigger('focus', this.triggers())) { if (this.outsideClick()) { this.hide(); } } } } |