@carbon/react
Version:
React components for the Carbon Design System
92 lines (87 loc) • 2.71 kB
JavaScript
/**
* 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.
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import PropTypes from 'prop-types';
import React from 'react';
import cx from 'classnames';
import { usePrefix } from '../../internal/usePrefix.js';
import { CircleStroke, LowSeverity, CircleFill, DiamondFill, Caution, CriticalSeverity, Critical } from '@carbon/icons-react';
var _path;
const ShapeIndicatorKinds = ['failed', 'critical', 'high', 'medium', 'low', 'cautious', 'undefined', 'stable', 'informative', 'incomplete', 'draft'];
// TODO: update to import '@carbon/icons-react'
const incompleteIcon = props => /*#__PURE__*/React.createElement("svg", _extends({
xmlns: "http://www.w3.org/2000/svg",
width: 16,
height: 16,
fill: "none",
"aria-hidden": "true"
}, props), /*#__PURE__*/React.createElement("path", {
fill: "#fff",
fillOpacity: 0.01,
d: "M0 0h16v16H0z",
style: {
mixBlendMode: 'multiply'
}
}), _path || (_path = /*#__PURE__*/React.createElement("path", {
fill: "#161616",
d: "M8 2a6 6 0 1 0 0 12A6 6 0 0 0 8 2Zm0 2a4.004 4.004 0 0 1 4 4H4a4.004 4.004 0 0 1 4-4Z"
})));
const shapeTypes = {
failed: Critical,
critical: CriticalSeverity,
high: Caution,
medium: DiamondFill,
low: LowSeverity,
cautious: Caution,
undefined: DiamondFill,
stable: CircleFill,
informative: LowSeverity,
incomplete: incompleteIcon,
draft: CircleStroke
};
const ShapeIndicator = /*#__PURE__*/React.forwardRef(function ShapeIndicatorContent({
className: customClassName,
kind,
label,
textSize = 12,
...rest
}, ref) {
const prefix = usePrefix();
const classNames = cx(`${prefix}--shape-indicator`, customClassName, {
[`${prefix}--shape-indicator--14`]: textSize == 14
});
const ShapeForKind = shapeTypes[kind];
if (!ShapeForKind) {
return null;
}
return /*#__PURE__*/React.createElement("div", {
className: classNames,
ref: ref
}, /*#__PURE__*/React.createElement(ShapeForKind, {
size: 16,
className: `${prefix}--shape-indicator--${kind}`
}), label);
});
ShapeIndicator.propTypes = {
/**
* Specify an optional className to add.
*/
className: PropTypes.string,
/**
* Specify the kind of the Shape Indicator
*/
kind: PropTypes.oneOf(ShapeIndicatorKinds).isRequired,
/**
* Label next to the shape.
*/
label: PropTypes.string.isRequired,
/**
* Specify the text size of the Shape Indicator. Defaults to 12.
*/
textSize: PropTypes.oneOf([12, 14])
};
export { ShapeIndicator, ShapeIndicatorKinds, ShapeIndicator as default };