UNPKG

4.32 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { OverridableStringUnion } from '@mui/types';
4import { OverridableComponent, OverrideProps } from '../OverridableComponent';
5import { Theme } from '../styles';
6import { FormControlClasses } from './formControlClasses';
7
8export interface FormControlPropsSizeOverrides {}
9export interface FormControlPropsColorOverrides {}
10
11export interface FormControlOwnProps {
12 /**
13 * The content of the component.
14 */
15 children?: React.HTMLAttributes<HTMLDivElement>['children'];
16 /**
17 * Override or extend the styles applied to the component.
18 */
19 classes?: Partial<FormControlClasses>;
20 /**
21 * The color of the component.
22 * It supports both default and custom theme colors, which can be added as shown in the
23 * [palette customization guide](https://mui.com/material-ui/customization/palette/#custom-colors).
24 * @default 'primary'
25 */
26 color?: OverridableStringUnion<
27 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning',
28 FormControlPropsColorOverrides
29 >;
30 /**
31 * If `true`, the label, input and helper text should be displayed in a disabled state.
32 * @default false
33 */
34 disabled?: boolean;
35 /**
36 * If `true`, the label is displayed in an error state.
37 * @default false
38 */
39 error?: boolean;
40 /**
41 * If `true`, the component will take up the full width of its container.
42 * @default false
43 */
44 fullWidth?: boolean;
45 /**
46 * If `true`, the component is displayed in focused state.
47 */
48 focused?: boolean;
49 /**
50 * If `true`, the label is hidden.
51 * This is used to increase density for a `FilledInput`.
52 * Be sure to add `aria-label` to the `input` element.
53 * @default false
54 */
55 hiddenLabel?: boolean;
56 /**
57 * If `dense` or `normal`, will adjust vertical spacing of this and contained components.
58 * @default 'none'
59 */
60 margin?: 'dense' | 'normal' | 'none';
61 /**
62 * If `true`, the label will indicate that the `input` is required.
63 * @default false
64 */
65 required?: boolean;
66 /**
67 * The size of the component.
68 * @default 'medium'
69 */
70 size?: OverridableStringUnion<'small' | 'medium', FormControlPropsSizeOverrides>;
71 /**
72 * The system prop that allows defining system overrides as well as additional CSS styles.
73 */
74 sx?: SxProps<Theme>;
75 /**
76 * The variant to use.
77 * @default 'outlined'
78 */
79 variant?: 'standard' | 'outlined' | 'filled';
80}
81
82export interface FormControlTypeMap<
83 AdditionalProps = {},
84 RootComponent extends React.ElementType = 'div',
85> {
86 props: AdditionalProps & FormControlOwnProps;
87 defaultComponent: RootComponent;
88}
89
90/**
91 * Provides context such as filled/focused/error/required for form inputs.
92 * Relying on the context provides high flexibility and ensures that the state always stays
93 * consistent across the children of the `FormControl`.
94 * This context is used by the following components:
95 *
96 * * FormLabel
97 * * FormHelperText
98 * * Input
99 * * InputLabel
100 *
101 * You can find one composition example below and more going to [the demos](https://mui.com/material-ui/react-text-field/#components).
102 *
103 * ```jsx
104 * <FormControl>
105 * <InputLabel htmlFor="my-input">Email address</InputLabel>
106 * <Input id="my-input" aria-describedby="my-helper-text" />
107 * <FormHelperText id="my-helper-text">We'll never share your email.</FormHelperText>
108 * </FormControl>
109 * ```
110 *
111 * ⚠️ Only one `InputBase` can be used within a FormControl because it creates visual inconsistencies.
112 * For instance, only one input can be focused at the same time, the state shouldn't be shared.
113 *
114 * Demos:
115 *
116 * - [Checkbox](https://mui.com/material-ui/react-checkbox/)
117 * - [Radio Group](https://mui.com/material-ui/react-radio-button/)
118 * - [Switch](https://mui.com/material-ui/react-switch/)
119 * - [Text Field](https://mui.com/material-ui/react-text-field/)
120 *
121 * API:
122 *
123 * - [FormControl API](https://mui.com/material-ui/api/form-control/)
124 */
125declare const FormControl: OverridableComponent<FormControlTypeMap>;
126
127export type FormControlProps<
128 RootComponent extends React.ElementType = FormControlTypeMap['defaultComponent'],
129 AdditionalProps = {},
130> = OverrideProps<FormControlTypeMap<AdditionalProps, RootComponent>, RootComponent> & {
131 component?: React.ElementType;
132};
133
134export default FormControl;