UNPKG

3.41 kBTypeScriptView Raw
1import * as React from 'react';
2import { SxProps } from '@mui/system';
3import { Theme, InternalStandardProps as StandardProps } from '..';
4import Typography, { TypographyProps } from '../Typography';
5import { FormControlLabelClasses } from './formControlLabelClasses';
6import { CreateSlotsAndSlotProps, SlotProps } from '../utils/types';
7
8export interface FormControlLabelSlots {
9 /**
10 * The component that renders the label.
11 * This is unused if `disableTypography` is true.
12 * @default Typography
13 */
14 typography: React.ElementType;
15}
16
17export type FormControlLabelSlotsAndSlotProps = CreateSlotsAndSlotProps<
18 FormControlLabelSlots,
19 {
20 typography: SlotProps<typeof Typography, {}, FormControlLabelProps>;
21 }
22>;
23
24export interface FormControlLabelProps
25 extends StandardProps<React.LabelHTMLAttributes<HTMLLabelElement>, 'children' | 'onChange'>,
26 FormControlLabelSlotsAndSlotProps {
27 /**
28 * If `true`, the component appears selected.
29 */
30 checked?: boolean;
31 /**
32 * Override or extend the styles applied to the component.
33 */
34 classes?: Partial<FormControlLabelClasses>;
35 /**
36 * The props used for each slot inside.
37 * @default {}
38 * @deprecated use the `slotProps` prop instead. This prop will be removed in v7. See [Migrating from deprecated APIs](https://mui.com/material-ui/migration/migrating-from-deprecated-apis/) for more details.
39 */
40 componentsProps?: {
41 /**
42 * Props applied to the Typography wrapper of the passed label.
43 * This is unused if disableTypography is true.
44 * @default {}
45 */
46 typography?: TypographyProps;
47 };
48 /**
49 * A control element. For instance, it can be a `Radio`, a `Switch` or a `Checkbox`.
50 */
51 control: React.ReactElement<unknown, any>;
52 /**
53 * If `true`, the control is disabled.
54 */
55 disabled?: boolean;
56 /**
57 * If `true`, the label is rendered as it is passed without an additional typography node.
58 */
59 disableTypography?: boolean;
60 /**
61 * Pass a ref to the `input` element.
62 */
63 inputRef?: React.Ref<any>;
64 /**
65 * A text or an element to be used in an enclosing label element.
66 */
67 label: React.ReactNode;
68 /**
69 * The position of the label.
70 * @default 'end'
71 */
72 labelPlacement?: 'end' | 'start' | 'top' | 'bottom';
73 name?: string;
74 /**
75 * Callback fired when the state is changed.
76 *
77 * @param {React.SyntheticEvent} event The event source of the callback.
78 * You can pull out the new checked state by accessing `event.target.checked` (boolean).
79 */
80 onChange?: (event: React.SyntheticEvent, checked: boolean) => void;
81 /**
82 * If `true`, the label will indicate that the `input` is required.
83 */
84 required?: boolean;
85 /**
86 * The system prop that allows defining system overrides as well as additional CSS styles.
87 */
88 sx?: SxProps<Theme>;
89 /**
90 * The value of the component.
91 */
92 value?: unknown;
93}
94
95/**
96 * Drop-in replacement of the `Radio`, `Switch` and `Checkbox` component.
97 * Use this component if you want to display an extra label.
98 *
99 * Demos:
100 *
101 * - [Checkbox](https://mui.com/material-ui/react-checkbox/)
102 * - [Radio Group](https://mui.com/material-ui/react-radio-button/)
103 * - [Switch](https://mui.com/material-ui/react-switch/)
104 *
105 * API:
106 *
107 * - [FormControlLabel API](https://mui.com/material-ui/api/form-control-label/)
108 */
109export default function FormControlLabel(props: FormControlLabelProps): React.JSX.Element;