@carbon/ibm-products
Version:
Carbon for IBM Products
152 lines (150 loc) • 5.09 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 { SidePanel } from "../SidePanel/SidePanel.js";
import React from "react";
import PropTypes from "prop-types";
import { Form } from "@carbon/react";
//#region src/components/CreateSidePanel/CreateSidePanel.tsx
/**
* Copyright IBM Corp. 2021, 2024
*
* 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-side-panel`;
const componentName = "CreateSidePanel";
/**
* Use with medium complexity creations if the user needs page context. On-page content can be seen and interacted with.
*/
const CreateSidePanel = React.forwardRef(({ className, children, disableSubmit, formTitle, formDescription, id, onRequestClose, onRequestSubmit, open, primaryButtonText, secondaryButtonText, selectorPageContent, selectorPrimaryFocus, subtitle, title, ...rest }, ref) => {
const actions = [{
label: primaryButtonText,
onClick: (event) => {
event.preventDefault();
onRequestSubmit?.();
},
kind: "primary",
disabled: disableSubmit,
type: "submit"
}, {
label: secondaryButtonText,
onClick: onRequestClose,
kind: "secondary"
}];
const formTitleId = uuidv4();
return selectorPageContent && /* @__PURE__ */ React.createElement(SidePanel, {
...rest,
id,
open,
ref,
selectorPageContent,
onRequestClose,
title,
subtitle,
selectorPrimaryFocus,
...getDevtoolsProps(componentName),
placement: "right",
slideIn: true,
animateTitle: false,
className: (0, import_classnames.default)(blockClass, className),
size: "md",
actions
}, /* @__PURE__ */ React.createElement("h3", {
className: `${blockClass}__form-title-text ${blockClass}__content-text`,
id: formTitleId
}, formTitle), /* @__PURE__ */ React.createElement("p", { className: `${blockClass}__form-description-text ${blockClass}__content-text` }, formDescription), /* @__PURE__ */ React.createElement(Form, {
className: `${blockClass}__form`,
"aria-labelledby": formTitleId,
onSubmit: (e) => e.preventDefault()
}, children));
});
CreateSidePanel.displayName = componentName;
CreateSidePanel.propTypes = {
/**
* Sets the body content of the create side panel
*/
/**@ts-ignore*/
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
/**
* Provide an optional class to be applied to the containing node.
*/
className: PropTypes.string,
/**
* The description of the CreateSidePanel serves to provide more information about the form within the panel.
*/
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 required field that provides a title for a form
*/
formTitle: PropTypes.node.isRequired,
/**
* Unique identifier
*/
id: PropTypes.string,
/**
* Specifies an optional handler which is called when the CreateSidePanel
* is closed.
*/
onRequestClose: PropTypes.func,
/**
* Specifies an optional handler which is called when the CreateSidePanel
* primary button is pressed.
*/
onRequestSubmit: PropTypes.func,
/**
* Specifies whether the CreateSidePanel is open or not.
*/
/**@ts-ignore*/
open: PropTypes.bool,
/**
* Specifies the primary button's text in the modal.
*/
primaryButtonText: PropTypes.string.isRequired,
/**
* Specifies the secondary button's text in the modal.
*/
secondaryButtonText: PropTypes.string.isRequired,
/**
* This is the selector to the element that contains all of the page content that will shrink if the panel is a slide in.
* This prop is required when using the `slideIn` variant of the side panel.
*/
selectorPageContent: PropTypes.string.isRequired,
/**
* Specifies which DOM element in the form should be focused.
*/
/**@ts-ignore*/
selectorPrimaryFocus: PropTypes.node.isRequired,
/**
* **Experimental:** Provide a `Slug` component to be rendered inside the `SidePanel` component
*/
slug: PropTypes.node,
/**
* The subtitle of the CreateSidePanel is optional and serves to provide more information about the modal.
*/
subtitle: PropTypes.node,
/**
* The title of the CreateSidePanel is usually the product or service name.
*/
title: PropTypes.string.isRequired
};
//#endregion
export { CreateSidePanel };