@bonprix-ds/react-side-sheet 1.1.1 → 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 {
@@ -56,8 +56,8 @@ export interface SheetContentProps {
56
56
  export interface SheetButtonBaseProps {
57
57
  /** The label of the button. */
58
58
  children: string;
59
- /** If used, an icon will be additionally shown. The value is a name of one icon from our icon set. */
60
- icon?: IconType;
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;
61
61
  /** The position of the icon relative to the content. */
62
62
  iconPosition?: "start" | "end";
63
63
  }
@@ -8,12 +8,13 @@ import { tv as a } from "tailwind-variants";
8
8
  import { backdrop as o, fadeAnimation as s, slideAnimation as c } from "@bonprix-ds/internal-components";
9
9
  import l from "@bonprix-ds/react-button";
10
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";
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 g, jsxs as _ } from "react/jsx-runtime";
15
+ import { jsx as v, jsxs as y } from "react/jsx-runtime";
15
16
  //#region src/SideSheetRoot.tsx
16
- var v = a({
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",
@@ -37,20 +38,20 @@ var v = a({
37
38
  true: { modal: "w-fit min-w-100 max-w-150" }
38
39
  }
39
40
  }
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({
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({
43
44
  hasDynamicWidth: u,
44
- prefersReducedMotion: y
45
- }), { innerOpen: w } = p(i ?? a ?? !1), T = n(null);
46
- return b ? void 0 : /* @__PURE__ */ g(r.Root, {
45
+ prefersReducedMotion: d
46
+ }), { innerOpen: w } = h(i ?? a ?? !1), T = n(null);
47
+ return f ? void 0 : /* @__PURE__ */ v(r.Root, {
47
48
  open: w,
48
49
  modal: !o,
49
- children: /* @__PURE__ */ _(r.Portal, { children: [/* @__PURE__ */ g(r.Overlay, {
50
+ children: /* @__PURE__ */ y(r.Portal, { children: [/* @__PURE__ */ v(r.Overlay, {
50
51
  className: S(),
51
52
  onClick: s,
52
53
  style: { zIndex: l }
53
- }), /* @__PURE__ */ g(r.Content, {
54
+ }), /* @__PURE__ */ v(r.Content, {
54
55
  ref: T,
55
56
  className: x(),
56
57
  style: { zIndex: l },
@@ -66,14 +67,14 @@ var v = a({
66
67
  "data-bpds-modeless": o,
67
68
  "data-bpds-has-dynamic-width": u,
68
69
  "aria-modal": !o,
69
- children: /* @__PURE__ */ g(d.Provider, {
70
+ children: /* @__PURE__ */ v(p.Provider, {
70
71
  value: l,
71
- children: /* @__PURE__ */ g(e.Provider, {
72
+ children: /* @__PURE__ */ v(e.Provider, {
72
73
  value: {
73
74
  onClose: s,
74
75
  onBack: c
75
76
  },
76
- children: /* @__PURE__ */ g("div", {
77
+ children: /* @__PURE__ */ v("div", {
77
78
  className: C(),
78
79
  children: t
79
80
  })
@@ -81,67 +82,67 @@ var v = a({
81
82
  })
82
83
  })] })
83
84
  });
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", {
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", {
87
88
  className: s(),
88
- children: [/* @__PURE__ */ _("div", {
89
+ children: [/* @__PURE__ */ y("div", {
89
90
  className: c(),
90
91
  children: [
91
- a && /* @__PURE__ */ g(u, {
92
+ a && /* @__PURE__ */ v(u, {
92
93
  onClick: a,
93
- icon: "arrow-left",
94
+ icon: /* @__PURE__ */ v(d, {}),
94
95
  label: "Zurück",
95
96
  variant: "tertiary",
96
97
  size: "small"
97
98
  }),
98
- /* @__PURE__ */ g(r.Title, {
99
+ /* @__PURE__ */ v(r.Title, {
99
100
  asChild: !0,
100
- children: /* @__PURE__ */ g("div", {
101
+ children: /* @__PURE__ */ v("div", {
101
102
  className: "grow",
102
- children: /* @__PURE__ */ g(i, {
103
+ children: /* @__PURE__ */ v(i, {
103
104
  className: "typography-bonprix-h6 my-0 line-clamp-2 text-start text-clr-on-bg-high",
104
105
  children: e
105
106
  })
106
107
  })
107
108
  }),
108
- /* @__PURE__ */ g(r.Close, {
109
+ /* @__PURE__ */ v(r.Close, {
109
110
  asChild: !0,
110
- children: /* @__PURE__ */ g(u, {
111
+ children: /* @__PURE__ */ v(u, {
111
112
  onClick: o,
112
- icon: "closer",
113
+ icon: /* @__PURE__ */ v(f, {}),
113
114
  label: "Schließen",
114
115
  variant: "tertiary",
115
116
  size: "small"
116
117
  })
117
118
  })
118
119
  ]
119
- }), n && /* @__PURE__ */ g("p", {
120
+ }), n && /* @__PURE__ */ v("p", {
120
121
  className: "typography-body1 my-0 text-start text-clr-on-bg-high",
121
122
  children: n
122
123
  })]
123
124
  });
124
- }, x = ({ children: e, disableHorizontalPadding: t = !1 }) => {
125
- let { scrollArea: n } = v({ disableHorizontalPadding: t });
126
- return /* @__PURE__ */ g("div", {
125
+ }, C = ({ children: e, disableHorizontalPadding: t = !1 }) => {
126
+ let { scrollArea: n } = b({ disableHorizontalPadding: t });
127
+ return /* @__PURE__ */ v("div", {
127
128
  className: n(),
128
129
  "data-bpds-disable-horizontal-padding": t,
129
130
  children: e
130
131
  });
131
- }, S = ({ children: e }) => {
132
- let { buttonSection: t } = v();
133
- return /* @__PURE__ */ g("div", {
132
+ }, w = ({ children: e }) => {
133
+ let { buttonSection: t } = b();
134
+ return /* @__PURE__ */ v("div", {
134
135
  className: "button-section-container",
135
- children: /* @__PURE__ */ g("div", {
136
+ children: /* @__PURE__ */ v("div", {
136
137
  className: i(t(), "button-section"),
137
138
  children: e
138
139
  })
139
140
  });
140
- }, C = ({ children: e, icon: n, iconPosition: r, loading: i, component: a = "button", ...o }) => {
141
+ }, T = ({ children: e, icon: n, iconPosition: r, loading: i, component: a = "button", ...o }) => {
141
142
  let { onClick: s, ...c } = o, u = a, { onClose: d } = t(), f = (e) => {
142
143
  s?.(e), d();
143
144
  };
144
- return /* @__PURE__ */ g(l, {
145
+ return /* @__PURE__ */ v(l, {
145
146
  component: u,
146
147
  ...c,
147
148
  variant: "primary",
@@ -152,9 +153,9 @@ var v = a({
152
153
  loading: i,
153
154
  children: e
154
155
  });
155
- }, w = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...a }) => {
156
+ }, E = ({ children: e, icon: n, iconPosition: r, component: i = "button", ...a }) => {
156
157
  let o = i, { onClose: s } = t();
157
- return /* @__PURE__ */ g(l, {
158
+ return /* @__PURE__ */ v(l, {
158
159
  component: o,
159
160
  ...a,
160
161
  variant: "secondary",
@@ -166,8 +167,8 @@ var v = a({
166
167
  children: e
167
168
  });
168
169
  };
169
- y.displayName = "SideSheet";
170
+ x.displayName = "SideSheet";
170
171
  //#endregion
171
- export { S as ButtonSection, x as Content, C as PrimaryButton, w as SecondaryButton, b as Title, y as default };
172
+ export { w as ButtonSection, C as Content, T as PrimaryButton, E as SecondaryButton, S as Title, x as default };
172
173
 
173
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","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,IAAO,Y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AAQ;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"}
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;I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BAAgB;GAAI;EAAc,CAAA;CACxE,CAAA;AAET,GAEaC,KAAwC,EACnD,aACA,SACA,iBACA,YACA,eAAY,UACZ,GAAGC,QAC6B;CAChC,IAAM,EAAE,YAAS,GAAGC,MAAeD,GAC7BE,IAAyBC,GACzB,EAAE,eAAY/C,EAAoB,GAClCgD,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.1",
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-button": "1.1.2",
48
- "@bonprix-ds/utils": "0.3.0",
49
- "@bonprix-ds/react-icon-button": "1.2.2",
50
- "@bonprix-ds/react-icon": "1.2.2"
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",