@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
70 lines (66 loc) • 1.95 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import PropTypes from 'prop-types';
import React__default from 'react';
import cx from 'classnames';
import { usePrefix } from '../../internal/usePrefix.js';
const FormGroup = _ref => {
let {
legendId,
legendText,
invalid = false,
children,
className,
message = false,
messageText = '',
...rest
} = _ref;
const prefix = usePrefix();
const classNamesFieldset = cx(`${prefix}--fieldset`, className);
return /*#__PURE__*/React__default.createElement("fieldset", _extends({}, invalid && {
'data-invalid': ''
}, {
className: classNamesFieldset
}, rest, {
"aria-labelledby": rest['aria-labelledby'] || legendId
}), /*#__PURE__*/React__default.createElement("legend", {
className: `${prefix}--label`,
id: legendId || rest['aria-labelledby']
}, legendText), children, message ? /*#__PURE__*/React__default.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> 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 };