@carbon/ibm-products
Version:
Carbon for IBM Products
100 lines (98 loc) • 4.67 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 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.
*/
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_index = require("../../node_modules/classnames/index.js");
const require_pconsole = require("../../global/js/utils/pconsole.js");
const require_settings = require("../../settings.js");
const require_EditTearsheet = require("./EditTearsheet.js");
const require_useRetrieveFormTitles = require("../../global/js/hooks/useRetrieveFormTitles.js");
let react = require("react");
react = require_runtime.__toESM(react);
let prop_types = require("prop-types");
prop_types = require_runtime.__toESM(prop_types);
let _carbon_react = require("@carbon/react");
//#region src/components/EditTearsheet/EditTearsheetForm.tsx
/**
* Copyright IBM Corp. 2022, 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.
*/
var import_classnames = /* @__PURE__ */ require_runtime.__toESM(require_index.default);
const componentName = "EditTearsheetForm";
const blockClass = `${require_settings.pkg.prefix}--tearsheet-edit__form`;
const defaults = { hasFieldset: true };
const EditTearsheetForm = (0, react.forwardRef)(({ children, className, description, fieldsetLegendText, fieldsetLegendId, hasFieldset = defaults.hasFieldset, subtitle, title, ...rest }, ref) => {
const formContext = (0, react.useContext)(require_EditTearsheet.FormContext);
const formNumber = (0, react.useContext)(require_EditTearsheet.FormNumberContext);
require_useRetrieveFormTitles.useRetrieveFormTitles({
formContext,
formNumber,
title
});
return formContext ? /* @__PURE__ */ react.default.createElement("div", {
...rest,
className: (0, import_classnames.default)(blockClass, className, {
[`${blockClass}__form--hidden-form`]: formNumber !== formContext?.currentForm,
[`${blockClass}__form--visible-form`]: formNumber === formContext?.currentForm
}),
ref
}, /* @__PURE__ */ react.default.createElement(_carbon_react.Grid, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Column, {
xlg: 12,
lg: 12,
md: 8,
sm: 4
}, /* @__PURE__ */ react.default.createElement("h4", { className: `${blockClass}--title` }, title), subtitle && /* @__PURE__ */ react.default.createElement("h5", { className: `${blockClass}--subtitle` }, subtitle), description && /* @__PURE__ */ react.default.createElement("p", { className: `${blockClass}--description` }, description)), /* @__PURE__ */ react.default.createElement(_carbon_react.Column, { span: 100 }, hasFieldset ? /* @__PURE__ */ react.default.createElement(_carbon_react.FormGroup, {
legendText: fieldsetLegendText,
className: `${blockClass}--fieldset`,
legendId: fieldsetLegendId
}, /* @__PURE__ */ react.default.createElement(_carbon_react.Grid, null, children)) : children))) : require_pconsole.default.warn(`You have tried using a ${componentName} component outside of a EditTearsheet. This is not allowed. ${componentName}s should always be children of the EditTearsheet`);
});
EditTearsheetForm.propTypes = {
/**
* Content that shows in the tearsheet form
*/
children: prop_types.default.node,
/**
* Sets an optional className to be added to the tearsheet form
*/
className: prop_types.default.string,
/**
* Sets an optional description on the form component
*/
description: prop_types.default.string,
/**
* This is the required legend id that appears as the aria-labelledby of fieldset for accessibility purposes.
*/
/**@ts-ignore */
fieldsetLegendId: prop_types.default.node,
/**
* This is the required legend text that appears above a fieldset html element for accessibility purposes.
* You can set the `hasFieldset` prop to false if you have multiple fieldset elements or want to control the children of your Full Page's form content.
* Otherwise, use CSS to hide/remove this label text.
*/
/**@ts-ignore */
fieldsetLegendText: prop_types.default.string,
/**
* This optional prop will render your form content inside of a fieldset html element
* and is defaulted to true.
* You can set this prop to `false` if you have multiple fieldset elements or want to control the children of your Full Page's form content.
*/
/**@ts-ignore*/
hasFieldset: prop_types.default.bool,
/**
* Sets an optional subtitle on the form component
*/
/**@ts-ignore*/
subtitle: prop_types.default.string,
/**
* Sets the title text for a tearsheet form
*/
title: prop_types.default.node.isRequired
};
//#endregion
exports.EditTearsheetForm = EditTearsheetForm;