@bonprix-ds/react-side-sheet 1.1.0 → 1.2.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.
@@ -1,5 +1,5 @@
1
1
  import React, { ComponentProps, ElementType, ReactNode } from "react";
2
- import type { IconType } from "@bonprix-ds/react-icon";
2
+ import type { IconOrElement } from "@bonprix-ds/react-icon";
3
3
  import { TitleLevel } from "@bonprix-ds/utils";
4
4
  import "./SideSheet.css";
5
5
  interface SheetProps {
@@ -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)
@@ -55,8 +56,8 @@ export interface SheetContentProps {
55
56
  export interface SheetButtonBaseProps {
56
57
  /** The label of the button. */
57
58
  children: string;
58
- /** If used, an icon will be additionally shown. The value is a name of one icon from our icon set. */
59
- icon?: IconType;
59
+ /** If used, an icon will be additionally shown. The value is either a name of one icon from our icon set or an inline `<svg>` element. */
60
+ icon?: IconOrElement;
60
61
  /** The position of the icon relative to the content. */
61
62
  iconPosition?: "start" | "end";
62
63
  }
@@ -1,34 +1,35 @@
1
1
  "use client";
2
2
  import e from "./SideSheetContext.js";
3
3
  import t from "./useConsumeSideSheet.js";
4
- import "react";
5
- import * as n from "@radix-ui/react-dialog";
6
- import { twMerge as r } from "tailwind-merge";
7
- import { tv as i } from "tailwind-variants";
8
- import { backdrop as a, fadeAnimation as o, slideAnimation as s } from "@bonprix-ds/internal-components";
9
- import c from "@bonprix-ds/react-button";
10
- import l from "@bonprix-ds/react-icon-button";
11
- import { ZIndexContext as u, useBreakpointDown as d, useInnerOpen as f, usePrefersReducedMotion as p } from "@bonprix-ds/utils";
12
- import { warnDeprecated as m } from "@bonprix-ds/utils/deprecation";
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 { ArrowLeftIcon as d, CloserIcon as f } from "@bonprix-ds/react-icon/icons";
12
+ import { ZIndexContext as p, useBreakpointDown as m, useInnerOpen as h, usePrefersReducedMotion as g } from "@bonprix-ds/utils";
13
+ import { warnDeprecated as _ } from "@bonprix-ds/utils/deprecation";
13
14
  import "#styles";
14
- import { jsx as h, jsxs as g } from "react/jsx-runtime";
15
+ import { jsx as v, jsxs as y } from "react/jsx-runtime";
15
16
  //#region src/SideSheetRoot.tsx
16
- var _ = i({
17
+ var b = a({
17
18
  slots: {
18
19
  modal: "preflight fixed -end-100 top-0 flex h-dvh flex-col bg-clr-bg-modal outline-none",
19
20
  header: "px-4 py-6",
20
21
  titleAndIcons: "flex items-center gap-2",
21
22
  scrollArea: "scroll-area relative h-full",
22
23
  buttonSection: "flex w-full shrink-0 flex-col gap-3 px-4 pt-6",
23
- backdrop: a(),
24
+ backdrop: o(),
24
25
  contentWrapper: "typography-body1 flex w-full grow flex-col overflow-hidden pb-6 text-clr-primary"
25
26
  },
26
27
  variants: {
27
28
  disableHorizontalPadding: { false: { scrollArea: "px-4" } },
28
29
  prefersReducedMotion: {
29
30
  false: {
30
- modal: s(),
31
- backdrop: o()
31
+ modal: c(),
32
+ backdrop: s()
32
33
  },
33
34
  true: { modal: "end-0" }
34
35
  },
@@ -37,109 +38,113 @@ var _ = i({
37
38
  true: { modal: "w-fit min-w-100 max-w-150" }
38
39
  }
39
40
  }
40
- }), v = ({ children: t, open: r, isOpen: i, modeless: a = !1, onClose: o, onBack: s, zIndex: c = 9999, hasDynamicWidth: l = !1 }) => {
41
- i !== void 0 && m("is-open-prop");
42
- let v = p(), y = d("m"), { modal: b, backdrop: x, contentWrapper: S } = _({
43
- hasDynamicWidth: l,
44
- prefersReducedMotion: v
45
- }), { innerOpen: C } = f(r ?? i ?? !1);
46
- return y ? void 0 : /* @__PURE__ */ h(n.Root, {
47
- open: C,
48
- modal: !a,
49
- children: /* @__PURE__ */ g(n.Portal, { children: [/* @__PURE__ */ h(n.Overlay, {
41
+ }), x = ({ children: t, open: i, isOpen: a, modeless: o = !1, onClose: s, onBack: c, zIndex: l = 9999, hasDynamicWidth: u = !1 }) => {
42
+ a !== void 0 && _("is-open-prop");
43
+ let d = g(), f = m("m"), { modal: x, backdrop: S, contentWrapper: C } = b({
44
+ hasDynamicWidth: u,
45
+ prefersReducedMotion: d
46
+ }), { innerOpen: w } = h(i ?? a ?? !1), T = n(null);
47
+ return f ? void 0 : /* @__PURE__ */ v(r.Root, {
48
+ open: w,
49
+ modal: !o,
50
+ children: /* @__PURE__ */ y(r.Portal, { children: [/* @__PURE__ */ v(r.Overlay, {
51
+ className: S(),
52
+ onClick: s,
53
+ style: { zIndex: l }
54
+ }), /* @__PURE__ */ v(r.Content, {
55
+ ref: T,
50
56
  className: x(),
51
- onClick: o,
52
- style: { zIndex: c }
53
- }), /* @__PURE__ */ h(n.Content, {
54
- className: b(),
55
- style: { zIndex: c },
57
+ style: { zIndex: l },
56
58
  "aria-describedby": void 0,
57
59
  onOpenAutoFocus: (e) => {
58
60
  e.preventDefault(), e.target.focus();
59
61
  },
62
+ onEscapeKeyDown: (e) => {
63
+ (!o || T.current?.contains(e.target)) && s();
64
+ },
60
65
  tabIndex: -1,
61
66
  "data-bpds": "side-sheet",
62
- "data-bpds-modeless": a,
63
- "data-bpds-has-dynamic-width": l,
64
- "aria-modal": !a,
65
- children: /* @__PURE__ */ h(u.Provider, {
66
- value: c,
67
- children: /* @__PURE__ */ h(e.Provider, {
67
+ "data-bpds-modeless": o,
68
+ "data-bpds-has-dynamic-width": u,
69
+ "aria-modal": !o,
70
+ children: /* @__PURE__ */ v(p.Provider, {
71
+ value: l,
72
+ children: /* @__PURE__ */ v(e.Provider, {
68
73
  value: {
69
- onClose: o,
70
- onBack: s
74
+ onClose: s,
75
+ onBack: c
71
76
  },
72
- children: /* @__PURE__ */ h("div", {
73
- className: S(),
77
+ children: /* @__PURE__ */ v("div", {
78
+ className: C(),
74
79
  children: t
75
80
  })
76
81
  })
77
82
  })
78
83
  })] })
79
84
  });
80
- }, y = ({ children: e, subline: r, level: i = "h3" }) => {
81
- let { onBack: a, onClose: o } = t(), { header: s, titleAndIcons: c } = _();
82
- return /* @__PURE__ */ g("div", {
85
+ }, S = ({ children: e, subline: n, level: i = "h3" }) => {
86
+ let { onBack: a, onClose: o } = t(), { header: s, titleAndIcons: c } = b();
87
+ return /* @__PURE__ */ y("div", {
83
88
  className: s(),
84
- children: [/* @__PURE__ */ g("div", {
89
+ children: [/* @__PURE__ */ y("div", {
85
90
  className: c(),
86
91
  children: [
87
- a && /* @__PURE__ */ h(l, {
92
+ a && /* @__PURE__ */ v(u, {
88
93
  onClick: a,
89
- icon: "arrow-left",
94
+ icon: /* @__PURE__ */ v(d, {}),
90
95
  label: "Zurück",
91
96
  variant: "tertiary",
92
97
  size: "small"
93
98
  }),
94
- /* @__PURE__ */ h(n.Title, {
99
+ /* @__PURE__ */ v(r.Title, {
95
100
  asChild: !0,
96
- children: /* @__PURE__ */ h("div", {
101
+ children: /* @__PURE__ */ v("div", {
97
102
  className: "grow",
98
- children: /* @__PURE__ */ h(i, {
103
+ children: /* @__PURE__ */ v(i, {
99
104
  className: "typography-bonprix-h6 my-0 line-clamp-2 text-start text-clr-on-bg-high",
100
105
  children: e
101
106
  })
102
107
  })
103
108
  }),
104
- /* @__PURE__ */ h(n.Close, {
109
+ /* @__PURE__ */ v(r.Close, {
105
110
  asChild: !0,
106
- children: /* @__PURE__ */ h(l, {
111
+ children: /* @__PURE__ */ v(u, {
107
112
  onClick: o,
108
- icon: "closer",
113
+ icon: /* @__PURE__ */ v(f, {}),
109
114
  label: "Schließen",
110
115
  variant: "tertiary",
111
116
  size: "small"
112
117
  })
113
118
  })
114
119
  ]
115
- }), r && /* @__PURE__ */ h("p", {
120
+ }), n && /* @__PURE__ */ v("p", {
116
121
  className: "typography-body1 my-0 text-start text-clr-on-bg-high",
117
- children: r
122
+ children: n
118
123
  })]
119
124
  });
120
- }, b = ({ children: e, disableHorizontalPadding: t = !1 }) => {
121
- let { scrollArea: n } = _({ disableHorizontalPadding: t });
122
- return /* @__PURE__ */ h("div", {
125
+ }, C = ({ children: e, disableHorizontalPadding: t = !1 }) => {
126
+ let { scrollArea: n } = b({ disableHorizontalPadding: t });
127
+ return /* @__PURE__ */ v("div", {
123
128
  className: n(),
124
129
  "data-bpds-disable-horizontal-padding": t,
125
130
  children: e
126
131
  });
127
- }, x = ({ children: e }) => {
128
- let { buttonSection: t } = _();
129
- return /* @__PURE__ */ h("div", {
132
+ }, w = ({ children: e }) => {
133
+ let { buttonSection: t } = b();
134
+ return /* @__PURE__ */ v("div", {
130
135
  className: "button-section-container",
131
- children: /* @__PURE__ */ h("div", {
132
- className: r(t(), "button-section"),
136
+ children: /* @__PURE__ */ v("div", {
137
+ className: i(t(), "button-section"),
133
138
  children: e
134
139
  })
135
140
  });
136
- }, S = ({ children: e, icon: n, iconPosition: r, loading: i, component: a = "button", ...o }) => {
137
- let { onClick: s, ...l } = o, u = a, { onClose: d } = t(), f = (e) => {
141
+ }, T = ({ children: e, icon: n, iconPosition: r, loading: i, component: a = "button", ...o }) => {
142
+ let { onClick: s, ...c } = o, u = a, { onClose: d } = t(), f = (e) => {
138
143
  s?.(e), d();
139
144
  };
140
- return /* @__PURE__ */ h(c, {
145
+ return /* @__PURE__ */ v(l, {
141
146
  component: u,
142
- ...l,
147
+ ...c,
143
148
  variant: "primary",
144
149
  onClick: f,
145
150
  icon: n,
@@ -148,9 +153,9 @@ var _ = i({
148
153
  loading: i,
149
154
  children: e
150
155
  });
151
- }, C = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...a }) => {
156
+ }, E = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...a }) => {
152
157
  let o = i, { onClose: s } = t();
153
- return /* @__PURE__ */ h(c, {
158
+ return /* @__PURE__ */ v(l, {
154
159
  component: o,
155
160
  ...a,
156
161
  variant: "secondary",
@@ -162,8 +167,8 @@ var _ = i({
162
167
  children: e
163
168
  });
164
169
  };
165
- v.displayName = "SideSheet";
170
+ x.displayName = "SideSheet";
166
171
  //#endregion
167
- export { x as ButtonSection, b as Content, S as PrimaryButton, C as SecondaryButton, y as Title, v as default };
172
+ export { w as ButtonSection, C as Content, T as PrimaryButton, E as SecondaryButton, S as Title, x as default };
168
173
 
169
174
  //# 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,KAAiB,EAAE,aAAU,SAAM,WAAQ,cAAW,IAAO,YAAS,WAAQ,YAAS,MAAM,qBAAkB,SAAmB;CACtI,AAAIC,MAAW,K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B,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","ArrowLeftIcon","CloserIcon","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 { IconOrElement } from \"@bonprix-ds/react-icon\";\nimport IconButton from \"@bonprix-ds/react-icon-button\";\nimport { ArrowLeftIcon, CloserIcon } from \"@bonprix-ds/react-icon/icons\";\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 either a name of one icon from our icon set or an inline `<svg>` element. */\n icon?: IconOrElement;\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={<ArrowLeftIcon />} 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={<CloserIcon />} 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":";;;;;;;;;;;;;;;;AAoBA,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,IAA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gD,KAAe,MAA+C;EAGlE,AADAC,IAAUzB,CAAK,GACfD,EAAQ;CACV;CACA,OACE,kBAACrB,GAAD;EACE,WAAW4C;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,eAAY/C,EAAoB;CACxC,OACE,kBAACE,GAAD;EACE,WAAW4C;EACX,GAAIF;EACJ,SAAQ;EACR,MAAK;EACL,SAASrB;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.0",
3
+ "version": "1.2.0",
4
4
  "description": "SideSheet component, implemented in React, for the Bonprix Design System.",
5
5
  "keywords": [],
6
6
  "license": "UNLICENSED",
@@ -42,12 +42,12 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@radix-ui/react-dialog": "1.1.23",
45
- "tailwind-merge": "2.6.1",
46
- "@bonprix-ds/internal-components": "0.2.2",
47
- "@bonprix-ds/react-icon": "1.2.2",
48
- "@bonprix-ds/react-button": "1.1.2",
49
- "@bonprix-ds/react-icon-button": "1.2.2",
50
- "@bonprix-ds/utils": "0.3.0"
45
+ "tailwind-merge": "2.5.4",
46
+ "@bonprix-ds/internal-components": "0.2.3",
47
+ "@bonprix-ds/react-button": "1.1.3",
48
+ "@bonprix-ds/react-icon": "1.3.0",
49
+ "@bonprix-ds/react-icon-button": "1.2.3",
50
+ "@bonprix-ds/utils": "0.4.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@testing-library/dom": "10.4.2",