-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAY-1744] Drawer Kit Refactor (#4028)
**What does this PR do?** A clear and concise description with your runway ticket url. **Screenshots:** Screenshots to visualize your addition/change **How to test?** Steps to confirm the desired behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See addition/change #### Checklist: - [ ] **LABELS** Add a label: `enhancement`, `bug`, `improvement`, `new kit`, `deprecated`, or `breaking`. See [Changelog & Labels](https://github.com/powerhome/playbook/wiki/Changelog-&-Labels) for details. - [ ] **DEPLOY** I have added the `milano` label to show I'm ready for a review. - [ ] **TESTS** I have added test coverage to my code.
- Loading branch information
1 parent
b4c2e7f
commit e3a9937
Showing
16 changed files
with
536 additions
and
581 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react' | ||
|
||
const noop = (): void => void 0 | ||
|
||
type DrawerContextType = { | ||
onClose: () => void | ||
} | ||
|
||
export const DrawerContext = React.createContext<DrawerContextType>({ | ||
onClose: noop, | ||
}) |
38 changes: 38 additions & 0 deletions
38
playbook/app/pb_kits/playbook/pb_drawer/docs/_drawer_behavior.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React, { useState } from "react" | ||
import { Button, Drawer, Flex } from "playbook-ui" | ||
|
||
const useDrawer = (visible = false) => { | ||
const [opened, setOpened] = useState(visible) | ||
const toggle = () => setOpened(!opened) | ||
|
||
return [opened, toggle] | ||
} | ||
|
||
const DrawerBehavior = () => { | ||
const [drawerOpen, toggleDrawerOpen] = useDrawer() | ||
|
||
return ( | ||
<> | ||
<Flex wrap> | ||
<Button id='sm' | ||
marginRight='md' | ||
onClick={toggleDrawerOpen} | ||
> | ||
{"Push Behavior"} | ||
</Button> | ||
</Flex> | ||
<Flex> | ||
<Drawer | ||
behavior={"push"} | ||
onClose={toggleDrawerOpen} | ||
opened={drawerOpen} | ||
size={"lg"} | ||
> | ||
Test me (Push Behavior) | ||
</Drawer> | ||
</Flex> | ||
</> | ||
) | ||
} | ||
|
||
export default DrawerBehavior |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 44 additions & 19 deletions
63
playbook/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,56 @@ | ||
import React from "react"; | ||
import { Button, Drawer, Icon, Title } from "playbook-ui"; | ||
import React, { useState, useEffect } from "react" | ||
import { Button, Drawer, Icon, Nav, NavItem } from "playbook-ui" | ||
|
||
const DrawerMenu = () => { | ||
const [isSmallScreen, setIsSmallScreen] = useState(false) | ||
|
||
useEffect(() => { | ||
const mediaQuery = window.matchMedia("(max-width: 600px)") | ||
setIsSmallScreen(mediaQuery.matches) | ||
const handler = (e) => setIsSmallScreen(e.matches) | ||
mediaQuery.addEventListener('change', handler) | ||
return () => mediaQuery.removeEventListener('change', handler) | ||
}, []) | ||
|
||
return ( | ||
<> | ||
<Button id="menuButton" | ||
padding="sm" | ||
<div> | ||
<Button id='menuButton' | ||
padding='xs' | ||
> | ||
<Icon icon="bars" | ||
size="3x" | ||
<Icon icon='bars' | ||
size='2x' | ||
/> | ||
</Button> | ||
<Drawer | ||
behavior="push" | ||
closeBreakpoint="md" | ||
menuButtonID="menuButton" | ||
overlay={false} | ||
placement="left" | ||
size="lg" | ||
breakpoint="md" | ||
placement='bottom' | ||
size='full' | ||
triggerId='menuButton' | ||
withinElement | ||
> | ||
<Title paddingBottom="md">A really neat menu</Title> | ||
<Button text="This Button does nothing" /> | ||
<Nav | ||
highlight={false} | ||
link='#' | ||
orientation={isSmallScreen ? 'vertical' : 'horizontal'} | ||
padding={isSmallScreen ? 'none' : 'sm'} | ||
> | ||
<NavItem link='#' | ||
text='About' | ||
/> | ||
<NavItem active | ||
link='#' | ||
text='Case Studies' | ||
/> | ||
<NavItem link='#' | ||
text='Service' | ||
/> | ||
<NavItem link='#' | ||
text='Contacts' | ||
/> | ||
</Nav> | ||
</Drawer> | ||
</> | ||
); | ||
}; | ||
</div> | ||
) | ||
} | ||
|
||
export default DrawerMenu; | ||
export default DrawerMenu |
24 changes: 21 additions & 3 deletions
24
playbook/app/pb_kits/playbook/pb_drawer/docs/_drawer_menu.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
Our drawer kit can fulfill your responsive menu needs! Using the `closeBreakpoint` prop you can have the menu close on smaller screens like phones/tablets. | ||
The Drawer component can be used to create responsive navigation menus and sidebars. It provides flexible options for controlling when and how the drawer appears based on screen size. | ||
|
||
### Within Element | ||
The `withinElement` prop allows you to render the drawer within its parent container: | ||
- The drawer will be positioned relative to its parent element | ||
- Useful for creating nested navigation structures | ||
- This must be used in conjunction with the `triggerId` prop | ||
|
||
This provides a clean way to create responsive navigation patterns that adapt to different screen sizes while maintaining a consistent user experience. | ||
|
||
### Trigger Id | ||
The `triggerId` prop allows you to connect an element to control the drawer: | ||
- The specified element will toggle the drawer open/closed | ||
- The element is automatically hidden when the drawer is opened via breakpoint | ||
- The element reappears when the drawer is closed via breakpoint | ||
|
||
### Breakpoint | ||
Use the `breakpoint` prop to control when the drawer automatically opens or closes based on screen size. For example, setting `breakpoint="md"` will: | ||
- Close the drawer on screens smaller than the medium breakpoint (992px) | ||
- Automatically open the drawer on screens larger than or equal to the medium breakpoint | ||
|
||
|
||
Set a menu button with the `menuButtonID` props. When the Drawer is open, the menu button will be hidden. But when your Brakpoint closes the drawer, you can toggle the Drawer open/close with your menu butotn. | ||
|
||
Also use the `withinElement` props to have the Drawer open within a specific element, instead of the default behavior of it taking up the entire screen size. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.