@bonprix-ds/react-side-sheet 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,6 +9,7 @@ interface SheetProps {
|
|
|
9
9
|
*
|
|
10
10
|
* It will be called in following cases:
|
|
11
11
|
* - Click on backdrop
|
|
12
|
+
* - Press of the `Escape` key (with `modeless`, only while the focus is inside the sheet)
|
|
12
13
|
* - Swipe down to close
|
|
13
14
|
* - Click on "close" icon button in the upper-right corner
|
|
14
15
|
* - Click on any button (PrimaryButton or SecondaryButton)
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import e from "./SideSheetContext.js";
|
|
3
3
|
import t from "./useConsumeSideSheet.js";
|
|
4
|
-
import "react";
|
|
5
|
-
import * as
|
|
6
|
-
import { twMerge as
|
|
7
|
-
import { tv as
|
|
8
|
-
import { backdrop as
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import { ZIndexContext as
|
|
12
|
-
import { warnDeprecated as
|
|
4
|
+
import { useRef as n } from "react";
|
|
5
|
+
import * as r from "@radix-ui/react-dialog";
|
|
6
|
+
import { twMerge as i } from "tailwind-merge";
|
|
7
|
+
import { tv as a } from "tailwind-variants";
|
|
8
|
+
import { backdrop as o, fadeAnimation as s, slideAnimation as c } from "@bonprix-ds/internal-components";
|
|
9
|
+
import l from "@bonprix-ds/react-button";
|
|
10
|
+
import u from "@bonprix-ds/react-icon-button";
|
|
11
|
+
import { ZIndexContext as d, useBreakpointDown as f, useInnerOpen as p, usePrefersReducedMotion as m } from "@bonprix-ds/utils";
|
|
12
|
+
import { warnDeprecated as h } from "@bonprix-ds/utils/deprecation";
|
|
13
13
|
import "#styles";
|
|
14
|
-
import { jsx as
|
|
14
|
+
import { jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
15
15
|
//#region src/SideSheetRoot.tsx
|
|
16
|
-
var
|
|
16
|
+
var v = a({
|
|
17
17
|
slots: {
|
|
18
18
|
modal: "preflight fixed -end-100 top-0 flex h-dvh flex-col bg-clr-bg-modal outline-none",
|
|
19
19
|
header: "px-4 py-6",
|
|
20
20
|
titleAndIcons: "flex items-center gap-2",
|
|
21
21
|
scrollArea: "scroll-area relative h-full",
|
|
22
22
|
buttonSection: "flex w-full shrink-0 flex-col gap-3 px-4 pt-6",
|
|
23
|
-
backdrop:
|
|
23
|
+
backdrop: o(),
|
|
24
24
|
contentWrapper: "typography-body1 flex w-full grow flex-col overflow-hidden pb-6 text-clr-primary"
|
|
25
25
|
},
|
|
26
26
|
variants: {
|
|
27
27
|
disableHorizontalPadding: { false: { scrollArea: "px-4" } },
|
|
28
28
|
prefersReducedMotion: {
|
|
29
29
|
false: {
|
|
30
|
-
modal:
|
|
31
|
-
backdrop:
|
|
30
|
+
modal: c(),
|
|
31
|
+
backdrop: s()
|
|
32
32
|
},
|
|
33
33
|
true: { modal: "end-0" }
|
|
34
34
|
},
|
|
@@ -37,73 +37,77 @@ var _ = i({
|
|
|
37
37
|
true: { modal: "w-fit min-w-100 max-w-150" }
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
}),
|
|
41
|
-
|
|
42
|
-
let
|
|
43
|
-
hasDynamicWidth:
|
|
44
|
-
prefersReducedMotion:
|
|
45
|
-
}), { innerOpen:
|
|
46
|
-
return
|
|
47
|
-
open:
|
|
48
|
-
modal: !
|
|
49
|
-
children: /* @__PURE__ */
|
|
40
|
+
}), y = ({ children: t, open: i, isOpen: a, modeless: o = !1, onClose: s, onBack: c, zIndex: l = 9999, hasDynamicWidth: u = !1 }) => {
|
|
41
|
+
a !== void 0 && h("is-open-prop");
|
|
42
|
+
let y = m(), b = f("m"), { modal: x, backdrop: S, contentWrapper: C } = v({
|
|
43
|
+
hasDynamicWidth: u,
|
|
44
|
+
prefersReducedMotion: y
|
|
45
|
+
}), { innerOpen: w } = p(i ?? a ?? !1), T = n(null);
|
|
46
|
+
return b ? void 0 : /* @__PURE__ */ g(r.Root, {
|
|
47
|
+
open: w,
|
|
48
|
+
modal: !o,
|
|
49
|
+
children: /* @__PURE__ */ _(r.Portal, { children: [/* @__PURE__ */ g(r.Overlay, {
|
|
50
|
+
className: S(),
|
|
51
|
+
onClick: s,
|
|
52
|
+
style: { zIndex: l }
|
|
53
|
+
}), /* @__PURE__ */ g(r.Content, {
|
|
54
|
+
ref: T,
|
|
50
55
|
className: x(),
|
|
51
|
-
|
|
52
|
-
style: { zIndex: c }
|
|
53
|
-
}), /* @__PURE__ */ h(n.Content, {
|
|
54
|
-
className: b(),
|
|
55
|
-
style: { zIndex: c },
|
|
56
|
+
style: { zIndex: l },
|
|
56
57
|
"aria-describedby": void 0,
|
|
57
58
|
onOpenAutoFocus: (e) => {
|
|
58
59
|
e.preventDefault(), e.target.focus();
|
|
59
60
|
},
|
|
61
|
+
onEscapeKeyDown: (e) => {
|
|
62
|
+
(!o || T.current?.contains(e.target)) && s();
|
|
63
|
+
},
|
|
60
64
|
tabIndex: -1,
|
|
61
65
|
"data-bpds": "side-sheet",
|
|
62
|
-
"data-bpds-modeless":
|
|
63
|
-
"data-bpds-has-dynamic-width":
|
|
64
|
-
"aria-modal": !
|
|
65
|
-
children: /* @__PURE__ */
|
|
66
|
-
value:
|
|
67
|
-
children: /* @__PURE__ */
|
|
66
|
+
"data-bpds-modeless": o,
|
|
67
|
+
"data-bpds-has-dynamic-width": u,
|
|
68
|
+
"aria-modal": !o,
|
|
69
|
+
children: /* @__PURE__ */ g(d.Provider, {
|
|
70
|
+
value: l,
|
|
71
|
+
children: /* @__PURE__ */ g(e.Provider, {
|
|
68
72
|
value: {
|
|
69
|
-
onClose:
|
|
70
|
-
onBack:
|
|
73
|
+
onClose: s,
|
|
74
|
+
onBack: c
|
|
71
75
|
},
|
|
72
|
-
children: /* @__PURE__ */
|
|
73
|
-
className:
|
|
76
|
+
children: /* @__PURE__ */ g("div", {
|
|
77
|
+
className: C(),
|
|
74
78
|
children: t
|
|
75
79
|
})
|
|
76
80
|
})
|
|
77
81
|
})
|
|
78
82
|
})] })
|
|
79
83
|
});
|
|
80
|
-
},
|
|
81
|
-
let { onBack: a, onClose: o } = t(), { header: s, titleAndIcons: c } =
|
|
82
|
-
return /* @__PURE__ */
|
|
84
|
+
}, b = ({ children: e, subline: n, level: i = "h3" }) => {
|
|
85
|
+
let { onBack: a, onClose: o } = t(), { header: s, titleAndIcons: c } = v();
|
|
86
|
+
return /* @__PURE__ */ _("div", {
|
|
83
87
|
className: s(),
|
|
84
|
-
children: [/* @__PURE__ */
|
|
88
|
+
children: [/* @__PURE__ */ _("div", {
|
|
85
89
|
className: c(),
|
|
86
90
|
children: [
|
|
87
|
-
a && /* @__PURE__ */
|
|
91
|
+
a && /* @__PURE__ */ g(u, {
|
|
88
92
|
onClick: a,
|
|
89
93
|
icon: "arrow-left",
|
|
90
94
|
label: "Zurück",
|
|
91
95
|
variant: "tertiary",
|
|
92
96
|
size: "small"
|
|
93
97
|
}),
|
|
94
|
-
/* @__PURE__ */
|
|
98
|
+
/* @__PURE__ */ g(r.Title, {
|
|
95
99
|
asChild: !0,
|
|
96
|
-
children: /* @__PURE__ */
|
|
100
|
+
children: /* @__PURE__ */ g("div", {
|
|
97
101
|
className: "grow",
|
|
98
|
-
children: /* @__PURE__ */
|
|
102
|
+
children: /* @__PURE__ */ g(i, {
|
|
99
103
|
className: "typography-bonprix-h6 my-0 line-clamp-2 text-start text-clr-on-bg-high",
|
|
100
104
|
children: e
|
|
101
105
|
})
|
|
102
106
|
})
|
|
103
107
|
}),
|
|
104
|
-
/* @__PURE__ */
|
|
108
|
+
/* @__PURE__ */ g(r.Close, {
|
|
105
109
|
asChild: !0,
|
|
106
|
-
children: /* @__PURE__ */
|
|
110
|
+
children: /* @__PURE__ */ g(u, {
|
|
107
111
|
onClick: o,
|
|
108
112
|
icon: "closer",
|
|
109
113
|
label: "Schließen",
|
|
@@ -112,34 +116,34 @@ var _ = i({
|
|
|
112
116
|
})
|
|
113
117
|
})
|
|
114
118
|
]
|
|
115
|
-
}),
|
|
119
|
+
}), n && /* @__PURE__ */ g("p", {
|
|
116
120
|
className: "typography-body1 my-0 text-start text-clr-on-bg-high",
|
|
117
|
-
children:
|
|
121
|
+
children: n
|
|
118
122
|
})]
|
|
119
123
|
});
|
|
120
|
-
},
|
|
121
|
-
let { scrollArea: n } =
|
|
122
|
-
return /* @__PURE__ */
|
|
124
|
+
}, x = ({ children: e, disableHorizontalPadding: t = !1 }) => {
|
|
125
|
+
let { scrollArea: n } = v({ disableHorizontalPadding: t });
|
|
126
|
+
return /* @__PURE__ */ g("div", {
|
|
123
127
|
className: n(),
|
|
124
128
|
"data-bpds-disable-horizontal-padding": t,
|
|
125
129
|
children: e
|
|
126
130
|
});
|
|
127
|
-
},
|
|
128
|
-
let { buttonSection: t } =
|
|
129
|
-
return /* @__PURE__ */
|
|
131
|
+
}, S = ({ children: e }) => {
|
|
132
|
+
let { buttonSection: t } = v();
|
|
133
|
+
return /* @__PURE__ */ g("div", {
|
|
130
134
|
className: "button-section-container",
|
|
131
|
-
children: /* @__PURE__ */
|
|
132
|
-
className:
|
|
135
|
+
children: /* @__PURE__ */ g("div", {
|
|
136
|
+
className: i(t(), "button-section"),
|
|
133
137
|
children: e
|
|
134
138
|
})
|
|
135
139
|
});
|
|
136
|
-
},
|
|
137
|
-
let { onClick: s, ...
|
|
140
|
+
}, C = ({ children: e, icon: n, iconPosition: r, loading: i, component: a = "button", ...o }) => {
|
|
141
|
+
let { onClick: s, ...c } = o, u = a, { onClose: d } = t(), f = (e) => {
|
|
138
142
|
s?.(e), d();
|
|
139
143
|
};
|
|
140
|
-
return /* @__PURE__ */
|
|
144
|
+
return /* @__PURE__ */ g(l, {
|
|
141
145
|
component: u,
|
|
142
|
-
...
|
|
146
|
+
...c,
|
|
143
147
|
variant: "primary",
|
|
144
148
|
onClick: f,
|
|
145
149
|
icon: n,
|
|
@@ -148,9 +152,9 @@ var _ = i({
|
|
|
148
152
|
loading: i,
|
|
149
153
|
children: e
|
|
150
154
|
});
|
|
151
|
-
},
|
|
155
|
+
}, w = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...a }) => {
|
|
152
156
|
let o = i, { onClose: s } = t();
|
|
153
|
-
return /* @__PURE__ */
|
|
157
|
+
return /* @__PURE__ */ g(l, {
|
|
154
158
|
component: o,
|
|
155
159
|
...a,
|
|
156
160
|
variant: "secondary",
|
|
@@ -162,8 +166,8 @@ var _ = i({
|
|
|
162
166
|
children: e
|
|
163
167
|
});
|
|
164
168
|
};
|
|
165
|
-
|
|
169
|
+
y.displayName = "SideSheet";
|
|
166
170
|
//#endregion
|
|
167
|
-
export {
|
|
171
|
+
export { S as ButtonSection, x as Content, C as PrimaryButton, w as SecondaryButton, b as Title, y as default };
|
|
168
172
|
|
|
169
173
|
//# sourceMappingURL=SideSheetRoot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SideSheetRoot.js","names":["SideSheetContext","useConsumeSideSheet","DialogPrimitive","Button","IconButton","generateClasses","tv","backdrop","slideAnimation","fadeAnimation","SideSheetRoot","isOpen","warnDeprecated","prefersReducedMotion","usePrefersReducedMotion","isMobile","useBreakpointDown","modalClass","useInnerOpen","open","innerOpen","modeless","onClose","event","hasDynamicWidth","ZIndexContext","zIndex","contentWrapper","Title","Level","header","titleAndIcons","onBack","subline","Content","scrollArea","disableHorizontalPadding","ButtonSection","twMerge","buttonSection","PrimaryButton","props","otherProps","Component","component","handleClick","onClick","SecondaryButton"],"sources":["../../src/SideSheetRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport React, { ComponentProps, ElementType, ReactNode } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { tv } from \"tailwind-variants\";\n\nimport { backdrop, fadeAnimation, slideAnimation } 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, useBreakpointDown, useInnerOpen, usePrefersReducedMotion, ZIndexContext } from \"@bonprix-ds/utils\";\nimport { warnDeprecated } from \"@bonprix-ds/utils/deprecation\";\n\nimport SideSheetContext from \"./SideSheetContext\";\nimport useConsumeSideSheet from \"./useConsumeSideSheet\";\n\nimport \"./SideSheet.css\";\n\nconst generateClasses = tv({\n slots: {\n modal: \"preflight fixed -end-100 top-0 flex h-dvh flex-col bg-clr-bg-modal outline-none\",\n header: \"px-4 py-6\",\n titleAndIcons: \"flex items-center gap-2\",\n scrollArea: \"scroll-area relative h-full\",\n buttonSection: \"flex w-full shrink-0 flex-col gap-3 px-4 pt-6\",\n backdrop: backdrop(),\n contentWrapper: \"typography-body1 flex w-full grow flex-col overflow-hidden pb-6 text-clr-primary\",\n },\n variants: {\n disableHorizontalPadding: {\n false: { scrollArea: \"px-4\" },\n },\n prefersReducedMotion: {\n false: {\n modal: slideAnimation(),\n backdrop: fadeAnimation(),\n },\n true: {\n modal: \"end-0\",\n },\n },\n hasDynamicWidth: {\n false: {\n modal: \"w-100\",\n },\n true: {\n modal: \"w-fit min-w-100 max-w-150\",\n },\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 * - 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 /** When set to false, interaction with outside elements will be disabled and only dialog content will be visible to screen readers. */\n modeless?: boolean;\n /** Makes the Sheet of 400px fixed or able to expand up to 600px depending on the content */\n hasDynamicWidth?: boolean;\n};\n\nconst SideSheetRoot = ({ children, open, isOpen, modeless = false, onClose, onBack, zIndex = 9999, hasDynamicWidth = false }: Props) => {\n if (isOpen !== undefined) warnDeprecated(\"is-open-prop\");\n const prefersReducedMotion = usePrefersReducedMotion();\n const isMobile = useBreakpointDown(\"m\");\n const { modal: modalClass, backdrop, contentWrapper } = generateClasses({ hasDynamicWidth, prefersReducedMotion });\n\n const { innerOpen } = useInnerOpen(open ?? isOpen ?? false);\n\n if (isMobile) return;\n\n const shiftFocusProgrammatically = (event: Event) => {\n event.preventDefault();\n const target = event.target as HTMLElement;\n target.focus();\n };\n\n return (\n <DialogPrimitive.Root open={innerOpen} modal={!modeless}>\n <DialogPrimitive.Portal>\n <DialogPrimitive.Overlay className={backdrop()} onClick={onClose} style={{ zIndex }} />\n <DialogPrimitive.Content\n className={modalClass()}\n style={{ zIndex }}\n aria-describedby={undefined}\n onOpenAutoFocus={shiftFocusProgrammatically}\n tabIndex={-1}\n data-bpds=\"side-sheet\"\n data-bpds-modeless={modeless}\n data-bpds-has-dynamic-width={hasDynamicWidth}\n aria-modal={!modeless}\n >\n <ZIndexContext.Provider value={zIndex}>\n <SideSheetContext.Provider value={{ onClose, onBack }}>\n <div className={contentWrapper()}>{children}</div>\n </SideSheetContext.Provider>\n </ZIndexContext.Provider>\n </DialogPrimitive.Content>\n </DialogPrimitive.Portal>\n </DialogPrimitive.Root>\n );\n};\n\nexport const Title = ({ children, subline, level: Level = \"h3\" }: SheetTitleProps) => {\n const { onBack, onClose } = useConsumeSideSheet();\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 <DialogPrimitive.Close asChild>\n <IconButton onClick={onClose} icon=\"closer\" label=\"Schließen\" variant=\"tertiary\" size=\"small\" />\n </DialogPrimitive.Close>\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 { scrollArea } = generateClasses({ disableHorizontalPadding });\n return (\n <div className={scrollArea()} data-bpds-disable-horizontal-padding={disableHorizontalPadding}>\n {children}\n </div>\n );\n};\n\nexport const ButtonSection = ({ children }: SheetButtonSectionProps) => {\n const { buttonSection } = generateClasses();\n return (\n <div className=\"button-section-container\">\n <div className={twMerge(buttonSection(), \"button-section\")}>{children}</div>\n </div>\n );\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 { onClick, ...otherProps } = props;\n const Component: ElementType = component;\n const { onClose } = useConsumeSideSheet();\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\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 } = useConsumeSideSheet();\n return (\n <Button\n component={Component}\n {...props}\n variant=\"secondary\"\n type=\"button\"\n onClick={onClose}\n icon={icon}\n iconPosition={iconPosition}\n size=\"large\"\n >\n {children}\n </Button>\n );\n};\n\nSideSheetRoot.displayName = \"SideSheet\";\n\nexport default SideSheetRoot;\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,IAAMK,IAAkBC,EAAG;CACzB,OAAO;EACL,OAAO;EACP,QAAQ;EACR,eAAe;EACf,YAAY;EACZ,eAAe;EACf,UAAUC,EAAS;EACnB,gBAAgB;CAClB;CACA,UAAU;EACR,0BAA0B,EACxB,OAAO,EAAE,YAAY,OAAO,EAC9B;EACA,sBAAsB;GACpB,OAAO;IACL,OAAOC,EAAe;IACtB,UAAUC,EAAc;GAC1B;GACA,MAAM,EACJ,OAAO,QACT;EACF;EACA,iBAAiB;GACf,OAAO,EACL,OAAO,QACT;GACA,MAAM,EACJ,OAAO,4BACT;EACF;CACF;AACF,CAAC,GAoFKC,KAAi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d,MAAK;EACI;EAER;CACK,CAAA;AAEZ,GAEaE,KAA0C,EACrD,aACA,SACA,iBACA,eAAY,UACZ,GAAGN,QACsB;CACzB,IAAME,IAAyBC,GACzB,EAAE,eAAY3C,EAAoB;CACxC,OACE,kBAACE,GAAD;EACE,WAAWwC;EACX,GAAIF;EACJ,SAAQ;EACR,MAAK;EACL,SAASnB;EACH;EACQ;EACd,MAAK;EAEJ;CACK,CAAA;AAEZ;AAEA,EAAc,cAAc"}
|
|
1
|
+
{"version":3,"file":"SideSheetRoot.js","names":["SideSheetContext","useConsumeSideSheet","DialogPrimitive","Button","IconButton","generateClasses","tv","backdrop","slideAnimation","fadeAnimation","SideSheetRoot","isOpen","warnDeprecated","prefersReducedMotion","usePrefersReducedMotion","isMobile","useBreakpointDown","modalClass","useInnerOpen","open","contentRef","useRef","innerOpen","modeless","onClose","event","hasDynamicWidth","ZIndexContext","zIndex","contentWrapper","Title","Level","header","titleAndIcons","onBack","subline","Content","scrollArea","disableHorizontalPadding","ButtonSection","twMerge","buttonSection","PrimaryButton","props","otherProps","Component","component","handleClick","onClick","SecondaryButton"],"sources":["../../src/SideSheetRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport React, { ComponentProps, ElementType, ReactNode, useRef } from \"react\";\nimport { twMerge } from \"tailwind-merge\";\nimport { tv } from \"tailwind-variants\";\n\nimport { backdrop, fadeAnimation, slideAnimation } 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, useBreakpointDown, useInnerOpen, usePrefersReducedMotion, ZIndexContext } from \"@bonprix-ds/utils\";\nimport { warnDeprecated } from \"@bonprix-ds/utils/deprecation\";\n\nimport SideSheetContext from \"./SideSheetContext\";\nimport useConsumeSideSheet from \"./useConsumeSideSheet\";\n\nimport \"./SideSheet.css\";\n\nconst generateClasses = tv({\n slots: {\n modal: \"preflight fixed -end-100 top-0 flex h-dvh flex-col bg-clr-bg-modal outline-none\",\n header: \"px-4 py-6\",\n titleAndIcons: \"flex items-center gap-2\",\n scrollArea: \"scroll-area relative h-full\",\n buttonSection: \"flex w-full shrink-0 flex-col gap-3 px-4 pt-6\",\n backdrop: backdrop(),\n contentWrapper: \"typography-body1 flex w-full grow flex-col overflow-hidden pb-6 text-clr-primary\",\n },\n variants: {\n disableHorizontalPadding: {\n false: { scrollArea: \"px-4\" },\n },\n prefersReducedMotion: {\n false: {\n modal: slideAnimation(),\n backdrop: fadeAnimation(),\n },\n true: {\n modal: \"end-0\",\n },\n },\n hasDynamicWidth: {\n false: {\n modal: \"w-100\",\n },\n true: {\n modal: \"w-fit min-w-100 max-w-150\",\n },\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 (with `modeless`, only while the focus is inside the sheet)\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 /** When set to false, interaction with outside elements will be disabled and only dialog content will be visible to screen readers. */\n modeless?: boolean;\n /** Makes the Sheet of 400px fixed or able to expand up to 600px depending on the content */\n hasDynamicWidth?: boolean;\n};\n\nconst SideSheetRoot = ({ children, open, isOpen, modeless = false, onClose, onBack, zIndex = 9999, hasDynamicWidth = false }: Props) => {\n if (isOpen !== undefined) warnDeprecated(\"is-open-prop\");\n const prefersReducedMotion = usePrefersReducedMotion();\n const isMobile = useBreakpointDown(\"m\");\n const { modal: modalClass, backdrop, contentWrapper } = generateClasses({ hasDynamicWidth, prefersReducedMotion });\n\n const { innerOpen } = useInnerOpen(open ?? isOpen ?? false);\n const contentRef = useRef<HTMLDivElement>(null);\n\n if (isMobile) return;\n\n const shiftFocusProgrammatically = (event: Event) => {\n event.preventDefault();\n const target = event.target as HTMLElement;\n target.focus();\n };\n\n const closeOnEscape = (event: KeyboardEvent) => {\n if (modeless && !contentRef.current?.contains(event.target as Node)) return;\n onClose();\n };\n\n return (\n <DialogPrimitive.Root open={innerOpen} modal={!modeless}>\n <DialogPrimitive.Portal>\n <DialogPrimitive.Overlay className={backdrop()} onClick={onClose} style={{ zIndex }} />\n <DialogPrimitive.Content\n ref={contentRef}\n className={modalClass()}\n style={{ zIndex }}\n aria-describedby={undefined}\n onOpenAutoFocus={shiftFocusProgrammatically}\n onEscapeKeyDown={closeOnEscape}\n tabIndex={-1}\n data-bpds=\"side-sheet\"\n data-bpds-modeless={modeless}\n data-bpds-has-dynamic-width={hasDynamicWidth}\n aria-modal={!modeless}\n >\n <ZIndexContext.Provider value={zIndex}>\n <SideSheetContext.Provider value={{ onClose, onBack }}>\n <div className={contentWrapper()}>{children}</div>\n </SideSheetContext.Provider>\n </ZIndexContext.Provider>\n </DialogPrimitive.Content>\n </DialogPrimitive.Portal>\n </DialogPrimitive.Root>\n );\n};\n\nexport const Title = ({ children, subline, level: Level = \"h3\" }: SheetTitleProps) => {\n const { onBack, onClose } = useConsumeSideSheet();\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 <DialogPrimitive.Close asChild>\n <IconButton onClick={onClose} icon=\"closer\" label=\"Schließen\" variant=\"tertiary\" size=\"small\" />\n </DialogPrimitive.Close>\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 { scrollArea } = generateClasses({ disableHorizontalPadding });\n return (\n <div className={scrollArea()} data-bpds-disable-horizontal-padding={disableHorizontalPadding}>\n {children}\n </div>\n );\n};\n\nexport const ButtonSection = ({ children }: SheetButtonSectionProps) => {\n const { buttonSection } = generateClasses();\n return (\n <div className=\"button-section-container\">\n <div className={twMerge(buttonSection(), \"button-section\")}>{children}</div>\n </div>\n );\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 { onClick, ...otherProps } = props;\n const Component: ElementType = component;\n const { onClose } = useConsumeSideSheet();\n const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {\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 } = useConsumeSideSheet();\n return (\n <Button\n component={Component}\n {...props}\n variant=\"secondary\"\n type=\"button\"\n onClick={onClose}\n icon={icon}\n iconPosition={iconPosition}\n size=\"large\"\n >\n {children}\n </Button>\n );\n};\n\nSideSheetRoot.displayName = \"SideSheet\";\n\nexport default SideSheetRoot;\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,IAAMK,IAAkBC,EAAG;CACzB,OAAO;EACL,OAAO;EACP,QAAQ;EACR,eAAe;EACf,YAAY;EACZ,eAAe;EACf,UAAUC,EAAS;EACnB,gBAAgB;CAClB;CACA,UAAU;EACR,0BAA0B,EACxB,OAAO,EAAE,YAAY,OAAO,EAC9B;EACA,sBAAsB;GACpB,OAAO;IACL,OAAOC,EAAe;IACtB,UAAUC,EAAc;GAC1B;GACA,MAAM,EACJ,OAAO,QACT;EACF;EACA,iBAAiB;GACf,OAAO,EACL,OAAO,QACT;GACA,MAAM,EACJ,OAAO,4BACT;EACF;CACF;AACF,CAAC,GAqFKC,KAAiB,EAAE,aAAU,SAAM,WAAQ,cAAW,I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ACfD,EAAQ;CACV;CACA,OACE,kBAACrB,GAAD;EACE,WAAW0C;EACX,GAAID;EACJ,SAAQ;EACR,SAASG;EACH;EACQ;EACd,MAAK;EACI;EAER;CACK,CAAA;AAEZ,GAEaE,KAA0C,EACrD,aACA,SACA,iBACA,eAAY,UACZ,GAAGN,QACsB;CACzB,IAAME,IAAyBC,GACzB,EAAE,eAAY7C,EAAoB;CACxC,OACE,kBAACE,GAAD;EACE,WAAW0C;EACX,GAAIF;EACJ,SAAQ;EACR,MAAK;EACL,SAASnB;EACH;EACQ;EACd,MAAK;EAEJ;CACK,CAAA;AAEZ;AAEA,EAAc,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonprix-ds/react-side-sheet",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "SideSheet component, implemented in React, for the Bonprix Design System.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"@radix-ui/react-dialog": "1.1.23",
|
|
45
45
|
"tailwind-merge": "2.6.1",
|
|
46
46
|
"@bonprix-ds/internal-components": "0.2.2",
|
|
47
|
-
"@bonprix-ds/react-icon": "1.2.2",
|
|
48
47
|
"@bonprix-ds/react-button": "1.1.2",
|
|
48
|
+
"@bonprix-ds/utils": "0.3.0",
|
|
49
49
|
"@bonprix-ds/react-icon-button": "1.2.2",
|
|
50
|
-
"@bonprix-ds/
|
|
50
|
+
"@bonprix-ds/react-icon": "1.2.2"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@testing-library/dom": "10.4.2",
|