ng-primitives 0.44.0 → 0.45.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.
Files changed (45) hide show
  1. package/combobox/combobox/combobox-state.d.ts +3 -2
  2. package/combobox/combobox/combobox.d.ts +9 -3
  3. package/combobox/combobox-button/combobox-button.d.ts +3 -2
  4. package/combobox/combobox-dropdown/combobox-dropdown.d.ts +52 -2
  5. package/combobox/combobox-input/combobox-input.d.ts +3 -2
  6. package/combobox/combobox-option/combobox-option.d.ts +3 -2
  7. package/combobox/combobox-portal/combobox-portal.d.ts +8 -21
  8. package/example-theme/index.css +1 -0
  9. package/fesm2022/ng-primitives-combobox.mjs +63 -87
  10. package/fesm2022/ng-primitives-combobox.mjs.map +1 -1
  11. package/fesm2022/ng-primitives-focus-trap.mjs +9 -1
  12. package/fesm2022/ng-primitives-focus-trap.mjs.map +1 -1
  13. package/fesm2022/ng-primitives-listbox.mjs +1 -1
  14. package/fesm2022/ng-primitives-listbox.mjs.map +1 -1
  15. package/fesm2022/ng-primitives-menu.mjs +372 -63
  16. package/fesm2022/ng-primitives-menu.mjs.map +1 -1
  17. package/fesm2022/ng-primitives-popover.mjs +62 -332
  18. package/fesm2022/ng-primitives-popover.mjs.map +1 -1
  19. package/fesm2022/ng-primitives-portal.mjs +359 -2
  20. package/fesm2022/ng-primitives-portal.mjs.map +1 -1
  21. package/fesm2022/ng-primitives-tooltip.mjs +51 -176
  22. package/fesm2022/ng-primitives-tooltip.mjs.map +1 -1
  23. package/focus-trap/focus-trap/focus-trap-state.d.ts +1 -0
  24. package/focus-trap/focus-trap/focus-trap.d.ts +5 -0
  25. package/menu/config/menu-config.d.ts +42 -0
  26. package/menu/index.d.ts +5 -1
  27. package/menu/menu/menu.d.ts +6 -2
  28. package/menu/menu-trigger/menu-trigger-state.d.ts +37 -0
  29. package/menu/menu-trigger/menu-trigger.d.ts +87 -13
  30. package/menu/submenu-trigger/submenu-trigger-state.d.ts +56 -0
  31. package/menu/submenu-trigger/submenu-trigger.d.ts +62 -10
  32. package/package.json +1 -1
  33. package/popover/index.d.ts +1 -2
  34. package/popover/popover/popover.d.ts +2 -43
  35. package/popover/popover-trigger/popover-trigger.d.ts +13 -107
  36. package/portal/index.d.ts +2 -0
  37. package/portal/overlay-token.d.ts +12 -0
  38. package/portal/overlay.d.ts +170 -0
  39. package/schematics/ng-generate/templates/combobox/combobox.__fileSuffix@dasherize__.ts.template +31 -0
  40. package/tooltip/index.d.ts +1 -1
  41. package/tooltip/tooltip/tooltip.d.ts +3 -25
  42. package/tooltip/tooltip-trigger/tooltip-trigger.d.ts +12 -63
  43. package/popover/popover/popover-token.d.ts +0 -10
  44. package/popover/utils/transform-origin.d.ts +0 -2
  45. package/tooltip/tooltip/tooltip-token.d.ts +0 -10
