UNPKG

@carbon/ibm-products

Version:
128 lines (126 loc) 5.22 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_usePortalTarget = require("../../global/js/hooks/usePortalTarget.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/CreateModal/CreateModal.tsx /** * Copyright IBM Corp. 2021, 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 = "CreateModal"; const blockClass = `${require_settings.pkg.prefix}--create-modal`; /** * The `CreateModal` component provides a way for a user to quickly generate a new resource. It is triggered by a user’s action, appears on top of the main page content, and is persistent until dismissed. The purpose of this modal should be immediately apparent to the user, with a clear and obvious path to completion. */ const CreateModal = react.default.forwardRef((props, ref) => { const { className, children, onRequestClose, onRequestSubmit, open, title, subtitle, description, secondaryButtonText, portalTarget: portalTargetIn, primaryButtonText, disableSubmit, selectorPrimaryFocus, ...rest } = props; return require_usePortalTarget.usePortalTarget(portalTargetIn)(/* @__PURE__ */ react.default.createElement(_carbon_react.ComposedModal, { ...rest, selectorPrimaryFocus, className: (0, import_classnames.default)(blockClass, className), open, ref, "aria-label": title, size: "sm", preventCloseOnClickOutside: true, onClose: () => { onRequestClose?.(); return false; }, ...require_devtools.getDevtoolsProps(componentName) }, /* @__PURE__ */ react.default.createElement(_carbon_react.ModalHeader, { title, titleClassName: `${blockClass}__title` }, subtitle && /* @__PURE__ */ react.default.createElement("p", { className: `${blockClass}__subtitle` }, subtitle)), /* @__PURE__ */ react.default.createElement(_carbon_react.ModalBody, { hasForm: true }, description && /* @__PURE__ */ react.default.createElement("p", { className: `${blockClass}__description` }, description), /* @__PURE__ */ react.default.createElement(_carbon_react.Form, { className: `${blockClass}__form`, "aria-label": title, onSubmit: (e) => e.preventDefault() }, children)), /* @__PURE__ */ react.default.createElement(_carbon_react.ModalFooter, null, /* @__PURE__ */ react.default.createElement(_carbon_react.Button, { type: "button", kind: "secondary", onClick: onRequestClose }, secondaryButtonText), /* @__PURE__ */ react.default.createElement(_carbon_react.Button, { type: "submit", kind: "primary", onClick: onRequestSubmit, disabled: disableSubmit }, primaryButtonText)))); }); CreateModal.propTypes = { /** * Children refers to all form items within a form inside of the modal's body. */ children: prop_types.default.node, /** * Specify an optional className to be applied to the modal root node */ className: prop_types.default.string, /** * The description of the CreateModal serves to provide more information about the modal. */ description: prop_types.default.node.isRequired, /** * 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 handler which is called when the CreateModal * is closed. */ onRequestClose: prop_types.default.func, /** * Specifies an optional handler which is called when the CreateModal * primary button is pressed. */ onRequestSubmit: prop_types.default.func, /** * Specifies whether the CreateModal is open or not. */ open: prop_types.default.bool, /** * The DOM node the tearsheet should be rendered within. Defaults to document.body. */ portalTarget: prop_types.default.node, /** * Specifies the primary button's text in the modal. */ primaryButtonText: prop_types.default.string.isRequired, /** * Specifies the secondary button's text in the modal. */ secondaryButtonText: prop_types.default.string.isRequired, /** * Specifies which DOM element in the form should be focused. */ selectorPrimaryFocus: prop_types.default.string.isRequired, /** * The subtitle of the CreateModal is optional and serves to provide more information about the modal. */ subtitle: prop_types.default.node, /** * The title of the CreateModal is usually the product or service name. */ title: prop_types.default.node.isRequired }; CreateModal.displayName = componentName; //#endregion exports.CreateModal = CreateModal;