Skip to content

Commit cbe691c

Browse files
authored
Drawer w/ toolbar updates (#2917)
* add disabled option for toolbar * update title prop from string to reactnode * add changeset * update changesets * adding timeout to fix snapshot * update tests
1 parent b67497a commit cbe691c

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

.changeset/brave-icons-taste.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
'@leafygreen-ui/drawer': patch
3+
---
4+
5+
- Updates `DrawerLayout` to accept the `disabled` property in `toolbarData` prop
6+
7+
```js
8+
<DrawerLayout
9+
toolbarData={[
10+
{
11+
...,
12+
disabled: true, // This drawer item is disabled
13+
},
14+
]}
15+
```
16+
- Updates `DrawerLayout` to support `ReactNode` for the `title` property in `toolbarData` prop
17+
18+
```js
19+
<DrawerLayout
20+
toolbarData={[
21+
{
22+
...,
23+
title: <span>Custom Title</span>, // This allows for custom React nodes as titles
24+
},
25+
]}
26+
```

packages/drawer/src/DrawerToolbarLayout/DrawerToolbarLayout.interactions.stories.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import { getTestUtils } from '../testing';
1818
import { DrawerToolbarLayout } from './DrawerToolbarLayout';
1919
import { DrawerToolbarLayoutProps } from './DrawerToolbarLayout.types';
2020

21+
// The tooltip sometimes lingers after the drawer closes, which can cause
22+
// snapshot tests to fail if the tooltip is not in the correct position.
23+
// Setting a delay of 1 second allows the tooltip to be in the correct position
24+
const TOOLTIP_SNAPSHOT_DELAY = 1000; // ms
25+
2126
const SEED = 0;
2227
faker.seed(SEED);
2328

@@ -163,6 +168,8 @@ export const OverlayOpensFirstToolbarItem: StoryObj<DrawerToolbarLayoutProps> =
163168
expect(isOpen()).toBe(true);
164169
expect(canvas.getByText('Code Title')).toBeVisible();
165170
});
171+
// Pause so the tooltip is in the correct position in the snapshot
172+
await new Promise(resolve => setTimeout(resolve, TOOLTIP_SNAPSHOT_DELAY));
166173
},
167174
};
168175

@@ -189,9 +196,6 @@ export const OverlaySwitchesToolbarItems: StoryObj<DrawerToolbarLayoutProps> = {
189196
});
190197

191198
userEvent.unhover(codeButton!);
192-
// Pause so the change is visible in the story
193-
await new Promise(resolve => setTimeout(resolve, 1000));
194-
195199
userEvent.click(dashboardButton!);
196200

197201
await waitFor(() => {
@@ -221,12 +225,12 @@ export const OverlayClosesDrawer: StoryObj<DrawerToolbarLayoutProps> = {
221225
expect(isOpen()).toBe(true);
222226
expect(canvas.getByText('Code Title')).toBeVisible();
223227
});
224-
// Pause so the change is visible in the story
225-
await new Promise(resolve => setTimeout(resolve, 1000));
226228

227229
userEvent.click(closeButton);
228230

229231
await waitFor(() => expect(isOpen()).toBe(false));
232+
// Pause so the tooltip is in the correct position in the snapshot
233+
await new Promise(resolve => setTimeout(resolve, TOOLTIP_SNAPSHOT_DELAY));
230234
},
231235
};
232236

@@ -250,6 +254,8 @@ export const EmbeddedOpensFirstToolbarItem: StoryObj<DrawerToolbarLayoutProps> =
250254
expect(isOpen()).toBe(true);
251255
expect(canvas.getByText('Code Title')).toBeVisible();
252256
});
257+
// Pause so the tooltip is in the correct position in the snapshot
258+
await new Promise(resolve => setTimeout(resolve, TOOLTIP_SNAPSHOT_DELAY));
253259
},
254260
};
255261

@@ -277,9 +283,6 @@ export const EmbeddedSwitchesToolbarItems: StoryObj<DrawerToolbarLayoutProps> =
277283
});
278284

279285
userEvent.unhover(codeButton!);
280-
// Pause so the change is visible in the story
281-
await new Promise(resolve => setTimeout(resolve, 1000));
282-
283286
userEvent.click(dashboardButton!);
284287