@@ -0,0 +1,170 @@
1
+ import { FocusOrigin } from '@angular/cdk/a11y';
2
+ import { Injector, Provider, TemplateRef, Type } from '@angular/core';
3
+ import { Middleware, Placement, Strategy } from '@floating-ui/dom';
4
+ import { Subject } from 'rxjs';
5
+ /**
6
+ * Configuration options for creating an overlay
7
+ * @internal
8
+ */
9
+ export interface NgpOverlayConfig<T = unknown> {
10
+ /** Content to display in the overlay (component or template) */
11
+ content: NgpOverlayContent<T>;
12
+ /** The element that triggers the overlay */
13
+ triggerElement: HTMLElement;
14
+ /** The injector to use for creating the portal */
15
+ injector: Injector;
16
+ /** Context data to pass to the overlay content */
17
+ context?: T | null;
18
+ /** Container element to attach the overlay to (defaults to document.body) */
19
+ container?: HTMLElement | null;
20
+ /** Preferred placement of the overlay relative to the trigger */
21
+ placement?: Placement;
22
+ /** Offset distance between the overlay and trigger in pixels */
23
+ offset?: number;
24
+ /** Whether to enable flip behavior when space is limited */
25
+ flip?: boolean;
26
+ /** Delay before showing the overlay in milliseconds */
27
+ showDelay?: number;
28
+ /** Delay before hiding the overlay in milliseconds */
29
+ hideDelay?: number;
30
+ /** Whether the overlay should be positioned with fixed or absolute strategy */
31
+ strategy?: Strategy;
32
+ /** The scroll strategy to use for the overlay */
33
+ scrollBehaviour?: 'reposition' | 'block';
34
+ /** Whether to close the overlay when clicking outside */
35
+ closeOnOutsideClick?: boolean;
36
+ /** Whether to close the overlay when pressing escape */
37
+ closeOnEscape?: boolean;
38
+ /** Whether to restore focus to the trigger element when hiding the overlay */
39
+ restoreFocus?: boolean;
40
+ /** Additional middleware for floating UI positioning */
41
+ additionalMiddleware?: Middleware[];
42
+ /** Additional providers */
43
+ providers?: Provider[];
44
+ }
45
+ /** Type for overlay content which can be either a template or component */
46
+ export type NgpOverlayContent<T> = TemplateRef<NgpOverlayTemplateContext<T>> | Type<unknown>;
47
+ /** Context for template-based overlays */
48
+ export type NgpOverlayTemplateContext<T> = {
49
+ $implicit: T;
50
+ };
51
+ /**
52
+ * NgpOverlay manages the lifecycle and positioning of overlay UI elements.
53
+ * It abstracts the common behavior shared by tooltips, popovers, menus, etc.
54
+ * @internal
55
+ */
56
+ export declare class NgpOverlay<T = unknown> {
57
+ private config;
58
+ private readonly disposables;
59
+ private readonly document;
60
+ private readonly destroyRef;
61
+ private readonly viewContainerRef;
62
+ private readonly viewportRuler;
63
+ private readonly focusMonitor;
64
+ /** Access any parent overlays */
65
+ private readonly parentOverlay;
66
+ /** Signal tracking the portal instance */
67
+ private readonly portal;
68
+ /** Signal tracking the overlay position */
69
+ readonly position: import("@angular/core").WritableSignal<{
70
+ x: number;
71
+ y: number;
72
+ }>;
73
+ /** Signal tracking the trigger element width */
74
+ readonly triggerWidth: import("@angular/core").WritableSignal<number | null>;
75
+ /** The transform origin for the overlay */
76
+ readonly transformOrigin: import("@angular/core").WritableSignal<string>;
77
+ /** Function to dispose the positioning auto-update */
78
+ private disposePositioning?;
79
+ /** Timeout handle for showing the overlay */
80
+ private openTimeout?;
81
+ /** Timeout handle for hiding the overlay */
82
+ private closeTimeout?;
83
+ /** Signal tracking whether the overlay is open */
84
+ readonly isOpen: import("@angular/core").WritableSignal<boolean>;
85
+ /** The scroll strategy */
86
+ private scrollStrategy;
87
+ /** An observable that emits when the overlay is closing */
88
+ readonly closing: Subject<void>;
89
+ /**
90
+ * Creates a new overlay instance
91
+ * @param config Initial configuration for the overlay
92
+ * @param destroyRef Reference for automatic cleanup
93
+ */
94
+ constructor(config: NgpOverlayConfig<T>);
95
+ /**
96
+ * Show the overlay with the specified delay
97
+ * @param showDelay Optional delay to override the configured showDelay
98
+ */
99
+ show(): Promise<void>;
100
+ /**
101
+ * Hide the overlay with the specified delay
102
+ * @param options Optional options for hiding the overlay
103
+ */
104
+ hide(options?: OverlayTriggerOptions): void;
105
+ /**
106
+ * Update the configuration of this overlay
107
+ * @param config New configuration (partial)
108
+ */
109
+ updateConfig(config: Partial<NgpOverlayConfig<T>>): void;
110
+ /**
111
+ * Immediately hide the overlay without any delay
112
+ */
113
+ hideImmediate(): void;
114
+ /**
115
+ * Toggle the overlay open/closed state
116
+ */
117
+ toggle(): void;
118
+ /**
119
+ * Force update the position of the overlay
120
+ */
121
+ updatePosition(): void;
122
+ /**
123
+ * Completely destroy this overlay instance
124
+ */
125
+ destroy(): void;
126
+ /**
127
+ * Get the elements of the overlay
128
+ */
129
+ getElements(): HTMLElement[];
130
+ /**
131
+ * Internal method to create the overlay
132
+ */
133
+ private createOverlay;
134
+ /**
135
+ * Internal method to setup positioning of the overlay
136
+ */
137
+ private setupPositioning;
138
+ /**
139
+ * Compute the overlay position using floating-ui
140
+ */
141
+ private computePosition;
142
+ /**
143
+ * Internal method to destroy the overlay portal
144
+ */
145
+ private destroyOverlay;
146
+ /**
147
+ * Get the transform origin for the overlay
148
+ */
149
+ private getTransformOrigin;
150
+ }
151
+ /**
152
+ * Helper function to create an overlay in a single call
153
+ * @internal
154
+ */
155
+ export declare function createOverlay<T>(config: NgpOverlayConfig<T>): NgpOverlay<T>;
156
+ /**
157
+ * Helper function to inject the NgpOverlay instance
158
+ * @internal
159
+ */
160
+ export declare function injectOverlay<T>(): NgpOverlay<T>;
161
+ export interface OverlayTriggerOptions {
162
+ /**
163
+ * Whether the visibility change should be immediate.
164
+ */
165
+ immediate?: boolean;
166
+ /**
167
+ * The origin of the focus event that triggered the visibility change.
168
+ */
169
+ origin?: FocusOrigin;
170
+ }
@@ -110,6 +110,15 @@ import { ChangeFn, provideValueAccessor, TouchedFn } from 'ng-primitives/utils';
110
110
  margin-top: 4px;
