UNPKG

4.02 kBTypeScriptView Raw
1import * as React from 'react';
2import { DistributiveOmit, OverridableStringUnion } from '@mui/types';
3import { SxProps } from '@mui/system';
4import { Theme } from '../styles';
5import { ExtendButtonBase, ExtendButtonBaseTypeMap } from '../ButtonBase';
6import { OverrideProps, OverridableComponent, OverridableTypeMap } from '../OverridableComponent';
7import { ButtonClasses } from './buttonClasses';
8
9export interface ButtonPropsVariantOverrides {}
10
11export interface ButtonPropsColorOverrides {}
12
13export interface ButtonPropsSizeOverrides {}
14
15export interface ButtonOwnProps {
16 /**
17 * The content of the component.
18 */
19 children?: React.ReactNode;
20 /**
21 * Override or extend the styles applied to the component.
22 */
23 classes?: Partial<ButtonClasses>;
24 /**
25 * The color of the component.
26 * It supports both default and custom theme colors, which can be added as shown in the
27 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
28 * @default 'primary'
29 */
30 color?: OverridableStringUnion<
31 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning',
32 ButtonPropsColorOverrides
33 >;
34 /**
35 * If `true`, the component is disabled.
36 * @default false
37 */
38 disabled?: boolean;
39 /**
40 * If `true`, no elevation is used.
41 * @default false
42 */
43 disableElevation?: boolean;
44 /**
45 * If `true`, the keyboard focus ripple is disabled.
46 * @default false
47 */
48 disableFocusRipple?: boolean;
49 /**
50 * Element placed after the children.
51 */
52 endIcon?: React.ReactNode;
53 /**
54 * If `true`, the button will take up the full width of its container.
55 * @default false
56 */
57 fullWidth?: boolean;
58 /**
59 * The URL to link to when the button is clicked.
60 * If defined, an `a` element will be used as the root node.
61 */
62 href?: string;
63 /**
64 * The size of the component.
65 * `small` is equivalent to the dense button styling.
66 * @default 'medium'
67 */
68 size?: OverridableStringUnion<'small' | 'medium' | 'large', ButtonPropsSizeOverrides>;
69 /**
70 * Element placed before the children.
71 */
72 startIcon?: React.ReactNode;
73 /**
74 * The system prop that allows defining system overrides as well as additional CSS styles.
75 */
76 sx?: SxProps<Theme>;
77 /**
78 * The variant to use.
79 * @default 'text'
80 */
81 variant?: OverridableStringUnion<'text' | 'outlined' | 'contained', ButtonPropsVariantOverrides>;
82}
83
84export type ButtonTypeMap<
85 AdditionalProps = {},
86 RootComponent extends React.ElementType = 'button',
87> = ExtendButtonBaseTypeMap<{
88 props: AdditionalProps & ButtonOwnProps;
89 defaultComponent: RootComponent;
90}>;
91
92/**
93 * utility to create component types that inherit props from ButtonBase.
94 * This component has an additional overload if the `href` prop is set which
95 * can make extension quite tricky
96 */
97export interface ExtendButtonTypeMap<TypeMap extends OverridableTypeMap> {
98 props: TypeMap['props'] &
99 (TypeMap['props'] extends { classes?: Record<string, string> }
100 ? DistributiveOmit<ButtonTypeMap['props'], 'classes'>
101 : ButtonTypeMap['props']);
102 defaultComponent: TypeMap['defaultComponent'];
103}
104
105export type ExtendButton<TypeMap extends OverridableTypeMap> = ((
106 props: { href: string } & OverrideProps<ExtendButtonBaseTypeMap<TypeMap>, 'a'>,
107) => React.JSX.Element) &
108 OverridableComponent<ExtendButtonBaseTypeMap<TypeMap>>;
109
110/**
111 *
112 * Demos:
113 *
114 * - [Button Group](https://mui.com/material-ui/react-button-group/)
115 * - [Button](https://mui.com/material-ui/react-button/)
116 *
117 * API:
118 *
119 * - [Button API](https://mui.com/material-ui/api/button/)
120 * - inherits [ButtonBase API](https://mui.com/material-ui/api/button-base/)
121 */
122declare const Button: ExtendButtonBase<ButtonTypeMap>;
123
124export type ButtonProps<
125 RootComponent extends React.ElementType = ButtonTypeMap['defaultComponent'],
126 AdditionalProps = {},
127> = OverrideProps<ButtonTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
128 component?: React.ElementType;
129};
130
131export default Button;