285288
await waitFor(() =>
@@ -308,11 +311,11 @@ export const EmbeddedClosesDrawer: StoryObj<DrawerToolbarLayoutProps> = {
308311
expect(isOpen()).toBe(true);
309312
expect(canvas.getByText('Code Title')).toBeVisible();
310313
});
311-
// Pause so the change is visible in the story
312-
await new Promise(resolve => setTimeout(resolve, 1000));
313314

314315
userEvent.click(closeButton!);
315316

316317
await waitFor(() => expect(isOpen()).toBe(false));
318+
// Pause so the tooltip is in the correct position in the snapshot
319+
await new Promise(resolve => setTimeout(resolve, TOOLTIP_SNAPSHOT_DELAY));
317320
},
318321
};

packages/drawer/src/DrawerToolbarLayout/DrawerToolbarLayout.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ const DRAWER_TOOLBAR_DATA: DrawerLayoutProps['toolbarData'] = [
197197
console.log('Plus clicked, does not update drawer');
198198
},
199199
},
200+
{
201+
id: 'Sparkle',
202+
label: 'Disabled item',
203+
glyph: 'Sparkle',
204+
disabled: true,
205+
},
200206
];
201207

202208
const Component: StoryFn<DrawerLayoutProps> = ({

packages/drawer/src/DrawerToolbarLayout/DrawerToolbarLayout.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { DrawerProps } from '../Drawer/Drawer.types';
88
type PickedOptionalDrawerProps = Pick<DrawerProps, 'onClose' | 'displayMode'>;
99
type PickedRequiredToolbarIconButtonProps = Pick<
1010
ToolbarIconButtonProps,
11-
'glyph' | 'label' | 'onClick'
11+
'glyph' | 'label' | 'onClick' | 'disabled'
1212
>;
1313

1414
interface LayoutBase extends PickedRequiredToolbarIconButtonProps {
@@ -22,7 +22,7 @@ interface LayoutWithContent extends LayoutBase {
2222
/**
2323
* The title of the drawer. This is not required if the toolbar item should not open a drawer.
2424
*/
25-
title: string;
25+
title: React.ReactNode;
2626

2727
/**
2828
* The content of the drawer. This is not required if the toolbar item should not open a drawer.

packages/drawer/src/DrawerToolbarLayout/DrawerToolbarLayoutContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const DrawerToolbarLayoutContainer = forwardRef<
9191
);
9292
}}
9393
active={toolbarItem.id === id}
94+
disabled={toolbarItem.disabled}
9495
/>
9596
))}
9697
</Toolbar>

packages/drawer/src/DrawerWithToolbarWrapper/DrawerWithToolbarWrapper.styles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const drawerIn = keyframes`
1818
from {
1919
// Because of .show() and .close() in the drawer component, transitioning from 0px to (x)px does not transition correctly. Using 1px along with css animations is a workaround to get the animation to work.
2020
grid-template-columns: ${TOOLBAR_WIDTH}px 1px;
21-
},
21+
}
2222
to {
2323
grid-template-columns: ${TOOLBAR_WIDTH}px ${PANEL_WIDTH}px;
2424
}
@@ -27,7 +27,7 @@ const drawerIn = keyframes`
2727
const drawerOut = keyframes`
2828
from {
2929
grid-template-columns: ${TOOLBAR_WIDTH}px ${PANEL_WIDTH}px;
30-
},
30+
}
3131
to {
3232
grid-template-columns: ${TOOLBAR_WIDTH}px 0px;
3333
}
@@ -38,7 +38,7 @@ const drawerOutMobile = keyframes`
3838
grid-template-columns: ${TOOLBAR_WIDTH}px calc(100vw - ${
3939
TOOLBAR_WIDTH * 2
4040
}px);
41-
},
41+
}
4242
to {
4343
grid-template-columns: ${TOOLBAR_WIDTH}px 0px;
4444
}
@@ -47,7 +47,7 @@ const drawerOutMobile = keyframes`
4747
const drawerInMobile = keyframes`
4848
from {
4949
grid-template-columns: ${TOOLBAR_WIDTH}px 1px;
50-
},
50+
}
5151
to {
5252
grid-template-columns: ${TOOLBAR_WIDTH}px calc(100vw - ${
5353
TOOLBAR_WIDTH * 2

0 commit comments

Comments
 (0)