@zealakit/overlay-react 1.0.0 → 1.0.1

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.
@@ -39,9 +39,18 @@ export declare function resolveExpandPlan({ placement, direction, rtl, }: {
39
39
  rtl?: boolean;
40
40
  }): ExpandPlan;
41
41
  /**
42
- * Keyframes for expand/collapse: the popup scales out of the anchor edge while
43
- * it fades in (opacity 0 to 1), and collapse is the exact reverse (opacity 1
44
- * to 0). Reduced motion keeps only the fade.
42
+ * How far (px) the reveal extends past the popup on the sides that do not
43
+ * move, so the arrow and box-shadow are not clipped while it grows.
44
+ */
45
+ export declare const EXPAND_CLIP_OVERFLOW = 32;
46
+ /** Share of the duration the expand fade takes; the growth uses all of it. */
47
+ export declare const EXPAND_FADE_PORTION = 0.3;
48
+ /**
49
+ * Keyframes for expand/collapse: the popup is revealed out of the anchor edge
50
+ * with a `clip-path` while it fades in (opacity 0 to 1), and collapse is the
51
+ * exact reverse. Content is never scaled, so text keeps its proportions.
52
+ * Without an anchor (Dialog) a uniform, slight scale is used. Reduced motion
53
+ * keeps only the fade.
45
54
  */
46
55
  export declare function createExpandKeyframes(phase: AnimationPhase, plan: ExpandPlan, reducedMotion?: boolean): Keyframe[];
47
56
  export { splitPlacement };
@@ -79,17 +79,52 @@ export function resolveExpandPlan({ placement, direction = "auto", rtl = false,
79
79
  };
80
80
  }
81
81
  /**
82
- * Keyframes for expand/collapse: the popup scales out of the anchor edge while
83
- * it fades in (opacity 0 to 1), and collapse is the exact reverse (opacity 1
84
- * to 0). Reduced motion keeps only the fade.
82
+ * How far (px) the reveal extends past the popup on the sides that do not
83
+ * move, so the arrow and box-shadow are not clipped while it grows.
84
+ */
85
+ export const EXPAND_CLIP_OVERFLOW = 32;
86
+ /**
87
+ * `clip-path` that reveals nothing but the overflow margin at the anchor edge.
88
+ * The clipped edge is the one opposite the anchor, so the popup grows away
89
+ * from it without scaling its content.
90
+ */
91
+ function expandClip(side, shown) {
92
+ const open = `${-EXPAND_CLIP_OVERFLOW}px`;
93
+ const closed = shown ? open : "100%";
94
+ // inset(top right bottom left)
95
+ switch (side) {
96
+ case "bottom":
97
+ return `inset(${open} ${open} ${closed} ${open})`;
98
+ case "top":
99
+ return `inset(${closed} ${open} ${open} ${open})`;
100
+ case "right":
101
+ return `inset(${open} ${closed} ${open} ${open})`;
102
+ default:
103
+ return `inset(${open} ${open} ${open} ${closed})`;
104
+ }
105
+ }
106
+ /** Share of the duration the expand fade takes; the growth uses all of it. */
107
+ export const EXPAND_FADE_PORTION = 0.3;
108
+ /**
109
+ * Keyframes for expand/collapse: the popup is revealed out of the anchor edge
110
+ * with a `clip-path` while it fades in (opacity 0 to 1), and collapse is the
111
+ * exact reverse. Content is never scaled, so text keeps its proportions.
112
+ * Without an anchor (Dialog) a uniform, slight scale is used. Reduced motion
113
+ * keeps only the fade.
85
114
  */
86
115
  export function createExpandKeyframes(phase, plan, reducedMotion = false) {
87
- const from = reducedMotion
88
- ? {}
89
- : {
90
- scale: plan.axis === "y" ? "1 0" : plan.axis === "x" ? "0 1" : "0.95 0.95",
91
- };
92
- const to = reducedMotion ? {} : { scale: "1 1" };
116
+ let from = {};
117
+ let to = {};
118
+ if (!reducedMotion) {
119
+ if (plan.side !== null && plan.axis !== "both") {
120
+ from = { clipPath: expandClip(plan.side, false) };
121
+ to = { clipPath: expandClip(plan.side, true) };
122
+ }
123
+ else {
124
+ from = { scale: "0.95 0.95" };
125
+ to = { scale: "1 1" };
126
+ }
127
+ }
93
128
  const hidden = {
94
129
  opacity: 0,
95
130
  transformOrigin: plan.transformOrigin,
@@ -100,6 +135,21 @@ export function createExpandKeyframes(phase, plan, reducedMotion = false) {
100
135
  transformOrigin: plan.transformOrigin,
101
136
  ...to,
102
137
  };
103
- return phase === "enter" ? [hidden, shown] : [shown, hidden];
138
+ if (reducedMotion) {
139
+ return phase === "enter" ? [hidden, shown] : [shown, hidden];
140
+ }
141
+ // The fade finishes early so the growth stays visible instead of playing
142
+ // while the popup is still nearly transparent.
143
+ return phase === "enter"
144
+ ? [
145
+ { ...hidden, offset: 0 },
146
+ { opacity: 1, offset: EXPAND_FADE_PORTION },
147
+ { ...shown, offset: 1 },
148
+ ]
149
+ : [
150
+ { ...shown, offset: 0 },
151
+ { opacity: 1, offset: 1 - EXPAND_FADE_PORTION },
152
+ { ...hidden, offset: 1 },
153
+ ];
104
154
  }
105
155
  export { splitPlacement };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zealakit/overlay-react",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "A lightweight foundation for building floating, layered, and interactive headless UI components for React.",
5
5
  "keywords": [
6
6
  "overlay",