@carbon/ibm-products
Version:
Carbon for IBM Products
96 lines (89 loc) • 3.21 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.
*/
'use strict';
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var index = require('../../_virtual/index.js');
var settings = require('../../settings.js');
var cx = require('classnames');
var react = require('@carbon/react');
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${settings.pkg.prefix}--empty-state`;
const componentName = 'EmptyStateContent';
const EmptyStateContent = /*#__PURE__*/React.forwardRef(props => {
const {
action,
link,
headingAs,
size,
subtitle,
title
} = props;
const HeadingComponent = headingAs ?? react.Heading;
return /*#__PURE__*/React.createElement(react.Section, {
className: `${blockClass}__content`
}, /*#__PURE__*/React.createElement(HeadingComponent, {
className: cx(`${blockClass}__header`, {
[`${blockClass}__header--small`]: size === 'sm'
})
}, title), subtitle && /*#__PURE__*/React.createElement("p", {
className: cx(`${blockClass}__subtitle`, {
[`${blockClass}__subtitle--small`]: size === 'sm'
})
}, subtitle), action?.text && action?.onClick && /*#__PURE__*/React.createElement(react.Button, _rollupPluginBabelHelpers.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.createElement(react.Link, _rollupPluginBabelHelpers.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: index.default.shape({
/**@ts-ignore*/
...react.Button.propTypes,
iconDescription: index.default.string,
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
}),
/**
* Empty state headingAs allows you to customize the type of heading element
*/
headingAs: index.default.elementType,
/**
* Empty state link object
*/
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
};
exports.EmptyStateContent = EmptyStateContent;