UNPKG

@carbon/ibm-products

Version:
127 lines (125 loc) 4.16 kB
/** * Copyright IBM Corp. 2020, 2026 * * 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 { __toESM } from "../../_virtual/_rolldown/runtime.js"; import { require_classnames } from "../../node_modules/classnames/index.js"; import { pkg } from "../../settings.js"; import { getDevtoolsProps } from "../../global/js/utils/devtools.js"; import "../../global/js/utils/props-helper.js"; import { EmptyStateV2 } from "./EmptyStateV2.deprecated.js"; import { EmptyStateContent } from "./EmptyStateContent.js"; import React from "react"; import PropTypes from "prop-types"; import { Button } from "@carbon/react"; //#region src/components/EmptyStates/EmptyState.tsx /** * 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. */ var import_classnames = /* @__PURE__ */ __toESM(require_classnames()); const blockClass = `${pkg.prefix}--empty-state`; const componentName = "EmptyState"; const defaults = { position: "top", size: "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. */ const EmptyState = React.forwardRef(({ v2 = false, ...props }, ref) => { if (v2) return /* @__PURE__ */ React.createElement(EmptyStateV2, props); const { action, className, illustration, illustrationDescription, illustrationPosition = defaults.position, link, size = defaults.size, headingAs, subtitle, title, ...rest } = props; return /* @__PURE__ */ React.createElement("div", { ...rest, className: (0, import_classnames.default)(blockClass, `${blockClass}-type--default`, className, { [`${blockClass}-position--${illustrationPosition}`]: !!illustration }), ref, ...getDevtoolsProps(componentName) }, illustration && /* @__PURE__ */ React.createElement("img", { src: illustration, alt: illustrationDescription, className: (0, import_classnames.default)([`${blockClass}__illustration`, `${blockClass}__illustration--${size}`]), "aria-hidden": "true" }), /* @__PURE__ */ React.createElement(EmptyStateContent, { action, link, size, headingAs, subtitle, title: title ?? "" })); }); 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, /** * 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.node, /** * Empty state heading */ title: PropTypes.node.isRequired, /** * **Deprecated:** Designates which version of the EmptyState component is being used. Refer to V2 documentation separately. * @deprecated */ v2: PropTypes.bool }; EmptyState.displayName = componentName; //#endregion export { EmptyState, defaults };