@carbon/ibm-products
Version:
Carbon for IBM Products
150 lines (145 loc) • 4.93 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 { EmptyStateV2 } from './EmptyStateV2.js';
import './ErrorEmptyState/ErrorEmptyState.js';
import './NoDataEmptyState/NoDataEmptyState.js';
import './NoTagsEmptyState/NoTagsEmptyState.js';
import './NotFoundEmptyState/NotFoundEmptyState.js';
import './NotificationsEmptyState/NotificationsEmptyState.js';
import './UnauthorizedEmptyState/UnauthorizedEmptyState.js';
import PropTypes from '../../_virtual/index.js';
import cx from 'classnames';
import { Button } from '@carbon/react';
import { getDevtoolsProps } from '../../global/js/utils/devtools.js';
import '../../global/js/utils/props-helper.js';
import { pkg } from '../../settings.js';
import { EmptyStateContent } from './EmptyStateContent.js';
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--empty-state`;
const componentName = 'EmptyState';
var sizes = /*#__PURE__*/function (sizes) {
sizes["lg"] = "lg";
sizes["sm"] = "sm";
return sizes;
}(sizes || {}); // Default values for props
const defaults = {
position: 'top',
size: sizes.lg
};
/**
* 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 EmptyState = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
let {
v2 = false,
...props
} = _ref;
// todo: deprecate v1
if (v2) {
return /*#__PURE__*/React__default.createElement(EmptyStateV2, props);
}
const {
action,
className,
illustration,
illustrationDescription,
illustrationPosition = defaults.position,
link,
size = defaults.size,
headingAs,
subtitle,
title,
...rest
} = props;
return /*#__PURE__*/React__default.createElement("div", _extends({}, rest, {
className: cx(blockClass, `${blockClass}-type--default`, className, {
[`${blockClass}-position--${illustrationPosition}`]: !!illustration
}),
ref: ref
}, getDevtoolsProps(componentName)), illustration && /*#__PURE__*/React__default.createElement("img", {
src: illustration,
alt: illustrationDescription,
className: cx([`${blockClass}__illustration`, `${blockClass}__illustration--${size}`]),
"aria-hidden": "true"
}), /*#__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
EmptyState = pkg.checkComponentEnabled(EmptyState, componentName);
EmptyState.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,
/**
* Empty state illustration, specify the `src` for a provided illustration to be displayed. In the case of requiring a light and dark illustration of your own, simply pass the corresponding illustration based on the current theme of your application.
* For example: `illustration={appTheme === 'dark' ? darkIllustration : lightIllustration}`
*/
illustration: PropTypes.string,
/**
* The alt text for custom provided illustrations
*/
/**@ts-ignore*/
illustrationDescription: PropTypes.string.isRequired.if(_ref2 => {
let {
illustration
} = _ref2;
return illustration;
}),
/**
* Designates the position of the illustration relative to the content
*/
illustrationPosition: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
/**
* Empty state link object
*/
/**@ts-ignore*/
link: PropTypes.any,
/**
* Empty state size
*/
size: PropTypes.oneOf(['lg', 'sm']),
/**
* Empty state subtext
*/
subtitle: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
/**
* Empty state heading
*/
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
/**
* Designates which version of the EmptyState component is being used.
* Refer to V2 documentation separately.
*/
v2: PropTypes.bool
};
EmptyState.displayName = componentName;
export { EmptyState, defaults };