UNPKG

5.91 kBJavaScriptView Raw
1'use client';
2
3var _span;
4import * as React from 'react';
5import PropTypes from 'prop-types';
6import clsx from 'clsx';
7import composeClasses from '@mui/utils/composeClasses';
8import formControlState from "../FormControl/formControlState.js";
9import useFormControl from "../FormControl/useFormControl.js";
10import { styled } from "../zero-styled/index.js";
11import memoTheme from "../utils/memoTheme.js";
12import { useDefaultProps } from "../DefaultPropsProvider/index.js";
13import capitalize from "../utils/capitalize.js";
14import formHelperTextClasses, { getFormHelperTextUtilityClasses } from "./formHelperTextClasses.js";
15import { jsx as _jsx } from "react/jsx-runtime";
16const useUtilityClasses = ownerState => {
17 const {
18 classes,
19 contained,
20 size,
21 disabled,
22 error,
23 filled,
24 focused,
25 required
26 } = ownerState;
27 const slots = {
28 root: ['root', disabled && 'disabled', error && 'error', size && `size${capitalize(size)}`, contained && 'contained', focused && 'focused', filled && 'filled', required && 'required']
29 };
30 return composeClasses(slots, getFormHelperTextUtilityClasses, classes);
31};
32const FormHelperTextRoot = styled('p', {
33 name: 'MuiFormHelperText',
34 slot: 'Root',
35 overridesResolver: (props, styles) => {
36 const {
37 ownerState
38 } = props;
39 return [styles.root, ownerState.size && styles[`size${capitalize(ownerState.size)}`], ownerState.contained && styles.contained, ownerState.filled && styles.filled];
40 }
41})(memoTheme(({
42 theme
43}) => ({
44 color: (theme.vars || theme).palette.text.secondary,
45 ...theme.typography.caption,
46 textAlign: 'left',
47 marginTop: 3,
48 marginRight: 0,
49 marginBottom: 0,
50 marginLeft: 0,
51 [`&.${formHelperTextClasses.disabled}`]: {
52 color: (theme.vars || theme).palette.text.disabled
53 },
54 [`&.${formHelperTextClasses.error}`]: {
55 color: (theme.vars || theme).palette.error.main
56 },
57 variants: [{
58 props: {
59 size: 'small'
60 },
61 style: {
62 marginTop: 4
63 }
64 }, {
65 props: ({
66 ownerState
67 }) => ownerState.contained,
68 style: {
69 marginLeft: 14,
70 marginRight: 14
71 }
72 }]
73})));
74const FormHelperText = /*#__PURE__*/React.forwardRef(function FormHelperText(inProps, ref) {
75 const props = useDefaultProps({
76 props: inProps,
77 name: 'MuiFormHelperText'
78 });
79 const {
80 children,
81 className,
82 component = 'p',
83 disabled,
84 error,
85 filled,
86 focused,
87 margin,
88 required,
89 variant,
90 ...other
91 } = props;
92 const muiFormControl = useFormControl();
93 const fcs = formControlState({
94 props,
95 muiFormControl,
96 states: ['variant', 'size', 'disabled', 'error', 'filled', 'focused', 'required']
97 });
98 const ownerState = {
99 ...props,
100 component,
101 contained: fcs.variant === 'filled' || fcs.variant === 'outlined',
102 variant: fcs.variant,
103 size: fcs.size,
104 disabled: fcs.disabled,
105 error: fcs.error,
106 filled: fcs.filled,
107 focused: fcs.focused,
108 required: fcs.required
109 };
110
111 // This issue explains why this is required: https://github.com/mui/material-ui/issues/42184
112 delete ownerState.ownerState;
113 const classes = useUtilityClasses(ownerState);
114 return /*#__PURE__*/_jsx(FormHelperTextRoot, {
115 as: component,
116 className: clsx(classes.root, className),
117 ref: ref,
118 ...other,
119 ownerState: ownerState,
120 children: children === ' ' ? // notranslate needed while Google Translate will not fix zero-width space issue
121 _span || (_span = /*#__PURE__*/_jsx("span", {
122 className: "notranslate",
123 children: "\u200B"
124 })) : children
125 });
126});
127process.env.NODE_ENV !== "production" ? FormHelperText.propTypes /* remove-proptypes */ = {
128 // ┌────────────────────────────── Warning ──────────────────────────────┐
129 // │ These PropTypes are generated from the TypeScript type definitions. │
130 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
131 // └─────────────────────────────────────────────────────────────────────┘
132 /**
133 * The content of the component.
134 *
135 * If `' '` is provided, the component reserves one line height for displaying a future message.
136 */
137 children: PropTypes.node,
138 /**
139 * Override or extend the styles applied to the component.
140 */
141 classes: PropTypes.object,
142 /**
143 * @ignore
144 */
145 className: PropTypes.string,
146 /**
147 * The component used for the root node.
148 * Either a string to use a HTML element or a component.
149 */
150 component: PropTypes.elementType,
151 /**
152 * If `true`, the helper text should be displayed in a disabled state.
153 */
154 disabled: PropTypes.bool,
155 /**
156 * If `true`, helper text should be displayed in an error state.
157 */
158 error: PropTypes.bool,
159 /**
160 * If `true`, the helper text should use filled classes key.
161 */
162 filled: PropTypes.bool,
163 /**
164 * If `true`, the helper text should use focused classes key.
165 */
166 focused: PropTypes.bool,
167 /**
168 * If `dense`, will adjust vertical spacing. This is normally obtained via context from
169 * FormControl.
170 */
171 margin: PropTypes.oneOf(['dense']),
172 /**
173 * If `true`, the helper text should use required classes key.
174 */
175 required: PropTypes.bool,
176 /**
177 * The system prop that allows defining system overrides as well as additional CSS styles.
178 */
179 sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
180 /**
181 * The variant to use.
182 */
183 variant: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([PropTypes.oneOf(['filled', 'outlined', 'standard']), PropTypes.string])
184} : void 0;
185export default FormHelperText;
\No newline at end of file