@janbox/storefront-ui 4.0.2 → 4.0.3

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.
@@ -3,8 +3,8 @@ import { useRef } from "react";
3
3
  import { motion } from "motion/react";
4
4
  import { getAccordionContentProps } from "./helpers.js";
5
5
  import { useAccordionContext } from "../accordion/helpers.js";
6
- import { Stylesheet } from "../../stylesheet/stylesheet.js";
7
6
  import { useAccordionGroupContext } from "../accordion-group/helpers.js";
7
+ import { Stylesheet } from "../../stylesheet/stylesheet.js";
8
8
  import { Primitive } from "../../primitive/primitive.js";
9
9
  const AccordionContent = ({ children, ref, ..._props }) => {
10
10
  const { accordionContentProps: accordionContentPropsByGroup = {} } = useAccordionGroupContext();
@@ -4,11 +4,13 @@ import { useFloating, autoUpdate, offset, hide, useMergeRefs, FloatingPortal } f
4
4
  import { getColorShadesByVariant } from "../../utils/index.js";
5
5
  import { cloneElement } from "react";
6
6
  import { FLOATING_Z_INDEX } from "../../theme/index.js";
7
+ import { usePortalContainer } from "../../theme/provider.js";
7
8
  import { Primitive } from "../primitive/primitive.js";
8
9
  import { getTypographyVar } from "../../theme/typography.js";
9
10
  const Badge = ({ color = "red", content, offset: offset$1 = 0, children }) => {
10
11
  var _a;
11
12
  const { main, contrast } = getColorShadesByVariant(color);
13
+ const portalRoot = usePortalContainer();
12
14
  const {
13
15
  floatingStyles,
14
16
  refs: { setFloating, setReference },
@@ -35,7 +37,7 @@ const Badge = ({ color = "red", content, offset: offset$1 = 0, children }) => {
35
37
  ...children.props,
36
38
  ref: mergedRefs
37
39
  }),
38
- context.open && /* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsx(
40
+ context.open && /* @__PURE__ */ jsx(FloatingPortal, { ...portalRoot && { root: portalRoot }, children: /* @__PURE__ */ jsx(
39
41
  "div",
40
42
  {
41
43
  style: {
@@ -5,6 +5,7 @@ import { useFloatingContext } from "../floating/helpers.js";
5
5
  import { FLOATING_Z_INDEX } from "../../../theme/index.js";
6
6
  import { useIsHydrated } from "../../../hooks/use-is-hydrated/index.js";
7
7
  import { createSxInterpolation } from "../../../utils/stylesheet.js";
8
+ import { usePortalContainer } from "../../../theme/provider.js";
8
9
  const FloatingContent = ({
9
10
  style,
10
11
  floatingPortalProps,
@@ -17,7 +18,10 @@ const FloatingContent = ({
17
18
  const { getFloatingProps, context } = useFloatingContext();
18
19
  const mergedRefs = useMergeRefs([context.refs.setFloating, ref]);
19
20
  const isHydrated = useIsHydrated();
20
- return /* @__PURE__ */ jsx(AnimatePresence, { children: context.open && isHydrated && /* @__PURE__ */ jsx(FloatingPortal, { root: document.body, ...floatingPortalProps, children: /* @__PURE__ */ jsx(
21
+ const portalRoot = usePortalContainer();
22
+ const { root = portalRoot, ...portalProps } = floatingPortalProps ?? {};
23
+ const resolvedRoot = root || void 0;
24
+ return /* @__PURE__ */ jsx(AnimatePresence, { children: context.open && isHydrated && /* @__PURE__ */ jsx(FloatingPortal, { root: resolvedRoot, ...portalProps, children: /* @__PURE__ */ jsx(
21
25
  FloatingOverlay,
22
26
  {
23
27
  ...floatingOverlayProps,
@@ -7,6 +7,7 @@ import { notificationStore } from "./helpers.js";
7
7
  import { getColorShadesByVariant } from "../../utils/index.js";
8
8
  import { FLOATING_Z_INDEX } from "../../theme/index.js";
9
9
  import CloseIcon from "../../assets/svg/times-close-delete.svg.js";
10
+ import { usePortalContainer } from "../../theme/provider.js";
10
11
  import { Primitive } from "../primitive/primitive.js";
11
12
  import { getTypographyVar } from "../../theme/typography.js";
12
13
  import { IconButton } from "../icon-button/icon-button.js";
@@ -17,7 +18,8 @@ const Notifications = () => {
17
18
  notificationStore.getSnapshot,
18
19
  notificationStore.getServerSnapshot
19
20
  );
20
- return /* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsx(
21
+ const portalRoot = usePortalContainer();
22
+ return /* @__PURE__ */ jsx(FloatingPortal, { ...portalRoot && { root: portalRoot }, children: /* @__PURE__ */ jsx(
21
23
  Primitive,
22
24
  {
23
25
  sx: {
@@ -4,6 +4,7 @@ import { useFloating, autoUpdate, shift, flip, size, FloatingPortal } from "@flo
4
4
  import { times, isNumber } from "lodash-es";
5
5
  import { motion } from "motion/react";
6
6
  import { getColorVar } from "../../../theme/palette.js";
7
+ import { usePortalContainer } from "../../../theme/provider.js";
7
8
  import { useIsHydrated } from "../../../hooks/use-is-hydrated/index.js";
8
9
  import { Primitive } from "../../primitive/primitive.js";
9
10
  const SWIPER_DOTS_SIZE_VAR = "--swiper-dots-size";
@@ -22,6 +23,7 @@ const SwiperDotsPaging = ({
22
23
  const [inViewIndexes, setInViewIndexes] = useState((api == null ? void 0 : api.slidesInView()) ?? []);
23
24
  const [totalSlides, setTotalSlides] = useState((api == null ? void 0 : api.slideNodes().length) ?? 0);
24
25
  const isHydrated = useIsHydrated();
26
+ const portalRoot = usePortalContainer();
25
27
  const {
26
28
  floatingStyles,
27
29
  refs: { setFloating, setReference }
@@ -81,7 +83,7 @@ const SwiperDotsPaging = ({
81
83
  }
82
84
  }
83
85
  ),
84
- /* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsx(
86
+ /* @__PURE__ */ jsx(FloatingPortal, { ...portalRoot && { root: portalRoot }, children: /* @__PURE__ */ jsx(
85
87
  Primitive,
86
88
  {
87
89
  style: {
@@ -3,6 +3,7 @@ import { useState, useRef, useCallback, useEffect } from "react";
3
3
  import { useFloating, autoUpdate, offset, size, FloatingPortal } from "@floating-ui/react";
4
4
  import { isEmpty, isNumber, isNil } from "lodash-es";
5
5
  import { getColorVar } from "../../../theme/palette.js";
6
+ import { usePortalContainer } from "../../../theme/provider.js";
6
7
  import ArrowLeftIcon from "../../../assets/svg/arrow-left.svg.js";
7
8
  import { SvgLoader } from "../../../components/svg-loader.js";
8
9
  import { Primitive } from "../../primitive/primitive.js";
@@ -23,6 +24,7 @@ const SwiperSideArrowsPaging = ({
23
24
  const [canScrollNext, setCanScrollNext] = useState(api.canScrollNext());
24
25
  const [isVisible, setIsVisible] = useState(visibility === "always");
25
26
  const [referenceStyle, setReferenceStyle] = useState(anchorSelector ? {} : { top: 0, bottom: 0 });
27
+ const portalRoot = usePortalContainer();
26
28
  const hoverStateRef = useRef({ root: false, floating: false });
27
29
  const updateVisibility = useCallback(() => {
28
30
  const { root, floating } = hoverStateRef.current;
@@ -136,7 +138,7 @@ const SwiperSideArrowsPaging = ({
136
138
  }
137
139
  }
138
140
  ),
139
- context.open && /* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsx(
141
+ context.open && /* @__PURE__ */ jsx(FloatingPortal, { ...portalRoot && { root: portalRoot }, children: /* @__PURE__ */ jsx(
140
142
  Primitive,
141
143
  {
142
144
  style: {
@@ -1,8 +1,8 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { useRef, useState, useEffect } from "react";
3
3
  import { motion } from "motion/react";
4
- import { Stylesheet } from "../../stylesheet/stylesheet.js";
5
4
  import { useTabsContext } from "../tabs/helpers.js";
5
+ import { Stylesheet } from "../../stylesheet/stylesheet.js";
6
6
  const TabIndicator = () => {
7
7
  const { activeIndex, tabIndicatorProps } = useTabsContext();
8
8
  const indicatorEl = useRef(null);
@@ -5,6 +5,7 @@ import { isUndefined, get } from "lodash-es";
5
5
  import { useControllableState } from "../../hooks/use-controllable-state.js";
6
6
  import { getColorVar } from "../../theme/palette.js";
7
7
  import { getTypographyVar } from "../../theme/typography.js";
8
+ import { usePortalContainer } from "../../theme/provider.js";
8
9
  import { Primitive } from "../primitive/primitive.js";
9
10
  function Tooltip({
10
11
  children,
@@ -22,6 +23,7 @@ function Tooltip({
22
23
  defaultValue: defaultOpen,
23
24
  value: open
24
25
  });
26
+ const portalRoot = usePortalContainer();
25
27
  const triggerRef = useRef(null);
26
28
  const arrowRef = useRef(null);
27
29
  const handleOpenChange = (val, event, reason) => {
@@ -78,7 +80,7 @@ function Tooltip({
78
80
  ref: mergedRefs
79
81
  })
80
82
  ),
81
- context.open && /* @__PURE__ */ jsx(FloatingPortal, { children: /* @__PURE__ */ jsxs(
83
+ context.open && /* @__PURE__ */ jsx(FloatingPortal, { ...portalRoot && { root: portalRoot }, children: /* @__PURE__ */ jsxs(
82
84
  Primitive,
83
85
  {
84
86
  style: {
@@ -1,7 +1,7 @@
1
1
  import { breakpoint, containerQuery, getSmallerScreens, mediaQuery, screens } from "./screens.js";
2
2
  import { getColorVar, groupedColors, paletteVars, parseColor } from "./palette.js";
3
3
  import { getSmallerTypographyVariants, getTypographyVar, typographyVars } from "./typography.js";
4
- import { ThemeProvider, useTheme } from "./provider.js";
4
+ import { ThemeProvider, usePortalContainer, useTheme } from "./provider.js";
5
5
  import { createTheme, defaultTheme } from "./create-theme.js";
6
6
  const FLOATING_Z_INDEX = 9999;
7
7
  export {
@@ -21,5 +21,6 @@ export {
21
21
  parseColor,
22
22
  screens,
23
23
  typographyVars,
24
+ usePortalContainer,
24
25
  useTheme
25
26
  };
@@ -1,8 +1,13 @@
1
- import { PropsWithChildren } from 'react';
1
+ import { FloatingPortal } from '@floating-ui/react';
2
+ import { ComponentProps, PropsWithChildren } from 'react';
2
3
  import { Theme } from '.';
4
+ type PortalContainer = ComponentProps<typeof FloatingPortal>['root'];
3
5
  export type ThemeProviderProps = PropsWithChildren<{
4
6
  theme: Theme;
5
7
  locale?: string;
8
+ root?: PortalContainer;
6
9
  }>;
10
+ export declare const usePortalContainer: () => HTMLElement | ShadowRoot | import('react').MutableRefObject<HTMLElement | ShadowRoot | null> | null | undefined;
7
11
  export declare const useTheme: () => Theme;
8
- export declare const ThemeProvider: ({ theme, children, locale }: ThemeProviderProps) => import("react/jsx-runtime").JSX.Element;
12
+ export declare const ThemeProvider: ({ theme, children, locale, root }: ThemeProviderProps) => import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -1,4 +1,4 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { Global } from "@emotion/react";
3
3
  import { useContext, createContext } from "react";
4
4
  import { getColorVar } from "./palette.js";
@@ -6,6 +6,9 @@ import { flatten } from "flat";
6
6
  import { flatMap } from "lodash-es";
7
7
  import { getTypographyVar } from "./typography.js";
8
8
  import { LocaleContext, FALLBACK_LOCALE } from "../i18n/index.js";
9
+ const usePortalContainer = () => {
10
+ return useContext(PortalContainerContext);
11
+ };
9
12
  const useTheme = () => {
10
13
  const context = useContext(ThemeContext);
11
14
  if (!context) {
@@ -14,11 +17,12 @@ const useTheme = () => {
14
17
  return context;
15
18
  };
16
19
  const ThemeContext = createContext(null);
17
- const ThemeProvider = ({ theme, children, locale = FALLBACK_LOCALE }) => {
18
- return /* @__PURE__ */ jsxs(ThemeContext.Provider, { value: theme, children: [
20
+ const PortalContainerContext = createContext(null);
21
+ const ThemeProvider = ({ theme, children, locale = FALLBACK_LOCALE, root }) => {
22
+ return /* @__PURE__ */ jsx(ThemeContext.Provider, { value: theme, children: /* @__PURE__ */ jsxs(PortalContainerContext.Provider, { value: root ?? null, children: [
19
23
  /* @__PURE__ */ jsx(Global, { styles: createGlobalStyle(theme) }),
20
24
  /* @__PURE__ */ jsx(LocaleContext.Provider, { value: locale, children })
21
- ] });
25
+ ] }) });
22
26
  };
23
27
  const createGlobalStyle = ({ palette, typography }) => {
24
28
  const flattenPalette = flatten(palette);
@@ -304,5 +308,6 @@ const createGlobalStyle = ({ palette, typography }) => {
304
308
  };
305
309
  export {
306
310
  ThemeProvider,
311
+ usePortalContainer,
307
312
  useTheme
308
313
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@janbox/storefront-ui",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
4
4
  "description": "Storefront UI component library for Janbox",
5
5
  "author": "Janbox",
6
6
  "keywords": [