@sixbell-telco/sdk 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { signal, Injectable, inject, input, computed, Component, output, ViewChild, ContentChild } from '@angular/core';
2
+ import { input, output, signal, computed, Component, inject, viewChild, contentChild, model, effect } from '@angular/core';
3
3
  import { IconComponent } from '@sixbell-telco/sdk/components/icon';
4
4
  import { matKeyboardArrowDown } from '@sixbell-telco/sdk/components/icon/material/baseline';
5
5
  import { cn } from '@sixbell-telco/sdk/utils/cn';
@@ -7,32 +7,321 @@ import { CdkConnectedOverlay, CdkOverlayOrigin } from '@angular/cdk/overlay';
7
7
  import { NgTemplateOutlet } from '@angular/common';
8
8
 
9
9
  /**
10
- * Service to manage dropdown state
11
- * Used by dropdown components to communicate state to chevron
10
+ * DropdownTrigger - Trigger element for opening dropdown content
11
+ *
12
+ * @remarks
13
+ * This component acts as the trigger that opens/closes the dropdown content.
14
+ * It can contain any content (buttons, avatars, text, icons, etc.).
15
+ * Uses CdkConnectedOverlay for positioning and management.
16
+ *
17
+ * @example
18
+ * ```html
19
+ * <st-dropdown>
20
+ * <st-dropdown-trigger>
21
+ * <button class="btn btn-primary">
22
+ * Open Menu
23
+ * <st-icon [icon]="chevronDown"></st-icon>
24
+ * </button>
25
+ * </st-dropdown-trigger>
26
+ * <st-dropdown-content>
27
+ * <st-dropdown-item>Item 1</st-dropdown-item>
28
+ * </st-dropdown-content>
29
+ * </st-dropdown>
30
+ * ```
12
31
  */