111
111
  max-height: 240px;
112
112
  overflow-y: auto;
113
+ transform-origin: var(--ngp-combobox-transform-origin);
114
+ }
115
+
116
+ [ngpComboboxDropdown][data-enter] {
117
+ animation: combobox-show 0.1s ease-out;
118
+ }
119
+
120
+ [ngpComboboxDropdown][data-exit] {
121
+ animation: combobox-hide 0.1s ease-out;
113
122
  }
114
123
 
115
124
  [ngpComboboxOption] {
@@ -148,6 +157,28 @@ import { ChangeFn, provideValueAccessor, TouchedFn } from 'ng-primitives/utils';
148
157
  font-weight: 500;
149
158
  text-align: center;
150
159
  }
160
+
161
+ @keyframes combobox-show {
162
+ 0% {
163
+ opacity: 0;
164
+ transform: scale(0.9);
165
+ }
166
+ 100% {
167
+ opacity: 1;
168
+ transform: scale(1);
169
+ }
170
+ }
171
+
172
+ @keyframes combobox-hide {
173
+ 0% {
174
+ opacity: 1;
175
+ transform: scale(1);
176
+ }
177
+ 100% {
178
+ opacity: 0;
179
+ transform: scale(0.9);
180
+ }
181
+ }
151
182
  `,
152
183
  })
153
184
  export class Combobox<%= componentSuffix %> implements ControlValueAccessor {
@@ -1,5 +1,5 @@
1
+ export { injectOverlayContext as injectTooltipContext } from 'ng-primitives/portal';
1
2
  export { NgpTooltipConfig, provideTooltipConfig } from './config/tooltip-config';
2
3
  export { NgpTooltipTrigger } from './tooltip-trigger/tooltip-trigger';
3
4
  export { injectTooltipTriggerState, provideTooltipTriggerState, } from './tooltip-trigger/tooltip-trigger-state';
4
5
  export { NgpTooltip } from './tooltip/tooltip';
5
- export { injectTooltipContext, NgpTooltipContextToken, provideTooltipContext, } from './tooltip/tooltip-token';
@@ -1,35 +1,13 @@
1
- import { OnInit } from '@angular/core';
2
1
  import * as i0 from "@angular/core";
3
2
  import * as i1 from "ng-primitives/internal";
4
3
  /**
5
4
  * Apply the `ngpTooltip` directive to an element that represents the tooltip. This typically would be a `div` inside an `ng-template`.
6
5
  */
7
- export declare class NgpTooltip implements OnInit {
6
+ export declare class NgpTooltip {
8
7
  /**
9
- * Access the tooltip element.
8
+ * Access the overlay.
10
9
  */
11
- private readonly tooltip;
12
- /**
13
- * Access the platform.
14
- */
15
- private readonly platform;
16
- /**
17
- * Access the trigger instance.
18
- */
19
- private readonly trigger;
20
- /**
21
- * Compute the x position of the tooltip.
22
- */
23
- protected readonly x: import("@angular/core").Signal<number>;
24
- /**
25
- * Compute the y position of the tooltip.
26
- */
27
- protected readonly y: import("@angular/core").Signal<number>;
28
- /**
29
- * Derive the transform origin of the popover.
30
- */
31
- protected readonly transformOrigin: import("@angular/core").Signal<string>;
32
- ngOnInit(): void;
10
+ protected readonly overlay: import("ng-primitives/portal").NgpOverlay<unknown>;
33
11
  static ɵfac: i0.ɵɵFactoryDeclaration<NgpTooltip, never>;
34
12
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgpTooltip, "[ngpTooltip]", ["ngpTooltip"], {}, {}, never, never, true, [{ directive: typeof i1.NgpExitAnimation; inputs: {}; outputs: {}; }]>;
35
13
  }
@@ -1,28 +1,16 @@
1
1
  import { BooleanInput, NumberInput } from '@angular/cdk/coercion';
2
- import { OnDestroy, TemplateRef, Type } from '@angular/core';
2
+ import { OnDestroy } from '@angular/core';
3
3
  import { Placement } from '@floating-ui/dom';
4
- import { NgpPortal } from 'ng-primitives/portal';
4
+ import { NgpOverlay, NgpOverlayContent } from 'ng-primitives/portal';
5
5
  import * as i0 from "@angular/core";
6
6
  /**
7
7
  * Apply the `ngpTooltipTrigger` directive to an element that triggers the tooltip to show.
8
8
  */
9
9
  export declare class NgpTooltipTrigger<T = null> implements OnDestroy {
10
- /**
11
- * Access the exit animation manager.
12
- */
13
- private readonly exitAnimationManager;
14
10
  /**
15
11
  * Access the trigger element
16
12
  */
17
13
  private readonly trigger;
18
- /**
19
- * Access the view container ref.
20
- */
21
- private readonly viewContainerRef;
22
- /**
23
- * Access the document.
24
- */
25
- private readonly document;
26
14
  /**
27
15
  * Access the injector.
28
16
  */
@@ -31,14 +19,10 @@ export declare class NgpTooltipTrigger<T = null> implements OnDestroy {
31
19
  * Access the global tooltip configuration.
32
20
  */
33
21
  private readonly config;
34
- /**
35
- * Access the disposable utilities
36
- */
37
- private readonly disposables;
38
22
  /**
39
23
  * Access the tooltip template ref.
40
24
  */
41
- readonly tooltip: import("@angular/core").InputSignal<NgpTooltipContent<T> | null>;
25
+ readonly tooltip: import("@angular/core").InputSignal<NgpOverlayContent<T> | undefined>;
42
26
  /**
43
27
  * Define if the trigger should be disabled.
44
28
  * @default false
@@ -75,48 +59,17 @@ export declare class NgpTooltipTrigger<T = null> implements OnDestroy {
75
59
  */
76
60
  readonly container: import("@angular/core").InputSignal<HTMLElement | null>;
77
61
  /**
78
- * Provide context to the tooltip.
79
- * @default null
80
- */
81
- readonly context: import("@angular/core").InputSignal<T | null>;
82
- /**
83
- * Store the tooltip view ref.
62
+ * Provide context to the tooltip. This can be used to pass data to the tooltip content.
84
63
  */
85
- protected viewRef: import("@angular/core").WritableSignal<NgpPortal | null>;
64
+ readonly context: import("@angular/core").InputSignal<T | undefined>;
86
65
  /**
87
- * Derive the tooltip middleware from the provided configuration.
88
- */
89
- private readonly middleware;
90
- /**
91
- * Store the computed position of the tooltip.
66
+ * The overlay that manages the tooltip
92
67
  * @internal
93
68
  */
94
- readonly position: import("@angular/core").WritableSignal<{
95
- x: number;
96
- y: number;
97
- }>;
98
- /**
99
- * The dispose function to stop computing the position of the tooltip.
100
- */
101
- private dispose?;
102
- /**
103
- * @internal
104
- * Store the trigger width.
105
- */
106
- readonly width: import("@angular/core").WritableSignal<number | null>;
107
- /**
108
- * @internal
109
- * The timeout to open the tooltip.
110
- */
111
- private openTimeout?;
112
- /**
113
- * @internal
114
- * The timeout to close the tooltip.
115
- */
116
- private closeTimeout?;
69
+ readonly overlay: import("@angular/core").WritableSignal<NgpOverlay<T> | null>;
117
70
  /**
71
+ * The open state of the tooltip.
118
72
  * @internal
119
- * Whether the tooltip is open or not.
120
73
  */
121
74
  readonly open: import("@angular/core").Signal<boolean>;
122
75
  /**
@@ -124,7 +77,6 @@ export declare class NgpTooltipTrigger<T = null> implements OnDestroy {
124
77
  * @internal
125
78
  */
126
79
  readonly state: import("ng-primitives/state").CreatedState<NgpTooltipTrigger<T>>;
127
- constructor();
128
80
  ngOnDestroy(): void;
129
81
  /**
130
82
  * Show the tooltip.
@@ -134,13 +86,10 @@ export declare class NgpTooltipTrigger<T = null> implements OnDestroy {
134
86
  * Hide the tooltip.
135
87
  */
136
88
  hide(): void;
137
- private createTooltip;
138
- private destroyTooltip;
89
+ /**
90
+ * Create the overlay that will contain the tooltip
91
+ */
92
+ private createOverlay;
139
93
  static ɵfac: i0.ɵɵFactoryDeclaration<NgpTooltipTrigger<any>, never>;
140
94
  static ɵdir: i0.ɵɵDirectiveDeclaration<NgpTooltipTrigger<any>, "[ngpTooltipTrigger]", ["ngpTooltipTrigger"], { "tooltip": { "alias": "ngpTooltipTrigger"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpTooltipTriggerDisabled"; "required": false; "isSignal": true; }; "placement": { "alias": "ngpTooltipTriggerPlacement"; "required": false; "isSignal": true; }; "offset": { "alias": "ngpTooltipTriggerOffset"; "required": false; "isSignal": true; }; "showDelay": { "alias": "ngpTooltipTriggerShowDelay"; "required": false; "isSignal": true; }; "hideDelay": { "alias": "ngpTooltipTriggerHideDelay"; "required": false; "isSignal": true; }; "flip": { "alias": "ngpTooltipTriggerFlip"; "required": false; "isSignal": true; }; "container": { "alias": "ngpTooltipTriggerContainer"; "required": false; "isSignal": true; }; "context": { "alias": "ngpTooltipTriggerContext"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
141
95
  }
142
- type NgpTooltipTemplateContext<T> = {
143
- $implicit: T;
144
- };
145
- type NgpTooltipContent<T> = TemplateRef<NgpTooltipTemplateContext<T>> | Type<unknown>;
146
- export {};
@@ -1,10 +0,0 @@
1
- import { InjectionToken, ValueProvider } from '@angular/core';
2
- export declare const NgpPopoverContextToken: InjectionToken<unknown>;
3
- /**
4
- * Inject the Popover context
5
- */
6
- export declare function injectPopoverContext<T>(): T;
7
- /**
8
- * Provide the Popover context
9
- */
10
- export declare function providePopoverContext<T>(context: T): ValueProvider;
@@ -1,2 +0,0 @@
1
- import type { Placement } from '@floating-ui/dom';
2
- export declare function getTransformOrigin(placement: Placement): string;
@@ -1,10 +0,0 @@
1
- import { InjectionToken, ValueProvider } from '@angular/core';
2
- export declare const NgpTooltipContextToken: InjectionToken<unknown>;
3
- /**
4
- * Inject the Tooltip context
5
- */
6
- export declare function injectTooltipContext<T>(): T;
7
- /**
8
- * Provide the Tooltip directive instance
9
- */
10
- export declare function provideTooltipContext<T>(context: T): ValueProvider;