From 73c2434e06e7b92d1cb1b85b58c89c17c3c1141e Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 20 Nov 2024 09:55:58 -0500 Subject: [PATCH] Test out breakpoint --- .../pb_kits/playbook/pb_drawer/_drawer.tsx | 65 +++++++++++++------ .../playbook/pb_drawer/docs/_drawer_menu.jsx | 22 +++++++ .../playbook/pb_drawer/docs/example.yml | 6 +- .../pb_kits/playbook/pb_drawer/docs/index.js | 1 + 4 files changed, 70 insertions(+), 24 deletions(-) create mode 100644 playbook/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.jsx diff --git a/playbook/app/pb_kits/playbook/pb_drawer/_drawer.tsx b/playbook/app/pb_kits/playbook/pb_drawer/_drawer.tsx index c238ece6fb..7f882d33f7 100644 --- a/playbook/app/pb_kits/playbook/pb_drawer/_drawer.tsx +++ b/playbook/app/pb_kits/playbook/pb_drawer/_drawer.tsx @@ -22,6 +22,7 @@ type DrawerProps = { htmlOptions?: { [key: string]: string | number | boolean | (() => void) }; id?: string; fullHeight?: boolean; + menuButtonID?: string; onClose?: () => void; opened: boolean; overlay: boolean; @@ -43,7 +44,8 @@ const Drawer = (props: DrawerProps): React.ReactElement => { id, size = "md", children, - fullHeight = false, + fullHeight = true, + menuButtonID, opened, onClose, overlay = true, @@ -102,6 +104,7 @@ const Drawer = (props: DrawerProps): React.ReactElement => { const classes = classnames(buildCss("pb_drawer_wrapper"), className); const [triggerOpened, setTriggerOpened] = useState(false); + const [menuButtonOpened, setMenuButtonOpened] = useState(false); const breakpointWidths: Record = { none: 0, @@ -139,7 +142,8 @@ const Drawer = (props: DrawerProps): React.ReactElement => { }; }, [breakpoint]); - const modalIsOpened = trigger ? triggerOpened : opened || isBreakpointOpen; + // Simplified modalIsOpened logic + const modalIsOpened = isBreakpointOpen || triggerOpened || menuButtonOpened || opened; const [animationState, setAnimationState] = useState(""); @@ -184,13 +188,34 @@ const Drawer = (props: DrawerProps): React.ReactElement => { }, [modalIsOpened, behavior, placement, size]); const api = { - onClose: trigger - ? function () { - setTriggerOpened(false); - } - : onClose, + onClose: () => { + if (trigger) { + setTriggerOpened(false); + } else if (menuButtonID) { + setMenuButtonOpened(false); + } + if (onClose) { + onClose(); + } + }, }; + useEffect(() => { + if (menuButtonID) { + const menuButton = document.getElementById(menuButtonID); + if (menuButton) { + const handleMenuButtonClick = () => { + console.log("menuButtonID", menuButtonID); + setMenuButtonOpened((prev) => !prev); + }; + menuButton.addEventListener("click", handleMenuButtonClick); + return () => { + menuButton.removeEventListener("click", handleMenuButtonClick); + }; + } + } + }, [menuButtonID]); + return (
{ {...htmlProps} className={classes} > - {isModalVisible && ( -
+ id={id} + onClick={overlay ? api.onClose : undefined} + >
e.stopPropagation()} > - {children} -
+ {children}
- )}
+ )} +
); }; diff --git a/playbook/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.jsx b/playbook/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.jsx new file mode 100644 index 0000000000..1352799fc1 --- /dev/null +++ b/playbook/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.jsx @@ -0,0 +1,22 @@ +import React from "react"; +import { Button, Drawer } from "playbook-ui"; + +const DrawerMenu = () => { + + return ( + <> + + +

Your drawer content here

+
+ + ); +}; + +export default DrawerMenu; diff --git a/playbook/app/pb_kits/playbook/pb_drawer/docs/example.yml b/playbook/app/pb_kits/playbook/pb_drawer/docs/example.yml index 32d166df0a..065d3436f3 100644 --- a/playbook/app/pb_kits/playbook/pb_drawer/docs/example.yml +++ b/playbook/app/pb_kits/playbook/pb_drawer/docs/example.yml @@ -5,8 +5,4 @@ examples: react: - - drawer_default: Default - - drawer_sizes: Sizes - - drawer_overlay: Overlay - - drawer_borders: Borders - - drawer_breakpoints: Open on Breakpoints + - drawer_menu: Menu Behavior diff --git a/playbook/app/pb_kits/playbook/pb_drawer/docs/index.js b/playbook/app/pb_kits/playbook/pb_drawer/docs/index.js index acb54022b4..9d318b9d39 100644 --- a/playbook/app/pb_kits/playbook/pb_drawer/docs/index.js +++ b/playbook/app/pb_kits/playbook/pb_drawer/docs/index.js @@ -3,3 +3,4 @@ export { default as DrawerSizes } from './_drawer_sizes.jsx' export { default as DrawerOverlay } from './_drawer_overlay.jsx' export { default as DrawerBorders } from './_drawer_borders.jsx' export { default as DrawerBreakpoints } from './_drawer_breakpoints.jsx' +export { default as DrawerMenu } from './_drawer_menu.jsx'