Skip to content

LG-5043: Drawer layout #2859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 92 commits into
base: LG-5026-drawer-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
2862f67
add toolbar
shaneeza Apr 11, 2025
5ff3380
Updates Readme (#2806)
TheSonOfThomp Apr 11, 2025
f84dc25
add keyboard focus management
shaneeza Apr 12, 2025
895b29b
fix focus hijacking
shaneeza Apr 14, 2025
5dd7270
naming
shaneeza Apr 14, 2025
1fb3687
updates types, fixes focus on click
shaneeza Apr 14, 2025
88e42a1
Toolbar focus state
shaneeza Apr 14, 2025
9f917f0
fix error
shaneeza Apr 14, 2025
90e6272
add stories
shaneeza Apr 14, 2025
1691d75
toolbar generated stories
shaneeza Apr 14, 2025
e50a8a2
ToolbarIconButton generated stories
shaneeza Apr 14, 2025
9f044d3
update comments
shaneeza Apr 14, 2025
15c4d51
add testids and add an error if trying to use ToolbarIconButton outsi…
shaneeza Apr 14, 2025
cadc553
interaction tests
shaneeza Apr 14, 2025
504ad86
WIP test harnesses
shaneeza Apr 14, 2025
17dcb6f
test harnesses
shaneeza Apr 16, 2025
beb1710
toolbar specs
shaneeza Apr 16, 2025
dcdb066
ToolbarIconButton specs
shaneeza Apr 16, 2025
9a577dd
lint
shaneeza Apr 16, 2025
f52491a
Merge branch 'main' of github.com:mongodb/leafygreen-ui into LG-5027-…
shaneeza Apr 16, 2025
22ab95c
pass className to styles
shaneeza Apr 16, 2025
ad76c37
README
shaneeza Apr 16, 2025
5c34f5d
add missing deps
shaneeza Apr 16, 2025
c2f7fd6
use test utils in interaction tests
shaneeza Apr 16, 2025
3cb2e4e
changesets
shaneeza Apr 16, 2025
a3c0159
remove darkMode from context
shaneeza Apr 16, 2025
21bcd41
Use latest version of `useBackdropClick` (#2810)
bruugey Apr 16, 2025
2e301f7
fix ts error
shaneeza Apr 16, 2025
ec3122c
some cleanup
shaneeza Apr 16, 2025
bd3d34e
add ref test
shaneeza Apr 16, 2025
52aab4a
use correct test
shaneeza Apr 16, 2025
35dd431
remove iconButton changes
shaneeza Apr 16, 2025
7a2dac8
Merge branch 'main' of github.com:mongodb/leafygreen-ui into LG-5027-…
shaneeza Apr 16, 2025
cfeceeb
hellllllo
shaneeza Apr 16, 2025
878a4b5
fix build error
shaneeza Apr 16, 2025
485b409
Storybook export `findStories` (#2808)
TheSonOfThomp Apr 17, 2025
f6ee112
transition styles
shaneeza Apr 17, 2025
7fb9273
wip, transitiob broken
shaneeza Apr 21, 2025
579c830
Updates `lg install` [LG-5040, LG-5041] (#2807)
TheSonOfThomp Apr 21, 2025
1dbfb70
adds two new icons (#2815)
bruugey Apr 22, 2025
3a96365
constants
shaneeza Apr 22, 2025
34b3b95
update README
shaneeza Apr 22, 2025
303aed6
Version Packages (#2811)
github-actions[bot] Apr 22, 2025
21f9e28
wip, translate grid, still not working
shaneeza Apr 22, 2025
cb78abb
build error and export const
shaneeza Apr 23, 2025
8840d27
move handle click to context
shaneeza Apr 23, 2025
12a3ef0
unique test ids for toolbarIconButton
shaneeza Apr 23, 2025
1964fd1
Merge branch 'main' of github.com:mongodb/leafygreen-ui into LG-5027-…
shaneeza Apr 23, 2025
f7ba181
move test harnesses to testing dir
shaneeza Apr 23, 2025
c378333
aria label check
shaneeza Apr 23, 2025
1f65d21
update README
shaneeza Apr 23, 2025
c661c83
toolbar layout, wip
shaneeza Apr 28, 2025
310ed9e
standalone overlay not working
shaneeza Apr 28, 2025
d1cf203
add back inner drawer styles
shaneeza Apr 28, 2025
3310079
scrolling and shadows
shaneeza Apr 29, 2025
58729c9
remove some comments and shouldAnimate
shaneeza Apr 29, 2025
08d4450
clean up embeddedDrawerLayout
shaneeza Apr 30, 2025
2bee595
comments
shaneeza Apr 30, 2025
eddcf06
overlayDrawerLayout cleanup
shaneeza Apr 30, 2025
c9fdc1e
constants for grid areas
shaneeza Apr 30, 2025
7b507b9
shadow transition
shaneeza Apr 30, 2025
60a9f40
rename removeShadowStyles
shaneeza Apr 30, 2025
d57ce12
remove some comments
shaneeza Apr 30, 2025
d8254e2
remove some styles
shaneeza May 1, 2025
4cf70e0
move to DrawerToolbarLayout
shaneeza May 1, 2025
944213a
update stories
shaneeza May 1, 2025
f2fd6dd
controls to exclude
shaneeza May 1, 2025
16871fd
update stories
shaneeza May 2, 2025
a9c9c31
Add more descriptive labels to some toolbar icons
shaneeza May 2, 2025
ce5fd1a
Merge branch 'LG-5027-toolbar' of github.com:mongodb/leafygreen-ui in…
shaneeza May 21, 2025
95aa6dc
clean up
shaneeza May 21, 2025
2b8f1e5
tsdocs for LayoutData
shaneeza May 21, 2025
47aa4bd
fix grid columns on mobile and remove overflow from story
shaneeza May 21, 2025
c1cebad
update stories
shaneeza May 21, 2025
eebeff4
merge conflict
shaneeza May 22, 2025
9065bbf
wip, position absolute standalone drawer animtion
shaneeza May 22, 2025
2e73458
wip: adjust keyframe timing in drawer animation for smoother transition
shaneeza May 22, 2025
f1c9961
feat: enhance drawer styles with border adjustments and animation fixes
shaneeza May 23, 2025
d42ee03
add opacity to inner container, add shouldAnimate check
shaneeza May 26, 2025
af4527f
added some clarifying comments about styles
shaneeza May 27, 2025
ed3462a
fix tests and run lint
shaneeza May 27, 2025
8186768
refactor: improve transition properties and ensure consistent animati…
shaneeza May 27, 2025
3214bb1
refactor: rename type for clarity and remove unused styles file
shaneeza May 27, 2025
2abcaf2
update README
shaneeza May 27, 2025
0691e42
add temp height to cloudnav story
shaneeza May 27, 2025
2d713ed
remove comment and pass args in stories
shaneeza May 27, 2025
a4dbbbb
update stories so arg does not override displayMode
shaneeza May 27, 2025
cda8fb3
add comment about story border
shaneeza May 27, 2025
e304b17
remove height transition
shaneeza May 28, 2025
2a67820
sandy feedback, semibold drawer title
shaneeza May 28, 2025
7632e09
refactor: update height properties to use 100% for consistency across…
shaneeza May 28, 2025
06b9672
remove comment
shaneeza May 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 63 additions & 9 deletions packages/drawer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ npm install @leafygreen-ui/drawer

## Example

### Single Overlay Drawer
### Single Overlay Drawer without Toolbar

#### Without `OverlayDrawerLayout`

```tsx
import React, { useState } from 'react';
Expand Down Expand Up @@ -59,7 +61,35 @@ function ExampleComponent() {
}
```

### Multiple Overlay Drawers
or

#### With `OverlayDrawerLayout`

```tsx
function ExampleComponent() {
const [open, setOpen] = useState(false);

return (
<DrawerStackProvider>
<OverlayDrawerLayout>
<Button onClick={() => setOpen(prevOpen => !prevOpen)}>
Open Drawer
</Button>
<Drawer
displayMode={DisplayMode.Overlay}
onClose={() => setOpen(false)}
open={open}
title="Drawer Title"
>
content
</Drawer>
</OverlayDrawerLayout>
</DrawerStackProvider>
);
}
```

### Multiple Overlay Drawers without Toolbar

```tsx
import React, { useState } from 'react';
Expand Down Expand Up @@ -104,7 +134,11 @@ function ExampleComponent() {
}
```

### Embedded Drawer
### Overlay Drawer with Toolbar

// TODO: in separate PR

### Embedded Drawer without Toolbar

```tsx
import React, { useState } from 'react';
Expand Down Expand Up @@ -142,6 +176,10 @@ function ExampleComponent() {
}
```

### Embedded Drawer with Toolbar

// TODO: in separate PR
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


## Properties

### Drawer
Expand All @@ -156,9 +194,24 @@ function ExampleComponent() {

### EmbeddedDrawerLayout

Use `EmbeddedDrawerLayout` when you need an embedded `Drawer` within a specific container.

| Prop | Type | Description | Default |
| -------------- | --------- | ----------------------------------------------------- | ------- |
| `isDrawerOpen` | `boolean` | Determines if the `Drawer` instance is open or closed | |
| `hasToolbar` | `boolean` | Determines if the `Toolbar` is present in the layout | `false` |

### OverlayDrawerLayout

Use `OverlayDrawerLayout` when you need an overlay `Drawer` that is positioned relative to a specific container rather than the entire app. The `OverlayDrawerLayout` adds `position: relative` to its container, ensuring the `Drawer` overlays only its parent element. If the `Drawer` should overlay the entire application, this layout is not necessary.

| Prop | Type | Description | Default |
| ------------ | --------- | ---------------------------------------------------- | ------- |
| `hasToolbar` | `boolean` | Determines if the `Toolbar` is present in the layout | `false` |

## DrawerToolbarLayout

// TODO: Add in separate PR

# Test Harnesses

Expand Down Expand Up @@ -240,10 +293,11 @@ const { findDrawer, getCloseButtonUtils, getDrawer, isOpen, queryDrawer } =
getTestUtils();
```

| Util | Description | Returns |
// TODO: toolbar utils in a separate PR
| Util | Description | Returns |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `findDrawer` | Returns a promise that resolves to the drawer element. The promise is rejected if no elements match or if more than one match is found. | `Promise<HTMLDialogElement>` \| `Promise<HTMLDivElement>` |
| `getCloseButtonUtils` | Returns the button test utils for the close button | [Button test utils return type](https://github.com/mongodb/leafygreen-ui/blob/main/packages/button/README.md#test-utils) |
| `getDrawer` | Returns the drawer element and throws if no elements match or if more than one match is found. | `HTMLDivElement` |
| `isOpen` | Checks the `aria-hidden` attribute and that the drawer element is visible based on CSS properties for `display`, `opacity`, `transform`, and `visibility` | `boolean` |
| `queryDrawer` | Returns the drawer element or `null` if no elements match and throws if more than one match is found. | `HTMLDivElement` |
| `findDrawer` | Returns a promise that resolves to the drawer element. The promise is rejected if no elements match or if more than one match is found. | `Promise<HTMLDialogElement>` \| `Promise<HTMLDivElement>` |
| `getCloseButtonUtils` | Returns the button test utils for the close button | [Button test utils return type](https://github.com/mongodb/leafygreen-ui/blob/main/packages/button/README.md#test-utils) |
| `getDrawer` | Returns the drawer element and throws if no elements match or if more than one match is found. | `HTMLDivElement` |
| `isOpen` | Checks the `aria-hidden` attribute and that the drawer element is visible based on CSS properties for `display`, `opacity`, `transform`, and `visibility` | `boolean` |
| `queryDrawer` | Returns the drawer element or `null` if no elements match and throws if more than one match is found. | `HTMLDivElement` |
1 change: 1 addition & 0 deletions packages/drawer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@leafygreen-ui/polymorphic": "workspace:^",
"@leafygreen-ui/tabs": "workspace:^",
"@leafygreen-ui/tokens": "workspace:^",
"@leafygreen-ui/toolbar": "workspace:^",
"@leafygreen-ui/typography": "workspace:^",
"@lg-tools/test-harnesses": "workspace:^",
"polished": "^4.2.2",
Expand Down
51 changes: 37 additions & 14 deletions packages/drawer/src/Drawer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { StoryFn, StoryObj } from '@storybook/react';

import Button from '@leafygreen-ui/button';
import { css } from '@leafygreen-ui/emotion';
import { palette } from '@leafygreen-ui/palette';
import { spacing } from '@leafygreen-ui/tokens';
import { Body } from '@leafygreen-ui/typography';

import { DisplayMode, Drawer, DrawerProps } from './Drawer';
import { DrawerStackProvider } from './DrawerStackContext';
import { EmbeddedDrawerLayout } from './EmbeddedDrawerLayout';
import { OverlayDrawerLayout } from './OverlayDrawerLayout';

const SEED = 0;
faker.seed(SEED);
Expand All @@ -25,6 +27,13 @@ const defaultExcludedControls = [
'open',
];

const snapshotStoryExcludedControlParams = [
...defaultExcludedControls,
'darkMode',
'displayMode',
'title',
];

export default {
title: 'Components/Drawer',
component: Drawer,
Expand All @@ -33,9 +42,11 @@ export default {
<div
className={css`
height: 100%;
width: 100%;
display: flex;
align-items: center;
margin: -100px;
width: 100vw;
border-bottom: 3px solid ${palette.green.base}; // Used to visualize the height of the parent container
`}
>
<StoryFn />
Expand Down Expand Up @@ -69,7 +80,7 @@ export default {
const LongContent = () => {
const paragraphs = useMemo(() => {
return faker.lorem
.paragraphs(20, '\n')
.paragraphs(30, '\n')
.split('\n')
.map((p, i) => <Body key={i}>{p}</Body>);
}, []);
Expand Down Expand Up @@ -115,7 +126,7 @@ const TemplateComponent: StoryFn<DrawerProps> = ({
<DrawerStackProvider>
<EmbeddedDrawerLayout
className={css`
height: 500px;
height: 90vh;
`}
isDrawerOpen={open}
>
Expand All @@ -137,9 +148,29 @@ const TemplateComponent: StoryFn<DrawerProps> = ({
</DrawerStackProvider>
) : (
<DrawerStackProvider>
<div>
{renderTrigger()}
{renderDrawer()}
<div
className={css`
height: 90vh;
overflow: auto;
width: 100%;
`}
>
<OverlayDrawerLayout>
<main
className={css`
padding: ${spacing[400]}px;
overflow: auto;
display: flex;
flex-direction: column;
align-items: flex-start;
gap: ${spacing[200]}px;
`}
>
{renderTrigger()}
<LongContent />
</main>
{renderDrawer()}
</OverlayDrawerLayout>
</div>
</DrawerStackProvider>
);
Expand All @@ -149,7 +180,6 @@ export const LiveExample: StoryObj<DrawerProps> = {
render: TemplateComponent,
args: {
children: <LongContent />,
initialOpen: false,
},
parameters: {
chromatic: {
Expand Down Expand Up @@ -228,13 +258,6 @@ export const MultipleDrawers: StoryObj<DrawerProps> = {
},
};

const snapshotStoryExcludedControlParams = [
...defaultExcludedControls,
'darkMode',
'displayMode',
'title',
];

export const LightModeOverlay: StoryObj<DrawerProps> = {
render: TemplateComponent,
args: {
Expand Down
1 change: 1 addition & 0 deletions packages/drawer/src/Drawer/Drawer.constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const HEADER_HEIGHT = 48;
export const MOBILE_BREAKPOINT = 390;
export const PANEL_WIDTH = 432;
export const TOOLBAR_WIDTH = 48;
Loading