@seed-design/stackflow 2.0.4 → 2.0.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.
@@ -15,7 +15,7 @@ var AppBarRoot = (0, react.forwardRef)((props, ref) => {
15
15
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_useAppBarContext.AppBarProvider, {
16
16
  value: api,
17
17
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_seed_design_react_primitive.Primitive.div, {
18
- ref: (0, _radix_ui_react_compose_refs.composeRefs)(api.refs.root, ref),
18
+ ref,
19
19
  ...(0, _seed_design_dom_utils.mergeProps)(api.rootProps, otherProps)
20
20
  })
21
21
  });
@@ -14,7 +14,7 @@ var AppBarRoot = forwardRef((props, ref) => {
14
14
  return /* @__PURE__ */ jsx(AppBarProvider, {
15
15
  value: api,
16
16
  children: /* @__PURE__ */ jsx(Primitive.div, {
17
- ref: composeRefs(api.refs.root, ref),
17
+ ref,
18
18
  ...mergeProps(api.rootProps, otherProps)
19
19
  })
20
20
  });
@@ -8,15 +8,14 @@ let react = require("react");
8
8
  //#region src/primitive/AppBar/useAppBar.tsx
9
9
  function useAppBar(_props) {
10
10
  const { stateProps } = require_useAppScreenContext.useAppScreenContext();
11
- const [root, rootRef] = (0, react.useState)(null);
12
11
  const [left, leftRef] = (0, react.useState)(null);
13
12
  const [right, rightRef] = (0, react.useState)(null);
14
13
  const leftOffset = require_useElementOffset.useElementOffset(left);
15
14
  const rightOffset = require_useElementOffset.useElementOffset(right);
16
- const centeredTitlePaddingX = root ? `${Math.max(leftOffset?.fromLeft ?? 0, rightOffset?.fromRight ?? 0)}px` : "initial";
15
+ const extents = [leftOffset?.fromLeft, rightOffset?.fromRight].filter((extent) => extent !== void 0);
16
+ const areaExtent = extents.length > 0 ? `${Math.max(...extents)}px` : "initial";
17
17
  return (0, react.useMemo)(() => ({
18
18
  refs: {
19
- root: rootRef,
20
19
  left: leftRef,
21
20
  right: rightRef
22
21
  },
@@ -24,9 +23,9 @@ function useAppBar(_props) {
24
23
  rootProps: (0, _seed_design_dom_utils.elementProps)({
25
24
  "data-part": require_anatomy.appBarAnatomy.root,
26
25
  ...stateProps,
27
- style: { "--centered-title-padding-x": centeredTitlePaddingX }
26
+ style: { "--app-bar-area-extent": areaExtent }
28
27
  })
29
- }), [stateProps, centeredTitlePaddingX]);
28
+ }), [stateProps, areaExtent]);
30
29
  }
31
30
  //#endregion
32
31
  exports.useAppBar = useAppBar;
@@ -4,7 +4,6 @@ export interface UseAppBarProps {
4
4
  export type UseAppBarReturn = ReturnType<typeof useAppBar>;
5
5
  export declare function useAppBar(_props: UseAppBarProps): {
6
6
  refs: {
7
- root: Dispatch<SetStateAction<HTMLElement | null>>;
8
7
  left: Dispatch<SetStateAction<HTMLElement | null>>;
9
8
  right: Dispatch<SetStateAction<HTMLElement | null>>;
10
9
  };
@@ -7,15 +7,14 @@ import { useMemo, useState } from "react";
7
7
  //#region src/primitive/AppBar/useAppBar.tsx
8
8
  function useAppBar(_props) {
9
9
  const { stateProps } = useAppScreenContext();
10
- const [root, rootRef] = useState(null);
11
10
  const [left, leftRef] = useState(null);
12
11
  const [right, rightRef] = useState(null);
13
12
  const leftOffset = useElementOffset(left);
14
13
  const rightOffset = useElementOffset(right);
15
- const centeredTitlePaddingX = root ? `${Math.max(leftOffset?.fromLeft ?? 0, rightOffset?.fromRight ?? 0)}px` : "initial";
14
+ const extents = [leftOffset?.fromLeft, rightOffset?.fromRight].filter((extent) => extent !== void 0);
15
+ const areaExtent = extents.length > 0 ? `${Math.max(...extents)}px` : "initial";
16
16
  return useMemo(() => ({
17
17
  refs: {
18
- root: rootRef,
19
18
  left: leftRef,
20
19
  right: rightRef
21
20
  },
@@ -23,9 +22,9 @@ function useAppBar(_props) {
23
22
  rootProps: elementProps({
24
23
  "data-part": appBarAnatomy.root,
25
24
  ...stateProps,
26
- style: { "--centered-title-padding-x": centeredTitlePaddingX }
25
+ style: { "--app-bar-area-extent": areaExtent }
27
26
  })
28
- }), [stateProps, centeredTitlePaddingX]);
27
+ }), [stateProps, areaExtent]);
29
28
  }
