UNPKG

@carbon/react

Version:

React components for the Carbon Design System

80 lines (74 loc) 2.57 kB
/** * Copyright IBM Corp. 2016, 2023 * * 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'; Object.defineProperty(exports, '__esModule', { value: true }); var PropTypes = require('prop-types'); var React = require('react'); var cx = require('classnames'); var usePrefix = require('../../internal/usePrefix.js'); var iconsReact = require('@carbon/icons-react'); const IconIndicatorKinds = ['failed', 'caution-major', 'caution-minor', 'undefined', 'succeeded', 'normal', 'in-progress', 'incomplete', 'not-started', 'pending', 'unknown', 'informative']; const iconTypes = { failed: iconsReact.ErrorFilled, ['caution-major']: iconsReact.WarningAltInvertedFilled, ['caution-minor']: iconsReact.WarningAltFilled, undefined: iconsReact.UndefinedFilled, succeeded: iconsReact.CheckmarkFilled, normal: iconsReact.CheckmarkOutline, ['in-progress']: iconsReact.InProgress, incomplete: iconsReact.Incomplete, ['not-started']: iconsReact.CircleDash, pending: iconsReact.PendingFilled, unknown: iconsReact.UnknownFilled, informative: iconsReact.WarningSquareFilled }; // eslint-disable-next-line react/display-name -- https://github.com/carbon-design-system/carbon/issues/20452 const IconIndicator = /*#__PURE__*/React.forwardRef(({ className: customClassName, kind, label, size = 16, // eslint-disable-next-line @typescript-eslint/no-unused-vars -- https://github.com/carbon-design-system/carbon/issues/20452 ...rest }, ref) => { const prefix = usePrefix.usePrefix(); const classNames = cx(`${prefix}--icon-indicator`, customClassName, { [`${prefix}--icon-indicator--20`]: size == 20 }); const IconForKind = iconTypes[kind]; if (!IconForKind) { return null; } return /*#__PURE__*/React.createElement("div", { className: classNames, ref: ref }, /*#__PURE__*/React.createElement(IconForKind, { size: size, className: `${prefix}--icon-indicator--${kind}` }), label); }); IconIndicator.propTypes = { /** * Specify an optional className to add. */ className: PropTypes.string, /** * Specify the kind of the Icon Indicator */ kind: PropTypes.oneOf(IconIndicatorKinds).isRequired, /** * Label next to the icon. */ label: PropTypes.string.isRequired, /** * Specify the size of the Icon Indicator. Defaults to 16. */ size: PropTypes.oneOf([16, 20]) }; exports.IconIndicator = IconIndicator; exports.IconIndicatorKinds = IconIndicatorKinds; exports.default = IconIndicator;