@carbon/ibm-products
Version:
Carbon for IBM Products
207 lines (196 loc) • 6.48 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 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.
*/
'use strict';
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
require('../../global/js/utils/props-helper.js');
var React = require('react');
var react = require('@carbon/react');
var index = require('../../_virtual/index.js');
var SidePanel = require('../SidePanel/SidePanel.js');
var cx = require('classnames');
var devtools = require('../../global/js/utils/devtools.js');
var settings = require('../../settings.js');
var uuidv4 = require('../../global/js/utils/uuidv4.js');
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${settings.pkg.prefix}--edit-side-panel`;
const componentName = 'EditSidePanel';
// NOTE: the component SCSS is not imported here: it is rolled up separately.
/**
* **This component is deprecated.** <br>
* Use with medium complexity edits if the user needs page context.
* @deprecated
*/
exports.EditSidePanel = /*#__PURE__*/React.forwardRef((_ref, ref) => {
let {
// The component props, in alphabetical order (for consistency).
children,
className,
disableSubmit,
id,
formTitle,
formDescription,
onRequestClose,
onRequestSubmit,
open,
placement = 'right',
primaryButtonText,
secondaryButtonText,
selectorPrimaryFocus,
selectorPageContent,
size = 'md',
slideIn,
subtitle,
title,
// Collect any other property values passed in.
...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.default();
return /*#__PURE__*/React.createElement(SidePanel.SidePanel, _rollupPluginBabelHelpers.extends({}, rest, {
open,
ref,
selectorPageContent,
onRequestClose,
title,
subtitle,
selectorPrimaryFocus,
id
}, devtools.getDevtoolsProps(componentName), {
placement: placement,
slideIn: slideIn,
animateTitle: false,
className: cx(blockClass, className),
size: size,
preventCloseOnClickOutside: true,
actions: actions
}), formTitle && /*#__PURE__*/React.createElement("h3", {
id: formTitleId,
className: `${blockClass}__form-title-text ${blockClass}__content-text`
}, formTitle), formDescription && /*#__PURE__*/React.createElement("p", {
className: `${blockClass}__form-description-text ${blockClass}__content-text`
}, formDescription), /*#__PURE__*/React.createElement(react.Form, {
className: `${blockClass}__form`,
"aria-labelledby": formTitleId
}, children));
});
/**@ts-ignore*/
exports.EditSidePanel.deprecated = {
level: 'warn',
details: `This component is deprecated and will be removed in the next major version.`
};
// Return a placeholder if not released and not enabled by feature flag
exports.EditSidePanel = settings.pkg.checkComponentEnabled(exports.EditSidePanel, componentName);
// The display name of the component, used by React. Note that displayName
// is used in preference to relying on function.name.
exports.EditSidePanel.displayName = componentName;
// The types and DocGen commentary for the component props,
// in alphabetical order (for consistency).
// See https://www.npmjs.com/package/prop-types#usage.
exports.EditSidePanel.propTypes = {
/**
* Sets the body content of the create side panel
*/
/**@ts-ignore*/
children: index.default.oneOfType([index.default.arrayOf(index.default.node), index.default.node]).isRequired,
/**
* Provide an optional class to be applied to the containing node.
*/
className: index.default.string,
/**
* 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: index.default.bool,
/**
* Specifies an optional field that provides a additional context for a form
*/
formDescription: index.default.node,
/**
* Specifies a required field that provides a title for a form
*/
formTitle: index.default.node.isRequired,
/**
* Unique identifier
*/
id: index.default.string,
/**
* Specifies an optional handler which is called when the CreateSidePanel
* is closed.
*/
onRequestClose: index.default.func,
/**
* Specifies an optional handler which is called when the CreateSidePanel
* primary button is pressed.
*/
onRequestSubmit: index.default.func,
/**
* Specifies whether the CreateSidePanel is open or not.
*/
open: index.default.bool.isRequired,
/**
* Determines if the side panel is on the right or left
*/
placement: index.default.oneOf(['left', 'right']),
/**
* Specifies the primary button's text in the modal.
*/
primaryButtonText: index.default.string.isRequired,
/**
* Specifies the secondary button's text in the modal.
*/
secondaryButtonText: index.default.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.
*/
/**@ts-ignore*/
selectorPageContent: index.default.string.isRequired.if(_ref2 => {
let {
slideIn
} = _ref2;
return slideIn;
}),
/**
* Specifies which DOM element in the form should be focused.
*/
/**@ts-ignore*/
selectorPrimaryFocus: index.default.node.isRequired,
/**
* Sets the size of the side panel
*/
size: index.default.oneOf(['xs', 'sm', 'md', 'lg', '2xl']),
/**
* Specifies which DOM element in the form should be focused.
*/
slideIn: index.default.bool,
/**
* **Experimental:** Provide a `Slug` component to be rendered inside the `SidePanel` component
*/
slug: index.default.node,
/**
* The subtitle of the CreateSidePanel is optional and serves to provide more information about the modal.
*/
subtitle: index.default.node,
/**
* The title of the CreateSidePanel is usually the product or service name.
*/
/**@ts-ignore*/
title: index.default.node.isRequired
};