@zag-js/popover 2.0.0-next.3 → 2.0.0-next.4

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,250 +1,363 @@
1
- import { Machine, EventObject, Service } from '@zag-js/core';
2
- import { DismissableElementHandlers, PersistentElementOptions, LayerSnapshot } from '@zag-js/dismissable';
3
- import { PositioningOptions, Placement, PlacementSide } from '@zag-js/popper';
4
- export { Placement, PositioningOptions } from '@zag-js/popper';
5
- import { PropTypes, CommonProperties, DirectionProperty, MaybeElement } from '@zag-js/types';
6
-
7
- interface OpenChangeDetails {
8
- open: boolean;
1
+ import { ViewportSize } from "./popover.style.js";
2
+ import { DismissableElementHandlers, LayerSnapshot, PersistentElementOptions } from "@zag-js/dismissable";
3
+ import { CommonProperties, DirectionProperty, MaybeElement, PopupActivationDirection, PropTypes } from "@zag-js/types";
4
+ import { EventObject, Machine, Service } from "@zag-js/core";
5
+ import { AnimationFrame } from "@zag-js/dom-query";
6
+ import { Placement, PlacementSide, PositioningOptions } from "@zag-js/popper";
7
+ /**
8
+ * Why the next animation should be skipped:
9
+ * - `click`: opened or closed from the keyboard on the trigger
10
+ * - `dismiss`: closed with Escape
11
+ * - `focus`: closed because focus left
12
+ * - `trigger-change`: moved between triggers, so repositioning snaps
13
+ */
14
+ export type InstantType = "click" | "dismiss" | "focus" | "trigger-change" | null;
15
+ /**
16
+ * What opened or closed the popover:
17
+ * - `trigger-click`: the trigger was pressed
18
+ * - `close-trigger`: the close trigger was pressed
19
+ * - `escape-key`: Escape was pressed
20
+ * - `interact-outside`: the pointer was pressed outside
21
+ * - `focus-outside`: focus moved outside
22
+ * - `script`: `setOpen` was called
23
+ */
24
+ export type OpenChangeReason = "trigger-click" | "close-trigger" | "escape-key" | "interact-outside" | "focus-outside" | "script";
25
+ export interface OpenChangeDetails {
26
+ open: boolean;
27
+ /**
28
+ * What opened or closed the popover
29
+ */
30
+ reason?: OpenChangeReason | undefined;
9
31
  }
10
- interface TriggerValueChangeDetails {
11
- /**
12
- * The value of the trigger
13
- */
14
- value: string | null;
15
- /**
16
- * The trigger element
17
- */
18
- triggerElement: HTMLElement | null;
32
+ export interface TriggerValueChangeDetails {
33
+ /**
34
+ * The value of the trigger
35
+ */
36
+ value: string | null;
37
+ /**
38
+ * The trigger element
39
+ */
40
+ triggerElement: HTMLElement | null;
19
41
  }
20
- interface IntlTranslations {
21
- closeTriggerLabel?: string | undefined;
42
+ export interface IntlTranslations {
43
+ closeTriggerLabel?: string | undefined;
22
44
  }
23
- interface ElementIds {
24
- anchor?: string | undefined;
25
- trigger?: (string | ((value?: string) => string)) | undefined;
26
- content?: string | undefined;
27
- title?: string | undefined;
28
- description?: string | undefined;
29
- closeTrigger?: string | undefined;
30
- positioner?: string | undefined;
31
- arrow?: string | undefined;
45
+ export interface ElementIds {
46
+ anchor?: string | undefined;
47
+ trigger?: (string | ((value?: string) => string)) | undefined;
48
+ content?: string | undefined;
49
+ title?: string | undefined;
50
+ description?: string | undefined;
51
+ closeTrigger?: string | undefined;
52
+ positioner?: string | undefined;
53
+ arrow?: string | undefined;
32
54
  }
33
- interface PopoverProps extends CommonProperties, DirectionProperty, DismissableElementHandlers, PersistentElementOptions {
34
- /**
35
- * Specifies the localized strings that identifies the accessibility elements and their states
36
- */
37
- translations?: IntlTranslations | undefined;
38
- /**
39
- * The ids of the elements in the popover. Useful for composition.
40
- */
41
- ids?: ElementIds | undefined;
42
- /**
43
- * Whether the popover should be modal. When set to `true`:
44
- * - interaction with outside elements will be disabled
45
- * - only popover content will be visible to screen readers
46
- * - scrolling is blocked
47
- * - focus is trapped within the popover
48
- *
49
- * @default false
50
- */
51
- modal?: boolean | undefined;
52
- /**
53
- * Whether to automatically set focus on the first focusable
54
- * content within the popover when opened.
55
- *
56
- * @default true
57
- */
58
- autoFocus?: boolean | undefined;
59
- /**
60
- * The element to focus on when the popover is opened.
61
- */
62
- initialFocusEl?: (() => HTMLElement | null) | null | undefined;
63
- /**
64
- * Element to receive focus when the popover is closed.
65
- */
66
- finalFocusEl?: (() => MaybeElement) | undefined;
67
- /**
68
- * Whether to restore focus to the element that had focus before the popover was opened.
69
- *
70
- * @default true
71
- */
72
- restoreFocus?: boolean | undefined;
73
- /**
74
- * Whether to close the popover when the user clicks outside of the popover.
75
- * @default true
76
- */
77
- closeOnInteractOutside?: boolean | undefined;
78
- /**
79
- * Whether to close the popover when the escape key is pressed.
80
- * @default true
81
- */
82
- closeOnEscape?: boolean | undefined;
83
- /**
84
- * Function invoked when the popover opens or closes
85
- */
86
- onOpenChange?: ((details: OpenChangeDetails) => void) | undefined;
87
- /**
88
- * The user provided options used to position the popover content
89
- */
90
- positioning?: PositioningOptions | undefined;
91
- /**
92
- * The controlled open state of the popover
93
- */
94
- open?: boolean | undefined;
95
- /**
96
- * The initial open state of the popover when rendered.
97
- * Use when you don't need to control the open state of the popover.
98
- */
99
- defaultOpen?: boolean | undefined;
100
- /**
101
- * The controlled trigger value
102
- */
103
- triggerValue?: string | null | undefined;
104
- /**
105
- * The initial trigger value when rendered.
106
- * Use when you don't need to control the trigger value.
107
- */
108
- defaultTriggerValue?: string | null | undefined;
109
- /**
110
- * Function called when the trigger value changes.
111
- */
112
- onTriggerValueChange?: ((details: TriggerValueChangeDetails) => void) | undefined;
55
+ export interface PopoverProps extends CommonProperties, DirectionProperty, DismissableElementHandlers, PersistentElementOptions {
56
+ /**
57
+ * Specifies the localized strings that identifies the accessibility elements and their states
58
+ */
59
+ translations?: IntlTranslations | undefined;
60
+ /**
61
+ * The ids of the elements in the popover. Useful for composition.
62
+ */
63
+ ids?: ElementIds | undefined;
64
+ /**
65
+ * Whether the popover should be modal. When set to `true`:
66
+ * - interaction with outside elements will be disabled
67
+ * - only popover content will be visible to screen readers
68
+ * - scrolling is blocked
69
+ * - focus is trapped within the popover
70
+ *
71
+ * @default false
72
+ */
73
+ modal?: boolean | undefined;
74
+ /**
75
+ * Whether to automatically set focus on the first focusable
76
+ * content within the popover when opened.
77
+ *
78
+ * @default true
79
+ */
80
+ autoFocus?: boolean | undefined;
81
+ /**
82
+ * The element to focus on when the popover is opened.
83
+ * Return `false` to skip moving focus, or `null` to use the default.
84
+ */
85
+ initialFocusEl?: (() => HTMLElement | null | false) | null | undefined;
86
+ /**
87
+ * Element to receive focus when the popover is closed.
88
+ */
89
+ finalFocusEl?: (() => MaybeElement) | undefined;
90
+ /**
91
+ * Whether to restore focus to the element that had focus before the popover was opened.
92
+ *
93
+ * @default true
94
+ */
95
+ restoreFocus?: boolean | undefined;
96
+ /**
97
+ * Whether to close the popover when the user clicks outside of the popover.
98
+ * @default true
99
+ */
100
+ closeOnInteractOutside?: boolean | undefined;
101
+ /**
102
+ * Whether to close the popover when the escape key is pressed.
103
+ * @default true
104
+ */
105
+ closeOnEscape?: boolean | undefined;
106
+ /**
107
+ * Function invoked when the popover opens or closes
108
+ */
109
+ onOpenChange?: ((details: OpenChangeDetails) => void) | undefined;
110
+ /**
111
+ * The user provided options used to position the popover content
112
+ */
113
+ positioning?: PositioningOptions | undefined;
114
+ /**
115
+ * The controlled open state of the popover
116
+ */
117
+ open?: boolean | undefined;
118
+ /**
119
+ * The initial open state of the popover when rendered.
120
+ * Use when you don't need to control the open state of the popover.
121
+ */
122
+ defaultOpen?: boolean | undefined;
123
+ /**
124
+ * The controlled trigger value
125
+ */
126
+ triggerValue?: string | null | undefined;
127
+ /**
128
+ * The initial trigger value when rendered.
129
+ * Use when you don't need to control the trigger value.
130
+ */
131
+ defaultTriggerValue?: string | null | undefined;
132
+ /**
133
+ * Function called when the trigger value changes.
134
+ */
135
+ onTriggerValueChange?: ((details: TriggerValueChangeDetails) => void) | undefined;
113
136
  }
114
137
  type PropsWithDefault = "closeOnInteractOutside" | "closeOnEscape" | "modal" | "autoFocus" | "restoreFocus" | "positioning";
115
138
  interface PrivateContext {
116
- /**
117
- * The computed layer stack state used for declarative styles and attributes.
118
- */
119
- layer: LayerSnapshot | null;
120
- /**
121
- * The elements that are rendered on mount
122
- */
123
- renderedElements: {
124
- title: boolean;
125
- description: boolean;
126
- };
127
- /**
128
- * The computed placement (maybe different from initial placement)
129
- */
130
- currentPlacement?: Placement | undefined;
131
- /**
132
- * The trigger value
133
- */
134
- triggerValue: string | null;
139
+ /**
140
+ * The computed layer stack state used for declarative styles and attributes.
141
+ */
142
+ layer: LayerSnapshot | null;
143
+ /**
144
+ * The elements that are rendered on mount
145
+ */
146
+ renderedElements: {
147
+ title: boolean;
148
+ description: boolean;
149
+ viewport: boolean;
150
+ };
151
+ /**
152
+ * The computed placement (maybe different from initial placement)
153
+ */
154
+ currentPlacement?: Placement | undefined;
155
+ /**
156
+ * The trigger value
157
+ */
158
+ triggerValue: string | null;
159
+ /**
160
+ * Where the current trigger sits relative to the previous one, after switching triggers while open
161
+ */
162
+ activationDirection: PopupActivationDirection | null;
163
+ /** The trigger value before the last switch, kept until the switch ends */
164
+ previousTriggerValue: string | null;
165
+ /**
166
+ * Why the next animation should be skipped
167
+ */
168
+ instant: InstantType;
169
+ /**
170
+ * Whether the content is animating between triggers
171
+ */
172
+ transitioning: boolean;
173
+ /**
174
+ * The size of the current content, when the viewport is rendered
175
+ */
176
+ viewportSize: ViewportSize | null;
135
177
  }
136
- interface PopoverSchema {
137
- props: PopoverProps;
138
- defaultPropKey: PropsWithDefault;
139
- state: "open" | "closed";
140
- context: PrivateContext;
141
- computed: {};
142
- event: EventObject;
143
- action: string;
144
- effect: string;
145
- guard: string;
178
+ export interface PopoverSchema {
179
+ props: PopoverProps;
180
+ defaultPropKey: PropsWithDefault;
181
+ state: "open" | "closed";
182
+ context: PrivateContext;
183
+ computed: {};
184
+ refs: {
185
+ renderedFrame: AnimationFrame;
186
+ initialFocusFrame: AnimationFrame;
187
+ cancelTriggerSwitch: VoidFunction | null;
188
+ awaitingViewportSize: boolean;
189
+ };
190
+ event: EventObject;
191
+ action: string;
192
+ effect: string;
193
+ guard: string;
146
194
  }
147
- type PopoverService = Service<PopoverSchema>;
148
- type PopoverMachine = Machine<PopoverSchema>;
149
- interface TriggerProps {
150
- /**
151
- * The value that identifies this specific trigger
152
- */
153
- value?: string | undefined;
195
+ export type PopoverService = Service<PopoverSchema>;
196
+ export type PopoverMachine = Machine<PopoverSchema>;
197
+ export interface TriggerProps {
198
+ /**
199
+ * The value that identifies this specific trigger
200
+ */
201
+ value?: string | undefined;
154
202
  }
155
- interface TriggerState {
156
- /**
157
- * The value that identifies this specific trigger
158
- */
159
- value: string | undefined;
160
- /**
161
- * Whether this trigger is the one that opened the popover
162
- */
163
- current: boolean;
164
- /**
165
- * Whether the popover is open
166
- */
167
- open: boolean;
203
+ export interface TriggerState {
204
+ /**
205
+ * The value that identifies this specific trigger
206
+ */
207
+ value: string | undefined;
208
+ /**
209
+ * Whether this trigger is the one that opened the popover
210
+ */
211
+ current: boolean;
212
+ /**
213
+ * Whether the popover is open
214
+ */
215
+ open: boolean;
168
216
  }
169
- interface PositionerState {
170
- /**
171
- * Whether the popover is nested within another layered element
172
- */
173
- nested: boolean;
174
- /**
175
- * Whether the popover has nested layered elements within it
176
- */
177
- hasNested: boolean;
217
+ export interface PositionerState {
218
+ /**
219
+ * Whether the popover is nested within another layered element
220
+ */
221
+ nested: boolean;
222
+ /**
223
+ * Whether the popover is moving from one trigger to another
224
+ */
225
+ transitioning: boolean;
226
+ /**
227
+ * Why the next animation should be skipped
228
+ */
229
+ instant: InstantType;
230
+ /**
231
+ * Whether the popover has nested layered elements within it
232
+ */
233
+ hasNested: boolean;
178
234
  }
179
- interface ContentState {
180
- /**
181
- * Whether the popover is open
182
- */
183
- open: boolean;
184
- /**
185
- * Whether the popover is modal
186
- */
187
- modal: boolean;
188
- /**
189
- * Whether the popover is nested within another layered element
190
- */
191
- nested: boolean;
192
- /**
193
- * Whether the popover has nested layered elements within it
194
- */
195
- hasNested: boolean;
196
- /**
197
- * The current placement of the content relative to the trigger
198
- */
199
- placement: Placement | undefined;
200
- /**
201
- * The side of the trigger the content is placed on
202
- */
203
- side: PlacementSide | undefined;
235
+ export interface ContentProps {
236
+ /**
237
+ * The trigger value this content belongs to. Use one content per trigger inside the viewport.
238
+ */
239
+ value?: string | undefined;
204
240
  }
205
- interface PopoverApi<T extends PropTypes = PropTypes> {
206
- /**
207
- * Whether the popover is open
208
- */
209
- open: boolean;
210
- /**
211
- * Function to open or close the popover
212
- */
213
- setOpen: (open: boolean) => void;
214
- /**
215
- * The trigger value
216
- */
217
- triggerValue: string | null;
218
- /**
219
- * Function to set the trigger value
220
- */
221
- setTriggerValue: (value: string | null) => void;
222
- /**
223
- * Function to reposition the popover
224
- */
225
- reposition: (options?: Partial<PositioningOptions>) => void;
226
- getArrowProps: () => T["element"];
227
- getArrowTipProps: () => T["element"];
228
- getAnchorProps: () => T["element"];
229
- /**
230
- * Returns the state of a specific trigger, including whether it's the currently active one
231
- */
232
- getTriggerState: (props?: TriggerProps) => TriggerState;
233
- getTriggerProps: (props?: TriggerProps) => T["button"];
234
- getIndicatorProps: () => T["element"];
235
- /**
236
- * Returns the state of the positioner
237
- */
238
- getPositionerState: () => PositionerState;
239
- getPositionerProps: () => T["element"];
240
- /**
241
- * Returns the state of the content
242
- */
243
- getContentState: () => ContentState;
244
- getContentProps: () => T["element"];
245
- getTitleProps: () => T["element"];
246
- getDescriptionProps: () => T["element"];
247
- getCloseTriggerProps: () => T["button"];
241
+ export interface ContentState {
242
+ /**
243
+ * Why the next animation should be skipped
244
+ */
245
+ instant: InstantType;
246
+ /**
247
+ * Whether the content is shown. For a content with a `value`, whether its trigger is the current one.
248
+ */
249
+ open: boolean;
250
+ /**
251
+ * Whether the popover is modal
252
+ */
253
+ modal: boolean;
254
+ /**
255
+ * Whether the popover is nested within another layered element
256
+ */
257
+ nested: boolean;
258
+ /**
259
+ * Whether the popover has nested layered elements within it
260
+ */
261
+ hasNested: boolean;
262
+ /**
263
+ * The current placement of the content relative to the trigger
264
+ */
265
+ placement: Placement | undefined;
266
+ /**
267
+ * The side of the trigger the content is placed on
268
+ */
269
+ side: PlacementSide | undefined;
270
+ /**
271
+ * Where the current trigger sits relative to the previous one, e.g. `"right"` or `"left down"`.
272
+ * `null` until the popover switches triggers while open.
273
+ */
274
+ activationDirection: PopupActivationDirection | null;
248
275
  }
249
-
250
- export type { ContentState, ElementIds, IntlTranslations, OpenChangeDetails, PopoverApi, PopoverMachine, PopoverProps, PopoverSchema, PopoverService, PositionerState, TriggerProps, TriggerState, TriggerValueChangeDetails };
276
+ export interface ViewportState {
277
+ /**
278
+ * Whether the popover is open
279
+ */
280
+ open: boolean;
281
+ /**
282
+ * Why the next animation should be skipped
283
+ */
284
+ instant: InstantType;
285
+ /**
286
+ * The side of the trigger the viewport is placed on
287
+ */
288
+ side: PlacementSide | undefined;
289
+ /**
290
+ * Where the current trigger sits relative to the previous one, e.g. `"right"` or `"left down"`.
291
+ * `null` until the popover switches triggers while open.
292
+ */
293
+ activationDirection: PopupActivationDirection | null;
294
+ /**
295
+ * Whether the popover is moving between triggers
296
+ */
297
+ transitioning: boolean;
298
+ }
299
+ export interface PopoverApi<T extends PropTypes = PropTypes> {
300
+ /**
301
+ * Whether the popover is open
302
+ */
303
+ open: boolean;
304
+ /**
305
+ * Function to open or close the popover
306
+ */
307
+ setOpen: (open: boolean, reason?: OpenChangeReason) => void;
308
+ /**
309
+ * The trigger value
310
+ */
311
+ triggerValue: string | null;
312
+ /**
313
+ * Function to set the trigger value
314
+ */
315
+ setTriggerValue: (value: string | null) => void;
316
+ /**
317
+ * Where the current trigger sits relative to the previous one, after switching triggers while open
318
+ */
319
+ activationDirection: PopupActivationDirection | null;
320
+ /**
321
+ * Returns the trigger values whose content to render: the current one, plus the previous one while
322
+ * it animates out after a switch. Oldest first.
323
+ */
324
+ getContentValues: () => string[];
325
+ /**
326
+ * Function to reposition the popover
327
+ */
328
+ reposition: (options?: Partial<PositioningOptions>) => void;
329
+ getArrowProps: () => T["element"];
330
+ getArrowTipProps: () => T["element"];
331
+ getAnchorProps: () => T["element"];
332
+ /**
333
+ * Returns the state of a specific trigger, including whether it's the currently active one
334
+ */
335
+ getTriggerState: (props?: TriggerProps) => TriggerState;
336
+ getTriggerProps: (props?: TriggerProps) => T["button"];
337
+ getIndicatorProps: () => T["element"];
338
+ /**
339
+ * Returns the state of the positioner
340
+ */
341
+ getPositionerState: () => PositionerState;
342
+ getPositionerProps: () => T["element"];
343
+ /**
344
+ * Returns the state of the content
345
+ */
346
+ getContentState: (props?: ContentProps) => ContentState;
347
+ getContentProps: (props?: ContentProps) => T["element"];
348
+ /**
349
+ * Returns the state of the viewport
350
+ */
351
+ getViewportState: () => ViewportState;
352
+ getViewportProps: () => T["element"];
353
+ /**
354
+ * Pass the content's `value` when there's one content per trigger
355
+ */
356
+ getTitleProps: (props?: ContentProps) => T["element"];
357
+ /**
358
+ * Pass the content's `value` when there's one content per trigger
359
+ */
360
+ getDescriptionProps: (props?: ContentProps) => T["element"];
361
+ getCloseTriggerProps: () => T["button"];
362
+ }
363
+ export type { Placement, PositioningOptions };
@@ -1,18 +1,4 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/popover.types.ts
17
- var popover_types_exports = {};
18
- module.exports = __toCommonJS(popover_types_exports);
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
4
+ });
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/popover",
3
- "version": "2.0.0-next.3",
3
+ "version": "2.0.0-next.4",
4
4
  "description": "Core logic for the popover widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,16 +29,16 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/anatomy": "2.0.0-next.3",
33
- "@zag-js/aria-hidden": "2.0.0-next.3",
34
- "@zag-js/core": "2.0.0-next.3",
35
- "@zag-js/dom-query": "2.0.0-next.3",
36
- "@zag-js/utils": "2.0.0-next.3",
37
- "@zag-js/dismissable": "2.0.0-next.3",
38
- "@zag-js/popper": "2.0.0-next.3",
39
- "@zag-js/remove-scroll": "2.0.0-next.3",
40
- "@zag-js/types": "2.0.0-next.3",
41
- "@zag-js/focus-trap": "2.0.0-next.3"
32
+ "@zag-js/anatomy": "2.0.0-next.4",
33
+ "@zag-js/aria-hidden": "2.0.0-next.4",
34
+ "@zag-js/core": "2.0.0-next.4",
35
+ "@zag-js/dom-query": "2.0.0-next.4",
36
+ "@zag-js/utils": "2.0.0-next.4",
37
+ "@zag-js/dismissable": "2.0.0-next.4",
38
+ "@zag-js/popper": "2.0.0-next.4",
39
+ "@zag-js/remove-scroll": "2.0.0-next.4",
40
+ "@zag-js/types": "2.0.0-next.4",
41
+ "@zag-js/focus-trap": "2.0.0-next.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "clean-package": "2.2.0"
@@ -71,7 +71,7 @@
71
71
  "./package.json": "./package.json"
72
72
  },
73
73
  "scripts": {
74
- "build": "tsup",
74
+ "build": "tsdown",
75
75
  "lint": "oxlint src",
76
76
  "typecheck": "tsc --noEmit"
77
77
  }