30
29
  //#endregion
31
30
  export { useAppBar };
@@ -4,6 +4,14 @@ let react = require("react");
4
4
  react = require_runtime.__toESM(react);
5
5
  //#region src/primitive/private/useElementOffset.ts
6
6
  var useLayoutEffect = typeof window !== "undefined" ? react.useLayoutEffect : react.useEffect;
7
+ function measure(element) {
8
+ const parent = element.offsetParent ?? document.body;
9
+ const { paddingLeft, paddingRight } = getComputedStyle(parent);
10
+ return {
11
+ fromLeft: element.offsetLeft + element.offsetWidth - Number.parseFloat(paddingLeft),
12
+ fromRight: parent.clientWidth - Number.parseFloat(paddingRight) - element.offsetLeft
13
+ };
14
+ }
7
15
  function useElementOffset(element) {
8
16
  const [offset, setOffset] = react.useState(void 0);
9
17
  useLayoutEffect(() => {
@@ -11,20 +19,10 @@ function useElementOffset(element) {
11
19
  setOffset(void 0);
12
20
  return;
13
21
  }
14
- if (element) {
15
- setOffset({
16
- fromLeft: element.offsetLeft + element.offsetWidth,
17
- fromRight: (element.offsetParent ?? document.body).clientWidth - element.offsetLeft
18
- });
19
- const resizeObserver = new ResizeObserver(() => {
20
- setOffset({
21
- fromLeft: element.offsetLeft + element.offsetWidth,
22
- fromRight: (element.offsetParent ?? document.body).clientWidth - element.offsetLeft
23
- });
24
- });
25
- resizeObserver.observe(element);
26
- return () => resizeObserver.unobserve(element);
27
- }
22
+ setOffset(measure(element));
23
+ const resizeObserver = new ResizeObserver(() => setOffset(measure(element)));
24
+ resizeObserver.observe(element);
25
+ return () => resizeObserver.disconnect();
28
26
  }, [element]);
29
27
  return offset;
30
28
  }
@@ -2,6 +2,14 @@
2
2
  import * as React from "react";
3
3
  //#region src/primitive/private/useElementOffset.ts
4
4
  var useLayoutEffect$1 = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
5
+ function measure(element) {
6
+ const parent = element.offsetParent ?? document.body;
7
+ const { paddingLeft, paddingRight } = getComputedStyle(parent);
8
+ return {
9
+ fromLeft: element.offsetLeft + element.offsetWidth - Number.parseFloat(paddingLeft),
10
+ fromRight: parent.clientWidth - Number.parseFloat(paddingRight) - element.offsetLeft
11
+ };
12
+ }
5
13
  function useElementOffset(element) {
6
14
  const [offset, setOffset] = React.useState(void 0);
7
15
  useLayoutEffect$1(() => {
@@ -9,20 +17,10 @@ function useElementOffset(element) {
9
17
  setOffset(void 0);
10
18
  return;
11
19
  }
12
- if (element) {
13
- setOffset({
14
- fromLeft: element.offsetLeft + element.offsetWidth,
15
- fromRight: (element.offsetParent ?? document.body).clientWidth - element.offsetLeft
16
- });
17
- const resizeObserver = new ResizeObserver(() => {
18
- setOffset({
19
- fromLeft: element.offsetLeft + element.offsetWidth,
20
- fromRight: (element.offsetParent ?? document.body).clientWidth - element.offsetLeft
21
- });
22
- });
23
- resizeObserver.observe(element);
24
- return () => resizeObserver.unobserve(element);
25
- }
20
+ setOffset(measure(element));
21
+ const resizeObserver = new ResizeObserver(() => setOffset(measure(element)));
22
+ resizeObserver.observe(element);
23
+ return () => resizeObserver.disconnect();
26
24
  }, [element]);
27
25
  return offset;
28
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seed-design/stackflow",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/daangn/seed-design.git",
@@ -40,7 +40,7 @@
40
40
  "clsx": "^2.1.1"
41
41
  },
42
42
  "devDependencies": {
43
- "@seed-design/css": "2.8.0",
43
+ "@seed-design/css": "2.9.0",
44
44
  "@stackflow/core": "^1.2.0",
45
45
  "@stackflow/react": "^1.5.1",
46
46
  "@types/react": "^19.2.2",
@@ -53,7 +53,7 @@
53
53
  "vite-plugin-dts": "^5.0.0"
54
54
  },
