@bonprix-ds/react-side-sheet 1.3.0 → 1.3.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.
|
@@ -62,7 +62,7 @@ export interface SheetContentProps {
|
|
|
62
62
|
export interface SheetButtonBaseProps {
|
|
63
63
|
/** The label of the button. */
|
|
64
64
|
children: string;
|
|
65
|
-
/** 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. */
|
|
65
|
+
/** If used, an icon will be additionally shown. The value is either an icon component from `bonprix-design-system/icons`, such as `<CartIcon />`, a name of one icon from our icon set or an inline `<svg>` element. */
|
|
66
66
|
icon?: IconOrElement;
|
|
67
67
|
/** The position of the icon relative to the content. */
|
|
68
68
|
iconPosition?: "start" | "end";
|
|
@@ -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","useFocusReturn","innerOpen","modeless","onClose","event","returnFocus","hasDynamicWidth","ZIndexContext","zIndex","contentWrapper","Title","Level","header","titleAndIcons","onBack","ArrowLeftIcon","backButtonLabel","CloserIcon","closeButtonLabel","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, useFocusReturn, 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 *\n * Once the sheet has closed, focus returns to the element that had it before the sheet opened. */\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 /** The accessible name of the close button. */\n closeButtonLabel?: string;\n /** The accessible name of the back button. */\n backButtonLabel?: string;\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 /**\n * When set to false, interaction with outside elements will be disabled and only dialog content will be visible to screen readers.\n *\n * A modeless sheet that closes while focus is outside it, such as on a page control that closed it, leaves focus there.\n */\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 = ({\n children,\n open,\n isOpen,\n modeless = false,\n onClose,\n onBack,\n zIndex = 9999,\n hasDynamicWidth = false,\n closeButtonLabel = \"Schließen\",\n backButtonLabel = \"Zurück\",\n}: 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 const { returnFocus } = useFocusReturn(innerOpen, contentRef);\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 returnFocusOnceClosed = (event: Event) => {\n event.preventDefault();\n returnFocus();\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 onCloseAutoFocus={returnFocusOnceClosed}\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, closeButtonLabel, backButtonLabel }}>\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, closeButtonLabel, backButtonLabel } = useConsumeSideSheet();\n const { header, titleAndIcons } = generateClasses();\n return (\n <div className={header()}>\n <div className={titleAndIcons()}>\n {onBack && <IconButton onClick={onBack} icon={<ArrowLeftIcon />} label={backButtonLabel} 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={closeButtonLabel} 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,GA+FKC,KAAiB,EACrB,aACA,SACA,WACA,cAAW,IACX,YACA,WACA,YAAS,MACT,qBAAkB,IAClB,sBAAmB,aACnB,qBAAkB,eACP;CACX,AAAIC,MAAW,KAAA,KAAWC,EAAe,cAAc;CACvD,IAAMC,IAAuBC,EAAwB,GAC/CC,IAAWC,EAAkB,GAAG,GAChC,EAAE,OAAOC,GAAY,aAAU,sBAAmBZ,EAAgB;EAAE;EAAiB;CAAqB,CAAC,GAE3G,EAAE,iBAAca,EAAaC,KAAQR,KAAU,EAAK,GACpDS,IAAaC,EAAuB,IAAI,GACxC,EAAE,mBAAgBC,EAAeC,GAAWH,CAAU;CAoB5D,OAlBIL,IAAU,SAmBZ,kBAACb,EAAgB,MAAjB;EAAsB,MAAMqB;EAAW,OAAO,CAACC;EAC7C,UAAA,kBAACtB,EAAgB,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E,kBAACE,GAAD;EACE,WAAWgD;EACX,GAAIF;EACJ,SAAQ;EACR,MAAK;EACL,SAASxB;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","useFocusReturn","innerOpen","modeless","onClose","event","returnFocus","hasDynamicWidth","ZIndexContext","zIndex","contentWrapper","Title","Level","header","titleAndIcons","onBack","ArrowLeftIcon","backButtonLabel","CloserIcon","closeButtonLabel","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, MouseEvent, 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, useFocusReturn, 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 *\n * Once the sheet has closed, focus returns to the element that had it before the sheet opened. */\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 /** The accessible name of the close button. */\n closeButtonLabel?: string;\n /** The accessible name of the back button. */\n backButtonLabel?: string;\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 an icon component from `bonprix-design-system/icons`, such as `<CartIcon />`, 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 /**\n * When set to false, interaction with outside elements will be disabled and only dialog content will be visible to screen readers.\n *\n * A modeless sheet that closes while focus is outside it, such as on a page control that closed it, leaves focus there.\n */\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 = ({\n children,\n open,\n isOpen,\n modeless = false,\n onClose,\n onBack,\n zIndex = 9999,\n hasDynamicWidth = false,\n closeButtonLabel = \"Schließen\",\n backButtonLabel = \"Zurück\",\n}: 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 const { returnFocus } = useFocusReturn(innerOpen, contentRef);\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 returnFocusOnceClosed = (event: Event) => {\n event.preventDefault();\n returnFocus();\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 onCloseAutoFocus={returnFocusOnceClosed}\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, closeButtonLabel, backButtonLabel }}>\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, closeButtonLabel, backButtonLabel } = useConsumeSideSheet();\n const { header, titleAndIcons } = generateClasses();\n return (\n <div className={header()}>\n <div className={titleAndIcons()}>\n {onBack && <IconButton onClick={onBack} icon={<ArrowLeftIcon />} label={backButtonLabel} 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={closeButtonLabel} 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: 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":";;;;;;;;;;;;;;;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KAAW,kBAAC,KAAD;GAAG,WAAU;GAAwD,UAAAA;EAAW,CAAA,CACzF;;AAET,GAEaC,KAAW,EAAE,aAAU,8BAA2B,SAA+B;CAC5F,IAAM,EAAE,kBAAerC,EAAgB,EAAE,4BAAyB,CAAC;CACnE,OACE,kBAAC,OAAD;EAAK,WAAWsC,EAAW;EAAG,wCAAsCC;EACjE;CACE,CAAA;AAET,GAEaC,KAAiB,EAAE,kBAAwC;CACtE,IAAM,EAAE,qBAAkBxC,EAAgB;CAC1C,OACE,kBAAC,OAAD;EAAK,WAAU;EACb,UAAA,kBAAC,OAAD;GAAK,WAAWyC,EAAQC,EAAc,GAAG,gBAAgB;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,eAAYnD,EAAoB,GAClCoD,KAAe,MAAyC;EAG5D,AADAC,IAAU5B,CAAK,GACfD,EAAQ;CACV;CACA,OACE,kBAACtB,GAAD;EACE,WAAWgD;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,eAAYnD,EAAoB;CACxC,OACE,kBAACE,GAAD;EACE,WAAWgD;EACX,GAAIF;EACJ,SAAQ;EACR,MAAK;EACL,SAASxB;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.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "SideSheet component, implemented in React, for the Bonprix Design System.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"provenance": true
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@bonprix-ds/internal-components": "0.2.
|
|
45
|
-
"@bonprix-ds/react-button": "1.1.
|
|
46
|
-
"@bonprix-ds/react-icon": "1.
|
|
47
|
-
"@bonprix-ds/react-icon-button": "1.2.
|
|
44
|
+
"@bonprix-ds/internal-components": "0.2.7",
|
|
45
|
+
"@bonprix-ds/react-button": "1.1.7",
|
|
46
|
+
"@bonprix-ds/react-icon": "1.4.0",
|
|
47
|
+
"@bonprix-ds/react-icon-button": "1.2.7",
|
|
48
48
|
"@bonprix-ds/utils": "0.6.0",
|
|
49
49
|
"@radix-ui/react-dialog": "1.3.1",
|
|
50
50
|
"tailwind-merge": "2.5.4"
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@testing-library/dom": "10.4.2",
|
|
55
55
|
"@testing-library/react": "16.3.3",
|
|
56
56
|
"@types/react": "19.3.0",
|
|
57
|
-
"vite": "8.3.
|
|
58
|
-
"vitest": "5.0
|
|
57
|
+
"vite": "8.3.8",
|
|
58
|
+
"vitest": "5.1.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"react": "^19",
|