Skip to content

Commit d43da03

Browse files
authored
feat!: rename DrawerModal to Drawer (#1715)
1 parent ea9a73b commit d43da03

26 files changed

+250
-202
lines changed

docs/migration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ consider additional positioning prop support on a case-by-case basis.
5757

5858
#### @zendeskgarden/react-modals
5959

60+
- `DrawerModal`: renamed to `Drawer`
6061
- `TooltipModal`: removed `popperModifiers` prop (see [note](#breaking-changes))
6162

6263
#### @zendeskgarden/react-pagination

packages/modals/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ npm install react react-dom styled-components @zendeskgarden/react-theming
1414

1515
## Usage
1616

17+
### Modal
18+
1719
```jsx
1820
import { ThemeProvider } from '@zendeskgarden/react-theming';
1921
import { Modal, Header, Body, Footer, FooterItem, Close } from '@zendeskgarden/react-modals';
@@ -38,3 +40,59 @@ import { Button } from '@zendeskgarden/react-buttons';
3840
</Modal>
3941
</ThemeProvider>;
4042
```
43+
44+
### Drawer
45+
46+
```jsx
47+
import { ThemeProvider } from '@zendeskgarden/react-theming';
48+
import { Drawer } from '@zendeskgarden/react-modals';
49+
import { Button } from '@zendeskgarden/react-buttons';
50+
51+
const [isOpen, setIsOpen] = useState(false)
52+
53+
<ThemeProvider>
54+
<Button onClick={() => setIsOpen(true)}>
55+
Open
56+
</Button>
57+
<Drawer isOpen={state.isOpen} onClose={() => setIsOpen(false)}>
58+
<Drawer.Header>Example Title</Drawer.Header>
59+
<Drawer.Body>Some content</Drawer.Body>
60+
<Drawer.Footer>
61+
<Drawer.FooterItem>
62+
<Button>Click</Button>
63+
</Drawer.FooterItem>
64+
</Drawer.Footer>
65+
<Drawer.Close aria-Label="Close" />
66+
</Drawer>
67+
</ThemeProvider>
68+
```
69+
70+
### TooltipModal
71+
72+
```jsx
73+
import { ThemeProvider } from '@zendeskgarden/react-theming';
74+
import { TooltipModal } from '@zendeskgarden/react-modals';
75+
import { Button } from '@zendeskgarden/react-buttons';
76+
77+
const [isOpen, setIsOpen] = useState(false);
78+
const buttonRef = useRef(null);
79+
80+
<ThemeProvider>
81+
<Button ref={buttonRef} onClick={() => setIsOpen(!isOpen)}>
82+
Open
83+
</Button>
84+
<TooltipModal
85+
onClose={() => setIsOpen(false)}
86+
referenceElement={isOpen && buttonRef.current ? buttonRef.current : undefined}
87+
>
88+
<TooltipModal.Title>Example Title</TooltipModal.Title>
89+
<TooltipModal.Body>Some content</TooltipModal.Body>
90+
<TooltipModal.Footer>
91+
<TooltipModal.FooterItem>
92+
<Button>Click</Button>
93+
</TooltipModal.FooterItem>
94+
</TooltipModal.Footer>
95+
<TooltipModal.Close aria-label="Close" />
96+
</TooltipModal>
97+
</ThemeProvider>;
98+
```

packages/modals/demo/drawerModal.stories.mdx renamed to packages/modals/demo/drawer.stories.mdx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { Meta, ArgsTable, Canvas, Story, Markdown } from '@storybook/addon-docs';
22
import { useArgs } from '@storybook/client-api';
3-
import { DrawerModal } from '@zendeskgarden/react-modals';
4-
import { DrawerModalStory } from './stories/DrawerModalStory';
3+
import { Drawer } from '@zendeskgarden/react-modals';
4+
import { DrawerStory } from './stories/DrawerStory';
55
import { MODAL_BODY as BODY, MODAL_FOOTER_ITEMS as FOOTER_ITEMS } from './stories/data';
66
import README from '../README.md';
77

88
<Meta
9-
title="Packages/Modals/DrawerModal"
10-
component={DrawerModal}
9+
title="Packages/Modals/Drawer"
10+
component={Drawer}
1111
subcomponents={{
12-
'DrawerModal.Body': DrawerModal.Body,
13-
'DrawerModal.Close': DrawerModal.Close,
14-
'DrawerModal.Footer': DrawerModal.Footer,
15-
'DrawerModal.FooterItem': DrawerModal.FooterItem,
16-
'DrawerModal.Header': DrawerModal.Header
12+
'Drawer.Body': Drawer.Body,
13+
'Drawer.Close': Drawer.Close,
14+
'Drawer.Footer': Drawer.Footer,
15+
'Drawer.FooterItem': Drawer.FooterItem,
16+
'Drawer.Header': Drawer.Header
1717
}}
1818
/>
1919

@@ -25,7 +25,7 @@ import README from '../README.md';
2525

2626
<Canvas>
2727
<Story
28-
name="DrawerModal"
28+
name="Drawer"
2929
args={{
3030
hasBody: true,
3131
body: BODY,
@@ -39,15 +39,15 @@ import README from '../README.md';
3939
}}
4040
argTypes={{
4141
appendToNode: { control: false },
42-
hasBody: { name: 'DrawerModal.Body', table: { category: 'Story' } },
43-
hasClose: { name: 'DrawerModal.Close', table: { category: 'Story' } },
44-
hasFooter: { name: 'DrawerModal.Footer', table: { category: 'Story' } },
45-
hasHeader: { name: 'DrawerModal.Header', table: { category: 'Story' } },
46-
footerItems: { name: 'DrawerModal.FooterItem[]', table: { category: 'Story' } },
47-
body: { name: 'children', table: { category: 'DrawerModal.Body' } },
48-
header: { name: 'children', table: { category: 'DrawerModal.Header' } },
49-
tag: { control: 'text', table: { category: 'DrawerModal.Header' } },
50-
closeAriaLabel: { name: 'aria-label', table: { category: 'DrawerModal.Close' } },
42+
hasBody: { name: 'Drawer.Body', table: { category: 'Story' } },
43+
hasClose: { name: 'Drawer.Close', table: { category: 'Story' } },
44+
hasFooter: { name: 'Drawer.Footer', table: { category: 'Story' } },
45+
hasHeader: { name: 'Drawer.Header', table: { category: 'Story' } },
46+
footerItems: { name: 'Drawer.FooterItem[]', table: { category: 'Story' } },
47+
body: { name: 'children', table: { category: 'Drawer.Body' } },
48+
header: { name: 'children', table: { category: 'Drawer.Header' } },
49+
tag: { control: 'text', table: { category: 'Drawer.Header' } },
50+
closeAriaLabel: { name: 'aria-label', table: { category: 'Drawer.Close' } },
5151
dialogAriaLabel: { name: 'aria-label' }
5252
}}
5353
parameters={{
@@ -62,7 +62,7 @@ import README from '../README.md';
6262
const updateArgs = useArgs()[1];
6363
const handleClick = () => updateArgs({ isOpen: true });
6464
const handleClose = () => updateArgs({ isOpen: false });
65-
return <DrawerModalStory {...args} onClick={handleClick} onClose={handleClose} />;
65+
return <DrawerStory {...args} onClick={handleClick} onClose={handleClose} />;
6666
}}
6767
</Story>
6868
</Canvas>

packages/modals/demo/stories/DrawerModalStory.tsx renamed to packages/modals/demo/stories/DrawerStory.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import React, { MouseEventHandler } from 'react';
99
import { Story } from '@storybook/react';
1010
import { useTheme } from 'styled-components';
1111
import Icon from '@zendeskgarden/svg-icons/src/16/arrow-left-stroke.svg';
12-
import { DrawerModal, IDrawerModalProps } from '@zendeskgarden/react-modals';
12+
import { Drawer, IDrawerProps } from '@zendeskgarden/react-modals';
1313
import { Button } from '@zendeskgarden/react-buttons';
1414
import { IFooterItem } from './types';
1515

16-
interface IArgs extends IDrawerModalProps {
16+
interface IArgs extends IDrawerProps {
1717
onClick: MouseEventHandler<HTMLElement>;
1818
hasBody: boolean;
1919
body: string;
@@ -27,7 +27,7 @@ interface IArgs extends IDrawerModalProps {
2727
closeAriaLabel: string;
2828
}
2929

30-
export const DrawerModalStory: Story<IArgs> = ({
30+
export const DrawerStory: Story<IArgs> = ({
3131
onClick,
3232
onClose,
3333
hasBody,
@@ -60,22 +60,22 @@ export const DrawerModalStory: Story<IArgs> = ({
6060
<Icon />
6161
</Button.EndIcon>
6262
</Button>
63-
<DrawerModal {...args} onClose={onClose} {...ariaProp}>
64-
{hasHeader && <DrawerModal.Header tag={tag}>{header}</DrawerModal.Header>}
65-
{hasBody ? <DrawerModal.Body>{body}</DrawerModal.Body> : body}
63+
<Drawer {...args} onClose={onClose} {...ariaProp}>
64+
{hasHeader && <Drawer.Header tag={tag}>{header}</Drawer.Header>}
65+
{hasBody ? <Drawer.Body>{body}</Drawer.Body> : body}
6666
{hasFooter && (
67-
<DrawerModal.Footer>
67+
<Drawer.Footer>
6868
{footerItems.map(({ text, type }, index) => (
69-
<DrawerModal.FooterItem key={index}>
69+
<Drawer.FooterItem key={index}>
7070
<Button isBasic={type === 'basic'} isPrimary={type === 'primary'} onClick={onClose}>
7171
{text}
7272
</Button>
73-
</DrawerModal.FooterItem>
73+
</Drawer.FooterItem>
7474
))}
75-
</DrawerModal.Footer>
75+
</Drawer.Footer>
7676
)}
77-
{hasClose && <DrawerModal.Close aria-label={closeAriaLabel} />}
78-
</DrawerModal>
77+
{hasClose && <Drawer.Close aria-label={closeAriaLabel} />}
78+
</Drawer>
7979
</>
8080
);
8181
};

packages/modals/src/elements/DrawerModal/Body.spec.tsx renamed to packages/modals/src/elements/Drawer/Body.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
import React from 'react';
99
import { render } from 'garden-test-utils';
10-
import { DrawerModal } from './DrawerModal';
10+
import { Drawer } from './Drawer';
1111

12-
describe('DrawerModal.Body', () => {
12+
describe('Drawer.Body', () => {
1313
it('passes ref to underlying DOM element', () => {
1414
const ref = React.createRef<HTMLDivElement>();
1515
const { getByText } = render(
16-
<DrawerModal isOpen>
17-
<DrawerModal.Body ref={ref}>content</DrawerModal.Body>
18-
</DrawerModal>
16+
<Drawer isOpen>
17+
<Drawer.Body ref={ref}>content</Drawer.Body>
18+
</Drawer>
1919
);
2020

2121
expect(getByText('content')).toBe(ref.current);

packages/modals/src/elements/DrawerModal/Body.tsx renamed to packages/modals/src/elements/Drawer/Body.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@
77

88
import React, { HTMLAttributes, forwardRef } from 'react';
99
import { useModalContext } from '../../utils/useModalContext';
10-
import { StyledDrawerModalBody } from '../../styled';
10+
import { StyledDrawerBody } from '../../styled';
1111

1212
const BodyComponent = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>((props, ref) => {
1313
const { getContentProps } = useModalContext();
1414

1515
return (
16-
<StyledDrawerModalBody
17-
{...(getContentProps(props) as HTMLAttributes<HTMLDivElement>)}
18-
ref={ref}
19-
>
16+
<StyledDrawerBody {...(getContentProps(props) as HTMLAttributes<HTMLDivElement>)} ref={ref}>
2017
{props.children}
21-
</StyledDrawerModalBody>
18+
</StyledDrawerBody>
2219
);
2320
});
2421

25-
BodyComponent.displayName = 'DrawerModal.Body';
22+
BodyComponent.displayName = 'Drawer.Body';
2623

2724
/**
2825
* @extends HTMLAttributes<HTMLDivElement>

packages/modals/src/elements/DrawerModal/Close.spec.tsx renamed to packages/modals/src/elements/Drawer/Close.spec.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77

88
import React from 'react';
99
import { render } from 'garden-test-utils';
10-
import { DrawerModal } from './DrawerModal';
10+
import { Drawer } from './Drawer';
1111

12-
describe('DrawerModal.Close', () => {
12+
describe('Drawer.Close', () => {
1313
it('passes ref to underlying DOM element', () => {
1414
const ref = React.createRef<HTMLButtonElement>();
1515
const { getByRole } = render(
16-
<DrawerModal isOpen>
17-
<DrawerModal.Close ref={ref} />
18-
</DrawerModal>
16+
<Drawer isOpen>
17+
<Drawer.Close ref={ref} />
18+
</Drawer>
1919
);
2020

2121
expect(getByRole('button')).toBe(ref.current);

packages/modals/src/elements/DrawerModal/Close.tsx renamed to packages/modals/src/elements/Drawer/Close.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import React, { ButtonHTMLAttributes, useEffect, forwardRef } from 'react';
9-
import { StyledDrawerModalClose } from '../../styled';
9+
import { StyledDrawerClose } from '../../styled';
1010
import { useText } from '@zendeskgarden/react-theming';
1111
import { useModalContext } from '../../utils/useModalContext';
1212
import XStrokeIcon from '@zendeskgarden/svg-icons/src/16/x-stroke.svg';
@@ -24,20 +24,20 @@ const CloseComponent = forwardRef<HTMLButtonElement, ButtonHTMLAttributes<HTMLBu
2424
const ariaLabel = useText(CloseComponent, props, 'aria-label', 'Close drawer');
2525

2626
return (
27-
<StyledDrawerModalClose
27+
<StyledDrawerClose
2828
{...(getCloseProps({
2929
...props,
3030
'aria-label': ariaLabel!
3131
}) as ButtonHTMLAttributes<HTMLButtonElement>)}
3232
ref={ref}
3333
>
3434
<XStrokeIcon />
35-
</StyledDrawerModalClose>
35+
</StyledDrawerClose>
3636
);
3737
}
3838
);
3939

40-
CloseComponent.displayName = 'DrawerModal.Close';
40+
CloseComponent.displayName = 'Drawer.Close';
4141

4242
/**
4343
* @extends ButtonHTMLAttributes<HTMLButtonElement>

packages/modals/src/elements/DrawerModal/DrawerModal.spec.tsx renamed to packages/modals/src/elements/Drawer/Drawer.spec.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
import React, { useRef, useState, createRef, forwardRef } from 'react';
99
import userEvent from '@testing-library/user-event';
1010
import { screen, render, waitFor } from 'garden-test-utils';
11-
import { DrawerModal } from './DrawerModal';
12-
import { IDrawerModalProps } from '../../types';
11+
import { Drawer } from './Drawer';
12+
import { IDrawerProps } from '../../types';
1313

14-
describe('DrawerModal', () => {
14+
describe('Drawer', () => {
1515
const user = userEvent.setup();
1616

1717
const DRAWER_MODAL_ID = 'TEST_ID';
1818

1919
type FixtureProps = {
2020
noHeader?: boolean;
21-
} & IDrawerModalProps;
21+
} & IDrawerProps;
2222

2323
const Example = forwardRef<HTMLDivElement, FixtureProps>(({ noHeader, ...props }, ref) => {
2424
const [isOpen, setIsOpen] = useState(false);
@@ -29,16 +29,16 @@ describe('DrawerModal', () => {
2929
<button ref={buttonRef} onClick={() => setIsOpen(true)}>
3030
Open Drawer
3131
</button>
32-
<DrawerModal ref={ref} isOpen={isOpen} onClose={() => setIsOpen(false)} {...props}>
33-
{!noHeader && <DrawerModal.Header>title</DrawerModal.Header>}
34-
<DrawerModal.Close />
35-
<DrawerModal.Body>body</DrawerModal.Body>
36-
<DrawerModal.Footer>
37-
<DrawerModal.FooterItem>
32+
<Drawer ref={ref} isOpen={isOpen} onClose={() => setIsOpen(false)} {...props}>
33+
{!noHeader && <Drawer.Header>title</Drawer.Header>}
34+
<Drawer.Close />
35+
<Drawer.Body>body</Drawer.Body>
36+
<Drawer.Footer>
37+
<Drawer.FooterItem>
3838
<button>Click</button>
39-
</DrawerModal.FooterItem>
40-
</DrawerModal.Footer>
41-
</DrawerModal>
39+
</Drawer.FooterItem>
40+
</Drawer.Footer>
41+
</Drawer>
4242
</>
4343
);
4444
});

0 commit comments

Comments
 (0)