@bonprix-ds/react-bottom-sheet 1.0.1 → 1.1.0

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.d.ts CHANGED
@@ -1,86 +1,2 @@
1
- import { ComponentProps } from 'react';
2
- import { default as default_2 } from 'react';
3
- import { ElementType } from 'react';
4
- import { IconType } from '@bonprix-ds/react-icon';
5
- import { ReactNode } from 'react';
6
- import { RefObject } from 'react';
7
- import { TitleLevel } from '@bonprix-ds/utils';
8
-
9
- declare const BottomSheet: {
10
- (props: BottomSheetProps): default_2.JSX.Element;
11
- displayName: string;
12
- Title: ({ children, subline, level }: SheetTitleProps) => default_2.JSX.Element;
13
- Content: ({ children, disableHorizontalPadding }: SheetContentProps) => default_2.JSX.Element;
14
- ButtonSection: ({ children }: SheetButtonSectionProps) => default_2.JSX.Element;
15
- PrimaryButton: <C extends default_2.ElementType>({ children, icon, iconPosition, loading, component, ...props }: SheetButtonBaseProps & {
16
- component?: C | undefined;
17
- } & Omit<default_2.ComponentProps<C>, keyof SheetButtonBaseProps | "component"> & {
18
- loading?: boolean;
19
- }) => default_2.JSX.Element;
20
- SecondaryButton: <C extends default_2.ElementType>({ children, icon, iconPosition, component, ...props }: SheetButtonProps<C>) => default_2.JSX.Element;
21
- };
22
- export default BottomSheet;
23
-
24
- export declare interface BottomSheetProps extends SheetProps {
25
- /** A reference to the root element of the sheet. */
26
- ref?: RefObject<HTMLDivElement>;
27
- }
28
-
29
- export declare interface SheetButtonBaseProps {
30
- /** The label of the button. */
31
- children: string;
32
- /** If used, an icon will be additionally shown. The value is a name of one icon from our icon set. */
33
- icon?: IconType;
34
- /** The position of the icon relative to the content. */
35
- iconPosition?: "start" | "end";
36
- }
37
-
38
- export declare type SheetButtonProps<C extends ElementType> = SheetButtonBaseProps & {
39
- /** The semantic component to render the Button. Preferrably `"button"`. Native props will be passed to this component. */
40
- component?: C;
41
- } & Omit<ComponentProps<C>, keyof SheetButtonBaseProps | "component">;
42
-
43
- export declare interface SheetButtonSectionProps {
44
- /** Primary and secondary buttons should be placed inside this section. */
45
- children: ReactNode;
46
- }
47
-
48
- export declare interface SheetContentProps {
49
- /** The content of the content section. */
50
- children: ReactNode;
51
- /** If `true`, the horizontal padding around the content will be removed. */
52
- disableHorizontalPadding?: boolean;
53
- }
54
-
55
- declare interface SheetProps {
56
- /** All of the subcomponents should be placed inside this property. */
57
- children: ReactNode;
58
- /** Toggles the visibility of the sheet. Should be used in conjunction with the `onClose` property. */
59
- isOpen: boolean;
60
- /** Callback function, that is triggered when the sheet is attempted to be closed.
61
- *
62
- * It will be called in following cases:
63
- * - Click on backdrop
64
- * - Press of the `Escape` key
65
- * - Swipe down to close
66
- * - Click on "close" icon button in the upper-right corner
67
- * - Click on any button (PrimaryButton or SecondaryButton)
68
- *
69
- * Should be used in conjunction with `isOpen`. */
70
- onClose: () => void;
71
- /** Callback to execute when clicking back icon. */
72
- onBack?: () => void;
73
- /** The z-index of the sheet.. */
74
- zIndex?: number;
75
- }
76
-
77
- export declare interface SheetTitleProps {
78
- /** The text content. */
79
- children: string;
80
- /** An optional subline that is displayed right below the title. */
81
- subline?: string;
82
- /** The heading level for the title. */
83
- level?: TitleLevel;
84
- }
85
-
86
- export { }
1
+ export { default } from "./src/BottomSheet";
2
+ export type { Props as BottomSheetProps, SheetButtonBaseProps, SheetButtonProps, SheetButtonSectionProps, SheetContentProps, SheetTitleProps, } from "./src/BottomSheet";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /* Radix prepends focus guards to `body` while a dialog is open. Chromium saves the scroll anchor of a page that is
2
+ left as an `nth-child` path, which the guards shift, so going back would restore the scroll position of another
3
+ element. Without an anchor, Chromium restores the plain scroll offset. Keyed to the guards rather than to the
4
+ open state, so it holds through the closing animation and across every copy of the package on the page. */
5
+ :root:has(> body > [data-radix-focus-guard]) {
6
+ overflow-anchor: none;
7
+ }
@@ -0,0 +1,17 @@
1
+ import React from "react";
2
+ import { type Props } from "./BottomSheetRoot";
3
+ export type { Props, SheetButtonBaseProps, SheetButtonProps, SheetButtonSectionProps, SheetContentProps, SheetTitleProps, } from "./BottomSheetRoot";
4
+ declare const BottomSheet: {
5
+ (props: Props): React.JSX.Element;
6
+ displayName: string;
7
+ Title: ({ children, subline, level: Level }: import("./BottomSheetRoot").SheetTitleProps) => React.JSX.Element;
8
+ Content: ({ children, disableHorizontalPadding }: import("./BottomSheetRoot").SheetContentProps) => React.JSX.Element;
9
+ ButtonSection: ({ children }: import("./BottomSheetRoot").SheetButtonSectionProps) => React.JSX.Element;
10
+ PrimaryButton: <C extends React.ElementType>({ children, icon, iconPosition, loading, component, ...props }: import("./BottomSheetRoot").SheetButtonBaseProps & {
11
+ component?: C | undefined;
12
+ } & Omit<React.ComponentProps<C>, keyof import("./BottomSheetRoot").SheetButtonBaseProps | "component"> & {
13
+ loading?: boolean;
14
+ }) => React.JSX.Element;
15
+ SecondaryButton: <C extends React.ElementType>({ children, icon, iconPosition, component, ...props }: import("./BottomSheetRoot").SheetButtonProps<C>) => React.JSX.Element;
16
+ };
17
+ export default BottomSheet;
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheet.js","names":[],"sources":["../../src/BottomSheet.tsx"],"sourcesContent":["import React from \"react\";\n\nimport BottomSheetRoot, { ButtonSection, Content, PrimaryButton, SecondaryButton, Title, type Props } from \"./BottomSheetRoot\";\n\nexport type {\n Props,\n SheetButtonBaseProps,\n SheetButtonProps,\n SheetButtonSectionProps,\n SheetContentProps,\n SheetTitleProps,\n} from \"./BottomSheetRoot\";\n\nconst BottomSheet = (props: Props) => <BottomSheetRoot {...props} />;\n\nBottomSheet.displayName = \"BottomSheet\";\n\nBottomSheet.Title = Title;\nBottomSheet.Content = Content;\nBottomSheet.ButtonSection = ButtonSection;\nBottomSheet.PrimaryButton = PrimaryButton;\nBottomSheet.SecondaryButton = SecondaryButton;\n\nexport default BottomSheet;\n"],"mappings":";;;;AAaA,IAAM,KAAe,MAAiB,kBAAC,GAAD,EAAiB,GAAI,EAAQ,CAAA;AAEnE,EAAY,cAAc,eAE1B,EAAY,QAAQ,GACpB,EAAY,UAAU,GACtB,EAAY,gBAAgB,GAC5B,EAAY,gBAAgB,GAC5B,EAAY,kBAAkB"}
1
+ {"version":3,"file":"BottomSheet.js","names":["BottomSheetRoot","BottomSheet","props","Title","Content","ButtonSection","PrimaryButton","SecondaryButton"],"sources":["../../src/BottomSheet.tsx"],"sourcesContent":["import React from \"react\";\n\nimport BottomSheetRoot, { ButtonSection, Content, PrimaryButton, SecondaryButton, Title, type Props } from \"./BottomSheetRoot\";\n\nexport type {\n Props,\n SheetButtonBaseProps,\n SheetButtonProps,\n SheetButtonSectionProps,\n SheetContentProps,\n SheetTitleProps,\n} from \"./BottomSheetRoot\";\n\nconst BottomSheet = (props: Props) => <BottomSheetRoot {...props} />;\n\nBottomSheet.displayName = \"BottomSheet\";\n\nBottomSheet.Title = Title;\nBottomSheet.Content = Content;\nBottomSheet.ButtonSection = ButtonSection;\nBottomSheet.PrimaryButton = PrimaryButton;\nBottomSheet.SecondaryButton = SecondaryButton;\n\nexport default BottomSheet;\n"],"mappings":";;;;AAaA,IAAMC,KAAe,MAAiB,kBAACD,GAAD,EAAiB,GAAIE,EAAQ,CAAA;AAEnE,EAAY,cAAc,eAE1B,EAAY,QAAQC,GACpB,EAAY,UAAUC,GACtB,EAAY,gBAAgBC,GAC5B,EAAY,gBAAgBC,GAC5B,EAAY,kBAAkBC"}
@@ -0,0 +1,10 @@
1
+ import { useScrollPosition } from "react-modal-sheet";
2
+ export interface BottomSheetContextProps {
3
+ scrollRef: ReturnType<typeof useScrollPosition>["scrollRef"];
4
+ scrollPosition: ReturnType<typeof useScrollPosition>["scrollPosition"];
5
+ onClose: () => void;
6
+ onBack?: () => void;
7
+ disableDrag: boolean;
8
+ }
9
+ declare const BottomSheetContext: import("react").Context<BottomSheetContextProps>;
10
+ export default BottomSheetContext;
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetContext.js","names":[],"sources":["../../src/BottomSheetContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { useScrollPosition } from \"react-modal-sheet\";\n\nexport interface BottomSheetContextProps {\n scrollRef: ReturnType<typeof useScrollPosition>[\"scrollRef\"];\n scrollPosition: ReturnType<typeof useScrollPosition>[\"scrollPosition\"];\n onClose: () => void;\n onBack?: () => void;\n disableDrag: boolean;\n}\n\nconst BottomSheetContext = createContext<BottomSheetContextProps>({\n scrollRef: () => null,\n scrollPosition: undefined,\n onClose: () => null,\n onBack: () => null,\n disableDrag: false,\n});\n\nexport default BottomSheetContext;\n"],"mappings":";;;AAaA,IAAM,IAAqB,EAAuC;CAChE,iBAAiB;CACjB,gBAAgB,KAAA;CAChB,eAAe;CACf,cAAc;CACd,aAAa;AACf,CAAC"}
1
+ {"version":3,"file":"BottomSheetContext.js","names":["BottomSheetContext","createContext"],"sources":["../../src/BottomSheetContext.ts"],"sourcesContent":["\"use client\";\n\nimport { createContext } from \"react\";\nimport { useScrollPosition } from \"react-modal-sheet\";\n\nexport interface BottomSheetContextProps {\n scrollRef: ReturnType<typeof useScrollPosition>[\"scrollRef\"];\n scrollPosition: ReturnType<typeof useScrollPosition>[\"scrollPosition\"];\n onClose: () => void;\n onBack?: () => void;\n disableDrag: boolean;\n}\n\nconst BottomSheetContext = createContext<BottomSheetContextProps>({\n scrollRef: () => null,\n scrollPosition: undefined,\n onClose: () => null,\n onBack: () => null,\n disableDrag: false,\n});\n\nexport default BottomSheetContext;\n"],"mappings":";;;AAaA,IAAMA,IAAqBC,EAAuC;CAChE,iBAAiB;CACjB,gBAAgB,KAAA;CAChB,eAAe;CACf,cAAc;CACd,aAAa;AACf,CAAC"}
@@ -0,0 +1,85 @@
1
+ import React, { type ComponentProps, type ElementType, type ReactNode, type RefObject } from "react";
2
+ import { type IconType } from "@bonprix-ds/react-icon";
3
+ import { TitleLevel } from "@bonprix-ds/utils";
4
+ import "./BottomSheet.css";
5
+ interface SheetProps {
6
+ /** All of the subcomponents should be placed inside this property. */
7
+ children: ReactNode;
8
+ /** Callback function, that is triggered when the sheet is attempted to be closed.
9
+ *
10
+ * It will be called in following cases:
11
+ * - Click on backdrop
12
+ * - Press of the `Escape` key
13
+ * - Swipe down to close
14
+ * - Click on "close" icon button in the upper-right corner
15
+ * - Click on any button (PrimaryButton or SecondaryButton)
16
+ *
17
+ * Should be used in conjunction with `open`. */
18
+ onClose: () => void;
19
+ /** Callback to execute when clicking back icon. */
20
+ onBack?: () => void;
21
+ /** The z-index of the sheet.. */
22
+ zIndex?: number;
23
+ }
24
+ type OpenProps = SheetProps & {
25
+ /** Toggles the visibility of the sheet. Should be used in conjunction with the `onClose` property. */
26
+ open: boolean;
27
+ /** @deprecated [is-open-prop] Use `open` instead. */
28
+ isOpen?: never;
29
+ };
30
+ type DeprecatedOpenProps = SheetProps & {
31
+ open?: never;
32
+ /**
33
+ * Toggles the visibility of the sheet. Should be used in conjunction with the `onClose` property.
34
+ * @deprecated [is-open-prop] Use `open` instead.
35
+ */
36
+ isOpen: boolean;
37
+ };
38
+ export interface SheetTitleProps {
39
+ /** The text content. */
40
+ children: string;
41
+ /** An optional subline that is displayed right below the title. */
42
+ subline?: string;
43
+ /** The heading level for the title. */
44
+ level?: TitleLevel;
45
+ }
46
+ export interface SheetButtonSectionProps {
47
+ /** Primary and secondary buttons should be placed inside this section. */
48
+ children: ReactNode;
49
+ }
50
+ export interface SheetContentProps {
51
+ /** The content of the content section. */
52
+ children: ReactNode;
53
+ /** If `true`, the horizontal padding around the content will be removed. */
54
+ disableHorizontalPadding?: boolean;
55
+ }
56
+ export interface SheetButtonBaseProps {
57
+ /** The label of the button. */
58
+ children: string;
59
+ /** If used, an icon will be additionally shown. The value is a name of one icon from our icon set. */
60
+ icon?: IconType;
61
+ /** The position of the icon relative to the content. */
62
+ iconPosition?: "start" | "end";
63
+ }
64
+ export type SheetButtonProps<C extends ElementType> = SheetButtonBaseProps & {
65
+ /** The semantic component to render the Button. Preferrably `"button"`. Native props will be passed to this component. */
66
+ component?: C;
67
+ } & Omit<ComponentProps<C>, keyof SheetButtonBaseProps | "component">;
68
+ type SheetPrimaryButtonProps<C extends ElementType> = SheetButtonProps<C> & {
69
+ /** If `true`, a loading spinner will be shown instead of the content. */
70
+ loading?: boolean;
71
+ };
72
+ export type Props = (DeprecatedOpenProps | OpenProps) & {
73
+ /** A reference to the root element of the sheet. */
74
+ ref?: RefObject<HTMLDivElement>;
75
+ };
76
+ declare const BottomSheetRoot: {
77
+ ({ children, open, isOpen, onClose, onBack, zIndex, ref }: Props): React.JSX.Element;
78
+ displayName: string;
79
+ };
80
+ export default BottomSheetRoot;
81
+ export declare const Title: ({ children, subline, level: Level }: SheetTitleProps) => React.JSX.Element;
82
+ export declare const Content: ({ children, disableHorizontalPadding }: SheetContentProps) => React.JSX.Element;
83
+ export declare const ButtonSection: ({ children }: SheetButtonSectionProps) => React.JSX.Element;
84
+ export declare const PrimaryButton: <C extends ElementType>({ children, icon, iconPosition, loading, component, ...props }: SheetPrimaryButtonProps<C>) => React.JSX.Element;
85
+ export declare const SecondaryButton: <C extends ElementType>({ children, icon, iconPosition, component, ...props }: SheetButtonProps<C>) => React.JSX.Element;
@@ -2,96 +2,101 @@
2
2
  import e from "./BottomSheetContext.js";
