@janbox/storefront-ui 4.0.2 → 4.0.4

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.
@@ -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: {
@@ -213,7 +213,7 @@ const CascaderFloatingContent = ({
213
213
  css: {
214
214
  color: getColorVar("neutral.500"),
215
215
  transition: "color 150ms",
216
- "&:hover": { color: getColorVar("primary.600") }
216
+ ":hover": { color: getColorVar("primary.600") }
217
217
  },
218
218
  children: "All"
219
219
  }
@@ -234,7 +234,7 @@ const CascaderFloatingContent = ({
234
234
  color: idx === expandedOptions.length - 1 ? getColorVar("primary.600") : getColorVar("neutral.600"),
235
235
  fontWeight: idx === expandedOptions.length - 1 ? 500 : void 0,
236
236
  transition: "color 150ms",
237
- "&:hover": { color: getColorVar("primary.600") }
237
+ ":hover": { color: getColorVar("primary.600") }
238
238
  },
239
239
  children: opt.breadcrumbLabel ?? opt.label
240
240
  }
@@ -1,2 +1,2 @@
1
1
  import { DialogFooterProps } from './types';
2
- export declare const DialogFooter: (props: DialogFooterProps) => import("@emotion/react/jsx-runtime").JSX.Element;
2
+ export declare const DialogFooter: ({ sx, ...props }: DialogFooterProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,20 +1,20 @@
1
- import { jsx } from "@emotion/react/jsx-runtime";
2
- import { mediaQuery } from "../../../theme/screens.js";
3
- import "../../../theme/palette.js";
4
- const DialogFooter = (props) => {
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Primitive } from "../../primitive/primitive.js";
3
+ const DialogFooter = ({ sx, ...props }) => {
5
4
  return /* @__PURE__ */ jsx(
6
- "div",
5
+ Primitive,
7
6
  {
8
- css: {
7
+ sx: {
9
8
  display: "flex",
10
9
  justifyContent: "flex-end",
11
- gap: "0.5rem",
12
- paddingTop: "0.5rem",
13
- paddingBottom: "0.5rem",
14
- paddingLeft: "1rem",
15
- paddingRight: "1rem",
10
+ gap: 8,
11
+ paddingTop: 8,
12
+ paddingBottom: 8,
13
+ paddingLeft: 16,
14
+ paddingRight: 16,
16
15
  position: "relative",
17
- [mediaQuery("sm")]: { paddingLeft: "1.25rem", paddingRight: "1.25rem" }
16
+ ...sx,
17
+ sm: { paddingLeft: 20, paddingRight: 20, ...sx == null ? void 0 : sx.sm }
18
18
  },
19
19
  ...props
20
20
  }
@@ -1,3 +1,3 @@
1
- import { HTMLAttributes } from 'react';
2
- export interface DialogFooterProps extends HTMLAttributes<HTMLDivElement> {
3
- }
1
+ import { PrimitiveProps } from '../../primitive';
2
+ import { JSX } from 'react';
3
+ export type DialogFooterProps = PrimitiveProps<JSX.IntrinsicElements['div'], 'div'>;
@@ -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,
@@ -1,14 +1,13 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { ClassNames } from "@emotion/react";
3
2
  import { isNil } from "lodash-es";
4
3
  import { Link as Link$1 } from "react-router";
5
4
  import { getLinkProps } from "./helpers.js";
6
5
  import { Booleanish } from "../../constants/index.js";
7
6
  import "react";
8
- import { mediaQuery } from "../../theme/screens.js";
9
7
  import "../../theme/palette.js";
10
8
  import { getTypographyVar } from "../../theme/typography.js";
11
9
  import { createUnderlineEffect } from "../../utils/stylesheet.js";
10
+ import { Stylesheet } from "../stylesheet/stylesheet.js";
12
11
  const Link = ({ children, ref, ..._props }) => {
13
12
  const { sx, textVariant, sm, md, lg, to, underline = false, className, ...rest } = getLinkProps(_props);
14
13
  const onClick = (e) => {
@@ -21,10 +20,10 @@ const Link = ({ children, ref, ..._props }) => {
21
20
  }
22
21
  (_a = rest.onClick) == null ? void 0 : _a.call(rest, e);
23
22
  };
24
- return /* @__PURE__ */ jsx(ClassNames, { children: ({ cx, css }) => /* @__PURE__ */ jsx(
23
+ return /* @__PURE__ */ jsx(Stylesheet, { children: ({ cx, css }) => /* @__PURE__ */ jsx(
25
24
  Link$1,
26
25
  {
27
- to: to ?? "#",
26
+ to: to ?? "",
28
27
  className: cx(
29
28
  className,
30
29
  css({
@@ -34,15 +33,15 @@ const Link = ({ children, ref, ..._props }) => {
34
33
  ...underline ? createUnderlineEffect() : {},
35
34
  ...createStyle({ textVariant }),
36
35
  ...sx,
37
- [mediaQuery("sm")]: {
36
+ sm: {
38
37
  ...createStyle(sm),
39
38
  ...sx == null ? void 0 : sx.sm
40
39
  },
41
- [mediaQuery("md")]: {
40
+ md: {
42
41
  ...createStyle(md),
43
42
  ...sx == null ? void 0 : sx.md
44
43
  },
45
- [mediaQuery("lg")]: {
44
+ lg: {
46
45
  ...createStyle(lg),
47
46
  ...sx == null ? void 0 : sx.lg
48
47
  }
@@ -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: {
@@ -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
  };
@@ -3,6 +3,8 @@ import { Theme } from '.';
3
3
  export type ThemeProviderProps = PropsWithChildren<{
4
4
  theme: Theme;
5
5
  locale?: string;
6
+ root?: HTMLElement;
6
7
  }>;
8
+ export declare const usePortalContainer: () => HTMLElement | null;
7
9
  export declare const useTheme: () => Theme;
8
- export declare const ThemeProvider: ({ theme, children, locale }: ThemeProviderProps) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const ThemeProvider: ({ theme, children, locale, root }: ThemeProviderProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,15 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { Global } from "@emotion/react";
3
- import { useContext, createContext } from "react";
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { CacheProvider, Global } from "@emotion/react";
3
+ import createCache from "@emotion/cache";
4
+ import { useState, useContext, createContext } from "react";
4
5
  import { getColorVar } from "./palette.js";
5
6
  import { flatten } from "flat";
6
7
  import { flatMap } from "lodash-es";
7
8
  import { getTypographyVar } from "./typography.js";
8
9
  import { LocaleContext, FALLBACK_LOCALE } from "../i18n/index.js";
10
+ const usePortalContainer = () => {
11
+ return useContext(PortalContainerContext);
12
+ };
9
13
  const useTheme = () => {
10
14
  const context = useContext(ThemeContext);
11
15
  if (!context) {
@@ -14,11 +18,13 @@ const useTheme = () => {
14
18
  return context;
15
19
  };
16
20
  const ThemeContext = createContext(null);
17
- const ThemeProvider = ({ theme, children, locale = FALLBACK_LOCALE }) => {
18
- return /* @__PURE__ */ jsxs(ThemeContext.Provider, { value: theme, children: [
21
+ const PortalContainerContext = createContext(null);
22
+ const ThemeProvider = ({ theme, children, locale = FALLBACK_LOCALE, root }) => {
23
+ const [emotionCache] = useState(() => createCache({ key: "jb", container: root }));
24
+ return /* @__PURE__ */ jsx(CacheProvider, { value: emotionCache, children: /* @__PURE__ */ jsx(ThemeContext.Provider, { value: theme, children: /* @__PURE__ */ jsxs(PortalContainerContext.Provider, { value: root ?? null, children: [
19
25
  /* @__PURE__ */ jsx(Global, { styles: createGlobalStyle(theme) }),
20
26
  /* @__PURE__ */ jsx(LocaleContext.Provider, { value: locale, children })
21
- ] });
27
+ ] }) }) });
22
28
  };
23
29
  const createGlobalStyle = ({ palette, typography }) => {
24
30
  const flattenPalette = flatten(palette);
@@ -304,5 +310,6 @@ const createGlobalStyle = ({ palette, typography }) => {
304
310
  };
305
311
  export {
306
312
  ThemeProvider,
313
+ usePortalContainer,
307
314
  useTheme
308
315
  };
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.4",
4
4
  "description": "Storefront UI component library for Janbox",
5
5
  "author": "Janbox",
6
6
  "keywords": [
@@ -53,12 +53,13 @@
53
53
  "access": "restricted"
54
54
  },
55
55
  "peerDependencies": {
56
- "@emotion/react": "*",
57
56
  "react": ">=19.0.0",
58
57
  "react-dom": ">=19.0.0",
59
58
  "react-router": ">=7.0.0"
60
59
  },
61
60
  "dependencies": {
61
+ "@emotion/cache": "^11.14.0",
62
+ "@emotion/react": "^11.14.0",
62
63
  "@floating-ui/react": "^0.27.13",
63
64
  "@floating-ui/react-dom": "^2.1.8",
64
65
  "@tanstack/react-virtual": "^3.10.9",