UNPKG

@carbon/react

Version:

React components for the Carbon Design System

89 lines (81 loc) 2.84 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. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js'); var PropTypes = require('prop-types'); var React = require('react'); var cx = require('classnames'); var usePrefix = require('../../internal/usePrefix.js'); function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes); var React__default = /*#__PURE__*/_interopDefaultLegacy(React); var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx); const FormGroup = ({ disabled = false, legendId, legendText, invalid = false, children, className, message = false, messageText = '', ...rest }) => { const prefix = usePrefix.usePrefix(); const classNamesFieldset = cx__default["default"](`${prefix}--fieldset`, className); return /*#__PURE__*/React__default["default"].createElement("fieldset", _rollupPluginBabelHelpers["extends"]({ disabled: disabled }, invalid && { 'data-invalid': '' }, { className: classNamesFieldset }, rest, { "aria-labelledby": rest['aria-labelledby'] || legendId }), /*#__PURE__*/React__default["default"].createElement("legend", { className: `${prefix}--label`, id: legendId || rest['aria-labelledby'] }, legendText), children, message ? /*#__PURE__*/React__default["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__default["default"].node, /** * Provide a custom className to be applied to the containing <fieldset> node */ className: PropTypes__default["default"].string, /** * Specify whether the FormGroup should be disabled */ disabled: PropTypes__default["default"].bool, /** * Specify whether the <FormGroup> is invalid */ invalid: PropTypes__default["default"].bool, /** * Provide id for the fieldset <legend> which corresponds to the fieldset * `aria-labelledby` */ legendId: PropTypes__default["default"].node, /** * Provide the text to be rendered inside of the fieldset <legend> */ legendText: PropTypes__default["default"].node.isRequired, /** * Specify whether the message should be displayed in the <FormGroup> */ message: PropTypes__default["default"].bool, /** * Provide the text for the message in the <FormGroup> */ messageText: PropTypes__default["default"].string }; exports["default"] = FormGroup;