Skip to content
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

docs(react-drawer): improve drawer stories examples #28283

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const CustomSize = () => {

<div className={styles.main}>
<Button appearance="primary" onClick={() => setOpen(true)}>
Toggle Drawer
Open Drawer
</Button>

<div className={styles.field}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { DrawerBody, DrawerHeader, DrawerHeaderTitle, DrawerInline } from '@fluentui/react-drawer';
import { Button, makeStyles, shorthands } from '@fluentui/react-components';
import { Button, makeStyles, shorthands, tokens } from '@fluentui/react-components';
import { Dismiss24Regular } from '@fluentui/react-icons';

const useStyles = makeStyles({
Expand All @@ -18,6 +18,7 @@ const useStyles = makeStyles({
display: 'flex',
justifyContent: 'center',
alignItems: 'flex-start',
columnGap: tokens.spacingHorizontalXS,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const Overlay = () => {
</DrawerOverlay>

<Button appearance="primary" onClick={() => setIsOpen(true)}>
Toggle
Open Drawer
</Button>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as React from 'react';
import { DrawerBody, DrawerHeader, DrawerHeaderTitle, DrawerOverlay } from '@fluentui/react-drawer';
import { Button } from '@fluentui/react-components';
import { Dismiss24Regular } from '@fluentui/react-icons';

export const OverlayNoModal = () => {
const [isOpen, setIsOpen] = React.useState(false);

return (
<div>
<DrawerOverlay modalType="non-modal" open={isOpen} onOpenChange={(_, { open }) => setIsOpen(open)}>
<DrawerHeader>
<DrawerHeaderTitle
action={
<Button
appearance="subtle"
aria-label="Close"
icon={<Dismiss24Regular />}
onClick={() => setIsOpen(false)}
/>
}
>
Overlay Drawer
</DrawerHeaderTitle>
</DrawerHeader>

<DrawerBody>
<p>Drawer content</p>
</DrawerBody>
</DrawerOverlay>

<Button appearance="primary" onClick={() => setIsOpen(!isOpen)}>
Toggle
</Button>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
import * as React from 'react';
import { DrawerBody, DrawerHeader, DrawerHeaderTitle, DrawerOverlay } from '@fluentui/react-drawer';
import { Button } from '@fluentui/react-components';
import { DrawerBody, DrawerHeader, DrawerHeaderTitle, DrawerOverlay, DrawerProps } from '@fluentui/react-drawer';
import { Button, makeStyles, tokens } from '@fluentui/react-components';
import { Dismiss24Regular } from '@fluentui/react-icons';

const useStyles = makeStyles({
content: {
display: 'flex',
justifyContent: 'center',
alignItems: 'flex-start',
columnGap: tokens.spacingHorizontalXS,
},
});

export const Position = () => {
const [leftOpen, setLeftOpen] = React.useState(false);
const [rightOpen, setRightOpen] = React.useState(false);
const styles = useStyles();

const [isOpen, setIsOpen] = React.useState(false);
const [position, setPosition] = React.useState<DrawerProps['position']>('left');

const onClickLeftButton = React.useCallback(() => {
setPosition('left');
setIsOpen(true);
}, []);

const onClickRightButton = React.useCallback(() => {
setPosition('right');
setIsOpen(true);
}, []);

return (
<div>
<DrawerOverlay position="left" open={leftOpen} onOpenChange={(_, { open }) => setLeftOpen(open)}>
<DrawerOverlay position={position} open={isOpen} onOpenChange={(_, { open }) => setIsOpen(open)}>
<DrawerHeader>
<DrawerHeaderTitle
action={
<Button
appearance="subtle"
aria-label="Close"
icon={<Dismiss24Regular />}
onClick={() => setLeftOpen(false)}
onClick={() => setIsOpen(false)}
/>
}
>
Left Drawer
{position === 'left' ? 'Left' : 'Right'} Drawer
</DrawerHeaderTitle>
</DrawerHeader>

Expand All @@ -30,34 +51,15 @@ export const Position = () => {
</DrawerBody>
</DrawerOverlay>

<Button appearance="primary" onClick={() => setLeftOpen(true)}>
Toggle left
</Button>

<Button appearance="primary" onClick={() => setRightOpen(true)}>
Toggle right
</Button>

<DrawerOverlay position="right" open={rightOpen} onOpenChange={(_, { open }) => setRightOpen(open)}>
<DrawerHeader>
<DrawerHeaderTitle
action={
<Button
appearance="subtle"
aria-label="Close"
icon={<Dismiss24Regular />}
onClick={() => setRightOpen(false)}
/>
}
>
Right Drawer
</DrawerHeaderTitle>
</DrawerHeader>
<div className={styles.content}>
<Button appearance="primary" onClick={onClickLeftButton}>
Open left
</Button>

<DrawerBody>
<p>Drawer content</p>
</DrawerBody>
</DrawerOverlay>
<Button appearance="primary" onClick={onClickRightButton}>
Open right
</Button>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const PreventClose = () => {
</DrawerOverlay>

<Button appearance="primary" onClick={() => setOpen(true)}>
Toggle
Open Drawer
</Button>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const Resizable = () => {
React.useEffect(() => {
window.addEventListener('mousemove', resize);
window.addEventListener('mouseup', stopResizing);

return () => {
window.removeEventListener('mousemove', resize);
window.removeEventListener('mouseup', stopResizing);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { DrawerBody, DrawerHeader, DrawerHeaderTitle, Drawer, DrawerProps } from '@fluentui/react-drawer';
import { makeStyles, shorthands, tokens } from '@fluentui/react-components';
import { Button, makeStyles, shorthands, tokens } from '@fluentui/react-components';
import { Dismiss24Regular } from '@fluentui/react-icons';

const useStyles = makeStyles({
root: {
Expand All @@ -15,6 +16,8 @@ const useStyles = makeStyles({
content: {
...shorthands.margin(tokens.spacingVerticalXL, tokens.spacingHorizontalXL),
...shorthands.flex(1),

gridRowGap: tokens.spacingVerticalXXL,
},
});

Expand All @@ -26,29 +29,50 @@ export const Responsive = () => {
const [isOpen, setIsOpen] = React.useState(true);
const [type, setType] = React.useState<DrawerType>('inline');

const onMediaQueryChange = React.useCallback(({ matches }) => setType(matches ? 'overlay' : 'inline'), [setType]);

React.useEffect(() => {
const match = window.matchMedia('(max-width: 720px)');

if (match.matches) {
setType('overlay');
}

match.addEventListener('change', ({ matches }) => setType(matches ? 'overlay' : 'inline'));
}, []);
match.addEventListener('change', onMediaQueryChange);

return () => match.removeEventListener('change', onMediaQueryChange);
}, [onMediaQueryChange]);

return (
<div className={styles.root}>
<p className={styles.content}>Resize the window to see the change</p>

<Drawer type={type} separator position="right" open={isOpen} onOpenChange={(_, { open }) => setIsOpen(open)}>
<Drawer type={type} separator position="left" open={isOpen} onOpenChange={(_, { open }) => setIsOpen(open)}>
<DrawerHeader>
<DrawerHeaderTitle>Responsive Drawer</DrawerHeaderTitle>
<DrawerHeaderTitle
action={
<Button
appearance="subtle"
aria-label="Close"
icon={<Dismiss24Regular />}
onClick={() => setIsOpen(false)}
/>
}
>
Responsive Drawer
</DrawerHeaderTitle>
</DrawerHeader>

<DrawerBody>
<p>Drawer content</p>
</DrawerBody>
</Drawer>

<div className={styles.content}>
<Button appearance="primary" onClick={() => setIsOpen(!isOpen)}>
Toggle
</Button>

<p>Resize the window to see the change</p>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { DrawerBody, DrawerHeader, DrawerHeaderTitle, DrawerInline } from '@fluentui/react-drawer';
import { Button, makeStyles, shorthands } from '@fluentui/react-components';
import { Button, makeStyles, shorthands, tokens } from '@fluentui/react-components';
import { Dismiss24Regular } from '@fluentui/react-icons';

const useStyles = makeStyles({
Expand All @@ -18,6 +18,7 @@ const useStyles = makeStyles({
display: 'flex',
justifyContent: 'center',
alignItems: 'flex-start',
columnGap: tokens.spacingHorizontalXS,
},
});

Expand All @@ -29,7 +30,7 @@ export const Separator = () => {

return (
<div className={styles.root}>
<DrawerInline position="right" open={leftOpen}>
<DrawerInline position="left" open={leftOpen}>
<DrawerHeader>
<DrawerHeaderTitle
action={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const Size = () => {

<div className={styles.main}>
<Button appearance="primary" onClick={() => setOpen(true)}>
Toggle Drawer
Open Drawer
</Button>

<div className={styles.field}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const WithNavigation = () => {
</DrawerOverlay>

<Button appearance="primary" onClick={() => setIsOpen(true)}>
Toggle
Open Drawer
</Button>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import previewMd from './DrawerPreview.md';

export { Default } from './DrawerDefault.stories';
export { Overlay } from './DrawerOverlay.stories';
export { OverlayNoModal } from './DrawerOverlayNoModal.stories';
export { Inline } from './DrawerInline.stories';
export { Position } from './DrawerPosition.stories';
export { Size } from './DrawerSize.stories';
export { CustomSize } from './DrawerCustomSize.stories';
export { Separator } from './DrawerSeparator.stories';
export { AlwaysOpen } from './DrawerAlwaysOpen.stories';
export { PreventClose } from './DrawerPreventClose.stories';
export { WithNavigation } from './DrawerWithNavigation.stories';
export { WithScroll } from './DrawerWithScroll.stories';
export { AlwaysOpen } from './DrawerAlwaysOpen.stories';
export { PreventClose } from './DrawerPreventClose.stories';
export { Responsive } from './DrawerResponsive.stories';
export { Resizable } from './DrawerResizable.stories';

Expand Down