13
- class DropdownService {
14
- _isOpen = signal(false);
32
+ class DropdownTriggerComponent {
33
+ /** Offset X in pixels */
34
+ offsetX = input(0);
35
+ /** Offset Y in pixels */
36
+ offsetY = input(0);
37
+ /** Origin X position */
38
+ originX = input('start');
39
+ /** Origin Y position */
40
+ originY = input('bottom');
41
+ /** Overlay X position */
42
+ overlayX = input('start');
43
+ /** Overlay Y position */
44
+ overlayY = input('top');
45
+ /** Fallback positions configuration */
46
+ fallbacks = input({ enabled: true });
47
+ /** Event emitted when dropdown is opened */
48
+ opened = output();
49
+ /** Event emitted when dropdown is closed */
50
+ closed = output();
51
+ /** Current open state */
52
+ isOpen = signal(false);
53
+ /** Internal state to control overlay visibility (keeps overlay open during close animation) */
54
+ overlayOpen = signal(false);
55
+ /** Current animation state */
56
+ animationState = signal('closed');
57
+ /** Current active position configuration */
58
+ currentPosition = signal(null);
59
+ /**
60
+ * Computed animation direction based on current position
61
+ * Returns the appropriate direction: 'top', 'bottom', 'left', or 'right'
62
+ */
63
+ animationDirection = computed(() => {
64
+ const position = this.currentPosition();
65
+ if (!position)
66
+ return 'bottom'; // default
67
+ // Determine direction based on overlay Y and X positions
68
+ // overlayY indicates vertical position (top/bottom/center)
69
+ // overlayX indicates horizontal position (start/end/center)
70
+ const overlayY = position.overlayY;
71
+ const overlayX = position.overlayX;
72
+ // Priority: check Y first, then X
73
+ if (overlayY === 'top') {
74
+ return 'top'; // Dropdown appears above
75
+ }
76
+ if (overlayY === 'bottom') {
77
+ return 'bottom'; // Dropdown appears below
78
+ }
79
+ if (overlayX === 'end') {
80
+ return 'left'; // Dropdown appears to the left (end aligns to left side of trigger)
81
+ }
82
+ if (overlayX === 'start') {
83
+ return 'right'; // Dropdown appears to the right (start aligns to right side of trigger)
84
+ }
85
+ return 'bottom'; // default
86
+ });
87
+ /**
88
+ * Static class mappings for different animation directions
89
+ * Maps animation directions to complete Tailwind class names
90
+ * All class names are static and detectable by Tailwind at build time
91
+ */
92
+ animationClassMap = {
93
+ bottom: 'data-[state=opening]:animate-fade-in-up data-[state=open]:animate-fade-in-up data-[state=closing]:animate-fade-out-down',
94
+ top: 'data-[state=opening]:animate-fade-in-down data-[state=open]:animate-fade-in-down data-[state=closing]:animate-fade-out-up',
95
+ left: 'data-[state=opening]:animate-fade-in-left data-[state=open]:animate-fade-in-left data-[state=closing]:animate-fade-out-right',
96
+ right: 'data-[state=opening]:animate-fade-in-right data-[state=open]:animate-fade-in-right data-[state=closing]:animate-fade-out-left',
97
+ };
98
+ /**
99
+ * Computed class string for animations
100
+ * Applies the correct animation based on position using static class names
101
+ */
102
+ animationClasses = computed(() => {
103
+ const direction = this.animationDirection();
104
+ const baseClasses = this.animationClassMap[direction];
105
+ const durationClasses = 'data-[state=closing]:animate-duration-150 data-[state=opening]:animate-duration-150 data-[state=open]:animate-duration-150 overflow-hidden';
106
+ return `${baseClasses} ${durationClasses}`;
107
+ });
108
+ /** Content template reference */
109
+ contentTemplate = null;
110
+ /**
111
+ * Computed positions array based on signal inputs
112
+ */
113
+ positions = computed(() => {
114
+ // Get current values and ensure they are strings
115
+ const originX = String(this.originX());
116
+ const originY = String(this.originY());
117
+ const overlayX = String(this.overlayX());
118
+ const overlayY = String(this.overlayY());
119
+ const offsetX = Number(this.offsetX());
120
+ const offsetY = Number(this.offsetY());
121
+ // Primary position using direct signal values
122
+ const primary = {
123
+ originX,
124
+ originY,
125
+ overlayX,
126
+ overlayY,
127
+ offsetX,
128
+ offsetY,
129
+ };
130
+ // If fallbacks are disabled, return only primary position
131
+ const fallbackConfig = this.fallbacks();
132
+ if (!fallbackConfig.enabled) {
133
+ return [primary];
134
+ }
135
+ // Use custom fallback positions if provided
136
+ if (fallbackConfig.positions && fallbackConfig.positions.length > 0) {
137
+ return [primary, ...fallbackConfig.positions];
138
+ }
139
+ // Generate default fallback positions
140
+ const fallbacks = this.generateDefaultFallbacks(primary);
141
+ return [primary, ...fallbacks];
142
+ });
143
+ /**
144
+ * Generate default fallback positions based on the primary position
145
+ * Provides comprehensive fallback coverage for all space constraints
146
+ */
147
+ generateDefaultFallbacks(primary) {
148
+ const fallbacks = [];
149
+ const primaryOriginX = primary.originX;
150
+ const primaryOriginY = primary.originY;
151
+ const primaryOverlayX = primary.overlayX;
152
+ const primaryOverlayY = primary.overlayY;
153
+ // Add basic axis flips
154
+ this.addAxisFlips(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY);
155
+ // Add standard dropdown positions
156
+ this.addStandardPositions(fallbacks, primary);
157
+ // Add center alignment fallbacks
158
+ this.addCenterFallbacks(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY);
159
+ return fallbacks;
160
+ }
161
+ /**
162
+ * Helper to flip Y position
163
+ */
164
+ getOppositeY(position) {
165
+ if (position === 'top')
166
+ return 'bottom';
167
+ if (position === 'bottom')
168
+ return 'top';
169
+ return 'center';
170
+ }
171
+ /**
172
+ * Helper to flip X position
173
+ */
174
+ getOppositeX(position) {
175
+ if (position === 'start')
176
+ return 'end';
177
+ if (position === 'end')
178
+ return 'start';
179
+ return 'center';
180
+ }
181
+ /**
182
+ * Helper to create position variant
183
+ */
184
+ createPosition(primary, originX, originY, overlayX, overlayY) {
185
+ return {
186
+ ...primary,
187
+ originX,
188
+ originY,
189
+ overlayX,
190
+ overlayY,
191
+ };
192
+ }
193
+ /**
194
+ * Add axis flip fallbacks
195
+ */
196
+ addAxisFlips(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY) {
197
+ // Flip Y axis
198
+ const oppositeY = this.getOppositeY(primaryOriginY);
199
+ const oppositeOverlayY = this.getOppositeY(primaryOverlayY);
200
+ fallbacks.push(this.createPosition(primary, primaryOriginX, oppositeY, primaryOverlayX, oppositeOverlayY));
201
+ // Flip X axis
202
+ const oppositeX = this.getOppositeX(primaryOriginX);
203
+ const oppositeOverlayX = this.getOppositeX(primaryOverlayX);
204
+ fallbacks.push(this.createPosition(primary, oppositeX, primaryOriginY, oppositeOverlayX, primaryOverlayY));
205
+ // Flip both axes
206
+ fallbacks.push(this.createPosition(primary, oppositeX, oppositeY, oppositeOverlayX, oppositeOverlayY));
207
+ }
208
+ /**
209
+ * Add standard dropdown positions
210
+ */
211
+ addStandardPositions(fallbacks, primary) {
212
+ const standardPositions = [
213
+ this.createPosition(primary, 'start', 'bottom', 'start', 'top'), // Classic dropdown
214
+ this.createPosition(primary, 'start', 'top', 'start', 'bottom'), // Dropup
215
+ this.createPosition(primary, 'end', 'top', 'start', 'top'), // Left side
216
+ this.createPosition(primary, 'start', 'top', 'end', 'top'), // Right side
217
+ this.createPosition(primary, 'center', 'bottom', 'center', 'top'), // Center dropdown
218
+ this.createPosition(primary, 'center', 'top', 'center', 'bottom'), // Center dropup
219
+ ];
220
+ for (const pos of standardPositions) {
221
+ if (!this.isPositionDuplicate(pos, [primary, ...fallbacks])) {
222
+ fallbacks.push(pos);
223
+ }
224
+ }
225
+ }
15
226
  /**
16
- * Current open state of the dropdown
227
+ * Add center alignment fallbacks
17
228
  */
18
- isOpen = this._isOpen.asReadonly();
229
+ addCenterFallbacks(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY) {
230
+ // Center horizontally
231
+ if (primaryOriginX !== 'center' || primaryOverlayX !== 'center') {
232
+ fallbacks.push(this.createPosition(primary, 'center', primaryOriginY, 'center', primaryOverlayY));
233
+ }
234
+ // Center vertically
235
+ if (primaryOriginY !== 'center' || primaryOverlayY !== 'center') {
236
+ fallbacks.push(this.createPosition(primary, primaryOriginX, 'center', primaryOverlayX, 'center'));
237
+ }
238
+ // Fully centered as last resort
239
+ const fullyCentered = this.createPosition(primary, 'center', 'center', 'center', 'center');
240
+ if (!this.isPositionDuplicate(fullyCentered, [primary, ...fallbacks])) {
241
+ fallbacks.push(fullyCentered);
242
+ }
243
+ }
19
244
  /**
20
- * Set the open state
245
+ * Check if position is duplicate
246
+ */
247
+ isPositionDuplicate(position, existing) {
248
+ return existing.some((pos) => pos.originX === position.originX &&
249
+ pos.originY === position.originY &&
250
+ pos.overlayX === position.overlayX &&
251
+ pos.overlayY === position.overlayY);
252
+ } /**
253
+ * Set the content template to be displayed in the overlay
21
254
  */
22
- setOpen(open) {
23
- this._isOpen.set(open);
255
+ setContentTemplate(template) {
256
+ this.contentTemplate = template;
24
257
  }
25
258
  /**
26
- * Toggle the open state
259
+ * Toggle the dropdown open/close state
27
260
  */
28
261
  toggle() {
29
- this._isOpen.update((current) => !current);
262
+ if (this.isOpen()) {
263
+ this.close();
264
+ return;
265
+ }
266
+ this.open();
267
+ }
268
+ /**
269
+ * Open the dropdown
270
+ * Sets up overlay with animation and emits opened event
271
+ */
272
+ open() {
273
+ if (this.isOpen() || !this.contentTemplate) {
274
+ return;
275
+ }
276
+ this.isOpen.set(true);
277
+ this.overlayOpen.set(true);
278
+ this.animationState.set('opening');
279
+ this.opened.emit();
280
+ }
281
+ /**
282
+ * Close the dropdown
283
+ * Triggers closing animation and emits closed event
284
+ */
285
+ close() {
286
+ if (!this.isOpen()) {
287
+ return;
288
+ }
289
+ this.animationState.set('closing');
290
+ this.closed.emit();
291
+ }
292
+ /**
293
+ * Handle animation end events
294
+ * Completes state transitions when animations finish
295
+ */
296
+ onAnimationEnd(event) {
297
+ const currentState = this.animationState();
298
+ // Opening animation complete
299
+ if (currentState === 'opening' && (event.animationName.includes('fade-in') || event.animationName.includes('morph-in'))) {
300
+ this.animationState.set('open');
301
+ return;
302
+ }
303
+ // Closing animation complete
304
+ if (currentState === 'closing' && event.animationName.includes('fade-out')) {
305
+ this.animationState.set('closed');
306
+ this.isOpen.set(false);
307
+ this.overlayOpen.set(false);
308
+ return;
309
+ }
310
+ }
311
+ /**
312
+ * Handle position changes from CDK overlay
313
+ */
314
+ onPositionChange(position) {
315
+ if (position?.connectionPair) {
316
+ this.currentPosition.set(position.connectionPair);
317
+ }
30
318
  }
31
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
32
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownService });
319
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownTriggerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
320
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.0", type: DropdownTriggerComponent, isStandalone: true, selector: "st-dropdown-trigger", inputs: { offsetX: { classPropertyName: "offsetX", publicName: "offsetX", isSignal: true, isRequired: false, transformFunction: null }, offsetY: { classPropertyName: "offsetY", publicName: "offsetY", isSignal: true, isRequired: false, transformFunction: null }, originX: { classPropertyName: "originX", publicName: "originX", isSignal: true, isRequired: false, transformFunction: null }, originY: { classPropertyName: "originY", publicName: "originY", isSignal: true, isRequired: false, transformFunction: null }, overlayX: { classPropertyName: "overlayX", publicName: "overlayX", isSignal: true, isRequired: false, transformFunction: null }, overlayY: { classPropertyName: "overlayY", publicName: "overlayY", isSignal: true, isRequired: false, transformFunction: null }, fallbacks: { classPropertyName: "fallbacks", publicName: "fallbacks", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { opened: "opened", closed: "closed" }, ngImport: i0, template: "<div\n\tcdkOverlayOrigin\n\t#trigger=\"cdkOverlayOrigin\"\n\tclass=\"inline-flex cursor-pointer items-center\"\n\t(click)=\"toggle()\"\n\t(keydown.enter)=\"toggle()\"\n\t(keydown.space)=\"toggle(); $event.preventDefault()\"\n\t(keydown.escape)=\"close()\"\n\t[attr.aria-expanded]=\"isOpen()\"\n\t[attr.aria-haspopup]=\"true\"\n\ttabindex=\"0\"\n\trole=\"button\"\n>\n\t<ng-content></ng-content>\n</div>\n\n<ng-template\n\tcdkConnectedOverlay\n\t[cdkConnectedOverlayPositions]=\"positions()\"\n\t[cdkConnectedOverlayOrigin]=\"trigger\"\n\t[cdkConnectedOverlayOpen]=\"overlayOpen()\"\n\t[cdkConnectedOverlayHasBackdrop]=\"true\"\n\t[cdkConnectedOverlayBackdropClass]=\"'cdk-overlay-transparent-backdrop'\"\n\t[cdkConnectedOverlayDisableClose]=\"true\"\n\t(backdropClick)=\"close()\"\n\t(positionChange)=\"onPositionChange($event)\"\n>\n\t<div [class]=\"animationClasses()\" (animationend)=\"onAnimationEnd($event)\" [attr.data-state]=\"animationState()\">\n\t\t<ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n\t</div>\n</ng-template>\n", dependencies: [{ kind: "directive", type: CdkConnectedOverlay, selector: "[cdk-connected-overlay], [connected-overlay], [cdkConnectedOverlay]", inputs: ["cdkConnectedOverlayOrigin", "cdkConnectedOverlayPositions", "cdkConnectedOverlayPositionStrategy", "cdkConnectedOverlayOffsetX", "cdkConnectedOverlayOffsetY", "cdkConnectedOverlayWidth", "cdkConnectedOverlayHeight", "cdkConnectedOverlayMinWidth", "cdkConnectedOverlayMinHeight", "cdkConnectedOverlayBackdropClass", "cdkConnectedOverlayPanelClass", "cdkConnectedOverlayViewportMargin", "cdkConnectedOverlayScrollStrategy", "cdkConnectedOverlayOpen", "cdkConnectedOverlayDisableClose", "cdkConnectedOverlayTransformOriginOn", "cdkConnectedOverlayHasBackdrop", "cdkConnectedOverlayLockPosition", "cdkConnectedOverlayFlexibleDimensions", "cdkConnectedOverlayGrowAfterOpen", "cdkConnectedOverlayPush", "cdkConnectedOverlayDisposeOnNavigation"], outputs: ["backdropClick", "positionChange", "attach", "detach", "overlayKeydown", "overlayOutsideClick"], exportAs: ["cdkConnectedOverlay"] }, { kind: "directive", type: CdkOverlayOrigin, selector: "[cdk-overlay-origin], [overlay-origin], [cdkOverlayOrigin]", exportAs: ["cdkOverlayOrigin"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] });
33
321
  }
