UNPKG

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