UNPKG

2.24 kBTypeScriptView Raw
1import * as React from 'react';
2import { EventHandlers } from '../utils/types';
3import { MuiCancellableEventHandler } from '../utils/muiCancellableEvent';
4export interface UseButtonRootSlotOwnProps {
5 'aria-disabled'?: React.AriaAttributes['aria-disabled'];
6 disabled?: boolean;
7 tabIndex?: number;
8 type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];
9 role?: React.AriaRole;
10 onBlur: React.FocusEventHandler;
11 onFocus: React.FocusEventHandler;
12 onKeyDown: MuiCancellableEventHandler<React.KeyboardEvent>;
13 onKeyUp: MuiCancellableEventHandler<React.KeyboardEvent>;
14 onMouseDown: React.MouseEventHandler;
15 onMouseLeave: React.MouseEventHandler;
16 ref: React.RefCallback<Element> | null;
17}
18export type UseButtonRootSlotProps<TOther = {}> = TOther & UseButtonRootSlotOwnProps;
19export interface UseButtonParameters {
20 /**
21 * If `true`, the component is disabled.
22 * @default false
23 */
24 disabled?: boolean;
25 /**
26 * If `true`, allows a disabled button to receive focus.
27 * @default false
28 */
29 focusableWhenDisabled?: boolean;
30 href?: string;
31 onFocusVisible?: React.FocusEventHandler;
32 rootRef?: React.Ref<Element>;
33 tabIndex?: NonNullable<React.HTMLAttributes<any>['tabIndex']>;
34 to?: string;
35 /**
36 * Type attribute applied when the `component` is `button`.
37 * @default 'button'
38 */
39 type?: React.ButtonHTMLAttributes<HTMLButtonElement>['type'];
40}
41export interface UseButtonReturnValue {
42 /**
43 * Resolver for the root slot's props.
44 * @param otherHandlers event handlers for the root slot
45 * @returns props that should be spread on the root slot
46 */
47 getRootProps: <TOther extends EventHandlers = {}>(otherHandlers?: TOther) => UseButtonRootSlotProps<TOther>;
48 /**
49 * If `true`, the component is being focused using keyboard.
50 */
51 focusVisible: boolean;
52 /**
53 * Callback for setting the `focusVisible` param.
54 */
55 setFocusVisible: React.Dispatch<React.SetStateAction<boolean>>;
56 /**
57 * If `true`, the component is active (pressed).
58 */
59 active: boolean;
60 /**
61 * A ref to the component's root DOM element.
62 */
63 rootRef: React.RefCallback<Element> | null;
64}