UNPKG

@carbon/react

Version:

React components for the Carbon Design System

79 lines (75 loc) 2.16 kB
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import PropTypes from 'prop-types'; import React from 'react'; import cx from 'classnames'; import { usePrefix } from '../../internal/usePrefix.js'; const FormGroup = ({ disabled = false, legendId, legendText, invalid = false, children, className, message = false, messageText = '', ...rest }) => { const prefix = usePrefix(); const classNamesFieldset = cx(`${prefix}--fieldset`, className); return /*#__PURE__*/React.createElement("fieldset", _extends({ disabled: disabled }, invalid && { 'data-invalid': '' }, { className: classNamesFieldset }, rest, { "aria-labelledby": rest['aria-labelledby'] || legendId }), /*#__PURE__*/React.createElement("legend", { className: `${prefix}--label`, id: legendId || rest['aria-labelledby'] }, legendText), children, message ? /*#__PURE__*/React.createElement("div", { className: `${prefix}--form__requirements` }, messageText) : null); }; FormGroup.propTypes = { /** * Provide the children form elements to be rendered inside of the <fieldset> */ children: PropTypes.node, /** * Provide a custom className to be applied to the containing <fieldset> node */ className: PropTypes.string, /** * Specify whether the FormGroup should be disabled */ disabled: PropTypes.bool, /** * Specify whether the <FormGroup> is invalid */ invalid: PropTypes.bool, /** * Provide id for the fieldset <legend> which corresponds to the fieldset * `aria-labelledby` */ legendId: PropTypes.node, /** * Provide the text to be rendered inside of the fieldset <legend> */ legendText: PropTypes.node.isRequired, /** * Specify whether the message should be displayed in the <FormGroup> */ message: PropTypes.bool, /** * Provide the text for the message in the <FormGroup> */ messageText: PropTypes.string }; export { FormGroup as default };