plainframe-ui 0.1.4 → 0.1.5

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.
package/dist/index.js CHANGED
@@ -2125,7 +2125,6 @@ import React8, {
2125
2125
  isValidElement as isValidElement4,
2126
2126
  cloneElement as cloneElement4,
2127
2127
  useRef as useRef5,
2128
- useLayoutEffect as useLayoutEffect2,
2129
2128
  useEffect as useEffect3
2130
2129
  } from "react";
2131
2130
  import { css as emCss } from "@emotion/react";
@@ -2294,80 +2293,7 @@ var SubMenuContent = ({ children, css: userCss }) => {
2294
2293
  const { open } = useSub();
2295
2294
  const parentLevel = useContext3(LevelCtx);
2296
2295
  const menuGap = useContext3(GapCtx);
2297
- const clipRef = useRef5(null);
2298
2296
  const innerRef = useRef5(null);
2299
- const seqRef = useRef5(0);
2300
- const firstRef = useRef5(true);
2301
- useLayoutEffect2(() => {
2302
- const clip = clipRef.current;
2303
- const inner = innerRef.current;
2304
- if (!clip || !inner) return;
2305
- const key = ++seqRef.current;
2306
- const dur = "360ms cubic-bezier(.25,.8,.4,1)";
2307
- if (firstRef.current) {
2308
- firstRef.current = false;
2309
- clip.style.transition = "none";
2310
- if (open) {
2311
- clip.style.maxHeight = "none";
2312
- clip.style.overflow = "visible";
2313
- } else {
2314
- clip.style.maxHeight = "0px";
2315
- clip.style.overflow = "hidden";
2316
- }
2317
- return;
2318
- }
2319
- const from = open ? 0 : inner.scrollHeight;
2320
- const to = open ? inner.scrollHeight : 0;
2321
- clip.style.transition = "none";
2322
- clip.style.overflow = "hidden";
2323
- clip.style.maxHeight = `${from}px`;
2324
- void clip.offsetHeight;
2325
- clip.style.transition = `max-height ${dur}`;
2326
- clip.style.maxHeight = `${to}px`;
2327
- const onEnd = (e) => {
2328
- if (e.target !== clip || e.propertyName !== "max-height") return;
2329
- if (key !== seqRef.current) return;
2330
- clip.style.transition = "none";
2331
- if (open) {
2332
- clip.style.maxHeight = "none";
2333
- clip.style.overflow = "visible";
2334
- } else {
2335
- clip.style.maxHeight = "0px";
2336
- clip.style.overflow = "hidden";
2337
- }
2338
- clip.removeEventListener("transitionend", onEnd);
2339
- clip.removeEventListener("transitioncancel", onCancel);
2340
- };
2341
- const onCancel = () => {
2342
- if (key !== seqRef.current) return;
2343
- clip.removeEventListener("transitionend", onEnd);
2344
- clip.removeEventListener("transitioncancel", onCancel);
2345
- };
2346
- clip.addEventListener("transitionend", onEnd);
2347
- clip.addEventListener("transitioncancel", onCancel);
2348
- return () => {
2349
- clip.removeEventListener("transitionend", onEnd);
2350
- clip.removeEventListener("transitioncancel", onCancel);
2351
- };
2352
- }, [open]);
2353
- useLayoutEffect2(() => {
2354
- const clip = clipRef.current;
2355
- const inner = innerRef.current;
2356
- if (!clip || !inner || !window.ResizeObserver) return;
2357
- const ro = new window.ResizeObserver(() => {
2358
- if (!open) return;
2359
- const isAnimating = clip.style.maxHeight !== "none" && (clip.style.transition || "").includes("max-height");
2360
- if (isAnimating) {
2361
- clip.style.transition = "none";
2362
- clip.style.maxHeight = "none";
2363
- clip.style.overflow = "visible";
2364
- }
2365
- });
2366
- ro.observe(inner);
2367
- return () => {
2368
- ro.disconnect();
2369
- };
2370
- }, [open]);
2371
2297
  useEffect3(() => {
2372
2298
  const root = innerRef.current;
2373
2299
  if (!root) return;
@@ -2404,25 +2330,16 @@ var SubMenuContent = ({ children, css: userCss }) => {
2404
2330
  });
2405
2331
  }
2406
2332
  }, [open]);
2407
- useEffect3(() => {
2408
- const clip = clipRef.current;
2409
- if (!clip) return;
2410
- const onFocusIn = () => {
2411
- clip.style.overflow = "visible";
2412
- };
2413
- const onFocusOut = (e) => {
2414
- if (!clip.contains(e.relatedTarget)) {
2415
- clip.style.overflow = open ? "visible" : "hidden";
2416
- }
2417
- };
2418
- clip.addEventListener("focusin", onFocusIn);
2419
- clip.addEventListener("focusout", onFocusOut);
2420
- return () => {
2421
- clip.removeEventListener("focusin", onFocusIn);
2422
- clip.removeEventListener("focusout", onFocusOut);
2423
- };
2424
- }, [open]);
2333
+ const clipCss = emCss({
2334
+ display: "grid",
2335
+ gridTemplateRows: open ? "1fr" : "0fr",
2336
+ transition: "grid-template-rows 360ms cubic-bezier(.25,.8,.4,1)",
2337
+ overflow: "hidden",
2338
+ contain: "layout style",
2339
+ position: "relative"
2340
+ });
2425
2341
  const innerCss = emCss({
2342
+ minHeight: 0,
2426
2343
  width: "100%",
2427
2344
  display: "flex",
2428
2345
  flexDirection: "column",
@@ -2430,7 +2347,7 @@ var SubMenuContent = ({ children, css: userCss }) => {
2430
2347
  margin: 0,
2431
2348
  padding: 0,
2432
2349
  opacity: open ? 1 : 0,
2433
- transform: open ? "translateY(0) scale(1)" : "translateY(16px) scale(0.96)",
2350
+ transform: open ? "translateY(0) scale(1)" : "translateY(1rem) scale(0.95)",
2434
2351
  transition: "opacity 0.35s ease, transform 0.28s ease",
2435
2352
  pointerEvents: open ? "auto" : "none",
2436
2353
  willChange: "opacity, transform"
@@ -2442,20 +2359,15 @@ var SubMenuContent = ({ children, css: userCss }) => {
2442
2359
  "data-open": open ? "" : void 0,
2443
2360
  className: "plainframe-ui-submenu-content",
2444
2361
  css: [emCss({ width: "100%" }), userCss],
2445
- children: /* @__PURE__ */ jsx9(
2362
+ children: /* @__PURE__ */ jsx9("div", { className: "plainframe-ui-submenu-clip", css: clipCss, children: /* @__PURE__ */ jsx9(
2446
2363
  "div",
2447
2364
  {
2448
- ref: clipRef,
2449
- className: "plainframe-ui-submenu-clip",
2450
- css: emCss({
2451
- willChange: "max-height",
2452
- contain: "layout style",
2453
- position: "relative",
2454
- overflow: "hidden"
2455
- }),
2456
- children: /* @__PURE__ */ jsx9("div", { ref: innerRef, className: "plainframe-ui-submenu-inner", css: innerCss, children })
2365
+ ref: innerRef,
2366
+ className: "plainframe-ui-submenu-inner",
2367
+ css: innerCss,
2368
+ children
2457
2369
  }
2458
- )
2370
+ ) })
2459
2371
  }
2460
2372
  ) });
2461
2373
  };