@carbon/ibm-products
Version:
Carbon for IBM Products
145 lines (143 loc) • 5.24 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.
*/
import { __toESM } from "../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../node_modules/classnames/index.js";
import { pkg } from "../../settings.js";
import { getDevtoolsProps } from "../../global/js/utils/devtools.js";
import uuidv4 from "../../global/js/utils/uuidv4.js";
import { TearsheetNarrow } from "../Tearsheet/TearsheetNarrow.js";
import React from "react";
import PropTypes from "prop-types";
import { Form } from "@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__ */ __toESM(require_classnames());
const blockClass = `${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.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 = uuidv4();
return /* @__PURE__ */ React.createElement(TearsheetNarrow, {
...rest,
title,
description,
className: (0, import_classnames.default)(blockClass, className),
actions,
open,
ref,
onClose: () => {
onRequestClose?.();
return false;
},
label,
selectorPrimaryFocus,
verticalPosition,
role: "presentation",
...getDevtoolsProps(componentName)
}, /* @__PURE__ */ React.createElement("h3", {
className: (0, import_classnames.default)(`${blockClass}__form-title-text`, formTextClass),
id: formTitleId
}, formTitle), /* @__PURE__ */ React.createElement("p", { className: (0, import_classnames.default)(`${blockClass}__form-description-text`, formTextClass) }, formDescription), /* @__PURE__ */ React.createElement(Form, {
className: `${blockClass}__form`,
"aria-labelledby": formTitleId,
onSubmit: (e) => e.preventDefault()
}, children));
});
CreateTearsheetNarrow.displayName = componentName;
CreateTearsheetNarrow.propTypes = {
/**
* Provide the contents of the CreateTearsheetNarrow.
*/
children: PropTypes.node.isRequired,
/**
* Provide an optional class to be applied to the containing node.
*/
className: PropTypes.string,
/**
* A description of the flow, displayed in the header area of the tearsheet.
*/
description: PropTypes.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: PropTypes.bool,
/**
* Specifies an optional field that provides a additional context for a form
*/
formDescription: PropTypes.node,
/**
* Specifies a field that provides a title for a form
*/
formTitle: PropTypes.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: PropTypes.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: PropTypes.func,
/**
* Specifies an optional handler which is called when the CreateTearsheetNarrow
* primary button is pressed.
*/
onRequestSubmit: PropTypes.func,
/**
* Specifies whether the tearsheet is currently open.
*/
open: PropTypes.bool,
/**
* Specifies the primary button's text in the CreateTearsheetNarrow.
*/
primaryButtonText: PropTypes.string.isRequired,
/**
* Specifies the secondary button's text in the CreateTearsheetNarrow.
*/
secondaryButtonText: PropTypes.string.isRequired,
/**
* Specifies which DOM element in the form should be focused.
*/
selectorPrimaryFocus: PropTypes.node,
/**
* The main title of the tearsheet, displayed in the header area.
*/
title: PropTypes.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: PropTypes.oneOf(["normal", "lower"])
};
//#endregion
export { CreateTearsheetNarrow };