3
3
  import t from "./useConsumeBottomSheet.js";
4
4
  import n from "./useCreateBottomSheet.js";
5
- import { useEffect as r, useRef as i } from "react";
6
- import { backdrop as a } from "@bonprix-ds/internal-components";
7
- import o from "@bonprix-ds/react-button";
8
- import s from "@bonprix-ds/react-icon-button";
9
- import c from "@bonprix-ds/react-typography";
10
- import { ZIndexContext as l, useInnerOpen as u, usePrefersReducedMotion as d } from "@bonprix-ds/utils";
11
- import { Sheet as f } from "react-modal-sheet";
12
- import { tv as p } from "tailwind-variants";
13
- import * as m from "@radix-ui/react-dialog";
14
- import { jsx as h, jsxs as g } from "react/jsx-runtime";
5
+ import r from "./useKeepScrollPositionOnPageHide.js";
6
+ import { useEffect as i, useRef as a } from "react";
7
+ import * as o from "@radix-ui/react-dialog";
8
+ import { Sheet as s } from "react-modal-sheet";
9
+ import { tv as c } from "tailwind-variants";
10
+ import { backdrop as l } from "@bonprix-ds/internal-components";
11
+ import u from "@bonprix-ds/react-button";
12
+ import d from "@bonprix-ds/react-icon-button";
13
+ import { ZIndexContext as f, useInnerOpen as p, usePrefersReducedMotion as m } from "@bonprix-ds/utils";
14
+ import { warnDeprecated as h } from "@bonprix-ds/utils/deprecation";
15
+ import "#styles";
16
+ import { jsx as g, jsxs as _ } from "react/jsx-runtime";
15
17
  //#region src/BottomSheetRoot.tsx
