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 222 223 224 225 226 227 228 229 230 231 232 | 1x 21x 21x 21x 21x 21x 55x 55x 21x 21x 21x 21x 21x 21x 21x 21x 3x 3x 21x 3x 3x 44x 21x 49x 43x 6x 21x 21x 35x 29x 21x 36x 36x 21x 21x 30x 4x 4x 46x 1x 1x 65x 65x 65x 25x 6x 6x 6x 25x 3x 3x 65x 65x | /** * Copyright (c) Siemens 2016 - 2025 * SPDX-License-Identifier: MIT */ import { animate, state, style, transition, trigger } from '@angular/animations'; import { NgTemplateOutlet } from '@angular/common'; import { booleanAttribute, ChangeDetectionStrategy, Component, computed, ElementRef, inject, input, model, OnChanges, OnDestroy, OnInit, signal, SimpleChanges } from '@angular/core'; import { areAnimationsDisabled } from '@siemens/element-ng/common'; import { BOOTSTRAP_BREAKPOINTS, ElementDimensions, ResizeObserverService } from '@siemens/element-ng/resize-observer'; import { SiSplitComponent, SiSplitPartComponent } from '@siemens/element-ng/split'; import { BehaviorSubject, Subject, Subscription } from 'rxjs'; /** @experimental */ @Component({ selector: 'si-list-details', imports: [NgTemplateOutlet, SiSplitComponent, SiSplitPartComponent], templateUrl: './si-list-details.component.html', styleUrl: './si-list-details.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'si-layout-inner list-details-layout d-flex flex-column', '[class.expanded]': 'hasLargeSize()', '[style.opacity]': 'opacity()' }, animations: [ trigger('detailsExpanded', [ state( 'collapsed', style({ marginInlineStart: '0' }) ), state( 'expanded', style({ marginInlineStart: '-100%' }) ), transition('collapsed <=> expanded', [animate('0.5s ease-in-out')]) ]) ] }) export class SiListDetailsComponent implements OnInit, OnChanges, OnDestroy { private resizeSubs?: Subscription; private elementRef = inject(ElementRef); private resizeObserver = inject(ResizeObserverService); private readonly animationsGloballyDisabled = areAnimationsDisabled(); /** * A numeric value defining the minimum width in px, which the component needs * to be displayed in its large layout. Whenever smaller than * this threshold, the small layout will be used. Default is * value is BOOTSTRAP_BREAKPOINTS.mdMinimum. * * @defaultValue BOOTSTRAP_BREAKPOINTS.mdMinimum */ readonly expandBreakpoint = input(BOOTSTRAP_BREAKPOINTS.mdMinimum); readonly hasLargeSize = computed(() => { const dimensions = this.resizeDimensions(); return !!dimensions && dimensions.width >= this.expandBreakpoint(); }); /** * Whether the details are currently active or not, mostly relevant in the * responsive scenario when the viewport only shows either the list or the detail. * * @defaultValue false */ readonly detailsActive = model(false); /** * Whether the list and detail parts should be resizable by a splitter or not. * This is only supported in the 'large' scenario (when `hasLargeSize` is `true`). * Default value is `false`. * * @defaultValue false */ readonly disableResizing = input(false, { transform: booleanAttribute }); /** * The percentage width of the list view of the overall component width. * * @defaultValue 32 */ readonly listWidth = model<number>(32); /** * Sets the minimal width of the list component in pixel. * * @defaultValue 300 */ readonly minListSize = input(300); /** * Sets the minimal width of the detail component in pixel. * * @defaultValue 300 */ readonly minDetailsSize = input(300); /** * An optional stateId to uniquely identify a component instance. * Required for persistence of ui state. */ readonly stateId = input<string>(); protected readonly splitSizes = computed<[number, number]>(() => [ this.listWidth(), 100 - this.listWidth() ]); protected readonly listStateId = computed(() => { const stateId = this.stateId(); return stateId ? `${stateId}-list` : undefined; }); protected readonly detailsStateId = computed(() => { const stateId = this.stateId(); return stateId ? `${stateId}-details` : undefined; }); protected readonly opacity = computed(() => (this.resizeDimensions() ? '' : '0')); /** @internal */ readonly detailsExpandedAnimation = computed(() => { if (!this.animationsGloballyDisabled && !this.hasLargeSize()) { return this.detailsActive() ? 'expanded' : 'collapsed'; } else { return 'disabled'; } }); // Used for focus transfer, can not use a focus trap for this. private hadLargeSizePreviously: boolean | undefined; private detailsActivePreviously: boolean | undefined; private previouslyFocusedElementInList: HTMLElement | undefined; /** @internal */ readonly transferFocusToList = new Subject<HTMLElement | undefined>(); /** * A behavior subject because the details component may only be created when details are visible. * @internal */ readonly transferFocusToDetails = new BehaviorSubject<boolean>(false); private animationDone?: () => void; ngOnChanges(changes: SimpleChanges): void { if (changes.detailsActive) { this.transferFocus(); } } ngOnInit(): void { this.resizeSubs = this.resizeObserver .observe(this.elementRef.nativeElement, 100, true) .subscribe(dimensions => { this.resizeDimensions.set(dimensions); this.transferFocus(); }); } ngOnDestroy(): void { this.resizeSubs?.unsubscribe(); } private readonly resizeDimensions = signal<ElementDimensions | undefined>(undefined); protected onSplitSizesChange(sizes: number[]): void { this.listWidth.set(sizes[0]); } /** @internal */ detailsBackClicked(options?: { animationDone?: () => void }): void { this.detailsActive.set(false); // This callback is used to route after the animation is done. this.animationDone = options?.animationDone; } protected detailsExpandedAnimationDone(): void { if (this.animationDone) { this.animationDone(); this.animationDone = undefined; } } // Transfer focus onto child panes if they would be inaccesible. private transferFocus(): void { // Check if dimensions have even been evaluated. const hasLargeSize = this.resizeDimensions() ? this.hasLargeSize() : undefined; const detailsActive = this.detailsActive(); if (this.hadLargeSizePreviously !== undefined && this.detailsActivePreviously !== undefined) { if ( detailsActive && !hasLargeSize && (!this.detailsActivePreviously || this.hadLargeSizePreviously) ) { if (!this.hadLargeSizePreviously) { this.previouslyFocusedElementInList = document?.activeElement as HTMLElement | undefined; } this.transferFocusToDetails.next(true); } if (!detailsActive && this.detailsActivePreviously) { this.transferFocusToList.next(this.previouslyFocusedElementInList); this.previouslyFocusedElementInList = undefined; } } this.hadLargeSizePreviously = hasLargeSize; this.detailsActivePreviously = detailsActive; } } |