@bonprix-ds/react-bottom-sheet 1.0.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 +85 -0
- package/dist/index.js +2 -0
- package/dist/src/BottomSheet.js +10 -0
- package/dist/src/BottomSheet.js.map +1 -0
- package/dist/src/BottomSheetContext.js +13 -0
- package/dist/src/BottomSheetContext.js.map +1 -0
- package/dist/src/BottomSheetRoot.js +168 -0
- package/dist/src/BottomSheetRoot.js.map +1 -0
- package/dist/src/useConsumeBottomSheet.js +8 -0
- package/dist/src/useConsumeBottomSheet.js.map +1 -0
- package/dist/src/useCreateBottomSheet.js +18 -0
- package/dist/src/useCreateBottomSheet.js.map +1 -0
- package/package.json +59 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
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
|
+
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
|
+
declare interface SheetButtonSectionProps {
|
|
44
|
+
/** Primary and secondary buttons should be placed inside this section. */
|
|
45
|
+
children: ReactNode;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
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
|
+
* - Swipe down to close
|
|
65
|
+
* - Click on "close" icon button in the upper-right corner
|
|
66
|
+
* - Click on any button (PrimaryButton or SecondaryButton)
|
|
67
|
+
*
|
|
68
|
+
* Should be used in conjunction with `isOpen`. */
|
|
69
|
+
onClose: () => void;
|
|
70
|
+
/** Callback to execute when clicking back icon. */
|
|
71
|
+
onBack?: () => void;
|
|
72
|
+
/** The z-index of the sheet.. */
|
|
73
|
+
zIndex?: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare interface SheetTitleProps {
|
|
77
|
+
/** The text content. */
|
|
78
|
+
children: string;
|
|
79
|
+
/** An optional subline that is displayed right below the title. */
|
|
80
|
+
subline?: string;
|
|
81
|
+
/** The heading level for the title. */
|
|
82
|
+
level?: TitleLevel;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import e, { ButtonSection as t, Content as n, PrimaryButton as r, SecondaryButton as i, Title as a } from "./BottomSheetRoot.js";
|
|
2
|
+
import "react";
|
|
3
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
4
|
+
//#region src/BottomSheet.tsx
|
|
5
|
+
var s = (t) => /* @__PURE__ */ o(e, { ...t });
|
|
6
|
+
s.displayName = "BottomSheet", s.Title = a, s.Content = n, s.ButtonSection = t, s.PrimaryButton = r, s.SecondaryButton = i;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { s as default };
|
|
9
|
+
|
|
10
|
+
//# sourceMappingURL=BottomSheet.js.map
|
|
@@ -0,0 +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 { Props, SheetButtonProps } 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":";;;;AAMA,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { createContext as e } from "react";
|
|
3
|
+
//#region src/BottomSheetContext.ts
|
|
4
|
+
var t = e({
|
|
5
|
+
scrollRef: () => null,
|
|
6
|
+
scrollPosition: void 0,
|
|
7
|
+
onClose: () => null,
|
|
8
|
+
onBack: () => null
|
|
9
|
+
});
|
|
10
|
+
//#endregion
|
|
11
|
+
export { t as default };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=BottomSheetContext.js.map
|
|
@@ -0,0 +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 titleId?: string;\n}\n\nconst BottomSheetContext = createContext<BottomSheetContextProps>({\n scrollRef: () => null,\n scrollPosition: undefined,\n onClose: () => null,\n onBack: () => null,\n});\n\nexport default BottomSheetContext;\n"],"mappings":";;;AAaA,IAAM,IAAqB,EAAuC;CAChE,iBAAiB;CACjB,gBAAgB,KAAA;CAChB,eAAe;CACf,cAAc;AAChB,CAAC"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import e from "./BottomSheetContext.js";
|
|
3
|
+
import t from "./useConsumeBottomSheet.js";
|
|
4
|
+
import n from "./useCreateBottomSheet.js";
|
|
5
|
+
import { useId as r } from "react";
|
|
6
|
+
import { backdrop as i } from "@bonprix-ds/internal-components";
|
|
7
|
+
import a from "@bonprix-ds/react-button";
|
|
8
|
+
import o from "@bonprix-ds/react-icon-button";
|
|
9
|
+
import s from "@bonprix-ds/react-typography";
|
|
10
|
+
import { ZIndexContext as c, useInnerOpen as l, usePrefersReducedMotion as u } from "@bonprix-ds/utils";
|
|
11
|
+
import { Sheet as d } from "react-modal-sheet";
|
|
12
|
+
import { tv as f } from "tailwind-variants";
|
|
13
|
+
import { jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
14
|
+
//#region src/BottomSheetRoot.tsx
|
|
15
|
+
var h = f({
|
|
16
|
+
slots: {
|
|
17
|
+
root: "preflight block",
|
|
18
|
+
container: "shadow-none rounded-none bg-clr-bg-modal max-h-[calc(100%-4rem)]",
|
|
19
|
+
header: "px-4 py-3",
|
|
20
|
+
titleAndIcons: "flex gap-2 items-center touch-pan-down",
|
|
21
|
+
contentWrapper: "flex flex-col w-full",
|
|
22
|
+
content: [
|
|
23
|
+
"typography-body1 text-clr-primary",
|
|
24
|
+
"*:flex *:-mx-0.5 *:px-0.5",
|
|
25
|
+
"*:min-h-0"
|
|
26
|
+
],
|
|
27
|
+
dragHandleContainer: "h-6 flex justify-center items-center shrink-0",
|
|
28
|
+
dragHandle: "h-1 w-8 rounded-full bg-clr-on-bg-low",
|
|
29
|
+
backdrop: i(),
|
|
30
|
+
scrollArea: "scroll-area relative"
|
|
31
|
+
},
|
|
32
|
+
variants: { disableHorizontalPadding: {
|
|
33
|
+
false: { scrollArea: "px-4" },
|
|
34
|
+
true: ""
|
|
35
|
+
} }
|
|
36
|
+
}), g = ({ children: t, isOpen: i, onClose: a, onBack: o, zIndex: s = 9999, ref: f }) => {
|
|
37
|
+
let g = u(), { root: _, container: v, dragHandleContainer: y, dragHandle: b, content: x, contentWrapper: S, backdrop: C } = h(), { isShown: w, scrollRef: T, scrollPosition: E } = n({ isOpen: i }), D = E === "middle" || E === "bottom", { innerOpen: O } = l(w), k = r();
|
|
38
|
+
return /* @__PURE__ */ m(d, {
|
|
39
|
+
isOpen: O,
|
|
40
|
+
onClose: a,
|
|
41
|
+
className: _(),
|
|
42
|
+
detent: "content",
|
|
43
|
+
"data-bpds": "bottom-sheet",
|
|
44
|
+
prefersReducedMotion: g,
|
|
45
|
+
style: {
|
|
46
|
+
"--touch-action": D ? "initial" : "pan-down",
|
|
47
|
+
pointerEvents: void 0,
|
|
48
|
+
visibility: O ? "visible" : "hidden",
|
|
49
|
+
zIndex: s
|
|
50
|
+
},
|
|
51
|
+
role: "dialog",
|
|
52
|
+
avoidKeyboard: !1,
|
|
53
|
+
"aria-labelledby": k,
|
|
54
|
+
children: [/* @__PURE__ */ m(d.Container, {
|
|
55
|
+
className: v(),
|
|
56
|
+
ref: f,
|
|
57
|
+
style: { pointerEvents: void 0 },
|
|
58
|
+
children: [/* @__PURE__ */ p(d.Header, {
|
|
59
|
+
unstyled: !0,
|
|
60
|
+
className: y(),
|
|
61
|
+
children: /* @__PURE__ */ p(d.DragIndicator, {
|
|
62
|
+
unstyled: !0,
|
|
63
|
+
className: b()
|
|
64
|
+
})
|
|
65
|
+
}), /* @__PURE__ */ p(c.Provider, {
|
|
66
|
+
value: s,
|
|
67
|
+
children: /* @__PURE__ */ p(e.Provider, {
|
|
68
|
+
value: {
|
|
69
|
+
scrollRef: T,
|
|
70
|
+
scrollPosition: E,
|
|
71
|
+
onClose: a,
|
|
72
|
+
onBack: o,
|
|
73
|
+
titleId: k
|
|
74
|
+
},
|
|
75
|
+
children: /* @__PURE__ */ p(d.Content, {
|
|
76
|
+
className: x(),
|
|
77
|
+
disableScroll: !0,
|
|
78
|
+
disableDrag: D,
|
|
79
|
+
children: /* @__PURE__ */ p("div", {
|
|
80
|
+
className: S(),
|
|
81
|
+
style: { paddingBottom: "max(var(--keyboard-inset-height, 0rem), var(--app-safe-area-inset-bottom, 1rem))" },
|
|
82
|
+
children: t
|
|
83
|
+
})
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
})]
|
|
87
|
+
}), /* @__PURE__ */ p(d.Backdrop, {
|
|
88
|
+
"aria-label": "Bottom Sheet schließen",
|
|
89
|
+
onTap: a,
|
|
90
|
+
className: C()
|
|
91
|
+
})]
|
|
92
|
+
});
|
|
93
|
+
}, _ = ({ children: e, subline: n, level: r = "h3" }) => {
|
|
94
|
+
let { onBack: i, onClose: a, titleId: c } = t(), { header: l, titleAndIcons: u } = h();
|
|
95
|
+
return /* @__PURE__ */ m("div", {
|
|
96
|
+
className: l(),
|
|
97
|
+
children: [/* @__PURE__ */ m("div", {
|
|
98
|
+
className: u(),
|
|
99
|
+
children: [
|
|
100
|
+
i && /* @__PURE__ */ p(o, {
|
|
101
|
+
onClick: i,
|
|
102
|
+
icon: "arrow-left",
|
|
103
|
+
label: "Zurück",
|
|
104
|
+
variant: "tertiary",
|
|
105
|
+
size: "small"
|
|
106
|
+
}),
|
|
107
|
+
/* @__PURE__ */ p(s, {
|
|
108
|
+
variant: "bonprix-h6",
|
|
109
|
+
component: r,
|
|
110
|
+
className: "grow line-clamp-2",
|
|
111
|
+
id: c,
|
|
112
|
+
children: e
|
|
113
|
+
}),
|
|
114
|
+
/* @__PURE__ */ p(o, {
|
|
115
|
+
onClick: a,
|
|
116
|
+
icon: "closer",
|
|
117
|
+
label: "Schließen",
|
|
118
|
+
variant: "tertiary",
|
|
119
|
+
size: "small"
|
|
120
|
+
})
|
|
121
|
+
]
|
|
122
|
+
}), n && /* @__PURE__ */ p(s, { children: n })]
|
|
123
|
+
});
|
|
124
|
+
}, v = ({ children: e, disableHorizontalPadding: n = !1 }) => {
|
|
125
|
+
let { scrollRef: r } = t(), { scrollArea: i } = h({ disableHorizontalPadding: n });
|
|
126
|
+
return /* @__PURE__ */ p("div", {
|
|
127
|
+
ref: r,
|
|
128
|
+
className: i(),
|
|
129
|
+
"data-bpds-disable-horizontal-padding": n,
|
|
130
|
+
tabIndex: 0,
|
|
131
|
+
children: e
|
|
132
|
+
});
|
|
133
|
+
}, y = ({ children: e }) => /* @__PURE__ */ p("div", {
|
|
134
|
+
className: "button-section w-full flex flex-col gap-3 px-4 pt-4 shrink-0 touch-pan-down",
|
|
135
|
+
children: e
|
|
136
|
+
}), b = ({ children: e, icon: n, iconPosition: r, loading: i, component: o = "button", ...s }) => {
|
|
137
|
+
let c = o, { onClick: l, ...u } = s, { onClose: d } = t(), f = (e) => {
|
|
138
|
+
l?.(e), d();
|
|
139
|
+
};
|
|
140
|
+
return /* @__PURE__ */ p(a, {
|
|
141
|
+
component: c,
|
|
142
|
+
...u,
|
|
143
|
+
variant: "primary",
|
|
144
|
+
onClick: f,
|
|
145
|
+
icon: n,
|
|
146
|
+
iconPosition: r,
|
|
147
|
+
size: "large",
|
|
148
|
+
loading: i,
|
|
149
|
+
children: e
|
|
150
|
+
});
|
|
151
|
+
}, x = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...o }) => {
|
|
152
|
+
let s = i, { onClose: c } = t();
|
|
153
|
+
return /* @__PURE__ */ p(a, {
|
|
154
|
+
component: s,
|
|
155
|
+
...o,
|
|
156
|
+
variant: "secondary",
|
|
157
|
+
onClick: c,
|
|
158
|
+
icon: n,
|
|
159
|
+
iconPosition: r,
|
|
160
|
+
size: "large",
|
|
161
|
+
children: e
|
|
162
|
+
});
|
|
163
|
+
};
|
|
164
|
+
g.displayName = "BottomSheet";
|
|
165
|
+
//#endregion
|
|
166
|
+
export { y as ButtonSection, v as Content, b as PrimaryButton, x as SecondaryButton, _ as Title, g as default };
|
|
167
|
+
|
|
168
|
+
//# sourceMappingURL=BottomSheetRoot.js.map
|
|
@@ -0,0 +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, { ComponentProps, ElementType, ReactNode, RefObject, useId } from \"react\";\nimport { Sheet } from \"react-modal-sheet\";\nimport { tv } from \"tailwind-variants\";\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)]\",\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 * - 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 // TODO: add aria-modal = true once we implemented the dialog pattern fully and i.e. manage the focus\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 titleId = useId();\n\n return (\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 // @ts-expect-error setting custom properties is not recognized by React.CSSProperties\n // This is consumed by the inner ScrollArea to fix drag to close.\n \"--touch-action\": disableDrag ? \"initial\" : \"pan-down\",\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 role=\"dialog\"\n avoidKeyboard={false}\n aria-labelledby={titleId}\n >\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 <Sheet.Container className={container()} ref={ref} style={{ pointerEvents: undefined }}>\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, titleId }}>\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 {/* TODO: Deactivate the animation, when the user prefers reduced motion: https://github.com/Temzasse/react-modal-sheet/issues/227 */}\n <Sheet.Backdrop aria-label=\"Bottom Sheet schließen\" onTap={onClose} className={backdrop()} />\n </Sheet>\n );\n};\n\nexport default BottomSheetRoot;\n\nexport const Title = ({ children, subline, level = \"h3\" }: SheetTitleProps) => {\n const { onBack, onClose, titleId } = 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 <Typography variant=\"bonprix-h6\" component={level} className=\"grow line-clamp-2\" id={titleId}>\n {children}\n </Typography>\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 } = useConsumeBottomSheet();\n const { scrollArea } = generateClasses({ disableHorizontalPadding });\n return (\n <div ref={setScrollRef} className={scrollArea()} data-bpds-disable-horizontal-padding={disableHorizontalPadding} tabIndex={0}>\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":";;;;;;;;;;;;;;AAgBA,IAAM,IAAkB,EAAG;CACzB,OAAO;EACL,MAAM;EACN,WAAW;EACX,QAAQ;EACR,eAAe;EACf,gBAAgB;EAChB,SAAS;GACP;GAGA;GAEA;EACF;EACA,qBAAqB;EACrB,YAAY;EACZ,UAAU,EAAS;EACnB,YAAY;CACd;CACA,UAAU,EACR,0BAA0B;EACxB,OAAO,EAAE,YAAY,OAAO;EAC5B,MAAM;CACR,EACF;AACF,CAAC,GAoEK,KAAmB,EAAE,aAAU,WAAQ,YAAS,WAAQ,YAAS,MAAM,aAAiB;CAE5F,IAAM,IAAuB,EAAwB,GAC/C,EAAE,SAAM,cAAW,wBAAqB,eAAY,YAAS,mBAAgB,gBAAa,EAAgB,GAC1G,EAAE,YAAS,cAAW,sBAAmB,EAAqB,EAAE,UAAO,CAAC,GAIxE,IAAc,MAAmB,YAAY,MAAmB,UAEhE,EAAE,iBAAc,EAAa,CAAO,GAEpC,IAAU,EAAM;CAEtB,OACE,kBAAC,GAAD;EACE,QAAQ;EACC;EACT,WAAW,EAAK;EAChB,QAAO;EACP,aAAU;EACY;EACtB,OAAO;GAGL,kBAAkB,IAAc,YAAY;GAE5C,eAAe,KAAA;GAEf,YAAY,IAAY,YAAY;GAC5B;EACV;EACA,MAAK;EACL,eAAe;EACf,mBAAiB;EAnBnB,UAAA,CAsBE,kBAAC,EAAM,WAAP;GAAiB,WAAW,EAAU;GAAQ;GAAK,OAAO,EAAE,eAAe,KAAA,EAAU;GAArF,UAAA,CACE,kBAAC,EAAM,QAAP;IAAc,UAAA;IAAS,WAAW,EAAoB;IACpD,UAAA,kBAAC,EAAM,eAAP;KAAqB,UAAA;KAAS,WAAW,EAAW;IAAI,CAAA;GAC5C,CAAA,GACd,kBAAC,EAAc,UAAf;IAAwB,OAAO;IAC7B,UAAA,kBAAC,EAAmB,UAApB;KAA6B,OAAO;MAAE;MAAW;MAAgB;MAAS;MAAQ;KAAQ;KACxF,UAAA,kBAAC,EAAM,SAAP;MACE,WAAW,EAAQ;MAEnB,eAAA;MAEa;MAEb,UAAA,kBAAC,OAAD;OACE,WAAW,EAAe;OAE1B,OAAO,EAAE,eAAe,mFAAmF;OAE1G;MACE,CAAA;KACQ,CAAA;IACY,CAAA;GACP,CAAA,CACT;EAEjB,CAAA,GAAA,kBAAC,EAAM,UAAP;GAAgB,cAAW;GAAyB,OAAO;GAAS,WAAW,EAAS;EAAI,CAAA,CACvF;;AAEX,GAIa,KAAS,EAAE,aAAU,YAAS,WAAQ,WAA4B;CAC7E,IAAM,EAAE,WAAQ,YAAS,eAAY,EAAsB,GACrD,EAAE,WAAQ,qBAAkB,EAAgB;CAClD,OACE,kBAAC,OAAD;EAAK,WAAW,EAAO;EAAvB,UAAA,CACE,kBAAC,OAAD;GAAK,WAAW,EAAc;GAA9B,UAAA;IACG,KAAU,kBAAC,GAAD;KAAY,SAAS;KAAQ,MAAK;KAAa,OAAM;KAAS,SAAQ;KAAW,MAAK;IAAS,CAAA;IAC1G,kBAAC,GAAD;KAAY,SAAQ;KAAa,WAAW;KAAO,WAAU;KAAoB,IAAI;KAClF;IACS,CAAA;IACZ,kBAAC,GAAD;KAAY,SAAS;KAAS,MAAK;KAAS,OAAM;KAAY,SAAQ;KAAW,MAAK;IAAS,CAAA;GAC5F;EACJ,CAAA,GAAA,KAAW,kBAAC,GAAD,EAAA,UAAa,EAAoB,CAAA,CAC1C;;AAET,GAEa,KAAW,EAAE,aAAU,8BAA2B,SAA+B;CAC5F,IAAM,EAAE,WAAW,MAAiB,EAAsB,GACpD,EAAE,kBAAe,EAAgB,EAAE,4BAAyB,CAAC;CACnE,OACE,kBAAC,OAAD;EAAK,KAAK;EAAc,WAAW,EAAW;EAAG,wCAAsC;EAA0B,UAAU;EACxH;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"}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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";
|
|
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(() => {
|
|
8
|
+
i ? document.dispatchEvent(new CustomEvent("app:enableSwipeToRefresh", { detail: { enable: !1 } })) : document.dispatchEvent(new CustomEvent("app:enableSwipeToRefresh", { detail: { enable: !0 } }));
|
|
9
|
+
}, [i]), {
|
|
10
|
+
isShown: a,
|
|
11
|
+
scrollRef: o,
|
|
12
|
+
scrollPosition: s
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
export { i as default };
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=useCreateBottomSheet.js.map
|
|
@@ -0,0 +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"}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bonprix-ds/react-bottom-sheet",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "BottomSheet component, implemented in React, for the Bonprix Design System.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public",
|
|
8
|
+
"provenance": true
|
|
9
|
+
},
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
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"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"react-modal-sheet": "5.6.0",
|
|
33
|
+
"@bonprix-ds/internal-components": "0.1.5",
|
|
34
|
+
"@bonprix-ds/react-icon": "1.1.3",
|
|
35
|
+
"@bonprix-ds/react-typography": "1.0.4",
|
|
36
|
+
"@bonprix-ds/react-button": "1.0.0",
|
|
37
|
+
"@bonprix-ds/react-icon-button": "1.1.5",
|
|
38
|
+
"@bonprix-ds/utils": "0.2.1"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^19.0.0",
|
|
42
|
+
"react-dom": "^19.0.0",
|
|
43
|
+
"tailwind-variants": "0.3.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"vite": "8.2.2",
|
|
47
|
+
"vitest": "4.1.11",
|
|
48
|
+
"@testing-library/dom": "10.4.1",
|
|
49
|
+
"@testing-library/react": "16.3.3",
|
|
50
|
+
"@types/react": "19.2.18",
|
|
51
|
+
"@vitejs/plugin-react": "6.1.1",
|
|
52
|
+
"rollup-preserve-directives": "1.1.3",
|
|
53
|
+
"unplugin-dts": "1.0.3",
|
|
54
|
+
"@microsoft/api-extractor": "7.59.0"
|
|
55
|
+
},
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "vite build"
|
|
58
|
+
}
|
|
59
|
+
}
|