UNPKG

4.45 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { Theme } from '../styles';
4import { TouchRippleActions, TouchRippleProps } from './TouchRipple';
5import { OverrideProps, OverridableComponent, OverridableTypeMap } from '../OverridableComponent';
6import { ButtonBaseClasses } from './buttonBaseClasses';
7
8export interface ButtonBaseOwnProps {
9 /**
10 * A ref for imperative actions.
11 * It currently only supports `focusVisible()` action.
12 */
13 action?: React.Ref<ButtonBaseActions>;
14 /**
15 * If `true`, the ripples are centered.
16 * They won't start at the cursor interaction position.
17 * @default false
18 */
19 centerRipple?: boolean;
20 /**
21 * The content of the component.
22 */
23 children?: React.ReactNode;
24 /**
25 * Override or extend the styles applied to the component.
26 */
27 classes?: Partial<ButtonBaseClasses>;
28 /**
29 * If `true`, the component is disabled.
30 * @default false
31 */
32 disabled?: boolean;
33 /**
34 * If `true`, the ripple effect is disabled.
35 *
36 * ⚠️ Without a ripple there is no styling for :focus-visible by default. Be sure
37 * to highlight the element by applying separate styles with the `.Mui-focusVisible` class.
38 * @default false
39 */
40 disableRipple?: boolean;
41 /**
42 * If `true`, the touch ripple effect is disabled.
43 * @default false
44 */
45 disableTouchRipple?: boolean;
46 /**
47 * If `true`, the base button will have a keyboard focus ripple.
48 * @default false
49 */
50 focusRipple?: boolean;
51 /**
52 * This prop can help identify which element has keyboard focus.
53 * The class name will be applied when the element gains the focus through keyboard interaction.
54 * It's a polyfill for the [CSS :focus-visible selector](https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo).
55 * The rationale for using this feature [is explained here](https://github.com/WICG/focus-visible/blob/HEAD/explainer.md).
56 * A [polyfill can be used](https://github.com/WICG/focus-visible) to apply a `focus-visible` class to other components
57 * if needed.
58 */
59 focusVisibleClassName?: string;
60 /**
61 * The component used to render a link when the `href` prop is provided.
62 * @default 'a'
63 */
64 LinkComponent?: React.ElementType;
65 /**
66 * Callback fired when the component is focused with a keyboard.
67 * We trigger a `onFocus` callback too.
68 */
69 onFocusVisible?: React.FocusEventHandler<any>;
70 /**
71 * The system prop that allows defining system overrides as well as additional CSS styles.
72 */
73 sx?: SxProps<Theme>;
74 /**
75 * @default 0
76 */
77 tabIndex?: NonNullable<React.HTMLAttributes<any>['tabIndex']>;
78 /**
79 * Props applied to the `TouchRipple` element.
80 */
81 TouchRippleProps?: Partial<TouchRippleProps>;
82 /**
83 * A ref that points to the `TouchRipple` element.
84 */
85 touchRippleRef?: React.Ref<TouchRippleActions>;
86}
87
88export interface ButtonBaseTypeMap<
89 AdditionalProps = {},
90 RootComponent extends React.ElementType = 'button',
91> {
92 props: AdditionalProps & ButtonBaseOwnProps;
93 defaultComponent: RootComponent;
94}
95
96/**
97 * utility to create component types that inherit props from ButtonBase.
98 * This component has an additional overload if the `href` prop is set which
99 * can make extension quite tricky
100 */
101export interface ExtendButtonBaseTypeMap<TypeMap extends OverridableTypeMap> {
102 props: TypeMap['props'] & Omit<ButtonBaseTypeMap['props'], 'classes'>;
103 defaultComponent: TypeMap['defaultComponent'];
104}
105
106export type ExtendButtonBase<TypeMap extends OverridableTypeMap> = ((
107 props: { href: string } & OverrideProps<ExtendButtonBaseTypeMap<TypeMap>, 'a'>,
108) => React.JSX.Element) &
109 OverridableComponent<ExtendButtonBaseTypeMap<TypeMap>>;
110
111/**
112 * `ButtonBase` contains as few styles as possible.
113 * It aims to be a simple building block for creating a button.
114 * It contains a load of style reset and some focus/ripple logic.
115 *
116 * Demos:
117 *
118 * - [Button](https://mui.com/material-ui/react-button/)
119 *
120 * API:
121 *
122 * - [ButtonBase API](https://mui.com/material-ui/api/button-base/)
123 */
124declare const ButtonBase: ExtendButtonBase<ButtonBaseTypeMap>;
125
126export type ButtonBaseProps<
127 RootComponent extends React.ElementType = ButtonBaseTypeMap['defaultComponent'],
128 AdditionalProps = {},
129> = OverrideProps<ButtonBaseTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
130 component?: React.ElementType;
131};
132
133export interface ButtonBaseActions {
134 focusVisible(): void;
135}
136
137export default ButtonBase;