UNPKG

@carbon/react

Version:

React components for the Carbon Design System

55 lines (53 loc) 1.67 kB
/** * Copyright IBM Corp. 2016, 2026 * * 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 { usePrefix } from "../../internal/usePrefix.js"; import classNames from "classnames"; import "react"; import PropTypes from "prop-types"; import { jsx, jsxs } from "react/jsx-runtime"; //#region src/components/FormGroup/FormGroup.tsx /** * Copyright IBM Corp. 2016, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ const FormGroup = ({ disabled = false, legendId, legendText, invalid = false, children, className, message = false, messageText = "", ...rest }) => { const prefix = usePrefix(); const classNamesFieldset = classNames(`${prefix}--fieldset`, className); return /* @__PURE__ */ jsxs("fieldset", { disabled, ...invalid && { "data-invalid": "" }, className: classNamesFieldset, ...rest, "aria-labelledby": rest["aria-labelledby"] || legendId, children: [ /* @__PURE__ */ jsx("legend", { className: `${prefix}--label`, id: legendId || rest["aria-labelledby"], children: legendText }), children, message ? /* @__PURE__ */ jsx("div", { className: `${prefix}--form__requirements`, children: messageText }) : null ] }); }; FormGroup.propTypes = { children: PropTypes.node, className: PropTypes.string, disabled: PropTypes.bool, invalid: PropTypes.bool, legendId: PropTypes.node, legendText: PropTypes.node.isRequired, message: PropTypes.bool, messageText: PropTypes.string }; //#endregion export { FormGroup as default };