@carbon/ibm-products
Version:
Carbon for IBM Products
125 lines (117 loc) • 4.32 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.
*/
import { extends as _extends } from '../../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import PropTypes from '../../../_virtual/index.js';
import { Button } from '@carbon/react';
import cx from 'classnames';
import { getDevtoolsProps } from '../../../global/js/utils/devtools.js';
import { pkg } from '../../../settings.js';
import { EmptyStateContent } from '../EmptyStateContent.js';
import { ErrorIllustration } from '../assets/ErrorIllustration.js';
import { defaults } from '../EmptyState.js';
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
const componentName = 'ErrorEmptyState';
/**
* The `EmptyState` component follows the Carbon guidelines for empty states with some added specifications around illustration usage. For additional usage guidelines and documentation please refer to the links above.
*/
let ErrorEmptyState = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
let {
// The component props, in alphabetical order (for consistency).
action,
className,
illustrationPosition = defaults.position,
illustrationDescription,
illustrationTheme,
link,
size = defaults.size,
headingAs,
subtitle,
title,
// Collect any other property values passed in.
...rest
} = _ref;
return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
className: cx(blockClass, className, `${blockClass}-position--${illustrationPosition}`, `${blockClass}-type--error`),
ref: ref
}, getDevtoolsProps(componentName)), /*#__PURE__*/React__default.createElement(ErrorIllustration, {
theme: illustrationTheme,
size: size,
alt: illustrationDescription || title
}), /*#__PURE__*/React__default.createElement(EmptyStateContent, {
action: action,
link: link,
size: size,
headingAs: headingAs,
subtitle: subtitle,
title: title || ''
}));
});
// Return a placeholder if not released and not enabled by feature flag
ErrorEmptyState = pkg.checkComponentEnabled(ErrorEmptyState, componentName);
// The display name of the component, used by React. Note that displayName
// is used in preference to relying on function.name.
ErrorEmptyState.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.
ErrorEmptyState.propTypes = {
/**
* Empty state action button
*/
action: PropTypes.shape({
/**@ts-ignore*/
...Button.propTypes,
kind: PropTypes.oneOf(['primary', 'secondary', 'tertiary']),
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
/**@ts-ignore*/
onClick: Button.propTypes.onClick,
text: PropTypes.string
}),
/**
* Provide an optional class to be applied to the containing node.
*/
className: PropTypes.string,
/**
* Empty state headingAs allows you to customize the type of heading element
*/
headingAs: PropTypes.elementType,
/**
* The alt text for empty state svg images. If not provided , title will be used.
*/
illustrationDescription: PropTypes.string,
/**
* Designates the position of the illustration relative to the content
*/
illustrationPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
/**
* Empty state illustration theme variations.
* To ensure you use the correct themed illustrations, you can conditionally specify light or dark
* based on your app's current theme value. Example:
* `illustrationTheme={appTheme === ('carbon--g100' || 'carbon--g90') ? 'dark' : 'light'}`
*/
illustrationTheme: PropTypes.oneOf(['light', 'dark']),
/**
* Empty state link object
*/
/**@ts-ignore*/
link: PropTypes.any,
/**
* Empty state size
*/
size: PropTypes.oneOf(['lg', 'sm']),
/**
* Empty state subtitle
*/
subtitle: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Empty state title
*/
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired
};
export { ErrorEmptyState };