55
55
  "peerDependencies": {
56
- "@seed-design/css": "^2.0.0",
56
+ "@seed-design/css": "^2.9.0",
57
57
  "@stackflow/core": ">=1.1.0",
58
58
  "@stackflow/react": ">=1.4.1",
59
59
  "react": ">=18.0.0",
@@ -17,10 +17,7 @@ export const AppBarRoot = forwardRef<HTMLDivElement, AppBarRootProps>((props, re
17
17
 
18
18
  return (
19
19
  <AppBarProvider value={api}>
20
- <Primitive.div
21
- ref={composeRefs(api.refs.root, ref)}
22
- {...mergeProps(api.rootProps, otherProps)}
23
- />
20
+ <Primitive.div ref={ref} {...mergeProps(api.rootProps, otherProps)} />
24
21
  </AppBarProvider>
25
22
  );
26
23
  });
@@ -12,20 +12,20 @@ export type UseAppBarReturn = ReturnType<typeof useAppBar>;
12
12
  export function useAppBar(_props: UseAppBarProps) {
13
13
  const { stateProps } = useAppScreenContext();
14
14
 
15
- const [root, rootRef] = useState<HTMLElement | null>(null);
16
15
  const [left, leftRef] = useState<HTMLElement | null>(null);
17
16
  const [right, rightRef] = useState<HTMLElement | null>(null);
18
17
 
19
18
  const leftOffset = useElementOffset(left);
20
19
  const rightOffset = useElementOffset(right);
21
- const centeredTitlePaddingX = root
22
- ? `${Math.max(leftOffset?.fromLeft ?? 0, rightOffset?.fromRight ?? 0)}px`
23
- : "initial";
20
+ const extents = [leftOffset?.fromLeft, rightOffset?.fromRight].filter(
21
+ (extent) => extent !== undefined,
22
+ );
23
+ // `initial` leaves the variable unset, which the recipe reads as having no area to clear.
24
+ const areaExtent = extents.length > 0 ? `${Math.max(...extents)}px` : "initial";
24
25
 
25
26
  return useMemo(
26
27
  () => ({
27
28
  refs: {
28
- root: rootRef,
29
29
  left: leftRef,
30
30
  right: rightRef,
31
31
  },
@@ -34,10 +34,10 @@ export function useAppBar(_props: UseAppBarProps) {
34
34
  "data-part": appBarAnatomy.root,
35
35
  ...stateProps,
36
36
  style: {
37
- "--centered-title-padding-x": centeredTitlePaddingX,
37
+ "--app-bar-area-extent": areaExtent,
38
38
  } as React.CSSProperties,
39
39
  }),
40
40
  }),
41
- [stateProps, centeredTitlePaddingX],
41
+ [stateProps, areaExtent],
42
42
  );
43
43
  }
@@ -2,10 +2,21 @@ import * as React from "react";
2
2
 
3
3
  const useLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
4
4
 
5
+ // Measured from the offset parent's content edges: the parent's padding carries the safe-area
6
+ // insets, which can move to the other side (a 180° rotation) without resizing anything, so a value
7
+ // that included the padding would go stale with no resize to trigger a re-measure.
8
+ function measure(element: HTMLElement) {
9
+ const parent = element.offsetParent ?? document.body;
10
+ const { paddingLeft, paddingRight } = getComputedStyle(parent);
11
+
12
+ return {
13
+ fromLeft: element.offsetLeft + element.offsetWidth - Number.parseFloat(paddingLeft),
14
+ fromRight: parent.clientWidth - Number.parseFloat(paddingRight) - element.offsetLeft,
15
+ };
16
+ }
17
+
5
18
  export function useElementOffset(element: HTMLElement | null) {
6
- const [offset, setOffset] = React.useState<{ fromLeft: number; fromRight: number } | undefined>(
7
- undefined,
8
- );
19
+ const [offset, setOffset] = React.useState<ReturnType<typeof measure> | undefined>(undefined);
9
20
 
10
21
  useLayoutEffect(() => {
11
22
  if (!element) {
@@ -13,24 +24,13 @@ export function useElementOffset(element: HTMLElement | null) {
13
24
  return;
14
25
  }
15
26
 
16
- if (element) {
17
- // provide as early as possible
18
- setOffset({
19
- fromLeft: element.offsetLeft + element.offsetWidth,
20
- fromRight: (element.offsetParent ?? document.body).clientWidth - element.offsetLeft,
21
- });
22
-
23
- const resizeObserver = new ResizeObserver(() => {
24
- const fromLeft = element.offsetLeft + element.offsetWidth;
25
- const fromRight = (element.offsetParent ?? document.body).clientWidth - element.offsetLeft;
27
+ // provide as early as possible
28
+ setOffset(measure(element));
26
29
 
27
- setOffset({ fromLeft, fromRight });
28
- });
30
+ const resizeObserver = new ResizeObserver(() => setOffset(measure(element)));
31
+ resizeObserver.observe(element);
29
32
 
30
- resizeObserver.observe(element);
31
-
32
- return () => resizeObserver.unobserve(element);
33
- }
33
+ return () => resizeObserver.disconnect();
34
34
  }, [element]);
35
35
 
36
36
  return offset;