UNPKG

@mui/joy

Version:

Joy UI is an open-source React component library that implements MUI's own design principles. It's comprehensive and can be used in production out of the box.

132 lines (131 loc) 4.73 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["children", "component", "slots", "slotProps"]; import * as React from 'react'; import PropTypes from 'prop-types'; import { unstable_useForkRef as useForkRef } from '@mui/utils'; import { unstable_composeClasses as composeClasses } from '@mui/base/composeClasses'; import { styled, useThemeProps } from '../styles'; import { getFormHelperTextUtilityClass } from './formHelperTextClasses'; import FormControlContext from '../FormControl/FormControlContext'; import formControlClasses from '../FormControl/formControlClasses'; import formLabelClasses from '../FormLabel/formLabelClasses'; import useSlot from '../utils/useSlot'; import { jsx as _jsx } from "react/jsx-runtime"; const useUtilityClasses = () => { const slots = { root: ['root'] }; return composeClasses(slots, getFormHelperTextUtilityClass, {}); }; const FormHelperTextRoot = styled('div', { name: 'JoyFormHelperText', slot: 'Root', overridesResolver: (props, styles) => styles.root })(({ theme }) => ({ '--Icon-fontSize': 'calc(var(--FormHelperText-lineHeight) * 1em)', display: 'flex', alignItems: 'center', gap: '2px', fontFamily: theme.vars.fontFamily.body, fontSize: `var(--FormHelperText-fontSize, ${theme.vars.fontSize.sm})`, lineHeight: `var(--FormHelperText-lineHeight, ${theme.vars.lineHeight.sm})`, color: `var(--FormHelperText-color, ${theme.vars.palette.text.tertiary})`, margin: 'var(--FormHelperText-margin, 0px)', [`.${formLabelClasses.root} + &`]: { '--FormHelperText-margin': '0px' // remove the margin if the helper text is next to the form label. }, [`.${formControlClasses.error} &`]: { '--Icon-color': 'currentColor' } })); /** * * Demos: * * - [Input](https://mui.com/joy-ui/react-input/) * * API: * * - [FormHelperText API](https://mui.com/joy-ui/api/form-helper-text/) */ const FormHelperText = /*#__PURE__*/React.forwardRef(function FormHelperText(inProps, ref) { const props = useThemeProps({ props: inProps, name: 'JoyFormHelperText' }); const { children, component, slots = {}, slotProps = {} } = props, other = _objectWithoutPropertiesLoose(props, _excluded); const rootRef = React.useRef(null); const handleRef = useForkRef(rootRef, ref); const formControl = React.useContext(FormControlContext); const setHelperText = formControl?.setHelperText; React.useEffect(() => { setHelperText?.(rootRef.current); return () => { setHelperText?.(null); }; }, [setHelperText]); const classes = useUtilityClasses(); const externalForwardedProps = _extends({}, other, { component, slots, slotProps }); const [SlotRoot, rootProps] = useSlot('root', { ref: handleRef, elementType: FormHelperTextRoot, externalForwardedProps, ownerState: props, additionalProps: { as: component, id: formControl?.['aria-describedby'] }, className: classes.root }); return /*#__PURE__*/_jsx(SlotRoot, _extends({}, rootProps, { children: children })); }); process.env.NODE_ENV !== "production" ? FormHelperText.propTypes /* remove-proptypes */ = { // ┌────────────────────────────── Warning ──────────────────────────────┐ // │ These PropTypes are generated from the TypeScript type definitions. │ // │ To update them, edit the TypeScript types and run `pnpm proptypes`. │ // └─────────────────────────────────────────────────────────────────────┘ /** * The content of the component. */ children: PropTypes.node, /** * The component used for the root node. * Either a string to use a HTML element or a component. */ component: PropTypes.elementType, /** * The props used for each slot inside. * @default {} */ slotProps: PropTypes.shape({ root: PropTypes.oneOfType([PropTypes.func, PropTypes.object]) }), /** * The components used for each slot inside. * @default {} */ slots: PropTypes.shape({ root: PropTypes.elementType }), /** * The system prop that allows defining system overrides as well as additional CSS styles. */ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]) } : void 0; export default FormHelperText;