UNPKG

2.87 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverridableStringUnion } from '@mui/types';
4import { Theme } from '../styles';
5import { OverridableComponent, OverrideProps, OverridableTypeMap } from '../OverridableComponent';
6import { FormLabelClasses } from './formLabelClasses';
7
8export interface FormLabelPropsColorOverrides {}
9
10/**
11 * This type is kept for compatibility. Use `FormLabelOwnProps` instead.
12 */
13export type FormLabelBaseProps = React.LabelHTMLAttributes<HTMLLabelElement>;
14
15export interface FormLabelOwnProps {
16 /**
17 * The content of the component.
18 */
19 children?: React.LabelHTMLAttributes<HTMLLabelElement>['children'];
20 /**
21 * Override or extend the styles applied to the component.
22 */
23 classes?: Partial<FormLabelClasses>;
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 */
29 color?: OverridableStringUnion<
30 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
31 FormLabelPropsColorOverrides
32 >;
33 /**
34 * If `true`, the label should be displayed in a disabled state.
35 */
36 disabled?: boolean;
37 /**
38 * If `true`, the label is displayed in an error state.
39 */
40 error?: boolean;
41 /**
42 * If `true`, the label should use filled classes key.
43 */
44 filled?: boolean;
45 /**
46 * If `true`, the input of this label is focused (used by `FormGroup` components).
47 */
48 focused?: boolean;
49 /**
50 * If `true`, the label will indicate that the `input` is required.
51 */
52 required?: boolean;
53 /**
54 * The system prop that allows defining system overrides as well as additional CSS styles.
55 */
56 sx?: SxProps<Theme>;
57}
58
59export interface FormLabelTypeMap<
60 AdditionalProps = {},
61 RootComponent extends React.ElementType = 'label',
62> {
63 props: AdditionalProps & FormLabelBaseProps & FormLabelOwnProps;
64 defaultComponent: RootComponent;
65}
66
67/**
68 *
69 * Demos:
70 *
71 * - [Checkbox](https://mui.com/material-ui/react-checkbox/)
72 * - [Radio Group](https://mui.com/material-ui/react-radio-button/)
73 * - [Switch](https://mui.com/material-ui/react-switch/)
74 *
75 * API:
76 *
77 * - [FormLabel API](https://mui.com/material-ui/api/form-label/)
78 */
79declare const FormLabel: OverridableComponent<FormLabelTypeMap>;
80
81export interface ExtendFormLabelTypeMap<TypeMap extends OverridableTypeMap> {
82 props: TypeMap['props'] & Pick<FormLabelOwnProps, 'filled' | 'color'>;
83 defaultComponent: TypeMap['defaultComponent'];
84}
85
86export type FormLabelProps<
87 RootComponent extends React.ElementType = FormLabelTypeMap['defaultComponent'],
88 AdditionalProps = {},
89> = OverrideProps<FormLabelTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
90 component?: React.ElementType;
91};
92
93export default FormLabel;