UNPKG

3.32 kBJavaScriptView Raw
1'use client';
2
3import * as React from 'react';
4import PropTypes from 'prop-types';
5import clsx from 'clsx';
6import composeClasses from '@mui/utils/composeClasses';
7import { styled } from "../zero-styled/index.js";
8import { useDefaultProps } from "../DefaultPropsProvider/index.js";
9import { getFormGroupUtilityClass } from "./formGroupClasses.js";
10import useFormControl from "../FormControl/useFormControl.js";
11import formControlState from "../FormControl/formControlState.js";
12import { jsx as _jsx } from "react/jsx-runtime";
13const useUtilityClasses = ownerState => {
14 const {
15 classes,
16 row,
17 error
18 } = ownerState;
19 const slots = {
20 root: ['root', row && 'row', error && 'error']
21 };
22 return composeClasses(slots, getFormGroupUtilityClass, classes);
23};
24const FormGroupRoot = styled('div', {
25 name: 'MuiFormGroup',
26 slot: 'Root',
27 overridesResolver: (props, styles) => {
28 const {
29 ownerState
30 } = props;
31 return [styles.root, ownerState.row && styles.row];
32 }
33})({
34 display: 'flex',
35 flexDirection: 'column',
36 flexWrap: 'wrap',
37 variants: [{
38 props: {
39 row: true
40 },
41 style: {
42 flexDirection: 'row'
43 }
44 }]
45});
46
47/**
48 * `FormGroup` wraps controls such as `Checkbox` and `Switch`.
49 * It provides compact row layout.
50 * For the `Radio`, you should be using the `RadioGroup` component instead of this one.
51 */
52const FormGroup = /*#__PURE__*/React.forwardRef(function FormGroup(inProps, ref) {
53 const props = useDefaultProps({
54 props: inProps,
55 name: 'MuiFormGroup'
56 });
57 const {
58 className,
59 row = false,
60 ...other
61 } = props;
62 const muiFormControl = useFormControl();
63 const fcs = formControlState({
64 props,
65 muiFormControl,
66 states: ['error']
67 });
68 const ownerState = {
69 ...props,
70 row,
71 error: fcs.error
72 };
73 const classes = useUtilityClasses(ownerState);
74 return /*#__PURE__*/_jsx(FormGroupRoot, {
75 className: clsx(classes.root, className),
76 ownerState: ownerState,
77 ref: ref,
78 ...other
79 });
80});
81process.env.NODE_ENV !== "production" ? FormGroup.propTypes /* remove-proptypes */ = {
82 // ┌────────────────────────────── Warning ──────────────────────────────┐
83 // │ These PropTypes are generated from the TypeScript type definitions. │
84 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
85 // └─────────────────────────────────────────────────────────────────────┘
86 /**
87 * The content of the component.
88 */
89 children: PropTypes.node,
90 /**
91 * Override or extend the styles applied to the component.
92 */
93 classes: PropTypes.object,
94 /**
95 * @ignore
96 */
97 className: PropTypes.string,
98 /**
99 * Display group of elements in a compact row.
100 * @default false
101 */
102 row: PropTypes.bool,
103 /**
104 * The system prop that allows defining system overrides as well as additional CSS styles.
105 */
106 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
107} : void 0;
108export default FormGroup;
\No newline at end of file