UNPKG

@carbon/ibm-products

Version:
147 lines (145 loc) 5.68 kB
/** * 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_settings = require("../../settings.js"); const require_devtools = require("../../global/js/utils/devtools.js"); const require_uuidv4 = require("../../global/js/utils/uuidv4.js"); const require_TearsheetNarrow = require("../Tearsheet/TearsheetNarrow.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/CreateTearsheetNarrow/CreateTearsheetNarrow.tsx /** * Copyright IBM Corp. 2021, 2021 * * 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 blockClass = `${require_settings.pkg.prefix}--create-tearsheet-narrow`; const componentName = "CreateTearsheetNarrow"; /** * Use a narrow tearsheet as an alternative to a modal when there is scrolling. * Use when the form fields can be broken down into sections using section headers. */ const CreateTearsheetNarrow = react.default.forwardRef(({ children, className, description, disableSubmit, formDescription, formTitle, label, open, onRequestClose, onRequestSubmit, primaryButtonText, secondaryButtonText, selectorPrimaryFocus, title, verticalPosition, ...rest }, ref) => { const actions = [{ label: primaryButtonText, onClick: onRequestSubmit, kind: "primary", disabled: disableSubmit }, { label: secondaryButtonText, onClick: onRequestClose, kind: "secondary" }]; const formTextClass = `${blockClass}__content-text`; const formTitleId = require_uuidv4.default(); return /* @__PURE__ */ react.default.createElement(require_TearsheetNarrow.TearsheetNarrow, { ...rest, title, description, className: (0, import_classnames.default)(blockClass, className), actions, open, ref, onClose: () => { onRequestClose?.(); return false; }, label, selectorPrimaryFocus, verticalPosition, role: "presentation", ...require_devtools.getDevtoolsProps(componentName) }, /* @__PURE__ */ react.default.createElement("h3", { className: (0, import_classnames.default)(`${blockClass}__form-title-text`, formTextClass), id: formTitleId }, formTitle), /* @__PURE__ */ react.default.createElement("p", { className: (0, import_classnames.default)(`${blockClass}__form-description-text`, formTextClass) }, formDescription), /* @__PURE__ */ react.default.createElement(_carbon_react.Form, { className: `${blockClass}__form`, "aria-labelledby": formTitleId, onSubmit: (e) => e.preventDefault() }, children)); }); CreateTearsheetNarrow.displayName = componentName; CreateTearsheetNarrow.propTypes = { /** * Provide the contents of the CreateTearsheetNarrow. */ children: prop_types.default.node.isRequired, /** * Provide an optional class to be applied to the containing node. */ className: prop_types.default.string, /** * A description of the flow, displayed in the header area of the tearsheet. */ description: prop_types.default.node, /** * Specifies a boolean for disabling or enabling the primary button. This is important for form validation * Returning `true` prevents the primary button from being clicked until required fields are completed. */ disableSubmit: prop_types.default.bool, /** * Specifies an optional field that provides a additional context for a form */ formDescription: prop_types.default.node, /** * Specifies a field that provides a title for a form */ formTitle: prop_types.default.node, /** * A label for the tearsheet, displayed in the header area of the tearsheet * to maintain context for the tearsheet (e.g. as the title changes from page * to page of a multi-page task). */ label: prop_types.default.node, /** * An optional handler that is called when the user closes the tearsheet (by * clicking the close button, if enabled, or clicking outside, if enabled). * Returning `false` here prevents the modal from closing. */ onRequestClose: prop_types.default.func, /** * Specifies an optional handler which is called when the CreateTearsheetNarrow * primary button is pressed. */ onRequestSubmit: prop_types.default.func, /** * Specifies whether the tearsheet is currently open. */ open: prop_types.default.bool, /** * Specifies the primary button's text in the CreateTearsheetNarrow. */ primaryButtonText: prop_types.default.string.isRequired, /** * Specifies the secondary button's text in the CreateTearsheetNarrow. */ secondaryButtonText: prop_types.default.string.isRequired, /** * Specifies which DOM element in the form should be focused. */ selectorPrimaryFocus: prop_types.default.node, /** * The main title of the tearsheet, displayed in the header area. */ title: prop_types.default.node, /** * The position of the top of tearsheet in the viewport. The 'normal' * position (the default) is a short distance down from the top of the * viewport, leaving room at the top for a global header bar to show through * from below. The 'lower' position provides a little extra room at the top * to allow an action bar navigation or breadcrumbs to also show through. */ verticalPosition: prop_types.default.oneOf(["normal", "lower"]) }; //#endregion exports.CreateTearsheetNarrow = CreateTearsheetNarrow;