UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

94 lines (88 loc) 3.09 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. */ import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js'; import React__default from 'react'; import PropTypes from '../../_virtual/index.js'; import { pkg } from '../../settings.js'; import cx from 'classnames'; import { Button, Section, Heading, Link } from '@carbon/react'; // The block part of our conventional BEM class names (blockClass__E--M). const blockClass = `${pkg.prefix}--empty-state`; const componentName = 'EmptyStateContent'; const EmptyStateContent = /*#__PURE__*/React__default.forwardRef(props => { const { action, link, headingAs, size, subtitle, title } = props; const HeadingComponent = headingAs ?? Heading; return /*#__PURE__*/React__default.createElement(Section, { className: `${blockClass}__content` }, /*#__PURE__*/React__default.createElement(HeadingComponent, { className: cx(`${blockClass}__header`, { [`${blockClass}__header--small`]: size === 'sm' }) }, title), subtitle && /*#__PURE__*/React__default.createElement("p", { className: cx(`${blockClass}__subtitle`, { [`${blockClass}__subtitle--small`]: size === 'sm' }) }, subtitle), action?.text && action?.onClick && /*#__PURE__*/React__default.createElement(Button, _extends({}, action, { className: `${blockClass}__action-button`, kind: action.kind || 'tertiary', onClick: action.onClick, renderIcon: action.renderIcon ?? undefined, size: 'sm' }), action.text), link?.text && link?.href && /*#__PURE__*/React__default.createElement(Link, _extends({}, link, { className: `${blockClass}__link`, href: link.href }), link.text)); }); // The display name of the component, used by React. Note that displayName // is used in preference to relying on function.name. EmptyStateContent.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. EmptyStateContent.propTypes = { /** * Empty state action button */ action: PropTypes.shape({ /**@ts-ignore*/ ...Button.propTypes, iconDescription: PropTypes.string, kind: PropTypes.oneOf(['primary', 'secondary', 'tertiary']), renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]), /**@ts-ignore*/ onClick: Button.propTypes.onClick, text: PropTypes.string }), /** * Empty state headingAs allows you to customize the type of heading element */ headingAs: PropTypes.elementType, /** * Empty state link object */ 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 { EmptyStateContent };