@carbon/ibm-products
Version:
Carbon for IBM Products
226 lines (212 loc) • 8.18 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');
var React = require('react');
var ProductiveCard = require('../ProductiveCard/ProductiveCard.js');
var index = require('../../_virtual/index.js');
var cx = require('classnames');
var devtools = require('../../global/js/utils/devtools.js');
var settings = require('../../settings.js');
// Carbon and package components we use.
/* TODO: @import(s) of carbon components and other package components. */
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${settings.pkg.prefix}--edit-update-cards`;
const componentName = 'EditUpdateCards';
// NOTE: the component SCSS is not imported here: it is rolled up separately.
// Default values can be included here and then assigned to the prop params,
// e.g. prop = defaults.prop,
// This gathers default values together neatly and ensures non-primitive
// values are initialized early to avoid react making unnecessary re-renders.
// Note that default values are not required for props that are 'required',
// nor for props where the component can apply undefined values reasonably.
// Default values should be provided when the component needs to make a choice
// or assumption when a prop is not supplied.
// Default values for props
// const defaults = {
// /* TODO: add defaults for relevant props if needed */
// };
/**
* **This component is deprecated.** <br>
Editable cards allow a user to view, modify, and save the content contained within the card.
These cards are generally used in instances where a user needs to make changes to a resource instances
(ex. configuration details), account plan, etc. Editable cards allow a user to edit something within context.
@deprecated
*/
exports.EditUpdateCards = /*#__PURE__*/React.forwardRef((_ref, ref) => {
let {
// The component props, in alphabetical order (for consistency).
actionIcons,
actionsPlacement,
className,
description,
editChildren,
editMode,
label,
onPrimaryButtonClick,
onSecondaryButtonClick,
previewChildren,
title,
titleSize,
primaryButtonIcon,
primaryButtonText,
secondaryButtonIcon,
secondaryButtonText,
// Collect any other property values passed in.
...rest
} = _ref;
// const [editCardMode, setEditCardMode] = useState(editMode);
const conditionalProps = {
onPrimaryButtonClick: onPrimaryButtonClick,
onSecondaryButtonClick: onSecondaryButtonClick,
primaryButtonIcon: primaryButtonIcon,
primaryButtonKind: 'ghost',
primaryButtonPlacement: 'top',
primaryButtonText: primaryButtonText,
secondaryButtonIcon: secondaryButtonIcon,
secondaryButtonKind: 'ghost',
secondaryButtonPlacement: 'top',
secondaryButtonText: secondaryButtonText
};
return /*#__PURE__*/React.createElement("div", _rollupPluginBabelHelpers.extends({}, rest, {
className: cx(blockClass,
// Apply the block class to the main HTML element
className,
// Apply any supplied class names to the main HTML element.
// example: `${blockClass}__template-string-class-${kind}-n-${size}`,
{
// switched classes dependant on props or state
// example: [`${blockClass}__here-if-small`]: size === 'sm',
[`${blockClass}__actions-bottom`]: actionsPlacement === 'bottom'
}),
ref: ref
}, devtools.getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement(ProductiveCard.ProductiveCard, _rollupPluginBabelHelpers.extends({
actionIcons: actionIcons,
actionsPlacement: actionsPlacement,
className: className,
description: description,
label: label,
title: title,
titleSize: titleSize
}, editMode && conditionalProps), editMode === false && /*#__PURE__*/React.createElement("div", null, previewChildren), editMode && /*#__PURE__*/React.createElement("div", null, editChildren)));
});
/**@ts-ignore*/
exports.EditUpdateCards.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.EditUpdateCards = settings.pkg.checkComponentEnabled(exports.EditUpdateCards, componentName);
// The display name of the component, used by React. Note that displayName
// is used in preference to relying on function.name.
exports.EditUpdateCards.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.EditUpdateCards.propTypes = {
/**
* Icons that are displayed on the card. Refer to design documentation for implementation guidelines. Note: href is deprecated. Set link.href for href functionality. If you are setting link object, href is a required property. link object supports all anchor element properties. Precedence: link.href > href. If link.href or href is set => anchor element, else button.
*/
/**@ts-ignore */
actionIcons: index.default.arrayOf(index.default.shape({
id: index.default.string,
icon: index.default.oneOfType([index.default.func, index.default.object]),
onKeyDown: index.default.func,
onClick: index.default.func,
iconDescription: index.default.string,
/**
* @deprecated please use the `link.href` instead
*/
href: index.default.string,
link: index.default.shape({
href: index.default.string.isRequired
})
})),
/**
* Determines if the action icons are on the top or bottom of the card
*/
actionsPlacement: index.default.oneOf(['top', 'bottom']),
/**
* Optional label for the top of the card.
*/
className: index.default.string,
/**
* Optional header description
*/
description: index.default.string,
/**
* Edit mode children
*/
editChildren: index.default.node,
/**
* Edit mode
*/
editMode: index.default.bool,
/**
* Optional label for the top of the card
*/
label: index.default.string,
/**
* Function that's called from the primary button or action icon
*/
onPrimaryButtonClick: index.default.func,
/**
* Function that's called from the secondary button or action icon
*/
onSecondaryButtonClick: index.default.func,
/**
* Preview mode children
*/
previewChildren: index.default.node,
/**
* Optional prop to allow overriding the icon rendering. Can be a React component class
*/
/**@ts-ignore */
primaryButtonIcon: index.default.oneOfType([index.default.func, index.default.object]),
/**
* Establishes the kind of button displayed for the primary button
*/
primaryButtonKind: index.default.oneOf(['primary', 'ghost']),
/**
* Determines if the primary button is on the top or bottom of the card
*/
primaryButtonPlacement: index.default.oneOf(['top', 'bottom']),
/**
* The text that's displayed in the primary button
*/
primaryButtonText: index.default.string,
/**
* Optionally specify an href for your Button to become an <a> element
*/
secondaryButtonHref: index.default.string,
/**
* Optional prop to allow overriding the icon rendering. Can be a React component class
*/
/**@ts-ignore */
secondaryButtonIcon: index.default.oneOfType([index.default.func, index.default.object]),
/**
* Establishes the kind of button displayed for the secondary button
*/
secondaryButtonKind: index.default.oneOf(['secondary', 'ghost']),
/**
* Determines if the secondary button is on the top or bottom of the card
*/
secondaryButtonPlacement: index.default.oneOf(['top', 'bottom']),
/**
* The text that's displayed in the secondary button
*/
secondaryButtonText: index.default.string,
/**
* Title that's displayed at the top of the card
*/
title: index.default.string,
/**
* Determines title size
*/
titleSize: index.default.oneOf(['default', 'large'])
/* TODO: add types and DocGen for all props. */
};