1 | import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
2 | import _typeof from "@babel/runtime/helpers/esm/typeof";
|
3 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
4 | import _extends from "@babel/runtime/helpers/esm/extends";
|
5 | import * as React from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import { refType } from '@mui/utils';
|
8 | import { unstable_composeClasses as composeClasses } from '@mui/base';
|
9 | import { alpha } from '@mui/system';
|
10 | import SwitchBase from '../internal/SwitchBase';
|
11 | import useThemeProps from '../styles/useThemeProps';
|
12 | import RadioButtonIcon from './RadioButtonIcon';
|
13 | import capitalize from '../utils/capitalize';
|
14 | import createChainedFunction from '../utils/createChainedFunction';
|
15 | import useRadioGroup from '../RadioGroup/useRadioGroup';
|
16 | import radioClasses, { getRadioUtilityClass } from './radioClasses';
|
17 | import styled, { rootShouldForwardProp } from '../styles/styled';
|
18 | import { jsx as _jsx } from "react/jsx-runtime";
|
19 |
|
20 | var useUtilityClasses = function useUtilityClasses(ownerState) {
|
21 | var classes = ownerState.classes,
|
22 | color = ownerState.color;
|
23 | var slots = {
|
24 | root: ['root', "color".concat(capitalize(color))]
|
25 | };
|
26 | return _extends({}, classes, composeClasses(slots, getRadioUtilityClass, classes));
|
27 | };
|
28 |
|
29 | var RadioRoot = styled(SwitchBase, {
|
30 | shouldForwardProp: function shouldForwardProp(prop) {
|
31 | return rootShouldForwardProp(prop) || prop === 'classes';
|
32 | },
|
33 | name: 'MuiRadio',
|
34 | slot: 'Root',
|
35 | overridesResolver: function overridesResolver(props, styles) {
|
36 | var ownerState = props.ownerState;
|
37 | return [styles.root, styles["color".concat(capitalize(ownerState.color))]];
|
38 | }
|
39 | })(function (_ref) {
|
40 | var theme = _ref.theme,
|
41 | ownerState = _ref.ownerState;
|
42 | return _extends({
|
43 | color: (theme.vars || theme).palette.text.secondary,
|
44 | '&:hover': {
|
45 | backgroundColor: theme.vars ? "rgba(".concat(ownerState.color === 'default' ? theme.vars.palette.action.activeChannel : theme.vars.palette[ownerState.color].mainChannel, " / ").concat(theme.vars.palette.action.hoverOpacity, ")") : alpha(ownerState.color === 'default' ? theme.palette.action.active : theme.palette[ownerState.color].main, theme.palette.action.hoverOpacity),
|
46 |
|
47 | '@media (hover: none)': {
|
48 | backgroundColor: 'transparent'
|
49 | }
|
50 | }
|
51 | }, ownerState.color !== 'default' && _defineProperty({}, "&.".concat(radioClasses.checked), {
|
52 | color: (theme.vars || theme).palette[ownerState.color].main
|
53 | }), _defineProperty({}, "&.".concat(radioClasses.disabled), {
|
54 | color: (theme.vars || theme).palette.action.disabled
|
55 | }));
|
56 | });
|
57 |
|
58 | function areEqualValues(a, b) {
|
59 | if (_typeof(b) === 'object' && b !== null) {
|
60 | return a === b;
|
61 | }
|
62 |
|
63 |
|
64 | return String(a) === String(b);
|
65 | }
|
66 |
|
67 | var defaultCheckedIcon = _jsx(RadioButtonIcon, {
|
68 | checked: true
|
69 | });
|
70 |
|
71 | var defaultIcon = _jsx(RadioButtonIcon, {});
|
72 |
|
73 | var Radio = React.forwardRef(function Radio(inProps, ref) {
|
74 | var _defaultIcon$props$fo, _defaultCheckedIcon$p;
|
75 |
|
76 | var props = useThemeProps({
|
77 | props: inProps,
|
78 | name: 'MuiRadio'
|
79 | });
|
80 |
|
81 | var checkedProp = props.checked,
|
82 | _props$checkedIcon = props.checkedIcon,
|
83 | checkedIcon = _props$checkedIcon === void 0 ? defaultCheckedIcon : _props$checkedIcon,
|
84 | _props$color = props.color,
|
85 | color = _props$color === void 0 ? 'primary' : _props$color,
|
86 | _props$icon = props.icon,
|
87 | icon = _props$icon === void 0 ? defaultIcon : _props$icon,
|
88 | nameProp = props.name,
|
89 | onChangeProp = props.onChange,
|
90 | _props$size = props.size,
|
91 | size = _props$size === void 0 ? 'medium' : _props$size,
|
92 | other = _objectWithoutProperties(props, ["checked", "checkedIcon", "color", "icon", "name", "onChange", "size"]);
|
93 |
|
94 | var ownerState = _extends({}, props, {
|
95 | color: color,
|
96 | size: size
|
97 | });
|
98 |
|
99 | var classes = useUtilityClasses(ownerState);
|
100 | var radioGroup = useRadioGroup();
|
101 | var checked = checkedProp;
|
102 | var onChange = createChainedFunction(onChangeProp, radioGroup && radioGroup.onChange);
|
103 | var name = nameProp;
|
104 |
|
105 | if (radioGroup) {
|
106 | if (typeof checked === 'undefined') {
|
107 | checked = areEqualValues(radioGroup.value, props.value);
|
108 | }
|
109 |
|
110 | if (typeof name === 'undefined') {
|
111 | name = radioGroup.name;
|
112 | }
|
113 | }
|
114 |
|
115 | return _jsx(RadioRoot, _extends({
|
116 | type: "radio",
|
117 | icon: React.cloneElement(icon, {
|
118 | fontSize: (_defaultIcon$props$fo = defaultIcon.props.fontSize) != null ? _defaultIcon$props$fo : size
|
119 | }),
|
120 | checkedIcon: React.cloneElement(checkedIcon, {
|
121 | fontSize: (_defaultCheckedIcon$p = defaultCheckedIcon.props.fontSize) != null ? _defaultCheckedIcon$p : size
|
122 | }),
|
123 | ownerState: ownerState,
|
124 | classes: classes,
|
125 | name: name,
|
126 | checked: checked,
|
127 | onChange: onChange,
|
128 | ref: ref
|
129 | }, other));
|
130 | });
|
131 | process.env.NODE_ENV !== "production" ? Radio.propTypes
|
132 |
|
133 | = {
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | |
140 |
|
141 |
|
142 | checked: PropTypes.bool,
|
143 |
|
144 | |
145 |
|
146 |
|
147 |
|
148 | checkedIcon: PropTypes.node,
|
149 |
|
150 | |
151 |
|
152 |
|
153 | classes: PropTypes.object,
|
154 |
|
155 | |
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | color: PropTypes
|
162 |
|
163 | .oneOfType([PropTypes.oneOf(['default', 'primary', 'secondary', 'error', 'info', 'success', 'warning']), PropTypes.string]),
|
164 |
|
165 | |
166 |
|
167 |
|
168 | disabled: PropTypes.bool,
|
169 |
|
170 | |
171 |
|
172 |
|
173 | disableRipple: PropTypes.bool,
|
174 |
|
175 | |
176 |
|
177 |
|
178 |
|
179 | icon: PropTypes.node,
|
180 |
|
181 | |
182 |
|
183 |
|
184 | id: PropTypes.string,
|
185 |
|
186 | |
187 |
|
188 |
|
189 | inputProps: PropTypes.object,
|
190 |
|
191 | |
192 |
|
193 |
|
194 | inputRef: refType,
|
195 |
|
196 | |
197 |
|
198 |
|
199 | name: PropTypes.string,
|
200 |
|
201 | |
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 | onChange: PropTypes.func,
|
209 |
|
210 | |
211 |
|
212 |
|
213 | required: PropTypes.bool,
|
214 |
|
215 | |
216 |
|
217 |
|
218 |
|
219 |
|
220 | size: PropTypes
|
221 |
|
222 | .oneOfType([PropTypes.oneOf(['medium', 'small']), PropTypes.string]),
|
223 |
|
224 | |
225 |
|
226 |
|
227 | sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
228 |
|
229 | |
230 |
|
231 |
|
232 | value: PropTypes.any
|
233 | } : void 0;
|
234 | export default Radio; |
\ | No newline at end of file |