forked from microsoft/fluentui
/
Panel.types.ts
501 lines (425 loc) · 14 KB
/
Panel.types.ts
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
import * as React from 'react';
import { IFocusTrapZoneProps } from '../../FocusTrapZone';
import { ILayerProps } from '../../Layer';
import { IOverlayProps } from '../../Overlay';
import { IStyle, ITheme } from '../../Styling';
import { IRefObject, IRenderFunction, IStyleFunctionOrObject } from '../../Utilities';
import { PanelBase } from './Panel.base';
/**
* {@docCategory Panel}
*/
export interface IPanel {
/**
* Forces the panel to open.
*/
open: () => void;
/**
* Forces the panel to dismiss.
*/
dismiss: (ev?: React.KeyboardEvent<HTMLElement>) => void;
}
/**
* {@docCategory Panel}
*/
export interface IPanelProps extends React.HTMLAttributes<PanelBase> {
/**
* Optional callback to access the IPanel interface. Use this instead of ref for accessing
* the public methods and properties of the component.
*/
componentRef?: IRefObject<IPanel>;
/**
* Whether the panel is displayed.
* If true, will cause panel to stay open even if dismissed.
* If false, will cause panel to stay hidden.
* If undefined, will allow the panel to control its own visility through open/dismiss methods.
* @defaultvalue undefined
*/
isOpen?: boolean;
/**
* Has the close button visible.
* @defaultvalue true
*/
hasCloseButton?: boolean;
/**
* Whether the panel can be light dismissed.
* @defaultvalue false
*/
isLightDismiss?: boolean;
/**
* Whether the panel is hidden on dismiss, instead of destroyed in the DOM.
* Protects the contents from being destroyed when the panel is dismissed.
* @defaultvalue false
*/
isHiddenOnDismiss?: boolean;
/**
* Whether the panel uses a modal overlay or not
* @defaultvalue true
*/
isBlocking?: boolean;
/**
* Determines if content should stretch to fill available space putting footer at the bottom of the page
* @defaultvalue false
*/
isFooterAtBottom?: boolean;
/**
* Header text for the Panel.
* @defaultvalue ""
*/
headerText?: string;
/**
* A callback function for when the Panel is opened, before the animation completes.
*/
onOpen?: () => void;
/**
* A callback function for when the Panel is opened, after the animation completes.
*/
onOpened?: () => void;
/**
* A callback function for when the panel is closed, before the animation completes.
* If the panel should NOT be dismissed based on some keyboard event, then simply call ev.preventDefault() on it
*/
onDismiss?: (ev?: React.SyntheticEvent<HTMLElement>) => void;
/**
* A callback function which is called **after** the Panel is dismissed and the animation is complete.
* (If you need to update the Panel's `isOpen` prop in response to a dismiss event, use `onDismiss` instead.)
*/
onDismissed?: () => void;
/**
* Call to provide customized styling that will layer on top of the variant rules.
*/
styles?: IStyleFunctionOrObject<IPanelStyleProps, IPanelStyles>;
/**
* Theme provided by High-Order Component.
*/
theme?: ITheme;
/**
* Additional css class to apply to the Panel
* @defaultvalue undefined
*/
className?: string;
/**
* Type of the panel.
* @defaultvalue PanelType.smallFixedFar
*/
type?: PanelType;
/**
* Custom panel width, used only when `type` is set to `PanelType.custom`.
*/
customWidth?: string;
/**
* Aria label on close button
*/
closeButtonAriaLabel?: string;
/**
* Optional parameter to provider the class name for header text
*/
headerClassName?: string;
/**
* Sets the HTMLElement to focus on when exiting the FocusTrapZone.
* @defaultvalue The element.target that triggered the Panel.
*/
elementToFocusOnDismiss?: HTMLElement;
/**
* Indicates if this Panel will ignore keeping track of HTMLElement that activated the Zone.
* Deprecated, use `focusTrapZoneProps`.
* @defaultvalue false
* @deprecated Use `focusTrapZoneProps`.
*/
ignoreExternalFocusing?: boolean;
/**
* Indicates whether Panel should force focus inside the focus trap zone.
* If not explicitly specified, behavior aligns with FocusTrapZone's default behavior.
* Deprecated, use `focusTrapZoneProps`.
* @deprecated Use `focusTrapZoneProps`.
*/
forceFocusInsideTrap?: boolean;
/**
* Indicates the selector for first focusable item.
* Deprecated, use `focusTrapZoneProps`.
* @deprecated Use `focusTrapZoneProps`.
*/
firstFocusableSelector?: string;
/**
* Optional props to pass to the FocusTrapZone component to manage focus in the panel.
*/
focusTrapZoneProps?: IFocusTrapZoneProps;
/**
* Optional props to pass to the Layer component hosting the panel.
*/
layerProps?: ILayerProps;
/**
* Optional props to pass to the Overlay component that the panel uses.
*/
overlayProps?: IOverlayProps;
/**
* Optional custom function to handle clicks outside the panel in lightdismiss mode
*/
onLightDismissClick?: () => void;
/**
* Optional custom function to handle clicks outside this component
*/
onOuterClick?: () => void;
/**
* Optional custom renderer navigation region. Replaces the region that contains the close button.
*/
onRenderNavigation?: IRenderFunction<IPanelProps>;
/**
* Optional custom renderer for content in the navigation region. Replaces current close button.
*/
onRenderNavigationContent?: IRenderFunction<IPanelProps>;
/**
* Optional custom renderer for header region. Replaces current title
*/
onRenderHeader?: IPanelHeaderRenderer;
/**
* Optional custom renderer for body region. Replaces any children passed into the component.
*/
onRenderBody?: IRenderFunction<IPanelProps>;
/**
* Optional custom renderer for footer region. Replaces sticky footer.
*/
onRenderFooter?: IRenderFunction<IPanelProps>;
/**
* Custom renderer for content in the sticky footer
*/
onRenderFooterContent?: IRenderFunction<IPanelProps>;
/**
* Deprecated property. Serves no function.
* @deprecated Serves no function.
*/
componentId?: string;
/**
* Allow body scroll on content and overlay. Changing after mounting has no effect.
* @defaultvalue false
*/
allowIosBodyScroll?: boolean;
}
/**
* Renderer function which takes an additional parameter, the ID to use for the element containing
* the panel's title. This allows the `aria-labelledby` for the panel popup to work correctly.
* Note that if `headerTextId` is provided, it **must** be used on an element, or screen readers
* will be confused by the reference to a nonexistent ID.
* {@docCategory Panel}
*/
export interface IPanelHeaderRenderer extends IRenderFunction<IPanelProps> {
/**
* @param props - Props given to the panel
* @param defaultRender - Default header renderer. If using this renderer in code that does not
* assign `headerTextId` to an element elsewhere, it **must** be passed to this function.
* @param headerTextId - If provided, this **must** be used as the ID of an element containing the
* panel's title, because the panel popup uses this ID as its aria-labelledby.
*/
(props?: IPanelProps, defaultRender?: IPanelHeaderRenderer, headerTextId?: string | undefined): JSX.Element | null;
}
/**
* {@docCategory Panel}
*/
export enum PanelType {
/**
* Renders the Panel with a `fluid` (full screen) width.
* Recommended for use on small screen breakpoints.
* - Small (320-479): full screen width, 16px left/right padding
* - Medium (480-639): full screen width, 16px left/right padding
* - Large (640-1023): full screen width, 32px left/right padding
* - XLarge (1024-1365): full screen width, 32px left/right padding
* - XXLarge (1366-up): full screen width, 40px left/right padding
*/
smallFluid = 0,
/**
* Renders the Panel in fixed-width `small` size, anchored to the far side (right in LTR mode).
* - Small (320-479): adapts to `PanelType.smallFluid` at this breakpoint
* - Medium (480-639): 340px width, 16px left/right padding
* - Large (640-1023): 340px width, 32px left/right padding
* - XLarge (1024-1365): 340px width, 32px left/right padding
* - XXLarge (1366-up): 340px width, 40px left/right padding
*/
smallFixedFar = 1,
/**
* Renders the Panel in fixed-width `small` size, anchored to the near side (left in LTR mode).
* - Small (320-479): 272px width, 16px left/right padding
* - Medium (480-639): 272px width, 16px left/right padding
* - Large (640-1023): 272px width, 32px left/right padding
* - XLarge (1024-1365): 272px width, 32px left/right padding
* - XXLarge (1366-up): 272px width, 40px left/right padding
*/
smallFixedNear = 2,
/**
* Renders the Panel in `medium` size, anchored to the far side (right in LTR mode).
* - Small (320-479): adapts to `PanelType.smallFluid` at this breakpoint
* - Medium (480-639): adapts to `PanelType.smallFixedFar` at this breakpoint
* - Large (640-1023): 592px width, 32px left/right padding
* - XLarge (1024-1365): 644px width, 32px left/right padding
* - XXLarge (1366-up): 644px width, 40px left/right padding
*/
medium = 3,
/**
* Renders the Panel in `large` size, anchored to the far side (right in LTR mode).
* - Small (320-479): adapts to `PanelType.smallFluid` at this breakpoint
* - Medium (480-639): adapts to `PanelType.smallFixedFar` at this breakpoint
* - Large (640-1023): adapts to `PanelType.medium` at this breakpoint
* - XLarge (1024-1365): 48px fixed left margin, fluid width, 32px left/right padding
* - XXLarge (1366-up): 428px fixed left margin, fluid width, 40px left/right padding
*/
large = 4,
/**
* Renders the Panel in `large` size, anchored to the far side (right in LTR mode), with a fixed width at XX-Large breakpoint.
* - Small (320-479): adapts to `PanelType.smallFluid` at this breakpoint
* - Medium (480-639): adapts to `PanelType.smallFixedFar` at this breakpoint
* - Large (640-1023): adapts to `PanelType.medium` at this breakpoint
* - XLarge (1024-1365): 48px fixed left margin, fluid width, 32px left/right padding
* - XXLarge (1366-up): 940px width, 40px left/right padding
*/
largeFixed = 5,
/**
* Renders the Panel in `extra large` size, anchored to the far side (right in LTR mode).
* - Small (320-479): adapts to `PanelType.smallFluid` at this breakpoint
* - Medium (480-639): adapts to `PanelType.smallFixedFar` at this breakpoint
* - Large (640-1023): adapts to `PanelType.medium` at this breakpoint
* - XLarge (1024-1365): adapts to `PanelType.large` at this breakpoint
* - XXLarge (1366-1919): 176px fixed left margin, fluid width, 40px left/right padding
* - XXXLarge (1920-up): 176px fixed left margin, fluid width, 40px left/right padding
*/
extraLarge = 6,
/**
* Renders the Panel in `custom` size using `customWidth`, anchored to the far side (right in LTR mode).
* - Has a fixed width provided by the `customWidth` prop
* - When screen width reaches the `customWidth` value it will behave like a fluid width Panel
* taking up 100% of the viewport width
*/
custom = 7,
/**
* Renders the Panel in `custom` size using `customWidth`, anchored to the near side (left in LTR mode).
* - Has a fixed width provided by the `customWidth` prop
* - When screen width reaches the `customWidth` value it will behave like a fluid width Panel
* taking up 100% of the viewport width
*/
customNear = 8
}
/**
* {@docCategory Panel}
*/
export interface IPanelStyleProps {
/**
* Theme provided by High-Order Component.
*/
theme: ITheme;
/**
* Accept custom classNames
*/
className?: string;
/**
* Is Panel open
*/
isOpen?: boolean;
/**
* Is animation currently running
*/
isAnimating?: boolean;
/**
* Is panel on right side
*/
isOnRightSide?: boolean;
/**
* Is panel hidden on dismiss
*/
isHiddenOnDismiss?: boolean;
/**
* Classname for FocusTrapZone element
*/
focusTrapZoneClassName?: string;
/**
* Determines if content should stretch to fill available space putting footer at the bottom of the page
*/
isFooterAtBottom?: boolean;
/**
* Based on state value setting footer to sticky or not
*/
isFooterSticky?: boolean;
/**
* Panel has close button
*/
hasCloseButton?: boolean;
/**
* Type of the panel.
*/
type?: PanelType;
/**
* Optional parameter to provider the class name for header text
*/
headerClassName?: string;
}
// TODO -Issue #5689: Comment in once Button is converted to mergeStyles
// export interface IPanelSubComponentStyles {
// /**
// * Styling for Icon child component.
// */
// // TODO: this should be the interface once we're on TS 2.9.2 but otherwise causes errors in 2.8.4
// // button: IStyleFunctionOrObject<IButtonStyleProps, IButtonStyles>;
// button: IStyleFunctionOrObject<any, any>;
// }
/**
* {@docCategory Panel}
*/
export interface IPanelStyles {
/**
* Style for the root element.
*/
root: IStyle;
/**
* Style for the overlay element.
*/
overlay: IStyle;
/**
* Style for the hidden element.
*/
hiddenPanel: IStyle;
/**
* Style for the main section element.
*/
main: IStyle;
/**
* Style for the navigation container element.
*/
commands: IStyle;
/**
* Style for the Body and Footer container element.
*/
contentInner: IStyle;
/**
* Style for the scrollable content area container element.
*/
scrollableContent: IStyle;
/**
* Style for the close button container element.
*/
navigation: IStyle;
/**
* Style for the close button IconButton element.
*/
closeButton: IStyle;
/**
* Style for the header container div element.
*/
header: IStyle;
/**
* Style for the header inner p element.
*/
headerText: IStyle;
/**
* Style for the body div element.
*/
content: IStyle;
/**
* Style for the footer div element.
*/
footer: IStyle;
/**
* Style for the inner footer div element.
*/
footerInner: IStyle;
// TODO -Issue #5689: Comment in once Button is converted to mergeStyles
/**
* Styling for subcomponents.
*/
// subComponentStyles: IPanelSubComponentStyles;
}