1 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
4 | import * as React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import clsx from 'clsx';
|
7 | import { refType } from '@mui/utils';
|
8 | import { unstable_composeClasses as composeClasses } from '@mui/base';
|
9 | import { useFormControl } from '../FormControl';
|
10 | import Typography from '../Typography';
|
11 | import capitalize from '../utils/capitalize';
|
12 | import styled from '../styles/styled';
|
13 | import useThemeProps from '../styles/useThemeProps';
|
14 | import formControlLabelClasses, { getFormControlLabelUtilityClasses } from './formControlLabelClasses';
|
15 | import formControlState from '../FormControl/formControlState';
|
16 | import { jsx as _jsx } from "react/jsx-runtime";
|
17 | import { jsxs as _jsxs } from "react/jsx-runtime";
|
18 |
|
19 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
20 | var classes = ownerState.classes,
|
21 | disabled = ownerState.disabled,
|
22 | labelPlacement = ownerState.labelPlacement,
|
23 | error = ownerState.error;
|
24 | var slots = {
|
25 | root: ['root', disabled && 'disabled', "labelPlacement".concat(capitalize(labelPlacement)), error && 'error'],
|
26 | label: ['label', disabled && 'disabled']
|
27 | };
|
28 | return composeClasses(slots, getFormControlLabelUtilityClasses, classes);
|
29 | };
|
30 |
|
31 | export var FormControlLabelRoot = styled('label', {
|
32 | name: 'MuiFormControlLabel',
|
33 | slot: 'Root',
|
34 | overridesResolver: function overridesResolver(props, styles) {
|
35 | var ownerState = props.ownerState;
|
36 | return [_defineProperty({}, "& .".concat(formControlLabelClasses.label), styles.label), styles.root, styles["labelPlacement".concat(capitalize(ownerState.labelPlacement))]];
|
37 | }
|
38 | })(function (_ref2) {
|
39 | var theme = _ref2.theme,
|
40 | ownerState = _ref2.ownerState;
|
41 | return _extends(_defineProperty({
|
42 | display: 'inline-flex',
|
43 | alignItems: 'center',
|
44 | cursor: 'pointer',
|
45 |
|
46 | verticalAlign: 'middle',
|
47 | WebkitTapHighlightColor: 'transparent',
|
48 | marginLeft: -11,
|
49 | marginRight: 16
|
50 | }, "&.".concat(formControlLabelClasses.disabled), {
|
51 | cursor: 'default'
|
52 | }), ownerState.labelPlacement === 'start' && {
|
53 | flexDirection: 'row-reverse',
|
54 | marginLeft: 16,
|
55 |
|
56 | marginRight: -11
|
57 | }, ownerState.labelPlacement === 'top' && {
|
58 | flexDirection: 'column-reverse',
|
59 | marginLeft: 16
|
60 | }, ownerState.labelPlacement === 'bottom' && {
|
61 | flexDirection: 'column',
|
62 | marginLeft: 16
|
63 | }, _defineProperty({}, "& .".concat(formControlLabelClasses.label), _defineProperty({}, "&.".concat(formControlLabelClasses.disabled), {
|
64 | color: (theme.vars || theme).palette.text.disabled
|
65 | })));
|
66 | });
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | var FormControlLabel = React.forwardRef(function FormControlLabel(inProps, ref) {
|
73 | var props = useThemeProps({
|
74 | props: inProps,
|
75 | name: 'MuiFormControlLabel'
|
76 | });
|
77 |
|
78 | var checked = props.checked,
|
79 | className = props.className,
|
80 | _props$componentsProp = props.componentsProps,
|
81 | componentsProps = _props$componentsProp === void 0 ? {} : _props$componentsProp,
|
82 | control = props.control,
|
83 | disabledProp = props.disabled,
|
84 | disableTypography = props.disableTypography,
|
85 | inputRef = props.inputRef,
|
86 | labelProp = props.label,
|
87 | _props$labelPlacement = props.labelPlacement,
|
88 | labelPlacement = _props$labelPlacement === void 0 ? 'end' : _props$labelPlacement,
|
89 | name = props.name,
|
90 | onChange = props.onChange,
|
91 | value = props.value,
|
92 | other = _objectWithoutProperties(props, ["checked", "className", "componentsProps", "control", "disabled", "disableTypography", "inputRef", "label", "labelPlacement", "name", "onChange", "value"]);
|
93 |
|
94 | var muiFormControl = useFormControl();
|
95 | var disabled = disabledProp;
|
96 |
|
97 | if (typeof disabled === 'undefined' && typeof control.props.disabled !== 'undefined') {
|
98 | disabled = control.props.disabled;
|
99 | }
|
100 |
|
101 | if (typeof disabled === 'undefined' && muiFormControl) {
|
102 | disabled = muiFormControl.disabled;
|
103 | }
|
104 |
|
105 | var controlProps = {
|
106 | disabled: disabled
|
107 | };
|
108 | ['checked', 'name', 'onChange', 'value', 'inputRef'].forEach(function (key) {
|
109 | if (typeof control.props[key] === 'undefined' && typeof props[key] !== 'undefined') {
|
110 | controlProps[key] = props[key];
|
111 | }
|
112 | });
|
113 | var fcs = formControlState({
|
114 | props: props,
|
115 | muiFormControl: muiFormControl,
|
116 | states: ['error']
|
117 | });
|
118 |
|
119 | var ownerState = _extends({}, props, {
|
120 | disabled: disabled,
|
121 | labelPlacement: labelPlacement,
|
122 | error: fcs.error
|
123 | });
|
124 |
|
125 | var classes = useUtilityClasses(ownerState);
|
126 | var label = labelProp;
|
127 |
|
128 | if (label != null && label.type !== Typography && !disableTypography) {
|
129 | label = _jsx(Typography, _extends({
|
130 | component: "span",
|
131 | className: classes.label
|
132 | }, componentsProps.typography, {
|
133 | children: label
|
134 | }));
|
135 | }
|
136 |
|
137 | return _jsxs(FormControlLabelRoot, _extends({
|
138 | className: clsx(classes.root, className),
|
139 | ownerState: ownerState,
|
140 | ref: ref
|
141 | }, other, {
|
142 | children: [React.cloneElement(control, controlProps), label]
|
143 | }));
|
144 | });
|
145 | process.env.NODE_ENV !== "production" ? FormControlLabel.propTypes
|
146 |
|
147 | = {
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | |
154 |
|
155 |
|
156 | checked: PropTypes.bool,
|
157 |
|
158 | |
159 |
|
160 |
|
161 | classes: PropTypes.object,
|
162 |
|
163 | |
164 |
|
165 |
|
166 | className: PropTypes.string,
|
167 |
|
168 | |
169 |
|
170 |
|
171 |
|
172 | componentsProps: PropTypes.shape({
|
173 | typography: PropTypes.object
|
174 | }),
|
175 |
|
176 | |
177 |
|
178 |
|
179 | control: PropTypes.element.isRequired,
|
180 |
|
181 | |
182 |
|
183 |
|
184 | disabled: PropTypes.bool,
|
185 |
|
186 | |
187 |
|
188 |
|
189 | disableTypography: PropTypes.bool,
|
190 |
|
191 | |
192 |
|
193 |
|
194 | inputRef: refType,
|
195 |
|
196 | |
197 |
|
198 |
|
199 | label: PropTypes.node,
|
200 |
|
201 | |
202 |
|
203 |
|
204 |
|
205 | labelPlacement: PropTypes.oneOf(['bottom', 'end', 'start', 'top']),
|
206 |
|
207 | |
208 |
|
209 |
|
210 | name: PropTypes.string,
|
211 |
|
212 | |
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 | onChange: PropTypes.func,
|
219 |
|
220 | |
221 |
|
222 |
|
223 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
224 |
|
225 | |
226 |
|
227 |
|
228 | value: PropTypes.any
|
229 | } : void 0;
|
230 | export default FormControlLabel; |
\ | No newline at end of file |