@bonprix-ds/react-bottom-sheet 1.3.1 → 1.3.3
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":"BottomSheetRoot.js","names":["BottomSheetContext","useConsumeBottomSheet","useCreateBottomSheet","useKeepScrollPositionOnLeave","DialogPrimitive","Button","IconButton","generateClasses","tv","backdrop","BottomSheetRoot","isOpen","warnDeprecated","prefersReducedMotion","usePrefersReducedMotion","open","disableDrag","scrollPosition","useInnerOpen","isShown","disableScrollLocking","innerOpen","contentRef","useRef","useFocusReturn","useEffect","returnFocus","nextOpen","onClose","Sheet","root","event","container","dragHandleContainer","dragHandle","ZIndexContext","zIndex","content","contentWrapper","Title","Level","header","titleAndIcons","onBack","ArrowLeftIcon","backButtonLabel","CloserIcon","closeButtonLabel","subline","Content","setScrollRef","scrollArea","disableHorizontalPadding","ButtonSection","PrimaryButton","props","Component","component","otherProps","handleClick","onClick","SecondaryButton"],"sources":["../../src/BottomSheetRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport React, { type ComponentProps, type ElementType, MouseEvent, type ReactNode, type RefObject, useEffect, useRef } from \"react\";\nimport { Sheet } from \"react-modal-sheet\";\nimport { tv } from \"tailwind-variants\";\n\nimport { backdrop } 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, useFocusReturn, useInnerOpen, usePrefersReducedMotion, ZIndexContext } from \"@bonprix-ds/utils\";\nimport { warnDeprecated } from \"@bonprix-ds/utils/deprecation\";\n\nimport BottomSheetContext from \"./BottomSheetContext\";\nimport useConsumeBottomSheet from \"./useConsumeBottomSheet\";\nimport useCreateBottomSheet from \"./useCreateBottomSheet\";\nimport useKeepScrollPositionOnLeave from \"./useKeepScrollPositionOnLeave\";\n\nimport \"./BottomSheet.css\";\n\nconst generateClasses = tv({\n slots: {\n root: \"preflight block\",\n container: \"max-h-[calc(100%-4rem)] rounded-none bg-clr-bg-modal shadow-none outline-none\",\n header: \"px-4 py-3\",\n titleAndIcons: \"flex touch-pan-down items-center gap-2\",\n contentWrapper: \"flex w-full flex-col\",\n content: [\n \"typography-body1 text-clr-primary\",\n // scroller must be a flexbox to fix scrollbar\n // scroller needs some padding to not cut off the focus-ring\n \"*:-mx-0.5 *:flex *:px-0.5\",\n // scroller must set min-h-0 in order to make scrolling work inside our flex context\n \"*:min-h-0\",\n ],\n dragHandleContainer: \"flex h-6 shrink-0 items-center justify-center\",\n dragHandle: \"h-1 w-8 rounded-full bg-clr-on-bg-low\",\n backdrop: backdrop(),\n scrollArea: \"scroll-area relative\",\n },\n variants: {\n disableHorizontalPadding: {\n false: { scrollArea: \"px-4\" },\n true: \"\",\n },\n },\n});\n\ninterface SheetProps {\n /** All of the subcomponents should be placed inside this property. */\n children: ReactNode;\n /** 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\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 /** A reference to the root element of the sheet. */\n ref?: RefObject<HTMLDivElement>;\n};\n\nconst BottomSheetRoot = ({\n children,\n open,\n isOpen,\n onClose,\n onBack,\n zIndex = 9999,\n ref,\n closeButtonLabel = \"Schließen\",\n backButtonLabel = \"Zurück\",\n}: Props) => {\n if (isOpen !== undefined) warnDeprecated(\"is-open-prop\");\n const prefersReducedMotion = usePrefersReducedMotion();\n const { root, container, dragHandleContainer, dragHandle, content, contentWrapper, backdrop } = generateClasses();\n const { isShown, scrollRef, scrollPosition } = useCreateBottomSheet({ open: open ?? isOpen ?? false });\n\n // When \"middle\" or \"bottom\", dragging is disabled to allow for regular scrolling.\n // When at \"top\", we need to enable drag to close. When `undefined`, the element is not scrollable and can be dragged, too.\n const disableDrag = scrollPosition === \"middle\" || scrollPosition === \"bottom\";\n\n const { innerOpen } = useInnerOpen(isShown);\n const disableScrollLocking = useKeepScrollPositionOnLeave(innerOpen);\n\n const contentRef = useRef<HTMLDivElement>(null);\n const { returnFocus } = useFocusReturn(innerOpen, contentRef);\n\n // Radix's `onCloseAutoFocus` waits until react-modal-sheet has animated the sheet away under `forceMount` - and never\n // fires where that animation does not settle. Closing is the reliable signal.\n useEffect(() => {\n if (!innerOpen) returnFocus();\n }, [innerOpen, returnFocus]);\n\n const focusSheet = (event: Event) => {\n event.preventDefault();\n (event.target as HTMLElement).focus();\n };\n\n const handleOpenChange = (nextOpen: boolean) => {\n if (!nextOpen) onClose();\n };\n\n return (\n <DialogPrimitive.Root open={innerOpen} onOpenChange={handleOpenChange}>\n <Sheet\n isOpen={innerOpen}\n onClose={onClose}\n className={root()}\n detent=\"content\"\n data-bpds=\"bottom-sheet\"\n prefersReducedMotion={prefersReducedMotion}\n disableScrollLocking={disableScrollLocking}\n style={{\n // We remove `pointer-events` handling from the library because it interfers with a lot of things like opened Selects that wouldn't close etc.\n pointerEvents: undefined,\n // When removing react-modal-sheet's pointerEvents handling, we need to adjust visibility because we can no longer rely on `pointer-events: none` being set on the wrapper that spans the whole page even when closed.\n visibility: innerOpen ? \"visible\" : \"hidden\",\n zIndex: zIndex,\n }}\n avoidKeyboard={false}\n >\n {/* `forceMount` leaves the mounting to the sheet, whose state machine keeps the container around for the closing animation. */}\n <DialogPrimitive.Content\n ref={contentRef}\n forceMount\n asChild\n aria-modal\n aria-describedby={undefined}\n tabIndex={-1}\n onOpenAutoFocus={focusSheet}\n >\n <Sheet.Container className={container()} ref={ref}>\n <Sheet.Header unstyled className={dragHandleContainer()}>\n <Sheet.DragIndicator unstyled className={dragHandle()} />\n </Sheet.Header>\n <ZIndexContext.Provider value={zIndex}>\n <BottomSheetContext.Provider\n value={{ scrollRef, scrollPosition, onClose, onBack, disableDrag, closeButtonLabel, backButtonLabel }}\n >\n <Sheet.Content\n className={content()}\n // disable default scrolling\n disableScroll\n // Dragging is still managed by `Sheet.Content` so we control it here\n disableDrag={disableDrag}\n >\n <div\n className={contentWrapper()}\n // Apply keyboard height as padding bottom to keep content above the keyboard\n style={{ paddingBottom: \"max(var(--keyboard-inset-height, 0rem), var(--app-safe-area-inset-bottom, 1rem))\" }}\n >\n {children}\n </div>\n </Sheet.Content>\n </BottomSheetContext.Provider>\n </ZIndexContext.Provider>\n </Sheet.Container>\n </DialogPrimitive.Content>\n {/* TODO: Deactivate the animation, when the user prefers reduced motion: https://github.com/Temzasse/react-modal-sheet/issues/227 */}\n {/* The backdrop carries no handler of its own: Radix dismisses the dialog on a press outside of its content. */}\n <Sheet.Backdrop className={backdrop()} />\n </Sheet>\n </DialogPrimitive.Root>\n );\n};\n\nexport default BottomSheetRoot;\n\nexport const Title = ({ children, subline, level: Level = \"h3\" }: SheetTitleProps) => {\n const { onBack, onClose, closeButtonLabel, backButtonLabel } = useConsumeBottomSheet();\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 <IconButton onClick={onClose} icon={<CloserIcon />} label={closeButtonLabel} variant=\"tertiary\" size=\"small\" />\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 { scrollRef: setScrollRef, disableDrag } = useConsumeBottomSheet();\n const { scrollArea } = generateClasses({ disableHorizontalPadding });\n return (\n <div\n ref={setScrollRef}\n className={scrollArea()}\n // react-modal-sheet writes this same property imperatively, but only once it has measured the element as\n // scrollable - and it bails before doing so on every open where that measurement is not ready yet, which\n // leaves the browser free to claim the downward swipe and cancel the drag. Setting it here closes that gap.\n style={{ touchAction: disableDrag ? \"auto\" : \"pan-down\" }}\n data-bpds-disable-horizontal-padding={disableHorizontalPadding}\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nexport const ButtonSection = ({ children }: SheetButtonSectionProps) => {\n return <div className=\"button-section flex w-full shrink-0 touch-pan-down flex-col gap-3 px-4 pt-4\">{children}</div>;\n};\n\nexport const PrimaryButton = <C extends ElementType>({\n children,\n icon,\n iconPosition,\n loading,\n component = \"button\" as C,\n ...props\n}: SheetPrimaryButtonProps<C>) => {\n const Component: ElementType = component;\n const { onClick, ...otherProps } = props;\n const { onClose } = useConsumeBottomSheet();\n const handleClick = (event: MouseEvent) => {\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 } = useConsumeBottomSheet();\n return (\n <Button component={Component} {...props} variant=\"secondary\" onClick={onClose} icon={icon} iconPosition={iconPosition} size=\"large\">\n {children}\n </Button>\n );\n};\n\nBottomSheetRoot.displayName = \"BottomSheet\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,IAAMO,IAAkBC,EAAG;CACzB,OAAO;EACL,MAAM;EACN,WAAW;EACX,QAAQ;EACR,eAAe;EACf,gBAAgB;EAChB,SAAS;GACP;GAGA;GAEA;EACF;EACA,qBAAqB;EACrB,YAAY;EACZ,UAAUC,EAAS;EACnB,YAAY;CACd;CACA,UAAU,EACR,0BAA0B;EACxB,OAAO,EAAE,YAAY,OAAO;EAC5B,MAAM;CACR,EACF;AACF,CAAC,GAyFKC,KAAmB,EACvB,aACA,SACA,WACA,YACA,WACA,YAAS,MACT,QACA,sBAAmB,aACnB,qBAAkB,eACP;CACX,AAAIC,MAAW,KAAA,KAAWC,EAAe,cAAc;CACvD,IAAMC,IAAuBC,EAAwB,GAC/C,EAAE,SAAM,cAAW,wBAAqB,eAAY,YAAS,mBAAgB,gBAAaP,EAAgB,GAC1G,EAAE,YAAS,cAAW,sBAAmBL,EAAqB,EAAE,MAAMa,KAAQJ,KAAU,GAAM,CAAC,GAI/FK,IAAcC,MAAmB,YAAYA,MAAmB,UAEhE,EAAE,iBAAcC,EAAaC,CAAO,GACpCC,IAAuBjB,EAA6BkB,CAAS,GAE7DC,IAAaC,EAAuB,IAAI,GACxC,EAAE,mBAAgBC,EAAeH,GAAWC,CAAU;CAiB5D,OAbAG,QAAgB;EACd,AAAKJ,KAAWK,EAAY;CAC9B,GAAG,CAACL,GAAWK,CAAW,CAAC,GAYzB,kBAACtB,EAAgB,MAAjB;EAAsB,MAAMiB;EAAW,eALf,MAAsB;GAC9C,AAAKM,KAAUC,EAAQ;EACzB;EAII,UAAA,kBAACC,GAAD;GACE,QAAQR;GACC;GACT,WAAWS,EAAK;GAChB,QAAO;GACP,aAAU;GACY;GACA;GACtB,OAAO;IAEL,eAAe,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AAyBC,GACzB,EAAE,eAAYxD,EAAsB;CAC1C,OACE,kBAACI,GAAD;EAAQ,WAAWmD;EAAW,GAAID;EAAO,SAAQ;EAAY,SAAS3B;EAAe;EAAoB;EAAc,MAAK;EACzH;CACK,CAAA;AAEZ;AAEA,EAAgB,cAAc"}
|
|
1
|
+
{"version":3,"file":"BottomSheetRoot.js","names":["BottomSheetContext","useConsumeBottomSheet","useCreateBottomSheet","useKeepScrollPositionOnLeave","DialogPrimitive","Button","IconButton","generateClasses","tv","backdrop","BottomSheetRoot","isOpen","warnDeprecated","prefersReducedMotion","usePrefersReducedMotion","open","disableDrag","scrollPosition","useInnerOpen","isShown","disableScrollLocking","innerOpen","contentRef","useRef","useFocusReturn","useEffect","returnFocus","nextOpen","onClose","Sheet","root","event","container","dragHandleContainer","dragHandle","ZIndexContext","zIndex","content","contentWrapper","Title","Level","header","titleAndIcons","onBack","ArrowLeftIcon","backButtonLabel","CloserIcon","closeButtonLabel","subline","Content","setScrollRef","scrollArea","disableHorizontalPadding","ButtonSection","PrimaryButton","props","Component","component","otherProps","handleClick","onClick","SecondaryButton"],"sources":["../../src/BottomSheetRoot.tsx"],"sourcesContent":["\"use client\";\n\nimport * as DialogPrimitive from \"@radix-ui/react-dialog\";\nimport React, { type ComponentProps, type ElementType, MouseEvent, type ReactNode, type RefObject, useEffect, useRef } from \"react\";\nimport { Sheet } from \"react-modal-sheet\";\nimport { tv } from \"tailwind-variants\";\n\nimport { backdrop } 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, useFocusReturn, useInnerOpen, usePrefersReducedMotion, ZIndexContext } from \"@bonprix-ds/utils\";\nimport { warnDeprecated } from \"@bonprix-ds/utils/deprecation\";\n\nimport BottomSheetContext from \"./BottomSheetContext\";\nimport useConsumeBottomSheet from \"./useConsumeBottomSheet\";\nimport useCreateBottomSheet from \"./useCreateBottomSheet\";\nimport useKeepScrollPositionOnLeave from \"./useKeepScrollPositionOnLeave\";\n\nimport \"./BottomSheet.css\";\n\nconst generateClasses = tv({\n slots: {\n root: \"preflight block\",\n container: \"max-h-[calc(100%-4rem)] rounded-none bg-clr-bg-modal shadow-none outline-none\",\n header: \"px-4 py-3\",\n titleAndIcons: \"flex touch-pan-down items-center gap-2\",\n contentWrapper: \"flex w-full flex-col\",\n content: [\n \"typography-body1 text-clr-primary\",\n // scroller must be a flexbox to fix scrollbar\n // scroller needs some padding to not cut off the focus-ring\n \"*:-mx-0.5 *:flex *:px-0.5\",\n // scroller must set min-h-0 in order to make scrolling work inside our flex context\n \"*:min-h-0\",\n ],\n dragHandleContainer: \"flex h-6 shrink-0 items-center justify-center\",\n dragHandle: \"h-1 w-8 rounded-full bg-clr-on-bg-low\",\n backdrop: backdrop(),\n scrollArea: \"scroll-area relative\",\n },\n variants: {\n disableHorizontalPadding: {\n false: { scrollArea: \"px-4\" },\n true: \"\",\n },\n },\n});\n\ninterface SheetProps {\n /** All of the subcomponents should be placed inside this property. */\n children: ReactNode;\n /** 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\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 /** A reference to the root element of the sheet. */\n ref?: RefObject<HTMLDivElement>;\n};\n\nconst BottomSheetRoot = ({\n children,\n open,\n isOpen,\n onClose,\n onBack,\n zIndex = 9999,\n ref,\n closeButtonLabel = \"Schließen\",\n backButtonLabel = \"Zurück\",\n}: Props) => {\n if (isOpen !== undefined) warnDeprecated(\"is-open-prop\");\n const prefersReducedMotion = usePrefersReducedMotion();\n const { root, container, dragHandleContainer, dragHandle, content, contentWrapper, backdrop } = generateClasses();\n const { isShown, scrollRef, scrollPosition } = useCreateBottomSheet({ open: open ?? isOpen ?? false });\n\n // When \"middle\" or \"bottom\", dragging is disabled to allow for regular scrolling.\n // When at \"top\", we need to enable drag to close. When `undefined`, the element is not scrollable and can be dragged, too.\n const disableDrag = scrollPosition === \"middle\" || scrollPosition === \"bottom\";\n\n const { innerOpen } = useInnerOpen(isShown);\n const disableScrollLocking = useKeepScrollPositionOnLeave(innerOpen);\n\n const contentRef = useRef<HTMLDivElement>(null);\n const { returnFocus } = useFocusReturn(innerOpen, contentRef);\n\n // Radix's `onCloseAutoFocus` waits until react-modal-sheet has animated the sheet away under `forceMount` - and never\n // fires where that animation does not settle. Closing is the reliable signal.\n useEffect(() => {\n if (!innerOpen) returnFocus();\n }, [innerOpen, returnFocus]);\n\n const focusSheet = (event: Event) => {\n event.preventDefault();\n (event.target as HTMLElement).focus();\n };\n\n const handleOpenChange = (nextOpen: boolean) => {\n if (!nextOpen) onClose();\n };\n\n return (\n <DialogPrimitive.Root open={innerOpen} onOpenChange={handleOpenChange}>\n <Sheet\n isOpen={innerOpen}\n onClose={onClose}\n className={root()}\n detent=\"content\"\n data-bpds=\"bottom-sheet\"\n prefersReducedMotion={prefersReducedMotion}\n disableScrollLocking={disableScrollLocking}\n style={{\n // We remove `pointer-events` handling from the library because it interfers with a lot of things like opened Selects that wouldn't close etc.\n pointerEvents: undefined,\n // When removing react-modal-sheet's pointerEvents handling, we need to adjust visibility because we can no longer rely on `pointer-events: none` being set on the wrapper that spans the whole page even when closed.\n visibility: innerOpen ? \"visible\" : \"hidden\",\n zIndex: zIndex,\n }}\n avoidKeyboard={false}\n >\n {/* `forceMount` leaves the mounting to the sheet, whose state machine keeps the container around for the closing animation. */}\n <DialogPrimitive.Content\n ref={contentRef}\n forceMount\n asChild\n aria-modal\n aria-describedby={undefined}\n tabIndex={-1}\n onOpenAutoFocus={focusSheet}\n >\n <Sheet.Container className={container()} ref={ref}>\n <Sheet.Header unstyled className={dragHandleContainer()}>\n <Sheet.DragIndicator unstyled className={dragHandle()} />\n </Sheet.Header>\n <ZIndexContext.Provider value={zIndex}>\n <BottomSheetContext.Provider\n value={{ scrollRef, scrollPosition, onClose, onBack, disableDrag, closeButtonLabel, backButtonLabel }}\n >\n <Sheet.Content\n className={content()}\n // disable default scrolling\n disableScroll\n // Dragging is still managed by `Sheet.Content` so we control it here\n disableDrag={disableDrag}\n >\n <div\n className={contentWrapper()}\n // Apply keyboard height as padding bottom to keep content above the keyboard\n style={{ paddingBottom: \"max(var(--keyboard-inset-height, 0rem), var(--app-safe-area-inset-bottom, 1rem))\" }}\n >\n {children}\n </div>\n </Sheet.Content>\n </BottomSheetContext.Provider>\n </ZIndexContext.Provider>\n </Sheet.Container>\n </DialogPrimitive.Content>\n {/* TODO: Deactivate the animation, when the user prefers reduced motion: https://github.com/Temzasse/react-modal-sheet/issues/227 */}\n {/* The backdrop carries no handler of its own: Radix dismisses the dialog on a press outside of its content. */}\n <Sheet.Backdrop className={backdrop()} />\n </Sheet>\n </DialogPrimitive.Root>\n );\n};\n\nexport default BottomSheetRoot;\n\nexport const Title = ({ children, subline, level: Level = \"h3\" }: SheetTitleProps) => {\n const { onBack, onClose, closeButtonLabel, backButtonLabel } = useConsumeBottomSheet();\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 <IconButton onClick={onClose} icon={<CloserIcon />} label={closeButtonLabel} variant=\"tertiary\" size=\"small\" />\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 { scrollRef: setScrollRef, disableDrag } = useConsumeBottomSheet();\n const { scrollArea } = generateClasses({ disableHorizontalPadding });\n return (\n <div\n ref={setScrollRef}\n className={scrollArea()}\n // react-modal-sheet writes this same property imperatively, but only once it has measured the element as\n // scrollable - and it bails before doing so on every open where that measurement is not ready yet, which\n // leaves the browser free to claim the downward swipe and cancel the drag. Setting it here closes that gap.\n style={{ touchAction: disableDrag ? \"auto\" : \"pan-down\" }}\n data-bpds-disable-horizontal-padding={disableHorizontalPadding}\n tabIndex={0}\n >\n {children}\n </div>\n );\n};\n\nexport const ButtonSection = ({ children }: SheetButtonSectionProps) => {\n return <div className=\"button-section flex w-full shrink-0 touch-pan-down flex-col gap-3 px-4 pt-4\">{children}</div>;\n};\n\nexport const PrimaryButton = <C extends ElementType>({\n children,\n icon,\n iconPosition,\n loading,\n component = \"button\" as C,\n ...props\n}: SheetPrimaryButtonProps<C>) => {\n const Component: ElementType = component;\n const { onClick, ...otherProps } = props;\n const { onClose } = useConsumeBottomSheet();\n const handleClick = (event: MouseEvent) => {\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 } = useConsumeBottomSheet();\n return (\n <Button component={Component} {...props} variant=\"secondary\" onClick={onClose} icon={icon} iconPosition={iconPosition} size=\"large\">\n {children}\n </Button>\n );\n};\n\nBottomSheetRoot.displayName = \"BottomSheet\";\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,IAAMO,IAAkBC,EAAG;CACzB,OAAO;EACL,MAAM;EACN,WAAW;EACX,QAAQ;EACR,eAAe;EACf,gBAAgB;EAChB,SAAS;GACP;GAGA;GAEA;EAC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|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.3",
|
|
4
4
|
"description": "BottomSheet component, implemented in React, for the Bonprix Design System.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -41,11 +41,11 @@
|
|
|
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.
|
|
48
|
-
"@bonprix-ds/utils": "0.
|
|
44
|
+
"@bonprix-ds/internal-components": "0.2.8",
|
|
45
|
+
"@bonprix-ds/react-button": "1.1.8",
|
|
46
|
+
"@bonprix-ds/react-icon": "1.4.1",
|
|
47
|
+
"@bonprix-ds/react-icon-button": "1.2.8",
|
|
48
|
+
"@bonprix-ds/utils": "0.7.0",
|
|
49
49
|
"@radix-ui/react-dialog": "1.3.1",
|
|
50
50
|
"react-modal-sheet": "5.6.0"
|
|
51
51
|
},
|
|
@@ -54,7 +54,7 @@
|
|
|
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.
|
|
57
|
+
"vite": "8.3.8",
|
|
58
58
|
"vitest": "5.1.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|