@octavius2929-personal/design-system 0.8.0 → 0.8.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.
package/dist/index.cjs CHANGED
@@ -1968,6 +1968,7 @@ function assignRef(ref, value) {
1968
1968
  function Menu({ trigger: trigger2, items }) {
1969
1969
  const { wrapper: wrapper4, list: list2, item: item3, dangerItem } = useStyles25();
1970
1970
  const [open, setOpen] = (0, import_react36.useState)(false);
1971
+ const [alignEnd, setAlignEnd] = (0, import_react36.useState)(false);
1971
1972
  const rootRef = (0, import_react36.useRef)(null);
1972
1973
  const listRef = (0, import_react36.useRef)(null);
1973
1974
  const triggerRef = (0, import_react36.useRef)(null);
@@ -1982,6 +1983,18 @@ function Menu({ trigger: trigger2, items }) {
1982
1983
  setOpen(false);
1983
1984
  triggerRef.current?.focus();
1984
1985
  };
1986
+ (0, import_react36.useLayoutEffect)(() => {
1987
+ if (!open) {
1988
+ setAlignEnd(false);
1989
+ return;
1990
+ }
1991
+ const listEl = listRef.current;
1992
+ const rootEl = rootRef.current;
1993
+ if (!listEl || !rootEl) return;
1994
+ const rootLeft = rootEl.getBoundingClientRect().left;
1995
+ const viewport = document.documentElement.clientWidth;
1996
+ setAlignEnd(rootLeft + listEl.offsetWidth > viewport);
1997
+ }, [open]);
1985
1998
  (0, import_react36.useEffect)(() => {
1986
1999
  if (!open) return;
1987
2000
  listRef.current?.querySelector('[role="menuitem"]')?.focus();
@@ -2049,21 +2062,31 @@ function Menu({ trigger: trigger2, items }) {
2049
2062
  });
2050
2063
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { ref: rootRef, className: wrapper4, children: [
2051
2064
  clonedTrigger,
2052
- open && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { ref: listRef, role: "menu", className: list2, onKeyDown: onMenuKeyDown, children: items.map((entry, index) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
2053
- "button",
2065
+ open && /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
2066
+ "div",
2054
2067
  {
2055
- type: "button",
2056
- role: "menuitem",
2057
- tabIndex: -1,
2058
- className: entry.danger ? dangerItem : item3,
2059
- onClick: () => {
2060
- entry.onClick?.();
2061
- setOpen(false);
2062
- },
2063
- children: entry.label
2064
- },
2065
- index
2066
- )) })
2068
+ ref: listRef,
2069
+ role: "menu",
2070
+ className: list2,
2071
+ "data-align": alignEnd ? "end" : "start",
2072
+ onKeyDown: onMenuKeyDown,
2073
+ children: items.map((entry, index) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
2074
+ "button",
2075
+ {
2076
+ type: "button",
2077
+ role: "menuitem",
2078
+ tabIndex: -1,
2079
+ className: entry.danger ? dangerItem : item3,
2080
+ onClick: () => {
2081
+ entry.onClick?.();
2082
+ setOpen(false);
2083
+ },
2084
+ children: entry.label
2085
+ },
2086
+ index
2087
+ ))
2088
+ }
2089
+ )
2067
2090
  ] });
2068
2091
  }
2069
2092