FrontPastel/node_modules/@mui/material/node/RadioGroup/RadioGroup.js

125 lines
5.5 KiB
JavaScript

"use strict";
'use client';
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _clsx = _interopRequireDefault(require("clsx"));
var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
var _FormGroup = _interopRequireDefault(require("../FormGroup"));
var _radioGroupClasses = require("./radioGroupClasses");
var _useForkRef = _interopRequireDefault(require("../utils/useForkRef"));
var _useControlled = _interopRequireDefault(require("../utils/useControlled"));
var _RadioGroupContext = _interopRequireDefault(require("./RadioGroupContext"));
var _useId = _interopRequireDefault(require("../utils/useId"));
var _jsxRuntime = require("react/jsx-runtime");
const _excluded = ["actions", "children", "className", "defaultValue", "name", "onChange", "value"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
const useUtilityClasses = props => {
const {
classes,
row,
error
} = props;
const slots = {
root: ['root', row && 'row', error && 'error']
};
return (0, _composeClasses.default)(slots, _radioGroupClasses.getRadioGroupUtilityClass, classes);
};
const RadioGroup = /*#__PURE__*/React.forwardRef(function RadioGroup(props, ref) {
const {
// private
// eslint-disable-next-line react/prop-types
actions,
children,
className,
defaultValue,
name: nameProp,
onChange,
value: valueProp
} = props,
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
const rootRef = React.useRef(null);
const classes = useUtilityClasses(props);
const [value, setValueState] = (0, _useControlled.default)({
controlled: valueProp,
default: defaultValue,
name: 'RadioGroup'
});
React.useImperativeHandle(actions, () => ({
focus: () => {
let input = rootRef.current.querySelector('input:not(:disabled):checked');
if (!input) {
input = rootRef.current.querySelector('input:not(:disabled)');
}
if (input) {
input.focus();
}
}
}), []);
const handleRef = (0, _useForkRef.default)(ref, rootRef);
const name = (0, _useId.default)(nameProp);
const contextValue = React.useMemo(() => ({
name,
onChange(event) {
setValueState(event.target.value);
if (onChange) {
onChange(event, event.target.value);
}
},
value
}), [name, onChange, setValueState, value]);
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioGroupContext.default.Provider, {
value: contextValue,
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormGroup.default, (0, _extends2.default)({
role: "radiogroup",
ref: handleRef,
className: (0, _clsx.default)(classes.root, className)
}, other, {
children: children
}))
});
});
process.env.NODE_ENV !== "production" ? RadioGroup.propTypes /* remove-proptypes */ = {
// ┌────────────────────────────── Warning ──────────────────────────────┐
// │ These PropTypes are generated from the TypeScript type definitions. │
// │ To update them, edit the d.ts file and run `pnpm proptypes`. │
// └─────────────────────────────────────────────────────────────────────┘
/**
* The content of the component.
*/
children: _propTypes.default.node,
/**
* @ignore
*/
className: _propTypes.default.string,
/**
* The default value. Use when the component is not controlled.
*/
defaultValue: _propTypes.default.any,
/**
* The name used to reference the value of the control.
* If you don't provide this prop, it falls back to a randomly generated name.
*/
name: _propTypes.default.string,
/**
* Callback fired when a radio button is selected.
*
* @param {React.ChangeEvent<HTMLInputElement>} event The event source of the callback.
* @param {string} value The value of the selected radio button.
* You can pull out the new value by accessing `event.target.value` (string).
*/
onChange: _propTypes.default.func,
/**
* Value of the selected radio button. The DOM API casts this to a string.
*/
value: _propTypes.default.any
} : void 0;
var _default = exports.default = RadioGroup;