UNPKG

18 kBTypeScriptView Raw
1import * as React from 'react';
2import { BaseButton } from './BaseButton';
3import { Button } from './Button';
4import { IButtonClassNames } from './BaseButton.classNames';
5import { ISplitButtonClassNames } from './SplitButton/SplitButton.classNames';
6import { IRefObject, IRenderFunction, KeyCodes, IComponentAs } from '../../Utilities';
7import { IContextualMenuProps } from '../../ContextualMenu';
8import { IIconProps } from '../../Icon';
9import { IStyle, ITheme } from '../../Styling';
10import { IKeytipProps } from '../../Keytip';
11/**
12 * {@docCategory Button}
13 */
14export interface IButton {
15 /**
16 * Sets focus to the button.
17 */
18 focus: () => void;
19 /**
20 * If there is a menu associated with this button and it is visible, this will dismiss the menu
21 */
22 dismissMenu: () => void;
23 /**
24 * If there is a menu associated with this button and it is visible, this will open the menu.
25 * Params are optional overrides to the ones defined in `menuProps` to apply to just this instance of
26 * opening the menu.
27 *
28 * @param shouldFocusOnContainer - override to the ContextualMenu shouldFocusOnContainer prop.
29 * BaseButton implementation defaults to 'undefined'.
30 * @param shouldFocusOnMount - override to the ContextualMenu shouldFocusOnMount prop. BaseButton implementation
31 * defaults to `true`.
32 */
33 openMenu: (shouldFocusOnContainer?: boolean, shouldFocusOnMount?: boolean) => void;
34}
35/**
36 * {@docCategory Button}
37 */
38export interface IButtonProps extends React.AllHTMLAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLDivElement | BaseButton | Button | HTMLSpanElement> {
39 /**
40 * Optional callback to access the IButton interface. Use this instead of ref for accessing
41 * the public methods and properties of the component.
42 */
43 componentRef?: IRefObject<IButton>;
44 /**
45 * Optional callback to access the root DOM element.
46 * @deprecated Temporary solution which will be replaced with ref in the V8 release.
47 */
48 elementRef?: React.Ref<HTMLElement>;
49 /**
50 * If provided, this component will be rendered as an anchor.
51 * @defaultvalue ElementType.anchor
52 */
53 href?: string;
54 /**
55 * Changes the visual presentation of the button to be emphasized (if defined)
56 * @defaultvalue false
57 */
58 primary?: boolean;
59 /**
60 * Unique id to identify the item. Typically a duplicate of key value.
61 */
62 uniqueId?: string | number;
63 /**
64 * Whether the button is disabled
65 */
66 disabled?: boolean;
67 /**
68 * Whether the button can have focus in disabled mode
69 */
70 allowDisabledFocus?: boolean;
71 /**
72 * If set to true and if this is a splitButton (split == true) then the primary action of a split button is disabled.
73 */
74 primaryDisabled?: boolean;
75 /**
76 * Custom styling for individual elements within the button DOM.
77 */
78 styles?: IButtonStyles;
79 /**
80 * Theme provided by HOC.
81 */
82 theme?: ITheme;
83 /**
84 * Whether the button is checked
85 */
86 checked?: boolean;
87 /**
88 * Whether button is a toggle button with distinct on and off states. This should be true for buttons that permanently
89 * change state when a press event finishes, such as a volume mute button.
90 */
91 toggle?: boolean;
92 /**
93 * If provided, additional class name to provide on the root element.
94 */
95 className?: string;
96 /**
97 * The aria label of the button for the benefit of screen readers.
98 */
99 ariaLabel?: string;
100 /**
101 * Detailed description of the button for the benefit of screen readers.
102 *
103 * Besides the compound button, other button types will need more information provided to screen reader.
104 */
105 ariaDescription?: string;
106 /**
107 * If provided and is true it adds an 'aria-hidden' attribute instructing screen readers to ignore the element.
108 */
109 ariaHidden?: boolean;
110 /**
111 * Text to render button label. If text is supplied, it will override any string in button children.
112 * Other children components will be passed through after the text.
113 */
114 text?: string;
115 /**
116 * The props for the icon shown in the button.
117 */
118 iconProps?: IIconProps;
119 /**
120 * Props for button menu. Providing this will default to showing the menu icon. See menuIconProps for overriding
121 * how the default icon looks. Providing this in addition of onClick and setting the split property to true will
122 * render a SplitButton.
123 */
124 menuProps?: IContextualMenuProps;
125 /**
126 * Callback that runs after Button's contextual menu was closed (removed from the DOM)
127 */
128 onAfterMenuDismiss?: () => void;
129 /**
130 * If set to true, and if menuProps and onClick are provided, the button will render as a SplitButton.
131 * @defaultvalue false
132 */
133 split?: boolean;
134 /**
135 * The props for the icon shown when providing a menu dropdown.
136 */
137 menuIconProps?: IIconProps;
138 /**
139 * Accessible label for the dropdown chevron button if this button is split.
140 */
141 splitButtonAriaLabel?: string;
142 /**
143 * Optional callback when menu is clicked.
144 */
145 onMenuClick?: (ev?: React.MouseEvent<HTMLElement> | React.KeyboardEvent<HTMLElement>, button?: IButtonProps) => void;
146 /**
147 * Custom render function for the icon
148 */
149 onRenderIcon?: IRenderFunction<IButtonProps>;
150 /**
151 * Custom render function for the label text.
152 */
153 onRenderText?: IRenderFunction<IButtonProps>;
154 /**
155 * Custom render function for the desciption text.
156 */
157 onRenderDescription?: IRenderFunction<IButtonProps>;
158 /**
159 * Custom render function for the aria description element.
160 */
161 onRenderAriaDescription?: IRenderFunction<IButtonProps>;
162 /**
163 * Custom render function for rendering the button children.
164 */
165 onRenderChildren?: IRenderFunction<IButtonProps>;
166 /**
167 * Custom render function for button menu icon
168 */
169 onRenderMenuIcon?: IRenderFunction<IButtonProps>;
170 /**
171 * Deprecated at v6.3.2, to be removed at \>= v7.0.0. Use `menuAs` instead.
172 * @deprecated Use `menuAs` instead.
173 */
174 onRenderMenu?: IRenderFunction<IContextualMenuProps>;
175 /**
176 * Render a custom menu in place of the normal one.
177 */
178 menuAs?: IComponentAs<IContextualMenuProps>;
179 /**
180 * Description of the action this button takes.
181 * Only used for compound buttons
182 */
183 secondaryText?: string;
184 /**
185 * Deprecated at v1.2.3, to be removed at \>= v2.0.0. Use specific button component instead.
186 * @defaultvalue ButtonType.default
187 * @deprecated Use specific button component instead.
188 */
189 buttonType?: ButtonType;
190 /**
191 * Deprecated at v0.56.2, to be removed at \>= v1.0.0. Just pass in button props instead.
192 * they will be mixed into the button/anchor element rendered by the component.
193 * @deprecated Use button props instead.
194 */
195 rootProps?: React.ButtonHTMLAttributes<HTMLButtonElement> | React.AnchorHTMLAttributes<HTMLAnchorElement>;
196 /**
197 * Any custom data the developer wishes to associate with the menu item.
198 * Deprecated, use `checked` if setting state.
199 * @deprecated unused, use `checked` if setting state.
200 */
201 toggled?: boolean;
202 /**
203 * Any custom data the developer wishes to associate with the menu item.
204 */
205 data?: any;
206 /**
207 * Method to provide the classnames to style a button.
208 * The default value for this prop is the getClassnames func
209 * defined in BaseButton.classnames.
210 * @defaultvalue getBaseButtonClassNames
211 */
212 getClassNames?: (theme: ITheme, className: string, variantClassName: string, iconClassName: string | undefined, menuIconClassName: string | undefined, disabled: boolean, checked: boolean, expanded: boolean, hasMenu: boolean, isSplit: boolean | undefined, allowDisabledFocus: boolean) => IButtonClassNames;
213 /**
214 * Method to provide the classnames to style a button.
215 * The default value for this prop is the getClassnames func
216 * defined in BaseButton.classnames.
217 * @defaultvalue getBaseSplitButtonClassNames
218 */
219 getSplitButtonClassNames?: (disabled: boolean, expanded: boolean, checked: boolean, allowDisabledFocus: boolean) => ISplitButtonClassNames;
220 /**
221 * Provides a custom KeyCode that can be used to open the button menu.
222 * The default KeyCode is the down arrow.
223 * A value of null can be provided to disable the key codes for opening the button menu.
224 */
225 menuTriggerKeyCode?: KeyCodes | null;
226 /**
227 * Optional keytip for this button
228 */
229 keytipProps?: IKeytipProps;
230 /**
231 * Menu will not be created or destroyed when opened or closed, instead it
232 * will be hidden. This will improve perf of the menu opening but could potentially
233 * impact overall perf by having more elements in the dom. Should only be used
234 * when perf is important.
235 * Note: This may increase the amount of time it takes for the button itself to mount.
236 */
237 persistMenu?: boolean;
238 /**
239 * If true, the persisted menu is rendered hidden when the button
240 * initially mounts. Non-persisted menus will
241 * not be in the component tree unless they are being shown
242 *
243 * Note: This increases the time the button will take to mount, but
244 * can improve perceived menu open perf. when the user opens the menu.
245 *
246 * @defaultvalue undefined, equivalent to false
247 *
248 * @deprecated There is known bug in Edge when this prop is true where scrollbars
249 * overlap with the content when a menu is first rendered hidden.
250 * See: https://github.com/microsoft/fluentui/issues/9034
251 * Please do not start using this. If you are already using this,
252 * please make sure that you are doing so only in non-Edge browsers
253 */
254 renderPersistedMenuHiddenOnMount?: boolean;
255 /**
256 * Experimental prop that get passed into the menuButton that's rendered as part of
257 * split button. Anything passed in will likely need to have accompanying
258 * style changes.
259 */
260 splitButtonMenuProps?: IButtonProps;
261 /**
262 * Style for the description text if applicable (for compound buttons.)
263 * Deprecated, use `secondaryText` instead.
264 * @deprecated Use `secondaryText` instead.
265 */
266 description?: IStyle;
267 /**
268 * yet unknown docs
269 */
270 defaultRender?: any;
271 /**
272 * Optional props to be applied only to the primary action button of SplitButton and not to the
273 * overall SplitButton container
274 */
275 primaryActionButtonProps?: IButtonProps;
276}
277/**
278 * {@docCategory Button}
279 */
280export declare enum ElementType {
281 /** <button> element. */
282 button = 0,
283 /** <a> element. */
284 anchor = 1
285}
286/**
287 * {@docCategory Button}
288 */
289export declare enum ButtonType {
290 normal = 0,
291 primary = 1,
292 hero = 2,
293 compound = 3,
294 command = 4,
295 icon = 5,
296 default = 6
297}
298/**
299 * {@docCategory Button}
300 */
301export interface IButtonStyles {
302 /**
303 * Style for the root element in the default enabled, non-toggled state.
304 */
305 root?: IStyle;
306 /**
307 * Style override for the root element in a checked state, layered on top of the root style.
308 */
309 rootChecked?: IStyle;
310 /**
311 * Style override for the root element in a disabled state, layered on top of the root style.
312 */
313 rootDisabled?: IStyle;
314 /**
315 * Style override applied to the root on hover in the default, enabled, non-toggled state.
316 */
317 rootHovered?: IStyle;
318 /**
319 * Style override applied to the root on focus in the default, enabled, non-toggled state.
320 */
321 rootFocused?: IStyle;
322 /**
323 * Style override applied to the root on pressed in the default, enabled, non-toggled state.
324 */
325 rootPressed?: IStyle;
326 /**
327 * Style override applied to the root on when menu is expanded in the default, enabled, non-toggled state.
328 */
329 rootExpanded?: IStyle;
330 /**
331 * Style override applied to the root on hover in a checked, enabled state
332 */
333 rootCheckedHovered?: IStyle;
334 /**
335 * Style override applied to the root on pressed in a checked, enabled state
336 */
337 rootCheckedPressed?: IStyle;
338 /**
339 * Style override applied to the root on hover in a checked, disabled state
340 */
341 rootCheckedDisabled?: IStyle;
342 /**
343 * Style override applied to the root on hover in a expanded state on hover
344 */
345 rootExpandedHovered?: IStyle;
346 /**
347 * Style override for the root element when it has a menu button, layered on top of the root style.
348 */
349 rootHasMenu?: IStyle;
350 /**
351 * Style for the flexbox container within the root element.
352 */
353 flexContainer?: IStyle;
354 /**
355 * Style for the text container within the flexbox container element (and contains the text and description).
356 */
357 textContainer?: IStyle;
358 /**
359 * Style for the icon on the near side of the label.
360 */
361 icon?: IStyle;
362 /**
363 * Style for the icon on the near side of the label on hover.
364 */
365 iconHovered?: IStyle;
366 /**
367 * Style for the icon on the near side of the label when pressed.
368 */
369 iconPressed?: IStyle;
370 /**
371 * Style for the icon on the near side of the label when expanded.
372 */
373 iconExpanded?: IStyle;
374 /**
375 * Style for the icon on the near side of the label when expanded and hovered.
376 */
377 iconExpandedHovered?: IStyle;
378 /**
379 * Style override for the icon when the button is disabled.
380 */
381 iconDisabled?: IStyle;
382 /**
383 * Style override for the icon when the button is checked.
384 */
385 iconChecked?: IStyle;
386 /**
387 * Style for the text content of the button.
388 */
389 label?: IStyle;
390 /**
391 * Style override for the text content when the button is hovered.
392 */
393 labelHovered?: IStyle;
394 /**
395 * Style override for the text content when the button is disabled.
396 */
397 labelDisabled?: IStyle;
398 /**
399 * Style override for the text content when the button is checked.
400 */
401 labelChecked?: IStyle;
402 /**
403 * Style for the menu chevron.
404 */
405 menuIcon?: IStyle;
406 /**
407 * Style for the menu chevron on hover.
408 */
409 menuIconHovered?: IStyle;
410 /**
411 * Style for the menu chevron when pressed.
412 */
413 menuIconPressed?: IStyle;
414 /**
415 * Style for the menu chevron when expanded.
416 */
417 menuIconExpanded?: IStyle;
418 /**
419 * Style for the menu chevron when expanded and hovered.
420 */
421 menuIconExpandedHovered?: IStyle;
422 /**
423 * Style override for the menu chevron when the button is disabled.
424 */
425 menuIconDisabled?: IStyle;
426 /**
427 * Style override for the menu chevron when the button is checked.
428 */
429 menuIconChecked?: IStyle;
430 /**
431 * Style for the description text if applicable (for compound buttons.)
432 */
433 description?: IStyle;
434 /**
435 * Style for the description text if applicable (for compound buttons.)
436 */
437 secondaryText?: IStyle;
438 /**
439 * Style override for the description text when the button is hovered.
440 */
441 descriptionHovered?: IStyle;
442 /**
443 * Style for the description text when the button is pressed.
444 */
445 descriptionPressed?: IStyle;
446 /**
447 * Style override for the description text when the button is disabled.
448 */
449 descriptionDisabled?: IStyle;
450 /**
451 * Style override for the description text when the button is checked.
452 */
453 descriptionChecked?: IStyle;
454 /**
455 * Style override for the screen reader text.
456 */
457 screenReaderText?: IStyle;
458 /**
459 * Style override for the container div around a SplitButton element
460 */
461 splitButtonContainer?: IStyle;
462 /**
463 * Style for container div around a SplitButton element when the button is hovered.
464 */
465 splitButtonContainerHovered?: IStyle;
466 /**
467 * Style for container div around a SplitButton element when the button is focused.
468 */
469 splitButtonContainerFocused?: IStyle;
470 /**
471 * Style for container div around a SplitButton element when the button is checked.
472 */
473 splitButtonContainerChecked?: IStyle;
474 /**
475 * Style for container div around a SplitButton element when the button is checked and hovered.
476 */
477 splitButtonContainerCheckedHovered?: IStyle;
478 /**
479 * Style override for the container div around a SplitButton element in a disabled state
480 */
481 splitButtonContainerDisabled?: IStyle;
482 /**
483 * Style override for the divider element that appears between the button and menu button
484 * for a split button.
485 */
486 splitButtonDivider?: IStyle;
487 /**
488 * Style override for the divider element that appears between the button and menu button
489 * for a split button in a disabled state.
490 */
491 splitButtonDividerDisabled?: IStyle;
492 /**
493 * Style override for the SplitButton menu button
494 */
495 splitButtonMenuButton?: IStyle;
496 /**
497 * Style override for the SplitButton menu button element in a disabled state.
498 */
499 splitButtonMenuButtonDisabled?: IStyle;
500 /**
501 * Style override for the SplitButton menu button element in a checked state
502 */
503 splitButtonMenuButtonChecked?: IStyle;
504 /**
505 * Style override for the SplitButton menu button element in an expanded state
506 */
507 splitButtonMenuButtonExpanded?: IStyle;
508 /**
509 * Style override for the SplitButton menu icon element
510 */
511 splitButtonMenuIcon?: IStyle;
512 /**
513 * Style override for the SplitButton menu icon element in a disabled state
514 */
515 splitButtonMenuIconDisabled?: IStyle;
516 /**
517 * Style override for the SplitButton FlexContainer.
518 */
519 splitButtonFlexContainer?: IStyle;
520 /**
521 * Style override for the SplitButton when only primaryButton is in a disabled state
522 */
523 splitButtonMenuFocused?: IStyle;
524}