16
- var _ = p({
18
+ var v = c({
17
19
  slots: {
18
20
  root: "preflight block",
19
- container: "shadow-none rounded-none bg-clr-bg-modal max-h-[calc(100%-4rem)] outline-none",
21
+ container: "max-h-[calc(100%-4rem)] rounded-none bg-clr-bg-modal shadow-none outline-none",
20
22
  header: "px-4 py-3",
21
- titleAndIcons: "flex gap-2 items-center touch-pan-down",
22
- contentWrapper: "flex flex-col w-full",
23
+ titleAndIcons: "flex touch-pan-down items-center gap-2",
24
+ contentWrapper: "flex w-full flex-col",
23
25
  content: [
24
26
  "typography-body1 text-clr-primary",
25
- "*:flex *:-mx-0.5 *:px-0.5",
27
+ "*:-mx-0.5 *:flex *:px-0.5",
26
28
  "*:min-h-0"
27
29
  ],
28
- dragHandleContainer: "h-6 flex justify-center items-center shrink-0",
30
+ dragHandleContainer: "flex h-6 shrink-0 items-center justify-center",
29
31
  dragHandle: "h-1 w-8 rounded-full bg-clr-on-bg-low",
30
- backdrop: a(),
32
+ backdrop: l(),
31
33
  scrollArea: "scroll-area relative"
32
34
  },
33
35
  variants: { disableHorizontalPadding: {
34
36
  false: { scrollArea: "px-4" },
35
37
  true: ""
36
38
  } }
37
- }), v = ({ children: t, isOpen: a, onClose: o, onBack: s, zIndex: c = 9999, ref: p }) => {
38
- let v = d(), { root: y, container: b, dragHandleContainer: x, dragHandle: S, content: C, contentWrapper: w, backdrop: T } = _(), { isShown: E, scrollRef: D, scrollPosition: O } = n({ isOpen: a }), k = O === "middle" || O === "bottom", { innerOpen: A } = u(E), j = i(null);
39
- return r(() => {
40
- A || (j.current?.focus(), j.current = null);
41
- }, [A]), /* @__PURE__ */ h(m.Root, {
42
- open: A,
39
+ }), y = ({ children: t, open: c, isOpen: l, onClose: u, onBack: d, zIndex: y = 9999, ref: b }) => {
40
+ l !== void 0 && h("is-open-prop");
41
+ let x = m(), { root: S, container: C, dragHandleContainer: w, dragHandle: T, content: E, contentWrapper: D, backdrop: O } = v(), { isShown: k, scrollRef: A, scrollPosition: j } = n({ open: c ?? l ?? !1 }), M = j === "middle" || j === "bottom", { innerOpen: N } = p(k);
42
+ r(N);
43
+ let P = a(null);
44
+ return i(() => {
45
+ N || (P.current?.focus(), P.current = null);
46
+ }, [N]), /* @__PURE__ */ g(o.Root, {
47
+ open: N,
43
48
  onOpenChange: (e) => {
44
- e || o();
49
+ e || u();
45
50
  },
46
- children: /* @__PURE__ */ g(f, {
47
- isOpen: A,
48
- onClose: o,
49
- className: y(),
51
+ children: /* @__PURE__ */ _(s, {
52
+ isOpen: N,
53
+ onClose: u,
54
+ className: S(),
50
55
  detent: "content",
51
56
  "data-bpds": "bottom-sheet",
52
- prefersReducedMotion: v,
57
+ prefersReducedMotion: x,
53
58
  style: {
54
59
  pointerEvents: void 0,
55
- visibility: A ? "visible" : "hidden",
56
- zIndex: c
60
+ visibility: N ? "visible" : "hidden",
61
+ zIndex: y
57
62
  },
58
63
  avoidKeyboard: !1,
59
- children: [/* @__PURE__ */ h(m.Content, {
64
+ children: [/* @__PURE__ */ g(o.Content, {
60
65
  forceMount: !0,
61
66
  asChild: !0,
62
67
  "aria-modal": !0,
63
68
  "aria-describedby": void 0,
64
69
  tabIndex: -1,
65
70
  onOpenAutoFocus: (e) => {
66
- e.preventDefault(), j.current = document.activeElement, e.target.focus();
71
+ e.preventDefault(), P.current = document.activeElement, e.target.focus();
67
72
  },
68
73
  onCloseAutoFocus: (e) => e.preventDefault(),
69
- children: /* @__PURE__ */ g(f.Container, {
70
- className: b(),
71
- ref: p,
72
- children: [/* @__PURE__ */ h(f.Header, {
74
+ children: /* @__PURE__ */ _(s.Container, {
75
+ className: C(),
76
+ ref: b,
77
+ children: [/* @__PURE__ */ g(s.Header, {
73
78
  unstyled: !0,
74
- className: x(),
75
- children: /* @__PURE__ */ h(f.DragIndicator, {
79
+ className: w(),
80
+ children: /* @__PURE__ */ g(s.DragIndicator, {
76
81
  unstyled: !0,
77
- className: S()
82
+ className: T()
78
83
  })
79
- }), /* @__PURE__ */ h(l.Provider, {
80
- value: c,
81
- children: /* @__PURE__ */ h(e.Provider, {
84
+ }), /* @__PURE__ */ g(f.Provider, {
85
+ value: y,
86
+ children: /* @__PURE__ */ g(e.Provider, {
82
87
  value: {
83
- scrollRef: D,
84
- scrollPosition: O,
85
- onClose: o,
86
- onBack: s,
87
- disableDrag: k
88
+ scrollRef: A,
89
+ scrollPosition: j,
90
+ onClose: u,
91
+ onBack: d,
92
+ disableDrag: M
88
93
  },
89
- children: /* @__PURE__ */ h(f.Content, {
90
- className: C(),
94
+ children: /* @__PURE__ */ g(s.Content, {
95
+ className: E(),
91
96
  disableScroll: !0,
92
- disableDrag: k,
93
- children: /* @__PURE__ */ h("div", {
94
- className: w(),
97
+ disableDrag: M,
98
+ children: /* @__PURE__ */ g("div", {
99
+ className: D(),
95
100
  style: { paddingBottom: "max(var(--keyboard-inset-height, 0rem), var(--app-safe-area-inset-bottom, 1rem))" },
96
101
  children: t
97
102
  })
@@ -99,36 +104,34 @@ var _ = p({
99
104
  })
100
105
  })]
101
106
  })
102
- }), /* @__PURE__ */ h(f.Backdrop, { className: T() })]
107
+ }), /* @__PURE__ */ g(s.Backdrop, { className: O() })]
103
108
  })
104
109
  });
105
- }, y = ({ children: e, subline: n, level: r = "h3" }) => {
106
- let { onBack: i, onClose: a } = t(), { header: o, titleAndIcons: l } = _();
107
- return /* @__PURE__ */ g("div", {
108
- className: o(),
109
- children: [/* @__PURE__ */ g("div", {
110
- className: l(),
110
+ }, b = ({ children: e, subline: n, level: r = "h3" }) => {
111
+ let { onBack: i, onClose: a } = t(), { header: s, titleAndIcons: c } = v();
112
+ return /* @__PURE__ */ _("div", {
113
+ className: s(),
114
+ children: [/* @__PURE__ */ _("div", {
115
+ className: c(),
111
116
  children: [
112
- i && /* @__PURE__ */ h(s, {
117
+ i && /* @__PURE__ */ g(d, {
113
118
  onClick: i,
114
119
  icon: "arrow-left",
115
120
  label: "Zurück",
116
121
  variant: "tertiary",
117
122
  size: "small"
118
123
  }),
119
- /* @__PURE__ */ h(m.Title, {
124
+ /* @__PURE__ */ g(o.Title, {
120
125
  asChild: !0,
121
- children: /* @__PURE__ */ h("div", {
126
+ children: /* @__PURE__ */ g("div", {
122
127
  className: "grow",
123
- children: /* @__PURE__ */ h(c, {
124
- variant: "bonprix-h6",
125
- component: r,
126
- className: "line-clamp-2",
128
+ children: /* @__PURE__ */ g(r, {
129
+ className: "typography-bonprix-h6 my-0 line-clamp-2 text-start text-clr-on-bg-high",
127
130
  children: e
128
131
  })
129
132
  })
130
133
  }),
131
- /* @__PURE__ */ h(s, {
134
+ /* @__PURE__ */ g(d, {
132
135
  onClick: a,
133
136
  icon: "closer",
134
137
  label: "Schließen",
@@ -136,11 +139,14 @@ var _ = p({
136
139
  size: "small"
137
140
  })
138
141
  ]
139
- }), n && /* @__PURE__ */ h(c, { children: n })]
142
+ }), n && /* @__PURE__ */ g("p", {
143
+ className: "typography-body1 my-0 text-start text-clr-on-bg-high",
144
+ children: n
145
+ })]
140
146
  });
141
- }, b = ({ children: e, disableHorizontalPadding: n = !1 }) => {
142
- let { scrollRef: r, disableDrag: i } = t(), { scrollArea: a } = _({ disableHorizontalPadding: n });
143
- return /* @__PURE__ */ h("div", {
147
+ }, x = ({ children: e, disableHorizontalPadding: n = !1 }) => {
148
+ let { scrollRef: r, disableDrag: i } = t(), { scrollArea: a } = v({ disableHorizontalPadding: n });
149
+ return /* @__PURE__ */ g("div", {
144
150
  ref: r,
145
151
  className: a(),
146
152
  style: { touchAction: i ? "auto" : "pan-down" },
@@ -148,16 +154,16 @@ var _ = p({
148
154
  tabIndex: 0,
149
155
  children: e
150
156
  });
151
- }, x = ({ children: e }) => /* @__PURE__ */ h("div", {
152
- className: "button-section w-full flex flex-col gap-3 px-4 pt-4 shrink-0 touch-pan-down",
157
+ }, S = ({ children: e }) => /* @__PURE__ */ g("div", {
158
+ className: "button-section flex w-full shrink-0 touch-pan-down flex-col gap-3 px-4 pt-4",
153
159
  children: e
154
- }), S = ({ children: e, icon: n, iconPosition: r, loading: i, component: a = "button", ...s }) => {
155
- let c = a, { onClick: l, ...u } = s, { onClose: d } = t(), f = (e) => {
156
- l?.(e), d();
160
+ }), C = ({ children: e, icon: n, iconPosition: r, loading: i, component: a = "button", ...o }) => {
161
+ let s = a, { onClick: c, ...l } = o, { onClose: d } = t(), f = (e) => {
162
+ c?.(e), d();
157
163
  };
158
- return /* @__PURE__ */ h(o, {
159
- component: c,
160
- ...u,
164
+ return /* @__PURE__ */ g(u, {
165
+ component: s,
166
+ ...l,
161
167
  variant: "primary",
162
168
  onClick: f,
163
169
  icon: n,
@@ -166,21 +172,21 @@ var _ = p({
166
172
  loading: i,
167
173
  children: e
168
174
  });
169
- }, C = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...a }) => {
170
- let s = i, { onClose: c } = t();
171
- return /* @__PURE__ */ h(o, {
172
- component: s,
175
+ }, w = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...a }) => {
176
+ let o = i, { onClose: s } = t();
177
+ return /* @__PURE__ */ g(u, {
178
+ component: o,
173
179
  ...a,
174
180
  variant: "secondary",
175
- onClick: c,
181
+ onClick: s,
176
182
  icon: n,
177
183
  iconPosition: r,
178
184
  size: "large",
179
185
  children: e
180
186
  });
181
187
  };
182
- v.displayName = "BottomSheet";
188
+ y.displayName = "BottomSheet";
183
189
  //#endregion
184
- export { x as ButtonSection, b as Content, S as PrimaryButton, C as SecondaryButton, y as Title, v as default };
190
+ export { S as ButtonSection, x as Content, C as PrimaryButton, w as SecondaryButton, b as Title, y as default };
185
191
 
186
192
  //# sourceMappingURL=BottomSheetRoot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BottomSheetRoot.js","names":[],"sources":["../../src/BottomSheetRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport { backdrop } from \"@bonprix-ds/internal-components\";\nimport Button from \"@bonprix-ds/react-button\";\nimport { type IconType } from \"@bonprix-ds/react-icon\";\nimport IconButton from \"@bonprix-ds/react-icon-button\";\nimport Typography from \"@bonprix-ds/react-typography\";\nimport { TitleLevel, useInnerOpen, usePrefersReducedMotion, ZIndexContext } from \"@bonprix-ds/utils\";\nimport React, { useEffect, useRef, type ComponentProps, type ElementType, type ReactNode, type RefObject } from \"react\";\nimport { Sheet } from \"react-modal-sheet\";\nimport { tv } from \"tailwind-variants\";\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\n\nimport BottomSheetContext from \"./BottomSheetContext\";\nimport useConsumeBottomSheet from \"./useConsumeBottomSheet\";\nimport useCreateBottomSheet from \"./useCreateBottomSheet\";\n\nconst generateClasses = tv({\n slots: {\n root: \"preflight block\",\n container: \"shadow-none rounded-none bg-clr-bg-modal max-h-[calc(100%-4rem)] outline-none\",\n header: \"px-4 py-3\",\n titleAndIcons: \"flex gap-2 items-center touch-pan-down\",\n contentWrapper: \"flex flex-col w-full\",\n content: [\n \"typography-body1 text-clr-primary\",\n // scroller must be a flexbox to fix scrollbar\n // scroller needs some padding to not cut off the focus-ring\n \"*:flex *:-mx-0.5 *:px-0.5\",\n // scroller must set min-h-0 in order to make scrolling work inside our flex context\n \"*:min-h-0\",\n ],\n dragHandleContainer: \"h-6 flex justify-center items-center shrink-0\",\n dragHandle: \"h-1 w-8 rounded-full bg-clr-on-bg-low\",\n backdrop: backdrop(),\n scrollArea: \"scroll-area relative\",\n },\n variants: {\n disableHorizontalPadding: {\n false: { scrollArea: \"px-4\" },\n true: \"\",\n },\n },\n});\n\ninterface SheetProps {\n /** All of the subcomponents should be placed inside this property. */\n children: ReactNode;\n /** Toggles the visibility of the sheet. Should be used in conjunction with the `onClose` property. */\n isOpen: boolean;\n /** Callback function, that is triggered when the sheet is attempted to be closed.\n *\n * It will be called in following cases:\n * - Click on backdrop\n * - Press of the `Escape` key\n * - Swipe down to close\n * - Click on \"close\" icon button in the upper-right corner\n * - Click on any button (PrimaryButton or SecondaryButton)\n *\n * Should be used in conjunction with `isOpen`. */\n onClose: () => void;\n /** Callback to execute when clicking back icon. */\n onBack?: () => void;\n /** The z-index of the sheet.. */\n zIndex?: number;\n}\n\nexport interface SheetTitleProps {\n /** The text content. */\n children: string;\n /** An optional subline that is displayed right below the title. */\n subline?: string;\n /** The heading level for the title. */\n level?: TitleLevel;\n}\n\nexport interface SheetButtonSectionProps {\n /** Primary and secondary buttons should be placed inside this section. */\n children: ReactNode;\n}\n\nexport interface SheetContentProps {\n /** The content of the content section. */\n children: ReactNode;\n /** If `true`, the horizontal padding around the content will be removed. */\n disableHorizontalPadding?: boolean;\n}\n\nexport interface SheetButtonBaseProps {\n /** The label of the button. */\n children: string;\n /** If used, an icon will be additionally shown. The value is a name of one icon from our icon set. */\n icon?: IconType;\n /** The position of the icon relative to the content. */\n iconPosition?: \"start\" | \"end\";\n}\n\nexport type SheetButtonProps<C extends ElementType> = SheetButtonBaseProps & {\n /** The semantic component to render the Button. Preferrably `\"button\"`. Native props will be passed to this component. */\n component?: C;\n} & Omit<ComponentProps<C>, keyof SheetButtonBaseProps | \"component\">;\n\ntype SheetPrimaryButtonProps<C extends ElementType> = SheetButtonProps<C> & {\n /** If `true`, a loading spinner will be shown instead of the content. */\n loading?: boolean;\n};\n\nexport interface Props extends SheetProps {\n /** A reference to the root element of the sheet. */\n ref?: RefObject<HTMLDivElement>;\n}\n\nconst BottomSheetRoot = ({ children, isOpen, onClose, onBack, zIndex = 9999, ref }: Props) => {\n const prefersReducedMotion = usePrefersReducedMotion();\n const { root, container, dragHandleContainer, dragHandle, content, contentWrapper, backdrop } = generateClasses();\n const { isShown, scrollRef, scrollPosition } = useCreateBottomSheet({ isOpen });\n\n // When \"middle\" or \"bottom\", dragging is disabled to allow for regular scrolling.\n // When at \"top\", we need to enable drag to close. When `undefined`, the element is not scrollable and can be dragged, too.\n const disableDrag = scrollPosition === \"middle\" || scrollPosition === \"bottom\";\n\n const { innerOpen } = useInnerOpen(isShown);\n\n const elementFocusedBeforeOpen = useRef<HTMLElement | null>(null);\n\n // Radix hands focus back to `Dialog.Trigger` on close, and this sheet has none: it is opened through `isOpen`.\n // Both ends are taken over here so that the sheet itself is focused and the element that opened it gets focus back.\n const focusSheet = (event: Event) => {\n event.preventDefault();\n elementFocusedBeforeOpen.current = document.activeElement as HTMLElement | null;\n (event.target as HTMLElement).focus();\n };\n\n // Radix restores focus when its focus scope unmounts, which `forceMount` defers until react-modal-sheet has\n // animated the sheet away - and never at all where that animation does not settle. Closing is the reliable signal.\n const keepFocusWhereItIs = (event: Event) => event.preventDefault();\n\n useEffect(() => {\n if (innerOpen) return;\n elementFocusedBeforeOpen.current?.focus();\n elementFocusedBeforeOpen.current = null;\n }, [innerOpen]);\n\n const handleOpenChange = (open: boolean) => {\n if (!open) onClose();\n };\n\n return (\n <DialogPrimitive.Root open={innerOpen} onOpenChange={handleOpenChange}>\n <Sheet\n isOpen={innerOpen}\n onClose={onClose}\n className={root()}\n detent=\"content\"\n data-bpds=\"bottom-sheet\"\n prefersReducedMotion={prefersReducedMotion}\n style={{\n // We remove `pointer-events` handling from the library because it interfers with a lot of things like opened Selects that wouldn't close etc.\n pointerEvents: undefined,\n // When removing react-modal-sheet's pointerEvents handling, we need to adjust visibility because we can no longer rely on `pointer-events: none` being set on the wrapper that spans the whole page even when closed.\n visibility: innerOpen ? \"visible\" : \"hidden\",\n zIndex: zIndex,\n }}\n avoidKeyboard={false}\n >\n {/* `forceMount` leaves the mounting to the sheet, whose state machine keeps the container around for the closing animation. */}\n <DialogPrimitive.Content\n forceMount\n asChild\n aria-modal\n aria-describedby={undefined}\n tabIndex={-1}\n onOpenAutoFocus={focusSheet}\n onCloseAutoFocus={keepFocusWhereItIs}\n >\n <Sheet.Container className={container()} ref={ref}>\n <Sheet.Header unstyled className={dragHandleContainer()}>\n <Sheet.DragIndicator unstyled className={dragHandle()} />\n </Sheet.Header>\n <ZIndexContext.Provider value={zIndex}>\n <BottomSheetContext.Provider value={{ scrollRef, scrollPosition, onClose, onBack, disableDrag }}>\n <Sheet.Content\n className={content()}\n // disable default scrolling\n disableScroll\n // Dragging is still managed by `Sheet.Content` so we control it here\n disableDrag={disableDrag}\n >\n <div\n className={contentWrapper()}\n // Apply keyboard height as padding bottom to keep content above the keyboard\n style={{ paddingBottom: \"max(var(--keyboard-inset-height, 0rem), var(--app-safe-area-inset-bottom, 1rem))\" }}\n >\n {children}\n </div>\n </Sheet.Content>\n </BottomSheetContext.Provider>\n </ZIndexContext.Provider>\n </Sheet.Container>\n </DialogPrimitive.Content>\n {/* TODO: Deactivate the animation, when the user prefers reduced motion: https://github.com/Temzasse/react-modal-sheet/issues/227 */}\n {/* The backdrop carries no handler of its own: Radix dismisses the dialog on a press outside of its content. */}\n <Sheet.Backdrop className={backdrop()} />\n </Sheet>\n </DialogPrimitive.Root>\n );\n};\n\nexport default BottomSheetRoot;\n\nexport const Title = ({ children, subline, level = \"h3\" }: SheetTitleProps) => {\n const { onBack, onClose } = useConsumeBottomSheet();\n const { header, titleAndIcons } = generateClasses();\n return (\n <div className={header()}>\n <div className={titleAndIcons()}>\n {onBack && <IconButton onClick={onBack} icon=\"arrow-left\" label=\"Zurück\" variant=\"tertiary\" size=\"small\" />}\n <DialogPrimitive.Title asChild>\n <div className=\"grow\">\n <Typography variant=\"bonprix-h6\" component={level} className=\"line-clamp-2\">\n {children}\n </Typography>\n </div>\n </DialogPrimitive.Title>\n <IconButton onClick={onClose} icon=\"closer\" label=\"Schließen\" variant=\"tertiary\" size=\"small\" />\n </div>\n {subline && <Typography>{subline}</Typography>}\n </div>\n );\n};\n\nexport const Content = ({ children, disableHorizontalPadding = false }: SheetContentProps) => {\n const { scrollRef: setScrollRef, disableDrag } = useConsumeBottomSheet();\n const { scrollArea } = generateClasses({ disableHorizontalPadding });\n return (\n <div\n ref={setScrollRef}\n className={scrollArea()}\n // react-modal-sheet writes this same property imperatively, but only once it has measured the element as\n // scrollable - and it bails before doing so on every open where that measurement is not ready yet, which\n // leaves the browser free to claim the downward swipe and cancel the drag. Setting it here closes that gap.\n style={{ touchAction: disableDrag ? \"auto\" : \"pan-down\" }}\n data-bpds-disable-horizontal-padding={disableHorizontalPadding}\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nexport const ButtonSection = ({ children }: SheetButtonSectionProps) => {\n return <div className=\"button-section w-full flex flex-col gap-3 px-4 pt-4 shrink-0 touch-pan-down\">{children}</div>;\n};\n\nexport const PrimaryButton = <C extends ElementType>({\n children,\n icon,\n iconPosition,\n loading,\n component = \"button\" as C,\n ...props\n}: SheetPrimaryButtonProps<C>) => {\n const Component: ElementType = component;\n const { onClick, ...otherProps } = props;\n const { onClose } = useConsumeBottomSheet();\n const handleClick = (event: React.MouseEvent) => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n onClick?.(event);\n onClose();\n };\n return (\n <Button\n component={Component}\n {...otherProps}\n variant=\"primary\"\n onClick={handleClick}\n icon={icon}\n iconPosition={iconPosition}\n size=\"large\"\n loading={loading}\n >\n {children}\n </Button>\n );\n};\n\nexport const SecondaryButton = <C extends ElementType>({\n children,\n icon,\n iconPosition,\n component = \"button\" as C,\n ...props\n}: SheetButtonProps<C>) => {\n const Component: ElementType = component;\n const { onClose } = useConsumeBottomSheet();\n return (\n <Button component={Component} {...props} variant=\"secondary\" onClick={onClose} icon={icon} iconPosition={iconPosition} size=\"large\">\n {children}\n </Button>\n );\n};\n\nBottomSheetRoot.displayName = \"BottomSheet\";\n"],"mappings":";;;;;;;;;;;;;;;AAiBA,IAAM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AAA,UAAa,EAAoB,CAAA,CAC1C;;AAET,GAEa,KAAW,EAAE,aAAU,8BAA2B,SAA+B;CAC5F,IAAM,EAAE,WAAW,GAAc,mBAAgB,EAAsB,GACjE,EAAE,kBAAe,EAAgB,EAAE,4BAAyB,CAAC;CACnE,OACE,kBAAC,OAAD;EACE,KAAK;EACL,WAAW,EAAW;EAItB,OAAO,EAAE,aAAa,IAAc,SAAS,WAAW;EACxD,wCAAsC;EACtC,UAAU;EAET;CACE,CAAA;AAET,GAEa,KAAiB,EAAE,kBACvB,kBAAC,OAAD;CAAK,WAAU;CAA+E;AAAc,CAAA,GAGxG,KAAwC,EACnD,aACA,SACA,iBACA,YACA,eAAY,UACZ,GAAG,QAC6B;CAChC,IAAM,IAAyB,GACzB,EAAE,YAAS,GAAG,MAAe,GAC7B,EAAE,eAAY,EAAsB,GACpC,KAAe,MAA4B;EAG/C,AADA,IAAU,CAAK,GACf,EAAQ;CACV;CACA,OACE,kBAAC,GAAD;EACE,WAAW;EACX,GAAI;EACJ,SAAQ;EACR,SAAS;EACH;EACQ;EACd,MAAK;EACI;EAER;CACK,CAAA;AAEZ,GAEa,KAA0C,EACrD,aACA,SACA,iBACA,eAAY,UACZ,GAAG,QACsB;CACzB,IAAM,IAAyB,GACzB,EAAE,eAAY,EAAsB;CAC1C,OACE,kBAAC,GAAD;EAAQ,WAAW;EAAW,GAAI;EAAO,SAAQ;EAAY,SAAS;EAAe;EAAoB;EAAc,MAAK;EACzH;CACK,CAAA;AAEZ;AAEA,EAAgB,cAAc"}
1
+ {"version":3,"file":"BottomSheetRoot.js","names":["BottomSheetContext","useConsumeBottomSheet","useCreateBottomSheet","useKeepScrollPositionOnPageHide","DialogPrimitive","Button","IconButton","generateClasses","tv","backdrop","BottomSheetRoot","isOpen","warnDeprecated","prefersReducedMotion","usePrefersReducedMotion","open","disableDrag","scrollPosition","useInnerOpen","isShown","innerOpen","elementFocusedBeforeOpen","useRef","useEffect","nextOpen","onClose","Sheet","root","event","container","dragHandleContainer","dragHandle","ZIndexContext","zIndex","content","contentWrapper","Title","Level","header","titleAndIcons","onBack","subline","Content","setScrollRef","scrollArea","disableHorizontalPadding","ButtonSection","PrimaryButton","props","Component","component","otherProps","handleClick","onClick","SecondaryButton"],"sources":["../../src/BottomSheetRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport React, { useEffect, useRef, type ComponentProps, type ElementType, type ReactNode, type RefObject } from \"react\";\nimport { Sheet } from \"react-modal-sheet\";\nimport { tv } from \"tailwind-variants\";\n\nimport { backdrop } from \"@bonprix-ds/internal-components\";\nimport Button from \"@bonprix-ds/react-button\";\nimport { type IconType } from \"@bonprix-ds/react-icon\";\nimport IconButton from \"@bonprix-ds/react-icon-button\";\nimport { TitleLevel, useInnerOpen, usePrefersReducedMotion, ZIndexContext } from \"@bonprix-ds/utils\";\nimport { warnDeprecated } from \"@bonprix-ds/utils/deprecation\";\n\nimport BottomSheetContext from \"./BottomSheetContext\";\nimport useConsumeBottomSheet from \"./useConsumeBottomSheet\";\nimport useCreateBottomSheet from \"./useCreateBottomSheet\";\nimport useKeepScrollPositionOnPageHide from \"./useKeepScrollPositionOnPageHide\";\n\nimport \"./BottomSheet.css\";\n\nconst generateClasses = tv({\n slots: {\n root: \"preflight block\",\n container: \"max-h-[calc(100%-4rem)] rounded-none bg-clr-bg-modal shadow-none outline-none\",\n header: \"px-4 py-3\",\n titleAndIcons: \"flex touch-pan-down items-center gap-2\",\n contentWrapper: \"flex w-full flex-col\",\n content: [\n \"typography-body1 text-clr-primary\",\n // scroller must be a flexbox to fix scrollbar\n // scroller needs some padding to not cut off the focus-ring\n \"*:-mx-0.5 *:flex *:px-0.5\",\n // scroller must set min-h-0 in order to make scrolling work inside our flex context\n \"*:min-h-0\",\n ],\n dragHandleContainer: \"flex h-6 shrink-0 items-center justify-center\",\n dragHandle: \"h-1 w-8 rounded-full bg-clr-on-bg-low\",\n backdrop: backdrop(),\n scrollArea: \"scroll-area relative\",\n },\n variants: {\n disableHorizontalPadding: {\n false: { scrollArea: \"px-4\" },\n true: \"\",\n },\n },\n});\n\ninterface SheetProps {\n /** All of the subcomponents should be placed inside this property. */\n children: ReactNode;\n /** Callback function, that is triggered when the sheet is attempted to be closed.\n *\n * It will be called in following cases:\n * - Click on backdrop\n * - Press of the `Escape` key\n * - Swipe down to close\n * - Click on \"close\" icon button in the upper-right corner\n * - Click on any button (PrimaryButton or SecondaryButton)\n *\n * Should be used in conjunction with `open`. */\n onClose: () => void;\n /** Callback to execute when clicking back icon. */\n onBack?: () => void;\n /** The z-index of the sheet.. */\n zIndex?: number;\n}\n\ntype OpenProps = SheetProps & {\n /** Toggles the visibility of the sheet. Should be used in conjunction with the `onClose` property. */\n open: boolean;\n /** @deprecated [is-open-prop] Use `open` instead. */\n isOpen?: never;\n};\n\ntype DeprecatedOpenProps = SheetProps & {\n open?: never;\n /**\n * Toggles the visibility of the sheet. Should be used in conjunction with the `onClose` property.\n * @deprecated [is-open-prop] Use `open` instead.\n */\n isOpen: boolean;\n};\n\nexport interface SheetTitleProps {\n /** The text content. */\n children: string;\n /** An optional subline that is displayed right below the title. */\n subline?: string;\n /** The heading level for the title. */\n level?: TitleLevel;\n}\n\nexport interface SheetButtonSectionProps {\n /** Primary and secondary buttons should be placed inside this section. */\n children: ReactNode;\n}\n\nexport interface SheetContentProps {\n /** The content of the content section. */\n children: ReactNode;\n /** If `true`, the horizontal padding around the content will be removed. */\n disableHorizontalPadding?: boolean;\n}\n\nexport interface SheetButtonBaseProps {\n /** The label of the button. */\n children: string;\n /** If used, an icon will be additionally shown. The value is a name of one icon from our icon set. */\n icon?: IconType;\n /** The position of the icon relative to the content. */\n iconPosition?: \"start\" | \"end\";\n}\n\nexport type SheetButtonProps<C extends ElementType> = SheetButtonBaseProps & {\n /** The semantic component to render the Button. Preferrably `\"button\"`. Native props will be passed to this component. */\n component?: C;\n} & Omit<ComponentProps<C>, keyof SheetButtonBaseProps | \"component\">;\n\ntype SheetPrimaryButtonProps<C extends ElementType> = SheetButtonProps<C> & {\n /** If `true`, a loading spinner will be shown instead of the content. */\n loading?: boolean;\n};\n\nexport type Props = (DeprecatedOpenProps | OpenProps) & {\n /** A reference to the root element of the sheet. */\n ref?: RefObject<HTMLDivElement>;\n};\n\nconst BottomSheetRoot = ({ children, open, isOpen, onClose, onBack, zIndex = 9999, ref }: Props) => {\n if (isOpen !== undefined) warnDeprecated(\"is-open-prop\");\n const prefersReducedMotion = usePrefersReducedMotion();\n const { root, container, dragHandleContainer, dragHandle, content, contentWrapper, backdrop } = generateClasses();\n const { isShown, scrollRef, scrollPosition } = useCreateBottomSheet({ open: open ?? isOpen ?? false });\n\n // When \"middle\" or \"bottom\", dragging is disabled to allow for regular scrolling.\n // When at \"top\", we need to enable drag to close. When `undefined`, the element is not scrollable and can be dragged, too.\n const disableDrag = scrollPosition === \"middle\" || scrollPosition === \"bottom\";\n\n const { innerOpen } = useInnerOpen(isShown);\n useKeepScrollPositionOnPageHide(innerOpen);\n\n const elementFocusedBeforeOpen = useRef<HTMLElement | null>(null);\n\n // Radix hands focus back to `Dialog.Trigger` on close, and this sheet has none: it is opened through `open`.\n // Both ends are taken over here so that the sheet itself is focused and the element that opened it gets focus back.\n const focusSheet = (event: Event) => {\n event.preventDefault();\n elementFocusedBeforeOpen.current = document.activeElement as HTMLElement | null;\n (event.target as HTMLElement).focus();\n };\n\n // Radix restores focus when its focus scope unmounts, which `forceMount` defers until react-modal-sheet has\n // animated the sheet away - and never at all where that animation does not settle. Closing is the reliable signal.\n const keepFocusWhereItIs = (event: Event) => event.preventDefault();\n\n useEffect(() => {\n if (innerOpen) return;\n elementFocusedBeforeOpen.current?.focus();\n elementFocusedBeforeOpen.current = null;\n }, [innerOpen]);\n\n const handleOpenChange = (nextOpen: boolean) => {\n if (!nextOpen) onClose();\n };\n\n return (\n <DialogPrimitive.Root open={innerOpen} onOpenChange={handleOpenChange}>\n <Sheet\n isOpen={innerOpen}\n onClose={onClose}\n className={root()}\n detent=\"content\"\n data-bpds=\"bottom-sheet\"\n prefersReducedMotion={prefersReducedMotion}\n style={{\n // We remove `pointer-events` handling from the library because it interfers with a lot of things like opened Selects that wouldn't close etc.\n pointerEvents: undefined,\n // When removing react-modal-sheet's pointerEvents handling, we need to adjust visibility because we can no longer rely on `pointer-events: none` being set on the wrapper that spans the whole page even when closed.\n visibility: innerOpen ? \"visible\" : \"hidden\",\n zIndex: zIndex,\n }}\n avoidKeyboard={false}\n >\n {/* `forceMount` leaves the mounting to the sheet, whose state machine keeps the container around for the closing animation. */}\n <DialogPrimitive.Content\n forceMount\n asChild\n aria-modal\n aria-describedby={undefined}\n tabIndex={-1}\n onOpenAutoFocus={focusSheet}\n onCloseAutoFocus={keepFocusWhereItIs}\n >\n <Sheet.Container className={container()} ref={ref}>\n <Sheet.Header unstyled className={dragHandleContainer()}>\n <Sheet.DragIndicator unstyled className={dragHandle()} />\n </Sheet.Header>\n <ZIndexContext.Provider value={zIndex}>\n <BottomSheetContext.Provider value={{ scrollRef, scrollPosition, onClose, onBack, disableDrag }}>\n <Sheet.Content\n className={content()}\n // disable default scrolling\n disableScroll\n // Dragging is still managed by `Sheet.Content` so we control it here\n disableDrag={disableDrag}\n >\n <div\n className={contentWrapper()}\n // Apply keyboard height as padding bottom to keep content above the keyboard\n style={{ paddingBottom: \"max(var(--keyboard-inset-height, 0rem), var(--app-safe-area-inset-bottom, 1rem))\" }}\n >\n {children}\n </div>\n </Sheet.Content>\n </BottomSheetContext.Provider>\n </ZIndexContext.Provider>\n </Sheet.Container>\n </DialogPrimitive.Content>\n {/* TODO: Deactivate the animation, when the user prefers reduced motion: https://github.com/Temzasse/react-modal-sheet/issues/227 */}\n {/* The backdrop carries no handler of its own: Radix dismisses the dialog on a press outside of its content. */}\n <Sheet.Backdrop className={backdrop()} />\n </Sheet>\n </DialogPrimitive.Root>\n );\n};\n\nexport default BottomSheetRoot;\n\nexport const Title = ({ children, subline, level: Level = \"h3\" }: SheetTitleProps) => {\n const { onBack, onClose } = useConsumeBottomSheet();\n const { header, titleAndIcons } = generateClasses();\n return (\n <div className={header()}>\n <div className={titleAndIcons()}>\n {onBack && <IconButton onClick={onBack} icon=\"arrow-left\" label=\"Zurück\" variant=\"tertiary\" size=\"small\" />}\n <DialogPrimitive.Title asChild>\n <div className=\"grow\">\n <Level className=\"typography-bonprix-h6 my-0 line-clamp-2 text-start text-clr-on-bg-high\">{children}</Level>\n </div>\n </DialogPrimitive.Title>\n <IconButton onClick={onClose} icon=\"closer\" label=\"Schließen\" variant=\"tertiary\" size=\"small\" />\n </div>\n {subline && <p className=\"typography-body1 my-0 text-start text-clr-on-bg-high\">{subline}</p>}\n </div>\n );\n};\n\nexport const Content = ({ children, disableHorizontalPadding = false }: SheetContentProps) => {\n const { scrollRef: setScrollRef, disableDrag } = useConsumeBottomSheet();\n const { scrollArea } = generateClasses({ disableHorizontalPadding });\n return (\n <div\n ref={setScrollRef}\n className={scrollArea()}\n // react-modal-sheet writes this same property imperatively, but only once it has measured the element as\n // scrollable - and it bails before doing so on every open where that measurement is not ready yet, which\n // leaves the browser free to claim the downward swipe and cancel the drag. Setting it here closes that gap.\n style={{ touchAction: disableDrag ? \"auto\" : \"pan-down\" }}\n data-bpds-disable-horizontal-padding={disableHorizontalPadding}\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nexport const ButtonSection = ({ children }: SheetButtonSectionProps) => {\n return <div className=\"button-section flex w-full shrink-0 touch-pan-down flex-col gap-3 px-4 pt-4\">{children}</div>;\n};\n\nexport const PrimaryButton = <C extends ElementType>({\n children,\n icon,\n iconPosition,\n loading,\n component = \"button\" as C,\n ...props\n}: SheetPrimaryButtonProps<C>) => {\n const Component: ElementType = component;\n const { onClick, ...otherProps } = props;\n const { onClose } = useConsumeBottomSheet();\n const handleClick = (event: React.MouseEvent) => {\n // oxlint-disable-next-line @typescript-eslint/no-unsafe-call\n onClick?.(event);\n onClose();\n };\n return (\n <Button\n component={Component}\n {...otherProps}\n variant=\"primary\"\n onClick={handleClick}\n icon={icon}\n iconPosition={iconPosition}\n size=\"large\"\n loading={loading}\n >\n {children}\n </Button>\n );\n};\n\nexport const SecondaryButton = <C extends ElementType>({\n children,\n icon,\n iconPosition,\n component = \"button\" as C,\n ...props\n}: SheetButtonProps<C>) => {\n const Component: ElementType = component;\n const { onClose } = useConsumeBottomSheet();\n return (\n <Button component={Component} {...props} variant=\"secondary\" onClick={onClose} icon={icon} iconPosition={iconPosition} size=\"large\">\n {children}\n </Button>\n );\n};\n\nBottomSheetRoot.displayName = \"BottomSheet\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAqBA,IAAMO,IAAkBC,EAAG;CACzB,OAAO;EACL,MAAM;EACN,WAAW;EACX,QAAQ;EACR,eAAe;EACf,gBAAgB;EAChB,SAAS;GACP;GAGA;GAEA;EACF;EACA,qBAAqB;EACrB,YAAY;EACZ,UAAUC,EAAS;EACnB,YAAY;CACd;CACA,UAAU,EACR,0BAA0B;EACxB,OAAO,EAAE,YAAY,OAAO;EAC5B,MAAM;CACR,EACF;AACF,CAAC,GAmFKC,KAAmB,EAAE,aAAU,SAAM,WAAQ,YAAS,WAAQ,YAAS,MAAM,aAAiB;CAClG,AAAIC,MAAW,KAAA,KAAWC,EAAe,cAAc;CACvD,IAAMC,IAAuBC,EAAwB,GAC/C,EAAE,SAAM,cAAW,wBAAqB,eAAY,YAAS,mBAAgB,gBAAaP,EAAgB,GAC1G,EAAE,YAAS,cAAW,sBAAmBL,EAAqB,EAAE,MAAMa,KAAQJ,KAAU,GAAM,CAAC,GAI/FK,IAAcC,MAAmB,YAAYA,MAAmB,UAEhE,EAAE,iBAAcC,EAAaC,CAAO;CAC1C,EAAgCC,CAAS;CAEzC,IAAMC,IAA2BC,EAA2B,IAAI;CAwBhE,OAVAC,QAAgB;EACd,AAAIH,MACJC,EAAyB,SAAS,MAAM,GACxC,EAAyB,UAAU;CACrC,GAAG,CAACD,CAAS,CAAC,GAOZ,kBAAChB,EAAgB,M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,GAAIE;EACJ,SAAQ;EACR,SAASC;EACH;EACQ;EACd,MAAK;EACI;EAER;CACK,CAAA;AAEZ,GAEaE,KAA0C,EACrD,aACA,SACA,iBACA,eAAY,UACZ,GAAGN,QACsB;CACzB,IAAMC,IAAyBC,GACzB,EAAE,eAAYjD,EAAsB;CAC1C,OACE,kBAACI,GAAD;EAAQ,WAAW4C;EAAW,GAAID;EAAO,SAAQ;EAAY,SAASvB;EAAe;EAAoB;EAAc,MAAK;EACzH;CACK,CAAA;AAEZ;AAEA,EAAgB,cAAc"}
@@ -0,0 +1,2 @@
1
+ declare const useConsumeBottomSheet: () => import("./BottomSheetContext").BottomSheetContextProps;
2
+ export default useConsumeBottomSheet;
@@ -1 +1 @@
1
- {"version":3,"file":"useConsumeBottomSheet.js","names":[],"sources":["../../src/useConsumeBottomSheet.ts"],"sourcesContent":["import { useContext } from \"react\";\n\nimport BottomSheetContext from \"./BottomSheetContext\";\n\nconst useConsumeBottomSheet = () => {\n return useContext(BottomSheetContext);\n};\n\nexport default useConsumeBottomSheet;\n"],"mappings":";;;AAIA,IAAM,UACG,EAAW,CAAkB"}
1
+ {"version":3,"file":"useConsumeBottomSheet.js","names":["BottomSheetContext","useConsumeBottomSheet","useContext"],"sources":["../../src/useConsumeBottomSheet.ts"],"sourcesContent":["import { useContext } from \"react\";\n\nimport BottomSheetContext from \"./BottomSheetContext\";\n\nconst useConsumeBottomSheet = () => {\n return useContext(BottomSheetContext);\n};\n\nexport default useConsumeBottomSheet;\n"],"mappings":";;;AAIA,IAAMC,UACGC,EAAWF,CAAkB"}
@@ -0,0 +1,9 @@
1
+ interface UseBottomSheetProps {
2
+ open: boolean;
3
+ }
4
+ declare const useCreateBottomSheet: ({ open }: UseBottomSheetProps) => {
5
+ isShown: boolean;
6
+ scrollRef: (element: HTMLElement | null) => void;
7
+ scrollPosition: "top" | "bottom" | "middle" | undefined;
8
+ };
9
+ export default useCreateBottomSheet;
@@ -1,10 +1,10 @@
1
1
  import { useEffect as e } from "react";
2
- import { useBreakpointBetween as t } from "@bonprix-ds/utils";
3
- import { useScrollPosition as n, useVirtualKeyboard as r } from "react-modal-sheet";
2
+ import { useScrollPosition as t, useVirtualKeyboard as n } from "react-modal-sheet";
3
+ import { useBreakpointBetween as r } from "@bonprix-ds/utils";
4
4
  //#region src/useCreateBottomSheet.ts
5
- var i = ({ isOpen: i }) => {
6
- let a = t("s", "m") && i, { scrollRef: o, scrollPosition: s } = n({ isEnabled: a });
7
- return r({ isEnabled: i }), e(() => {
5
+ var i = ({ open: i }) => {
6
+ let a = r("s", "m") && i, { scrollRef: o, scrollPosition: s } = t({ isEnabled: a });
7
+ return n({ isEnabled: i }), e(() => {
8
8
  i ? document.dispatchEvent(new CustomEvent("app:enableSwipeToRefresh", { detail: { enable: !1 } })) : document.dispatchEvent(new CustomEvent("app:enableSwipeToRefresh", { detail: { enable: !0 } }));
9
9
  }, [i]), {
10
10
  isShown: a,
@@ -1 +1 @@
1
- {"version":3,"file":"useCreateBottomSheet.js","names":[],"sources":["../../src/useCreateBottomSheet.ts"],"sourcesContent":["import { useBreakpointBetween } from \"@bonprix-ds/utils\";\nimport { useEffect } from \"react\";\nimport { useScrollPosition, useVirtualKeyboard } from \"react-modal-sheet\";\n\ninterface UseBottomSheetProps {\n isOpen: boolean;\n}\n\nconst useCreateBottomSheet = ({ isOpen }: UseBottomSheetProps) => {\n const isSmallScreen = useBreakpointBetween(\"s\", \"m\");\n const isShown = isSmallScreen && isOpen;\n\n const { scrollRef, scrollPosition } = useScrollPosition({\n isEnabled: isShown,\n });\n\n useVirtualKeyboard({ isEnabled: isOpen });\n\n // Disable swipe-to-refresh for the app: // https://bonprix.atlassian.net/wiki/spaces/App/pages/368706073/Javascript\n useEffect(() => {\n if (isOpen) {\n document.dispatchEvent(new CustomEvent(\"app:enableSwipeToRefresh\", { detail: { enable: false } }));\n } else {\n document.dispatchEvent(new CustomEvent(\"app:enableSwipeToRefresh\", { detail: { enable: true } }));\n }\n }, [isOpen]);\n\n return {\n isShown,\n scrollRef,\n scrollPosition,\n };\n};\n\nexport default useCreateBottomSheet;\n"],"mappings":";;;;AAQA,IAAM,KAAwB,EAAE,gBAAkC;CAEhE,IAAM,IADgB,EAAqB,KAAK,GAChC,KAAiB,GAE3B,EAAE,cAAW,sBAAmB,EAAkB,EACtD,WAAW,EACb,CAAC;CAaD,OAXA,EAAmB,EAAE,WAAW,EAAO,CAAC,GAGxC,QAAgB;EACd,AAAI,IACF,SAAS,cAAc,IAAI,YAAY,4BAA4B,EAAE,QAAQ,EAAE,QAAQ,GAAM,EAAE,CAAC,CAAC,IAEjG,SAAS,cAAc,IAAI,YAAY,4BAA4B,EAAE,QAAQ,EAAE,QAAQ,GAAK,EAAE,CAAC,CAAC;CAEpG,GAAG,CAAC,CAAM,CAAC,GAEJ;EACL;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"useCreateBottomSheet.js","names":["useCreateBottomSheet","isShown","useBreakpointBetween","open","useScrollPosition","useVirtualKeyboard","useEffect"],"sources":["../../src/useCreateBottomSheet.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useScrollPosition, useVirtualKeyboard } from \"react-modal-sheet\";\n\nimport { useBreakpointBetween } from \"@bonprix-ds/utils\";\n\ninterface UseBottomSheetProps {\n open: boolean;\n}\n\nconst useCreateBottomSheet = ({ open }: UseBottomSheetProps) => {\n const isSmallScreen = useBreakpointBetween(\"s\", \"m\");\n const isShown = isSmallScreen && open;\n\n const { scrollRef, scrollPosition } = useScrollPosition({\n isEnabled: isShown,\n });\n\n useVirtualKeyboard({ isEnabled: open });\n\n // Disable swipe-to-refresh for the app: // https://bonprix.atlassian.net/wiki/spaces/App/pages/368706073/Javascript\n useEffect(() => {\n if (open) {\n document.dispatchEvent(new CustomEvent(\"app:enableSwipeToRefresh\", { detail: { enable: false } }));\n } else {\n document.dispatchEvent(new CustomEvent(\"app:enableSwipeToRefresh\", { detail: { enable: true } }));\n }\n }, [open]);\n\n return {\n isShown,\n scrollRef,\n scrollPosition,\n };\n};\n\nexport default useCreateBottomSheet;\n"],"mappings":";;;;AASA,IAAMA,KAAwB,EAAE,cAAgC;CAE9D,IAAMC,IADgBC,EAAqB,KAAK,GAChC,KAAiBC,GAE3B,EAAE,cAAW,sBAAmBC,EAAkB,EACtD,WAAWH,EACb,CAAC;CAaD,OAXAI,EAAmB,EAAE,WAAWF,EAAK,CAAC,GAGtCG,QAAgB;EACd,AAAIH,IACF,SAAS,cAAc,IAAI,YAAY,4BAA4B,EAAE,QAAQ,EAAE,QAAQ,GAAM,EAAE,CAAC,CAAC,IAEjG,SAAS,cAAc,IAAI,YAAY,4BAA4B,EAAE,QAAQ,EAAE,QAAQ,GAAK,EAAE,CAAC,CAAC;CAEpG,GAAG,CAACA,CAAI,CAAC,GAEF;EACL;EACA;EACA;CACF;AACF"}
@@ -0,0 +1,2 @@
1
+ declare const useKeepScrollPositionOnPageHide: (isEnabled: boolean) => void;
2
+ export default useKeepScrollPositionOnPageHide;
@@ -0,0 +1,26 @@
1
+ import { useEffect as e } from "react";
2
+ //#region src/useKeepScrollPositionOnPageHide.ts
3
+ var t = (e) => e.stopImmediatePropagation(), n = (n) => {
4
+ e(() => {
5
+ if (!n) return;
6
+ let e, r = () => {
7
+ let n = -parseFloat(document.body.style.marginTop);
8
+ n > 0 && (e = n, window.addEventListener("scroll", t, { capture: !0 }), document.body.style.marginTop = "", document.documentElement.style.overflow = "", window.scrollTo({
9
+ top: n,
10
+ behavior: "instant"
11
+ }));
12
+ }, i = (n) => {
13
+ n.persisted && e !== void 0 && (window.removeEventListener("scroll", t, { capture: !0 }), document.documentElement.style.overflow = "hidden", document.body.style.marginTop = `-${e}px`, window.scrollTo({
14
+ top: 0,
15
+ behavior: "instant"
16
+ }), e = void 0);
17
+ };
18
+ return window.addEventListener("pagehide", r), window.addEventListener("pageshow", i), () => {
19
+ window.removeEventListener("pagehide", r), window.removeEventListener("pageshow", i), window.removeEventListener("scroll", t, { capture: !0 });
20
+ };
21
+ }, [n]);
22
+ };
23
+ //#endregion
24
+ export { n as default };
25
+
26
+ //# sourceMappingURL=useKeepScrollPositionOnPageHide.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useKeepScrollPositionOnPageHide.js","names":["keepScrollEventsFromTheLock","event","useKeepScrollPositionOnPageHide","isEnabled","lockedScrollY","unlock","scrollY","lockAgain"],"sources":["../../src/useKeepScrollPositionOnPageHide.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\n// The page's scroll event targets `document`, so a capturing listener on `window` runs before react-modal-sheet's\n// own listener on `window`, which scrolls the page back to the top on every scroll while the lock is on. Stopping\n// the event there withholds it from every scroll listener on the page, not just the lock's - which is harmless only\n// because it is in place solely between `pagehide` and `pageshow`, while nothing on the page can be seen.\nconst keepScrollEventsFromTheLock = (event: Event) => event.stopImmediatePropagation();\n\n// On iOS, react-modal-sheet locks the page by scrolling it to the top and shifting `body` up by a negative\n// `margin-top`. A page that is left in that state is saved with its scroll position at the top, so going back\n// would land there. The lock is lifted while the page is hidden, and put back if it returns from the bfcache.\n// The shift is read back from `body`'s inline `margin-top`, which only the lock sets while the sheet is open.\n//\n// All of this mirrors react-modal-sheet's private `preventScrollMobileSafari`, which is why its version is pinned.\n// \"react-modal-sheet still locks the page on iOS the way this hook undoes it\" in BottomSheet.browser.test.tsx runs\n// against the real library and fails as soon as an update changes the lock - check this hook before bumping it.\nconst useKeepScrollPositionOnPageHide = (isEnabled: boolean) => {\n useEffect(() => {\n if (!isEnabled) return;\n\n let lockedScrollY: number | undefined;\n\n const unlock = () => {\n const scrollY = -parseFloat(document.body.style.marginTop);\n if (!(scrollY > 0)) return;\n\n lockedScrollY = scrollY;\n window.addEventListener(\"scroll\", keepScrollEventsFromTheLock, { capture: true });\n document.body.style.marginTop = \"\";\n document.documentElement.style.overflow = \"\";\n window.scrollTo({ top: scrollY, behavior: \"instant\" });\n };\n\n const lockAgain = (event: PageTransitionEvent) => {\n if (!event.persisted || lockedScrollY === undefined) return;\n\n window.removeEventListener(\"scroll\", keepScrollEventsFromTheLock, { capture: true });\n document.documentElement.style.overflow = \"hidden\";\n document.body.style.marginTop = `-${lockedScrollY}px`;\n window.scrollTo({ top: 0, behavior: \"instant\" });\n lockedScrollY = undefined;\n };\n\n window.addEventListener(\"pagehide\", unlock);\n window.addEventListener(\"pageshow\", lockAgain);\n\n return () => {\n window.removeEventListener(\"pagehide\", unlock);\n window.removeEventListener(\"pageshow\", lockAgain);\n window.removeEventListener(\"scroll\", keepScrollEventsFromTheLock, { capture: true });\n };\n }, [isEnabled]);\n};\n\nexport default useKeepScrollPositionOnPageHide;\n"],"mappings":";;AAMA,IAAMA,KAA+B,MAAiBC,EAAM,yBAAyB,GAU/EC,KAAmC,MAAuB;CAC9D,QAAgB;EACd,IAAI,CAACC,GAAW;EAEhB,IAAIC,GAEEC,UAAe;GACnB,IAAMC,IAAU,CAAC,WAAW,SAAS,KAAK,MAAM,SAAS;GACzD,AAAMA,IAAU,MAEhB,IAAgBA,GAChB,OAAO,iBAAiB,UAAUN,GAA6B,EAAE,SAAS,GAAK,CAAC,GAChF,SAAS,KAAK,MAAM,YAAY,IAChC,SAAS,gBAAgB,MAAM,WAAW,IAC1C,OAAO,SAAS;IAAE,KAAKM;IAAS,UAAU;GAAU,CAAC;EACvD,GAEMC,KAAa,MAA+B;GAChD,AAAKN,EAAM,aAAaG,MAAkB,KAAA,MAE1C,OAAO,oBAAoB,UAAUJ,GAA6B,EAAE,SAAS,GAAK,CAAC,GACnF,SAAS,gBAAgB,MAAM,WAAW,UAC1C,SAAS,KAAK,MAAM,YAAY,IAAII,EAAc,KAClD,OAAO,SAAS;IAAE,KAAK;IAAG,UAAU;GAAU,CAAC,GAC/C,IAAgB,KAAA;EAClB;EAKA,OAHA,OAAO,iBAAiB,YAAYC,CAAM,GAC1C,OAAO,iBAAiB,YAAYE,CAAS,SAEhC;GAGX,AAFA,OAAO,oBAAoB,YAAYF,CAAM,GAC7C,OAAO,oBAAoB,YAAYE,CAAS,GAChD,OAAO,oBAAoB,UAAUP,GAA6B,EAAE,SAAS,GAAK,CAAC;EACrF;CACF,GAAG,CAACG,CAAS,CAAC;AAChB"}
package/dist/styles.js ADDED
@@ -0,0 +1 @@
1
+ import "./src/BottomSheet.css";
package/package.json CHANGED
@@ -1,14 +1,34 @@
1
1
  {
2
2
  "name": "@bonprix-ds/react-bottom-sheet",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "BottomSheet component, implemented in React, for the Bonprix Design System.",
5
- "type": "module",
6
- "publishConfig": {
7
- "access": "public",
8
- "provenance": true
5
+ "keywords": [],
6
+ "license": "UNLICENSED",
7
+ "author": "",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/bonprix/design-system.git",
11
+ "directory": "packages/react/bottom-sheet"
9
12
  },
13
+ "files": [
14
+ "dist",
15
+ "!dist/tsconfig.tsbuildinfo",
16
+ "!dist/vite.config.d.ts",
17
+ "!dist/**/*.test.d.ts"
18
+ ],
19
+ "type": "module",
20
+ "sideEffects": [
21
+ "**/*.css",
22
+ "./dist/styles.js"
23
+ ],
10
24
  "module": "./dist/index.js",
11
- "sideEffects": false,
25
+ "types": "./dist/index.d.ts",
26
+ "imports": {
27
+ "#styles": {
28
+ "browser": "./dist/styles.js",
29
+ "default": "./dist/no-styles.js"
30
+ }
31
+ },
12
32
  "exports": {
13
33
  ".": {
14
34
  "import": "./dist/index.js",
@@ -16,43 +36,31 @@
16
36
  "default": "./dist/index.js"
17
37
  }
18
38
  },
19
- "types": "./dist/index.d.ts",
20
- "files": [
21
- "dist"
22
- ],
23
- "keywords": [],
24
- "author": "",
25
- "license": "UNLICENSED",
26
- "repository": {
27
- "type": "git",
28
- "url": "git+https://github.com/bonprix/design-system.git",
29
- "directory": "packages/react/bottom-sheet"
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "provenance": true
30
42
  },
31
43
  "dependencies": {
32
44
  "@radix-ui/react-dialog": "1.1.23",
33
45
  "react-modal-sheet": "5.6.0",
34
- "@bonprix-ds/internal-components": "0.2.0",
35
- "@bonprix-ds/react-button": "1.1.0",
36
- "@bonprix-ds/react-icon": "1.2.0",
37
- "@bonprix-ds/react-icon-button": "1.2.0",
38
- "@bonprix-ds/react-typography": "1.0.4",
39
- "@bonprix-ds/utils": "0.2.2"
40
- },
41
- "peerDependencies": {
42
- "react": "^19.0.0",
43
- "react-dom": "^19.0.0",
44
- "tailwind-variants": "0.3.1"
46
+ "@bonprix-ds/internal-components": "0.2.2",
47
+ "@bonprix-ds/react-button": "1.1.2",
48
+ "@bonprix-ds/react-icon": "1.2.2",
49
+ "@bonprix-ds/react-icon-button": "1.2.2",
50
+ "@bonprix-ds/utils": "0.3.0"
45
51
  },
46
52
  "devDependencies": {
47
- "vite": "8.2.2",
48
- "vitest": "4.1.11",
49
53
  "@testing-library/dom": "10.4.2",
50
54
  "@testing-library/react": "16.3.3",
51
- "@types/react": "19.2.18",
52
- "@vitejs/plugin-react": "6.1.1",
53
- "rollup-preserve-directives": "1.1.3",
54
- "unplugin-dts": "1.1.0",
55
- "@microsoft/api-extractor": "7.59.1"
55
+ "@types/react": "19.3.0",
56
+ "vite": "8.3.2",
57
+ "vitest": "4.1.11",
58
+ "@bonprix-ds/vite-config": "0.0.0"
59
+ },
60
+ "peerDependencies": {
61
+ "react": "^19",
62
+ "react-dom": "^19",
63
+ "tailwind-variants": "0.3.1"
56
64
  },
57
65
  "scripts": {
58
66
  "build": "vite build"