@carbon/ibm-products
Version:
Carbon for IBM Products
101 lines (90 loc) • 3.36 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.
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import PropTypes from '../../_virtual/index.js';
import cx from 'classnames';
import { getDevtoolsProps } from '../../global/js/utils/devtools.js';
import { pkg } from '../../settings.js';
import { CircleDash, CheckmarkOutline, Incomplete, Warning } from '@carbon/react/icons';
import { Themes, Kinds } from './Checklist.types.js';
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${pkg.prefix}--checklist__icon`;
const componentName = 'ChecklistIcon';
// NOTE: the component SCSS is not imported here: it is rolled up separately.
// Default values can be included here and then assigned to the prop params,
// e.g. prop = defaults.prop,
// This gathers default values together neatly and ensures non-primitive
// values are initialized early to avoid react making unnecessary re-renders.
// Note that default values are not required for props that are 'required',
// nor for props where the component can apply undefined values reasonably.
// Default values should be provided when the component needs to make a choice
// or assumption when a prop is not supplied.
// Default values for props
const defaults = {
theme: Themes.light
};
/**
* TODO: A description of the component.
*/
let ChecklistIcon = /*#__PURE__*/React__default.forwardRef(
/**
* @param {{className?: string, kind?: import('./Checklist.types').Kind, theme?: import('./Checklist.types').Theme}} props type description
*/
(_ref, ref) => {
let {
className,
kind,
theme = defaults.theme,
...rest
} = _ref;
let Icon;
switch (kind) {
case 'error':
Icon = Warning;
break;
case 'indeterminate':
Icon = Incomplete;
break;
case 'checked':
Icon = CheckmarkOutline;
break;
default:
// "unchecked" or "disabled"
Icon = CircleDash;
break;
}
return /*#__PURE__*/React__default.createElement("span", _extends({}, rest, {
className: cx(blockClass, className, `${blockClass}--${kind}`, `${blockClass}__${theme}`),
ref: ref
}, getDevtoolsProps(componentName)), /*#__PURE__*/React__default.createElement(Icon, {
size: 16
}));
});
// Return a placeholder if not released and not enabled by feature flag
// ChecklistIcon = pkg.checkComponentEnabled(ChecklistIcon, componentName);
// The display name of the component, used by React. Note that displayName
// is used in preference to relying on function.name.
// ChecklistIcon.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.
ChecklistIcon.propTypes = {
/**
* Provide an optional class to be applied to the containing node.
*/
className: PropTypes.string,
/**
* The icon to be displayed.
*/
kind: PropTypes.oneOf([Kinds.unchecked, Kinds.indeterminate, Kinds.checked, Kinds.disabled, Kinds.error]),
/**
* Determines the theme of the component.
*/
theme: PropTypes.oneOf([Themes.light, Themes.dark])
};
export { ChecklistIcon };