-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Expand file tree
/
Copy pathDisableMotion.stories.tsx
More file actions
204 lines (186 loc) · 5.57 KB
/
DisableMotion.stories.tsx
File metadata and controls
204 lines (186 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import * as React from 'react';
import type { JSXElement } from '@fluentui/react-components';
import {
Button,
Dialog,
DialogActions,
DialogBody,
DialogContent,
DialogSurface,
DialogTitle,
DialogTrigger,
Drawer,
DrawerBody,
DrawerHeader,
DrawerHeaderTitle,
makeStyles,
tokens,
useRestoreFocusSource,
useRestoreFocusTarget,
} from '@fluentui/react-components';
import { Dismiss24Regular } from '@fluentui/react-icons';
import description from './DisableMotion.stories.md';
const useStyles = makeStyles({
root: {
display: 'flex',
flexDirection: 'column',
gap: '40px',
},
section: {
display: 'flex',
flexDirection: 'column',
gap: '12px',
},
sectionTitle: {
fontSize: tokens.fontSizeBase400,
fontWeight: tokens.fontWeightSemibold,
margin: '0',
},
sectionDescription: {
fontSize: tokens.fontSizeBase300,
color: tokens.colorNeutralForeground3,
margin: '0',
},
buttons: {
display: 'flex',
gap: '12px',
},
drawerContainer: {
border: `2px solid ${tokens.colorNeutralStroke1}`,
borderRadius: tokens.borderRadiusMedium,
overflow: 'hidden',
display: 'flex',
height: '300px',
backgroundColor: tokens.colorNeutralBackground1,
},
drawerContent: {
flex: '1',
padding: '16px',
display: 'flex',
alignItems: 'flex-start',
gap: '12px',
},
});
// --- Dialog examples ---
const DialogExample = () => {
const classes = useStyles();
return (
<div className={classes.section}>
<p className={classes.sectionTitle}>Dialog</p>
<p className={classes.sectionDescription}>
Dialog has two motion slots: <code>surfaceMotion</code> on Dialog and <code>backdropMotion</code> on
DialogSurface. You can disable them independently.
</p>
<div className={classes.buttons}>
<Dialog surfaceMotion={null}>
<DialogTrigger disableButtonEnhancement>
<Button>surfaceMotion disabled</Button>
</DialogTrigger>
<DialogSurface>
<DialogBody>
<DialogTitle>Surface motion disabled</DialogTitle>
<DialogContent>
The <code>surfaceMotion</code> slot is set to <code>null</code>, so the dialog surface appears instantly
without a scale animation. The backdrop still fades in normally.
</DialogContent>
<DialogActions>
<DialogTrigger disableButtonEnhancement>
<Button appearance="secondary">Close</Button>
</DialogTrigger>
</DialogActions>
</DialogBody>
</DialogSurface>
</Dialog>
<Dialog surfaceMotion={null}>
<DialogTrigger disableButtonEnhancement>
<Button>Both motions disabled</Button>
</DialogTrigger>
<DialogSurface backdropMotion={null}>
<DialogBody>
<DialogTitle>All motion disabled</DialogTitle>
<DialogContent>
Both <code>surfaceMotion</code> and <code>backdropMotion</code> are set to <code>null</code>, so the
dialog and its backdrop appear instantly.
</DialogContent>
<DialogActions>
<DialogTrigger disableButtonEnhancement>
<Button appearance="secondary">Close</Button>
</DialogTrigger>
</DialogActions>
</DialogBody>
</DialogSurface>
</Dialog>
</div>
</div>
);
};
// --- Drawer example ---
const DrawerExample = () => {
const classes = useStyles();
const [isOpen, setIsOpen] = React.useState(false);
const restoreFocusTargetAttributes = useRestoreFocusTarget();
const restoreFocusSourceAttributes = useRestoreFocusSource();
return (
<div className={classes.section}>
<p className={classes.sectionTitle}>Drawer</p>
<p className={classes.sectionDescription}>
Drawer has <code>surfaceMotion</code> and <code>backdropMotion</code> slots. Setting both to <code>null</code>{' '}
disables the slide and backdrop animations.
</p>
<div className={classes.drawerContainer}>
<Drawer
type="overlay"
surfaceMotion={null}
backdropMotion={null}
separator
open={isOpen}
onOpenChange={(_, { open }) => setIsOpen(open)}
{...restoreFocusSourceAttributes}
>
<DrawerHeader>
<DrawerHeaderTitle
action={
<Button
appearance="subtle"
aria-label="Close"
icon={<Dismiss24Regular />}
onClick={() => setIsOpen(false)}
/>
}
>
Drawer (no motion)
</DrawerHeaderTitle>
</DrawerHeader>
<DrawerBody>
<p>
Both <code>surfaceMotion</code> and <code>backdropMotion</code> are <code>null</code>, so this drawer
appears instantly without a slide animation.
</p>
</DrawerBody>
</Drawer>
<div className={classes.drawerContent}>
<Button {...restoreFocusTargetAttributes} appearance="primary" onClick={() => setIsOpen(!isOpen)}>
Open drawer
</Button>
</div>
</div>
</div>
);
};
// --- Story ---
export const DisableMotion = (): JSXElement => {
const classes = useStyles();
return (
<div className={classes.root}>
<DialogExample />
<DrawerExample />
</div>
);
};
DisableMotion.parameters = {
docs: {
description: {
story: description,
},
},
};