UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

125 lines (117 loc) 4.51 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 index = require('../../../_virtual/index.js'); var cx = require('classnames'); var react = require('@carbon/react'); var devtools = require('../../../global/js/utils/devtools.js'); var settings = require('../../../settings.js'); var EmptyStateContent = require('../EmptyStateContent.js'); var NoDataIllustration = require('../assets/NoDataIllustration.js'); var EmptyState = require('../EmptyState.js'); // The block part of our conventional BEM class names (blockClass__E--M). const blockClass = `${settings.pkg.prefix}--empty-state`; const componentName = 'NoDataEmptyState'; /** * 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.NoDataEmptyState = /*#__PURE__*/React.forwardRef((_ref, ref) => { let { // The component props, in alphabetical order (for consistency). action, className, illustrationPosition = EmptyState.defaults.position, illustrationTheme, illustrationDescription, link, size = EmptyState.defaults.size, headingAs, subtitle, title, // Collect any other property values passed in. ...rest } = _ref; return /*#__PURE__*/React.createElement("div", _rollupPluginBabelHelpers.extends({}, rest, { className: cx(blockClass, className, `${blockClass}-position--${illustrationPosition}`, `${blockClass}-type--noData`), ref: ref }, devtools.getDevtoolsProps(componentName)), /*#__PURE__*/React.createElement(NoDataIllustration.NoDataIllustration, { theme: illustrationTheme, size: size, alt: illustrationDescription || title }), /*#__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.NoDataEmptyState = settings.pkg.checkComponentEnabled(exports.NoDataEmptyState, componentName); // The display name of the component, used by React. Note that displayName // is used in preference to relying on function.name. exports.NoDataEmptyState.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.NoDataEmptyState.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, /** * The alt text for empty state svg images. If not provided , title will be used. */ illustrationDescription: index.default.string, /** * Designates the position of the illustration relative to the content */ illustrationPosition: index.default.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: index.default.oneOf(['light', 'dark']), /** * Empty state link object */ /**@ts-ignore */ link: index.default.any, /** * Empty state size */ size: index.default.oneOf(['lg', 'sm']), /** * Empty state subtitle */ subtitle: index.default.oneOfType([index.default.string, index.default.node]), /** * Empty state title */ title: index.default.oneOfType([index.default.string, index.default.node]).isRequired };