UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

152 lines (146 loc) 5.12 kB
/** * 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 EmptyStateV2 = require('./EmptyStateV2.js'); require('./ErrorEmptyState/ErrorEmptyState.js'); require('./NoDataEmptyState/NoDataEmptyState.js'); require('./NoTagsEmptyState/NoTagsEmptyState.js'); require('./NotFoundEmptyState/NotFoundEmptyState.js'); require('./NotificationsEmptyState/NotificationsEmptyState.js'); require('./UnauthorizedEmptyState/UnauthorizedEmptyState.js'); var index = require('../../_virtual/index.js'); var cx = require('classnames'); var react = require('@carbon/react'); var devtools = require('../../global/js/utils/devtools.js'); require('../../global/js/utils/props-helper.js'); var settings = require('../../settings.js'); var EmptyStateContent = require('./EmptyStateContent.js'); // The block part of our conventional BEM class names (blockClass__E--M). const blockClass = `${settings.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. */ exports.EmptyState = /*#__PURE__*/React.forwardRef((_ref, ref) => { let { v2 = false, ...props } = _ref; // todo: deprecate v1 if (v2) { return /*#__PURE__*/React.createElement(EmptyStateV2.EmptyStateV2, props); } const { action, className, illustration, illustrationDescription, illustrationPosition = defaults.position, link, size = defaults.size, headingAs, subtitle, title, ...rest } = props; return /*#__PURE__*/React.createElement("div", _rollupPluginBabelHelpers.extends({}, rest, { className: cx(blockClass, `${blockClass}-type--default`, className, { [`${blockClass}-position--${illustrationPosition}`]: !!illustration }), ref: ref }, devtools.getDevtoolsProps(componentName)), illustration && /*#__PURE__*/React.createElement("img", { src: illustration, alt: illustrationDescription, className: cx([`${blockClass}__illustration`, `${blockClass}__illustration--${size}`]), "aria-hidden": "true" }), /*#__PURE__*/React.createElement(EmptyStateContent.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 exports.EmptyState = settings.pkg.checkComponentEnabled(exports.EmptyState, componentName); exports.EmptyState.propTypes = { /** * Empty state action button */ action: index.default.shape({ /**@ts-ignore*/ ...react.Button.propTypes, kind: index.default.oneOf(['primary', 'secondary', 'tertiary']), renderIcon: index.default.oneOfType([index.default.func, index.default.object]), /**@ts-ignore*/ onClick: react.Button.propTypes.onClick, text: index.default.string }), /** * Provide an optional class to be applied to the containing node. */ className: index.default.string, /** * Empty state headingAs allows you to customize the type of heading element */ headingAs: index.default.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: index.default.string, /** * The alt text for custom provided illustrations */ /**@ts-ignore*/ illustrationDescription: index.default.string.isRequired.if(_ref2 => { let { illustration } = _ref2; return illustration; }), /** * Designates the position of the illustration relative to the content */ illustrationPosition: index.default.oneOf(['top', 'right', 'bottom', 'left']), /** * Empty state link object */ /**@ts-ignore*/ link: index.default.any, /** * Empty state size */ size: index.default.oneOf(['lg', 'sm']), /** * Empty state subtext */ subtitle: index.default.oneOfType([index.default.string, index.default.node]), /** * Empty state heading */ title: index.default.oneOfType([index.default.string, index.default.node]).isRequired, /** * Designates which version of the EmptyState component is being used. * Refer to V2 documentation separately. */ v2: index.default.bool }; exports.EmptyState.displayName = componentName; exports.defaults = defaults;