34
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownService, decorators: [{
35
- type: Injectable
322
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownTriggerComponent, decorators: [{
323
+ type: Component,
324
+ args: [{ selector: 'st-dropdown-trigger', standalone: true, imports: [CdkConnectedOverlay, CdkOverlayOrigin, NgTemplateOutlet], template: "<div\n\tcdkOverlayOrigin\n\t#trigger=\"cdkOverlayOrigin\"\n\tclass=\"inline-flex cursor-pointer items-center\"\n\t(click)=\"toggle()\"\n\t(keydown.enter)=\"toggle()\"\n\t(keydown.space)=\"toggle(); $event.preventDefault()\"\n\t(keydown.escape)=\"close()\"\n\t[attr.aria-expanded]=\"isOpen()\"\n\t[attr.aria-haspopup]=\"true\"\n\ttabindex=\"0\"\n\trole=\"button\"\n>\n\t<ng-content></ng-content>\n</div>\n\n<ng-template\n\tcdkConnectedOverlay\n\t[cdkConnectedOverlayPositions]=\"positions()\"\n\t[cdkConnectedOverlayOrigin]=\"trigger\"\n\t[cdkConnectedOverlayOpen]=\"overlayOpen()\"\n\t[cdkConnectedOverlayHasBackdrop]=\"true\"\n\t[cdkConnectedOverlayBackdropClass]=\"'cdk-overlay-transparent-backdrop'\"\n\t[cdkConnectedOverlayDisableClose]=\"true\"\n\t(backdropClick)=\"close()\"\n\t(positionChange)=\"onPositionChange($event)\"\n>\n\t<div [class]=\"animationClasses()\" (animationend)=\"onAnimationEnd($event)\" [attr.data-state]=\"animationState()\">\n\t\t<ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n\t</div>\n</ng-template>\n" }]
36
325
  }] });
37
326
 
38
327
  /**
@@ -40,7 +329,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
40
329
  * Automatically rotates based on dropdown state and positions itself correctly
41
330
  */
