@carbon/ibm-products
Version:
Carbon for IBM Products
103 lines (91 loc) • 3.52 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.
*/
;
var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var index = require('../../_virtual/index.js');
var cx = require('classnames');
var devtools = require('../../global/js/utils/devtools.js');
var settings = require('../../settings.js');
var icons = require('@carbon/react/icons');
var Checklist_types = require('./Checklist.types.js');
// The block part of our conventional BEM class names (blockClass__E--M).
const blockClass = `${settings.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: Checklist_types.Themes.light
};
/**
* TODO: A description of the component.
*/
let ChecklistIcon = /*#__PURE__*/React.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 = icons.Warning;
break;
case 'indeterminate':
Icon = icons.Incomplete;
break;
case 'checked':
Icon = icons.CheckmarkOutline;
break;
default:
// "unchecked" or "disabled"
Icon = icons.CircleDash;
break;
}
return /*#__PURE__*/React.createElement("span", _rollupPluginBabelHelpers.extends({}, rest, {
className: cx(blockClass, className, `${blockClass}--${kind}`, `${blockClass}__${theme}`),
ref: ref
}, devtools.getDevtoolsProps(componentName)), /*#__PURE__*/React.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: index.default.string,
/**
* The icon to be displayed.
*/
kind: index.default.oneOf([Checklist_types.Kinds.unchecked, Checklist_types.Kinds.indeterminate, Checklist_types.Kinds.checked, Checklist_types.Kinds.disabled, Checklist_types.Kinds.error]),
/**
* Determines the theme of the component.
*/
theme: index.default.oneOf([Checklist_types.Themes.light, Checklist_types.Themes.dark])
};
exports.ChecklistIcon = ChecklistIcon;