42
331
  class DropdownChevronComponent {
43
- dropdownService = inject(DropdownService, { optional: true });
332
+ /**
333
+ * Inject parent trigger component to access its isOpen signal
334
+ * Use SkipSelf to get the immediate parent trigger
335
+ */
336
+ trigger = inject(DropdownTriggerComponent, { optional: true, skipSelf: true });
44
337
  /**
45
338
  * Custom icon to use instead of default arrow down
46
339
  */
@@ -63,8 +356,9 @@ class DropdownChevronComponent {
63
356
  position = input('right');
64
357
  /**
65
358
  * Whether the chevron is open (rotated)
359
+ * Derives from the parent trigger's isOpen signal
66
360
  */
67
- isOpen = computed(() => this.dropdownService?.isOpen() ?? false);
361
+ isOpen = computed(() => this.trigger?.isOpen() ?? false);
68
362
  /**
69
363
  * Computed classes for the chevron
70
364
  */
@@ -101,7 +395,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
101
395
  * ```
102
396
  */
103
397
  class DropdownContentComponent {
104
- template;
398
+ template = viewChild.required('contentTemplate');
105
399
  /** Custom CSS classes */
106
400
  class = input('');
107
401
  /** Size variant */
@@ -129,15 +423,12 @@ class DropdownContentComponent {
129
423
  this.closeRequested.emit();
130
424
  }
131
425
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownContentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
132
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.0", type: DropdownContentComponent, isStandalone: true, selector: "st-dropdown-content", inputs: { class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, shadow: { classPropertyName: "shadow", publicName: "shadow", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { closeRequested: "closeRequested" }, viewQueries: [{ propertyName: "template", first: true, predicate: ["contentTemplate"], descendants: true, static: true }], exportAs: ["dropdownContent"], ngImport: i0, template: "<ng-template #contentTemplate>\n\t<ul [class]=\"contentClass()\">\n\t\t<ng-content></ng-content>\n\t</ul>\n</ng-template>\n" });
426
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.0", type: DropdownContentComponent, isStandalone: true, selector: "st-dropdown-content", inputs: { class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, shadow: { classPropertyName: "shadow", publicName: "shadow", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { closeRequested: "closeRequested" }, viewQueries: [{ propertyName: "template", first: true, predicate: ["contentTemplate"], descendants: true, isSignal: true }], exportAs: ["dropdownContent"], ngImport: i0, template: "<ng-template #contentTemplate>\n\t<ul [class]=\"contentClass()\">\n\t\t<ng-content></ng-content>\n\t</ul>\n</ng-template>\n" });
133
427
  }
134
428
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownContentComponent, decorators: [{
135
429
  type: Component,
136
430
  args: [{ selector: 'st-dropdown-content', standalone: true, exportAs: 'dropdownContent', template: "<ng-template #contentTemplate>\n\t<ul [class]=\"contentClass()\">\n\t\t<ng-content></ng-content>\n\t</ul>\n</ng-template>\n" }]
137
- }], propDecorators: { template: [{
138
- type: ViewChild,
139
- args: ['contentTemplate', { static: true }]
140
- }] } });
431
+ }] });
141
432
 
142
433
  /**
143
434
  * DropdownGroup - Groups related dropdown items together
@@ -155,22 +446,134 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
155
446
  }] });
156
447
 
157
448
  /**
158
- * DropdownItemCheckbox - Checkbox dropdown item
159
- * Provides checkbox functionality for dropdown selections
160
- */
161
- class DropdownItemCheckboxComponent {
162
- /**
163
- * Whether the checkbox is checked
164
- */
165
- checked = input(false);
166
- /**
167
- * Whether the menu item is disabled
168
- */
169
- disabled = input(false);
170
- /**
171
- * Custom indicator character or text
172
- */
173
- indicator = input('✓');
449
+ * Dropdown - Main container component for dropdown menus
450
+ *
451
+ * @remarks
452
+ * This is the root container that provides a wrapper for trigger and content components.
453
+ * The trigger and content components coordinate themselves through this parent component.
454
+ *
455
+ * @example
456
+ * ```html
457
+ * <st-dropdown>
458
+ * <st-dropdown-trigger [showChevron]="true">
459
+ * <button class="btn btn-primary">Open Menu</button>
460
+ * </st-dropdown-trigger>
461
+ * <st-dropdown-content>
462
+ * <st-dropdown-item>Item 1</st-dropdown-item>
463
+ * <st-dropdown-item>Item 2</st-dropdown-item>
464
+ * </st-dropdown-content>
465
+ * </st-dropdown>
466
+ * ```
467
+ *
468
+ * @example
469
+ * ```html
470
+ * <!-- Listen to open/close events -->
471
+ * <st-dropdown (opened)="onOpened()" (closed)="onClosed()">
472
+ * ...
473
+ * </st-dropdown>
474
+ *
475
+ * <!-- Programmatic control with model signal -->
476
+ * <st-dropdown [(open)]="isDropdownOpen">
477
+ * ...
478
+ * <button (click)="isDropdownOpen.set(true)">Open</button>
479
+ * <button (click)="isDropdownOpen.set(false)">Close</button>
480
+ * <div>Is open: {{ isDropdownOpen() }}</div>
481
+ * </st-dropdown>
482
+ * ```
483
+ */
484
+ class DropdownComponent {
485
+ // Use contentChild() signal instead of @ContentChild decorator
486
+ trigger = contentChild.required(DropdownTriggerComponent);
487
+ content = contentChild.required(DropdownContentComponent);
488
+ /** Model signal for open/close state - allows two-way binding [(open)]="isDropdownOpen" */
489
+ open = model(false);
490
+ /** Event emitted when dropdown is opened - exposed from trigger */
491
+ opened = output();
492
+ /** Event emitted when dropdown is closed - exposed from trigger */
493
+ closed = output();
494
+ constructor() {
495
+ const _prevState = { trigger: null, content: null };
496
+ /**
497
+ * One-time template wiring effect
498
+ * Fires once when trigger and content become available
499
+ * Sets up template injection and subscribes to trigger outputs exactly once
500
+ */
501
+ effect(() => {
502
+ const trigger = this.trigger();
503
+ const content = this.content();
504
+ if (trigger && content && !_prevState.trigger) {
505
+ trigger.setContentTemplate(content.template());
506
+ _prevState.trigger = trigger;
507
+ _prevState.content = content;
508
+ if (trigger.opened) {
509
+ _prevState.openUnsub = trigger.opened.subscribe(() => {
510
+ this.opened.emit();
511
+ });
512
+ }
513
+ if (trigger.closed) {
514
+ _prevState.closedUnsub = trigger.closed.subscribe(() => {
515
+ this.closed.emit();
516
+ });
517
+ }
518
+ }
519
+ });
520
+ /**
521
+ * Model-to-trigger sync effect
522
+ * Tracks last synced model value to detect external changes
523
+ * Only syncs when model changes from what was previously synced
524
+ * Prevents control loops when showcase updates model in response to trigger events
525
+ */
526
+ const _lastSyncedModel = signal(this.open());
527
+ effect(() => {
528
+ const currentModel = this.open();
529
+ const lastSynced = _lastSyncedModel();
530
+ if (currentModel === lastSynced) {
531
+ return;
532
+ }
533
+ const trigger = this.trigger();
534
+ if (!trigger) {
535
+ return;
536
+ }
537
+ const triggerIsOpen = trigger.isOpen();
538
+ if (currentModel && !triggerIsOpen) {
539
+ trigger.open();
540
+ }
541
+ else if (!currentModel && triggerIsOpen) {
542
+ trigger.close();
543
+ }
544
+ _lastSyncedModel.set(currentModel);
545
+ });
546
+ }
547
+ /**
548
+ * Get the current open state
549
+ */
550
+ isOpen = computed(() => this.open());
551
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
552
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.2.0", version: "19.2.0", type: DropdownComponent, isStandalone: true, selector: "st-dropdown", inputs: { open: { classPropertyName: "open", publicName: "open", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { open: "openChange", opened: "opened", closed: "closed" }, queries: [{ propertyName: "trigger", first: true, predicate: DropdownTriggerComponent, descendants: true, isSignal: true }, { propertyName: "content", first: true, predicate: DropdownContentComponent, descendants: true, isSignal: true }], exportAs: ["stDropdown"], ngImport: i0, template: "<ng-content></ng-content>\n" });
553
+ }
554
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownComponent, decorators: [{
555
+ type: Component,
556
+ args: [{ selector: 'st-dropdown', standalone: true, exportAs: 'stDropdown', template: "<ng-content></ng-content>\n" }]
557
+ }], ctorParameters: () => [] });
558
+
559
+ /**
560
+ * DropdownItemCheckbox - Checkbox dropdown item
561
+ * Provides checkbox functionality for dropdown selections
562
+ */
563
+ class DropdownItemCheckboxComponent {
564
+ dropdown = inject(DropdownComponent, { optional: true });
565
+ /**
566
+ * Whether the checkbox is checked
567
+ */
568
+ checked = input(false);
569
+ /**
570
+ * Whether the menu item is disabled
571
+ */
572
+ disabled = input(false);
573
+ /**
574
+ * Custom indicator character or text
575
+ */
576
+ indicator = input('✓');
174
577
  /**
175
578
  * Whether to show the indicator
176
579
  */
@@ -179,6 +582,11 @@ class DropdownItemCheckboxComponent {
179
582
  * Custom CSS classes
180
583
  */
181
584
  class = input('');
585
+ /**
586
+ * Whether to close the dropdown when the item is selected
587
+ * @defaultValue true
588
+ */
589
+ closeOnSelect = input(false);
182
590
  /**
183
591
  * Emitted when the checkbox state changes
184
592
  */
@@ -201,6 +609,9 @@ class DropdownItemCheckboxComponent {
201
609
  const newChecked = !this.checked();
202
610
  this.checkedChanged.emit(newChecked);
203
611
  this.triggered.emit();
612
+ if (this.closeOnSelect()) {
613
+ this.dropdown?.trigger()?.close();
614
+ }
204
615
  }
205
616
  }
206
617
  /**
@@ -211,7 +622,7 @@ class DropdownItemCheckboxComponent {
211
622
  'menu-active': this.checked(),
212
623
  }, this.class());
213
624
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownItemCheckboxComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
214
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.0", type: DropdownItemCheckboxComponent, isStandalone: true, selector: "st-dropdown-item-checkbox", inputs: { checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, indicator: { classPropertyName: "indicator", publicName: "indicator", isSignal: true, isRequired: false, transformFunction: null }, showIndicator: { classPropertyName: "showIndicator", publicName: "showIndicator", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checkedChanged: "checkedChanged", triggered: "triggered" }, ngImport: i0, template: "<li\n\t[class]=\"itemClass()\"\n\t[attr.data-state]=\"dataState()\"\n\t(click)=\"onItemClick()\"\n\t(keydown.enter)=\"onItemClick()\"\n\t(keydown.space)=\"onItemClick()\"\n\t[attr.tabindex]=\"disabled() ? -1 : 0\"\n\trole=\"menuitemcheckbox\"\n\t[attr.aria-checked]=\"checked()\"\n\t[attr.aria-disabled]=\"disabled()\"\n>\n\t<a class=\"flex items-center justify-between\">\n\t\t<span class=\"flex-1\">\n\t\t\t<ng-content></ng-content>\n\t\t</span>\n\t\t@if (showIndicator()) {\n\t\t\t<span\n\t\t\t\tclass=\"ml-auto text-xs transition-opacity duration-300 ease-in-out group-aria-[checked=false]:opacity-0 group-aria-[checked=true]:opacity-100\"\n\t\t\t>\n\t\t\t\t{{ indicator() }}\n\t\t\t</span>\n\t\t}\n\t</a>\n</li>\n" });
625
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.0", type: DropdownItemCheckboxComponent, isStandalone: true, selector: "st-dropdown-item-checkbox", inputs: { checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, indicator: { classPropertyName: "indicator", publicName: "indicator", isSignal: true, isRequired: false, transformFunction: null }, showIndicator: { classPropertyName: "showIndicator", publicName: "showIndicator", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, closeOnSelect: { classPropertyName: "closeOnSelect", publicName: "closeOnSelect", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checkedChanged: "checkedChanged", triggered: "triggered" }, ngImport: i0, template: "<li\n\t[class]=\"itemClass()\"\n\t[attr.data-state]=\"dataState()\"\n\t(click)=\"onItemClick()\"\n\t(keydown.enter)=\"onItemClick()\"\n\t(keydown.space)=\"onItemClick()\"\n\t[attr.tabindex]=\"disabled() ? -1 : 0\"\n\trole=\"menuitemcheckbox\"\n\t[attr.aria-checked]=\"checked()\"\n\t[attr.aria-disabled]=\"disabled()\"\n>\n\t<a class=\"flex items-center justify-between\">\n\t\t<span class=\"flex-1\">\n\t\t\t<ng-content></ng-content>\n\t\t</span>\n\t\t@if (showIndicator()) {\n\t\t\t<span\n\t\t\t\tclass=\"ml-auto text-xs transition-opacity duration-300 ease-in-out group-aria-[checked=false]:opacity-0 group-aria-[checked=true]:opacity-100\"\n\t\t\t>\n\t\t\t\t{{ indicator() }}\n\t\t\t</span>\n\t\t}\n\t</a>\n</li>\n" });
215
626
  }
216
627
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownItemCheckboxComponent, decorators: [{
217
628
  type: Component,
@@ -223,6 +634,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
223
634
  * Provides radio button functionality for dropdown selections
224
635
  */
225
636
  class DropdownItemRadioComponent {
637
+ dropdown = inject(DropdownComponent, { optional: true });
226
638
  /**
227
639
  * Whether the radio is checked
228
640
  */
@@ -247,6 +659,11 @@ class DropdownItemRadioComponent {
247
659
  * Custom CSS classes
248
660
  */
249
661
  class = input('');
662
+ /**
663
+ * Whether to close the dropdown when the item is selected
664
+ * @defaultValue true
665
+ */
666
+ closeOnSelect = input(true);
250
667
  /**
251
668
  * Emitted when the radio state changes
252
669
  */
@@ -268,6 +685,9 @@ class DropdownItemRadioComponent {
268
685
  if (!this.disabled() && !this.checked()) {
269
686
  this.checkedChanged.emit(this.value());
270
687
  this.triggered.emit();
688
+ if (this.closeOnSelect()) {
689
+ this.dropdown?.trigger()?.close();
690
+ }
271
691
  }
272
692
  }
273
693
  /**
@@ -278,309 +698,13 @@ class DropdownItemRadioComponent {
278
698
  'menu-active': this.checked(),
279
699
  }, this.class());
280
700
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownItemRadioComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
281
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.0", type: DropdownItemRadioComponent, isStandalone: true, selector: "st-dropdown-item-radio", inputs: { checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, indicator: { classPropertyName: "indicator", publicName: "indicator", isSignal: true, isRequired: false, transformFunction: null }, showIndicator: { classPropertyName: "showIndicator", publicName: "showIndicator", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checkedChanged: "checkedChanged", triggered: "triggered" }, ngImport: i0, template: "<li\n\t[class]=\"itemClass()\"\n\t[attr.data-state]=\"dataState()\"\n\t(click)=\"onItemClick()\"\n\t(keydown.enter)=\"onItemClick()\"\n\t(keydown.space)=\"onItemClick()\"\n\t[attr.tabindex]=\"disabled() ? -1 : 0\"\n\trole=\"menuitemradio\"\n\t[attr.aria-checked]=\"checked()\"\n\t[attr.aria-disabled]=\"disabled()\"\n>\n\t<a class=\"flex items-center justify-between\">\n\t\t<span class=\"flex-1\">\n\t\t\t<ng-content></ng-content>\n\t\t</span>\n\t\t@if (showIndicator()) {\n\t\t\t<span\n\t\t\t\tclass=\"ml-auto text-xs transition-opacity duration-300 ease-in-out group-aria-[checked=false]:opacity-0 group-aria-[checked=true]:opacity-100\"\n\t\t\t>\n\t\t\t\t{{ indicator() }}\n\t\t\t</span>\n\t\t}\n\t</a>\n</li>\n" });
701
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.0", type: DropdownItemRadioComponent, isStandalone: true, selector: "st-dropdown-item-radio", inputs: { checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: true, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, indicator: { classPropertyName: "indicator", publicName: "indicator", isSignal: true, isRequired: false, transformFunction: null }, showIndicator: { classPropertyName: "showIndicator", publicName: "showIndicator", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, closeOnSelect: { classPropertyName: "closeOnSelect", publicName: "closeOnSelect", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checkedChanged: "checkedChanged", triggered: "triggered" }, ngImport: i0, template: "<li\n\t[class]=\"itemClass()\"\n\t[attr.data-state]=\"dataState()\"\n\t(click)=\"onItemClick()\"\n\t(keydown.enter)=\"onItemClick()\"\n\t(keydown.space)=\"onItemClick()\"\n\t[attr.tabindex]=\"disabled() ? -1 : 0\"\n\trole=\"menuitemradio\"\n\t[attr.aria-checked]=\"checked()\"\n\t[attr.aria-disabled]=\"disabled()\"\n>\n\t<a class=\"flex items-center justify-between\">\n\t\t<span class=\"flex-1\">\n\t\t\t<ng-content></ng-content>\n\t\t</span>\n\t\t@if (showIndicator()) {\n\t\t\t<span\n\t\t\t\tclass=\"ml-auto text-xs transition-opacity duration-300 ease-in-out group-aria-[checked=false]:opacity-0 group-aria-[checked=true]:opacity-100\"\n\t\t\t>\n\t\t\t\t{{ indicator() }}\n\t\t\t</span>\n\t\t}\n\t</a>\n</li>\n" });
282
702
  }
283
703
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownItemRadioComponent, decorators: [{
284
704
  type: Component,
285
705
  args: [{ selector: 'st-dropdown-item-radio', standalone: true, imports: [], template: "<li\n\t[class]=\"itemClass()\"\n\t[attr.data-state]=\"dataState()\"\n\t(click)=\"onItemClick()\"\n\t(keydown.enter)=\"onItemClick()\"\n\t(keydown.space)=\"onItemClick()\"\n\t[attr.tabindex]=\"disabled() ? -1 : 0\"\n\trole=\"menuitemradio\"\n\t[attr.aria-checked]=\"checked()\"\n\t[attr.aria-disabled]=\"disabled()\"\n>\n\t<a class=\"flex items-center justify-between\">\n\t\t<span class=\"flex-1\">\n\t\t\t<ng-content></ng-content>\n\t\t</span>\n\t\t@if (showIndicator()) {\n\t\t\t<span\n\t\t\t\tclass=\"ml-auto text-xs transition-opacity duration-300 ease-in-out group-aria-[checked=false]:opacity-0 group-aria-[checked=true]:opacity-100\"\n\t\t\t>\n\t\t\t\t{{ indicator() }}\n\t\t\t</span>\n\t\t}\n\t</a>\n</li>\n" }]
286
706
  }] });
287
707
 
288
- /**
289
- * DropdownTrigger - Trigger element for opening dropdown content
290
- *
291
- * @remarks
292
- * This component acts as the trigger that opens/closes the dropdown content.
293
- * It can contain any content (buttons, avatars, text, icons, etc.).
294
- * Uses CdkConnectedOverlay for positioning and management.
295
- *
296
- * @example
297
- * ```html
298
- * <st-dropdown>
299
- * <st-dropdown-trigger>
300
- * <button class="btn btn-primary">
301
- * Open Menu
302
- * <st-icon [icon]="chevronDown"></st-icon>
303
- * </button>
304
- * </st-dropdown-trigger>
305
- * <st-dropdown-content>
306
- * <st-dropdown-item>Item 1</st-dropdown-item>
307
- * </st-dropdown-content>
308
- * </st-dropdown>
309
- * ```
310
- */
311
- class DropdownTriggerComponent {
312
- /** Offset X in pixels */
313
- offsetX = input(0);
314
- /** Offset Y in pixels */
315
- offsetY = input(0);
316
- /** Origin X position */
317
- originX = input('start');
318
- /** Origin Y position */
319
- originY = input('bottom');
320
- /** Overlay X position */
321
- overlayX = input('start');
322
- /** Overlay Y position */
323
- overlayY = input('top');
324
- /** Fallback positions configuration */
325
- fallbacks = input({ enabled: true });
326
- /** Event emitted when dropdown is opened */
327
- opened = output();
328
- /** Event emitted when dropdown is closed */
329
- closed = output();
330
- /** Current open state */
331
- isOpen = signal(false);
332
- /** Current active position configuration */
333
- currentPosition = signal(null);
334
- /** Content template reference */
335
- contentTemplate = null;
336
- /**
337
- * Computed positions array based on signal inputs
338
- */
339
- positions = computed(() => {
340
- // Get current values and ensure they are strings
341
- const originX = String(this.originX());
342
- const originY = String(this.originY());
343
- const overlayX = String(this.overlayX());
344
- const overlayY = String(this.overlayY());
345
- const offsetX = Number(this.offsetX());
346
- const offsetY = Number(this.offsetY());
347
- // Primary position using direct signal values
348
- const primary = {
349
- originX,
350
- originY,
351
- overlayX,
352
- overlayY,
353
- offsetX,
354
- offsetY,
355
- };
356
- // If fallbacks are disabled, return only primary position
357
- const fallbackConfig = this.fallbacks();
358
- if (!fallbackConfig.enabled) {
359
- return [primary];
360
- }
361
- // Use custom fallback positions if provided
362
- if (fallbackConfig.positions && fallbackConfig.positions.length > 0) {
363
- return [primary, ...fallbackConfig.positions];
364
- }
365
- // Generate default fallback positions
366
- const fallbacks = this.generateDefaultFallbacks(primary);
367
- return [primary, ...fallbacks];
368
- });
369
- /**
370
- * Generate default fallback positions based on the primary position
371
- * Provides comprehensive fallback coverage for all space constraints
372
- */
373
- generateDefaultFallbacks(primary) {
374
- const fallbacks = [];
375
- const primaryOriginX = primary.originX;
376
- const primaryOriginY = primary.originY;
377
- const primaryOverlayX = primary.overlayX;
378
- const primaryOverlayY = primary.overlayY;
379
- // Add basic axis flips
380
- this.addAxisFlips(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY);
381
- // Add standard dropdown positions
382
- this.addStandardPositions(fallbacks, primary);
383
- // Add center alignment fallbacks
384
- this.addCenterFallbacks(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY);
385
- return fallbacks;
386
- }
387
- /**
388
- * Helper to flip Y position
389
- */
390
- getOppositeY(position) {
391
- if (position === 'top')
392
- return 'bottom';
393
- if (position === 'bottom')
394
- return 'top';
395
- return 'center';
396
- }
397
- /**
398
- * Helper to flip X position
399
- */
400
- getOppositeX(position) {
401
- if (position === 'start')
402
- return 'end';
403
- if (position === 'end')
404
- return 'start';
405
- return 'center';
406
- }
407
- /**
408
- * Helper to create position variant
409
- */
410
- createPosition(primary, originX, originY, overlayX, overlayY) {
411
- return {
412
- ...primary,
413
- originX,
414
- originY,
415
- overlayX,
416
- overlayY,
417
- };
418
- }
419
- /**
420
- * Add axis flip fallbacks
421
- */
422
- addAxisFlips(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY) {
423
- // Flip Y axis
424
- const oppositeY = this.getOppositeY(primaryOriginY);
425
- const oppositeOverlayY = this.getOppositeY(primaryOverlayY);
426
- fallbacks.push(this.createPosition(primary, primaryOriginX, oppositeY, primaryOverlayX, oppositeOverlayY));
427
- // Flip X axis
428
- const oppositeX = this.getOppositeX(primaryOriginX);
429
- const oppositeOverlayX = this.getOppositeX(primaryOverlayX);
430
- fallbacks.push(this.createPosition(primary, oppositeX, primaryOriginY, oppositeOverlayX, primaryOverlayY));
431
- // Flip both axes
432
- fallbacks.push(this.createPosition(primary, oppositeX, oppositeY, oppositeOverlayX, oppositeOverlayY));
433
- }
434
- /**
435
- * Add standard dropdown positions
436
- */
437
- addStandardPositions(fallbacks, primary) {
438
- const standardPositions = [
439
- this.createPosition(primary, 'start', 'bottom', 'start', 'top'), // Classic dropdown
440
- this.createPosition(primary, 'start', 'top', 'start', 'bottom'), // Dropup
441
- this.createPosition(primary, 'end', 'top', 'start', 'top'), // Left side
442
- this.createPosition(primary, 'start', 'top', 'end', 'top'), // Right side
443
- this.createPosition(primary, 'center', 'bottom', 'center', 'top'), // Center dropdown
444
- this.createPosition(primary, 'center', 'top', 'center', 'bottom'), // Center dropup
445
- ];
446
- for (const pos of standardPositions) {
447
- if (!this.isPositionDuplicate(pos, [primary, ...fallbacks])) {
448
- fallbacks.push(pos);
449
- }
450
- }
451
- }
452
- /**
453
- * Add center alignment fallbacks
454
- */
455
- addCenterFallbacks(fallbacks, primary, primaryOriginX, primaryOriginY, primaryOverlayX, primaryOverlayY) {
456
- // Center horizontally
457
- if (primaryOriginX !== 'center' || primaryOverlayX !== 'center') {
458
- fallbacks.push(this.createPosition(primary, 'center', primaryOriginY, 'center', primaryOverlayY));
459
- }
460
- // Center vertically
461
- if (primaryOriginY !== 'center' || primaryOverlayY !== 'center') {
462
- fallbacks.push(this.createPosition(primary, primaryOriginX, 'center', primaryOverlayX, 'center'));
463
- }
464
- // Fully centered as last resort
465
- const fullyCentered = this.createPosition(primary, 'center', 'center', 'center', 'center');
466
- if (!this.isPositionDuplicate(fullyCentered, [primary, ...fallbacks])) {
467
- fallbacks.push(fullyCentered);
468
- }
469
- }
470
- /**
471
- * Check if position is duplicate
472
- */
473
- isPositionDuplicate(position, existing) {
474
- return existing.some((pos) => pos.originX === position.originX &&
475
- pos.originY === position.originY &&
476
- pos.overlayX === position.overlayX &&
477
- pos.overlayY === position.overlayY);
478
- } /**
479
- * Set the content template to be displayed in the overlay
480
- */
481
- setContentTemplate(template) {
482
- this.contentTemplate = template;
483
- }
484
- /**
485
- * Toggle the dropdown open/close state
486
- */
487
- toggle() {
488
- if (this.isOpen()) {
489
- this.close();
490
- }
491
- else {
492
- this.open();
493
- }
494
- }
495
- /**
496
- * Open the dropdown
497
- */
498
- open() {
499
- if (this.isOpen() || !this.contentTemplate)
500
- return;
501
- this.isOpen.set(true);
502
- this.opened.emit();
503
- }
504
- /**
505
- * Close the dropdown
506
- */
507
- close() {
508
- if (!this.isOpen())
509
- return;
510
- this.isOpen.set(false);
511
- this.closed.emit();
512
- }
513
- /**
514
- * Handle position changes from CDK overlay
515
- */
516
- onPositionChange(position) {
517
- if (position?.connectionPair) {
518
- this.currentPosition.set(position.connectionPair);
519
- }
520
- }
521
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownTriggerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
522
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.0", type: DropdownTriggerComponent, isStandalone: true, selector: "st-dropdown-trigger", inputs: { offsetX: { classPropertyName: "offsetX", publicName: "offsetX", isSignal: true, isRequired: false, transformFunction: null }, offsetY: { classPropertyName: "offsetY", publicName: "offsetY", isSignal: true, isRequired: false, transformFunction: null }, originX: { classPropertyName: "originX", publicName: "originX", isSignal: true, isRequired: false, transformFunction: null }, originY: { classPropertyName: "originY", publicName: "originY", isSignal: true, isRequired: false, transformFunction: null }, overlayX: { classPropertyName: "overlayX", publicName: "overlayX", isSignal: true, isRequired: false, transformFunction: null }, overlayY: { classPropertyName: "overlayY", publicName: "overlayY", isSignal: true, isRequired: false, transformFunction: null }, fallbacks: { classPropertyName: "fallbacks", publicName: "fallbacks", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { opened: "opened", closed: "closed" }, ngImport: i0, template: "<div\n\tcdkOverlayOrigin\n\t#trigger=\"cdkOverlayOrigin\"\n\tclass=\"inline-flex cursor-pointer items-center\"\n\t(click)=\"toggle()\"\n\t(keydown.enter)=\"toggle()\"\n\t(keydown.space)=\"toggle(); $event.preventDefault()\"\n\t[attr.aria-expanded]=\"isOpen()\"\n\t[attr.aria-haspopup]=\"true\"\n\ttabindex=\"0\"\n\trole=\"button\"\n>\n\t<ng-content></ng-content>\n</div>\n\n<ng-template\n\tcdkConnectedOverlay\n\t[cdkConnectedOverlayPositions]=\"positions()\"\n\t[cdkConnectedOverlayOrigin]=\"trigger\"\n\t[cdkConnectedOverlayOpen]=\"isOpen()\"\n\t[cdkConnectedOverlayHasBackdrop]=\"true\"\n\t[cdkConnectedOverlayBackdropClass]=\"'cdk-overlay-transparent-backdrop'\"\n\t(backdropClick)=\"close()\"\n\t(detach)=\"close()\"\n\t(positionChange)=\"onPositionChange($event)\"\n>\n\t<ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n</ng-template>\n", dependencies: [{ kind: "directive", type: CdkConnectedOverlay, selector: "[cdk-connected-overlay], [connected-overlay], [cdkConnectedOverlay]", inputs: ["cdkConnectedOverlayOrigin", "cdkConnectedOverlayPositions", "cdkConnectedOverlayPositionStrategy", "cdkConnectedOverlayOffsetX", "cdkConnectedOverlayOffsetY", "cdkConnectedOverlayWidth", "cdkConnectedOverlayHeight", "cdkConnectedOverlayMinWidth", "cdkConnectedOverlayMinHeight", "cdkConnectedOverlayBackdropClass", "cdkConnectedOverlayPanelClass", "cdkConnectedOverlayViewportMargin", "cdkConnectedOverlayScrollStrategy", "cdkConnectedOverlayOpen", "cdkConnectedOverlayDisableClose", "cdkConnectedOverlayTransformOriginOn", "cdkConnectedOverlayHasBackdrop", "cdkConnectedOverlayLockPosition", "cdkConnectedOverlayFlexibleDimensions", "cdkConnectedOverlayGrowAfterOpen", "cdkConnectedOverlayPush", "cdkConnectedOverlayDisposeOnNavigation"], outputs: ["backdropClick", "positionChange", "attach", "detach", "overlayKeydown", "overlayOutsideClick"], exportAs: ["cdkConnectedOverlay"] }, { kind: "directive", type: CdkOverlayOrigin, selector: "[cdk-overlay-origin], [overlay-origin], [cdkOverlayOrigin]", exportAs: ["cdkOverlayOrigin"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }] });
523
- }
524
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownTriggerComponent, decorators: [{
525
- type: Component,
526
- args: [{ selector: 'st-dropdown-trigger', standalone: true, imports: [CdkConnectedOverlay, CdkOverlayOrigin, NgTemplateOutlet], template: "<div\n\tcdkOverlayOrigin\n\t#trigger=\"cdkOverlayOrigin\"\n\tclass=\"inline-flex cursor-pointer items-center\"\n\t(click)=\"toggle()\"\n\t(keydown.enter)=\"toggle()\"\n\t(keydown.space)=\"toggle(); $event.preventDefault()\"\n\t[attr.aria-expanded]=\"isOpen()\"\n\t[attr.aria-haspopup]=\"true\"\n\ttabindex=\"0\"\n\trole=\"button\"\n>\n\t<ng-content></ng-content>\n</div>\n\n<ng-template\n\tcdkConnectedOverlay\n\t[cdkConnectedOverlayPositions]=\"positions()\"\n\t[cdkConnectedOverlayOrigin]=\"trigger\"\n\t[cdkConnectedOverlayOpen]=\"isOpen()\"\n\t[cdkConnectedOverlayHasBackdrop]=\"true\"\n\t[cdkConnectedOverlayBackdropClass]=\"'cdk-overlay-transparent-backdrop'\"\n\t(backdropClick)=\"close()\"\n\t(detach)=\"close()\"\n\t(positionChange)=\"onPositionChange($event)\"\n>\n\t<ng-container *ngTemplateOutlet=\"contentTemplate\"></ng-container>\n</ng-template>\n" }]
527
- }] });
528
-
529
- /**
530
- * Dropdown - Main container component for dropdown menus
531
- *
532
- * @remarks
533
- * This is the root container that provides a wrapper for trigger and content components.
534
- * The trigger and content components coordinate themselves through this parent component.
535
- *
536
- * @example
537
- * ```html
538
- * <st-dropdown>
539
- * <st-dropdown-trigger [showChevron]="true">
540
- * <button class="btn btn-primary">Open Menu</button>
541
- * </st-dropdown-trigger>
542
- * <st-dropdown-content>
543
- * <st-dropdown-item>Item 1</st-dropdown-item>
544
- * <st-dropdown-item>Item 2</st-dropdown-item>
545
- * </st-dropdown-content>
546
- * </st-dropdown>
547
- * ```
548
- */
549
- class DropdownComponent {
550
- dropdownService = inject(DropdownService);
551
- trigger;
552
- content;
553
- ngAfterContentInit() {
554
- // Connect trigger and content after they're available
555
- if (this.trigger && this.content) {
556
- this.trigger.setContentTemplate(this.content.template);
557
- // Listen for close requests from content
558
- this.content.closeRequested.subscribe(() => {
559
- this.trigger.close();
560
- });
561
- // Sync trigger state with service
562
- this.trigger.opened.subscribe(() => {
563
- this.dropdownService.setOpen(true);
564
- });
565
- this.trigger.closed.subscribe(() => {
566
- this.dropdownService.setOpen(false);
567
- });
568
- }
569
- }
570
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
571
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.0", type: DropdownComponent, isStandalone: true, selector: "st-dropdown", providers: [DropdownService], queries: [{ propertyName: "trigger", first: true, predicate: DropdownTriggerComponent, descendants: true }, { propertyName: "content", first: true, predicate: DropdownContentComponent, descendants: true }], ngImport: i0, template: "<ng-content></ng-content>\n" });
572
- }
573
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownComponent, decorators: [{
574
- type: Component,
575
- args: [{ selector: 'st-dropdown', standalone: true, providers: [DropdownService], template: "<ng-content></ng-content>\n" }]
576
- }], propDecorators: { trigger: [{
577
- type: ContentChild,
578
- args: [DropdownTriggerComponent]
579
- }], content: [{
580
- type: ContentChild,
581
- args: [DropdownContentComponent]
582
- }] } });
583
-
584
708
  /**
585
709
  * A selectable item component for use within dropdown menus
586
710
  *
@@ -618,6 +742,11 @@ class DropdownItemComponent {
618
742
  * @defaultValue false
619
743
  */
620
744
  disabled = input(false);
745
+ /**
746
+ * Whether to close the dropdown when the item is selected
747
+ * @defaultValue true
748
+ */
749
+ closeOnSelect = input(true);
621
750
  /**
622
751
  * Event emitted when the item is selected
623
752
  */
@@ -630,7 +759,9 @@ class DropdownItemComponent {
630
759
  if (this.disabled())
631
760
  return;
632
761
  this.selected.emit();
633
- this.dropdown?.trigger?.close();
762
+ if (this.closeOnSelect()) {
763
+ this.dropdown?.trigger()?.close();
764
+ }
634
765
  }
635
766
  /**
636
767
  * Computed CSS classes for the menu item
@@ -640,7 +771,7 @@ class DropdownItemComponent {
640
771
  'menu-active': this.active(),
641
772
  }, this.class());
642
773
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownItemComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
643
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.0", type: DropdownItemComponent, isStandalone: true, selector: "st-dropdown-item", inputs: { active: { classPropertyName: "active", publicName: "active", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selected: "selected" }, ngImport: i0, template: "<li\n\t[class]=\"itemClass()\"\n\t(click)=\"handleSelect()\"\n\t(keydown.enter)=\"handleSelect()\"\n\t(keydown.space)=\"handleSelect(); $event.preventDefault()\"\n\t[attr.tabindex]=\"disabled() ? -1 : 0\"\n\trole=\"menuitem\"\n\t[attr.aria-disabled]=\"disabled()\"\n>\n\t<a>\n\t\t<ng-content></ng-content>\n\t</a>\n</li>\n" });
774
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.2.0", type: DropdownItemComponent, isStandalone: true, selector: "st-dropdown-item", inputs: { active: { classPropertyName: "active", publicName: "active", isSignal: true, isRequired: false, transformFunction: null }, class: { classPropertyName: "class", publicName: "class", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, closeOnSelect: { classPropertyName: "closeOnSelect", publicName: "closeOnSelect", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { selected: "selected" }, ngImport: i0, template: "<li\n\t[class]=\"itemClass()\"\n\t(click)=\"handleSelect()\"\n\t(keydown.enter)=\"handleSelect()\"\n\t(keydown.space)=\"handleSelect(); $event.preventDefault()\"\n\t[attr.tabindex]=\"disabled() ? -1 : 0\"\n\trole=\"menuitem\"\n\t[attr.aria-disabled]=\"disabled()\"\n>\n\t<a>\n\t\t<ng-content></ng-content>\n\t</a>\n</li>\n" });
644
775
  }
645
776
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: DropdownItemComponent, decorators: [{
646
777
  type: Component,
@@ -697,5 +828,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImpor
697
828
  * Generated bundle index. Do not edit.
698
829
  */
699
830
 
700
- export { DropdownChevronComponent, DropdownComponent, DropdownContentComponent, DropdownGroupComponent, DropdownItemCheckboxComponent, DropdownItemComponent, DropdownItemRadioComponent, DropdownLabelComponent, DropdownSeparatorComponent, DropdownService, DropdownTriggerComponent };
831
+ export { DropdownChevronComponent, DropdownComponent, DropdownContentComponent, DropdownGroupComponent, DropdownItemCheckboxComponent, DropdownItemComponent, DropdownItemRadioComponent, DropdownLabelComponent, DropdownSeparatorComponent, DropdownTriggerComponent };
701
832
  //# sourceMappingURL=sixbell-telco-sdk-components-dropdown.mjs.map