diff --git a/packages/ibm-products/src/components/StatusIcon/StatusIcon.js b/packages/ibm-products/src/components/StatusIcon/StatusIcon.js deleted file mode 100644 index aad89dc9e2..0000000000 --- a/packages/ibm-products/src/components/StatusIcon/StatusIcon.js +++ /dev/null @@ -1,259 +0,0 @@ -/** - * Copyright IBM Corp. 2021, 2022 - * - * 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 React, { forwardRef } from 'react'; -import PropTypes from 'prop-types'; -import cx from 'classnames'; - -import { - Misuse, - ErrorFilled, - WarningAltInvertedFilled, - WarningAltFilled, - UndefinedFilled, - UnknownFilled, - CheckmarkFilled, - InformationSquareFilled, - InProgress, - CheckmarkOutline, - Pending, -} from '@carbon/react/icons'; - -import { getDevtoolsProps } from '../../global/js/utils/devtools'; -import { pkg } from '../../settings'; - -const blockClass = `${pkg.prefix}--status-icon`; -const componentName = 'StatusIcon'; - -/** -The `StatusIcon` component follows the Carbon guidelines for status icons with -some added specifications around illustration usage. For additional usage -guidelines and documentation please refer to the links above. - -_Status icons_ are an important method of communicating severity level -information to users. The shapes and colors, communicate severity that enable -users to quickly assess and identify status and respond accordingly. - */ -export let StatusIcon = forwardRef( - ({ kind, theme, size, className, iconDescription, ...rest }, ref) => { - const icons = { - fatal: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - critical: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - 'major-warning': { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - 'minor-warning': { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - undefined: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - unknown: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - normal: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - info: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - 'in-progress': { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - running: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - pending: { - sm: forwardRef((props, ref) => ( - - )), - md: forwardRef((props, ref) => ( - - )), - lg: forwardRef((props, ref) => ( - - )), - xl: forwardRef((props, ref) => ( - - )), - }, - }; - - const IconComponent = icons[kind]?.[size]; - - const classNames = cx(className, blockClass, `${blockClass}--${theme}`, { - [`${blockClass}--${theme}-${kind}`]: kind, - }); - - return ( - IconComponent && ( - - {iconDescription} - - ) - ); - } -); - -StatusIcon = pkg.checkComponentEnabled(StatusIcon, componentName); - -StatusIcon.displayName = componentName; - -StatusIcon.propTypes = { - /** - * Provide an optional class to be applied to the modal root node. - */ - className: PropTypes.string, - /** - * A required prop that provides a title element and tooltip for the icon for accessibility purposes - */ - iconDescription: PropTypes.string.isRequired, - /** - * A required prop that displays the respective icon associated with the status - */ - kind: PropTypes.oneOf([ - 'fatal', - 'critical', - 'major-warning', - 'minor-warning', - 'undefined', - 'unknown', - 'normal', - 'info', - 'in-progress', - 'running', - 'pending', - ]).isRequired, - - /** - * A required prop that displays the size of the icon associate with the status - */ - size: PropTypes.oneOf(['sm', 'md', 'lg', 'xl']).isRequired, - - /** - * A required prop that displays the theme of the icon associated with the status - */ - theme: PropTypes.oneOf(['light', 'dark']).isRequired, -}; diff --git a/packages/ibm-products/src/components/StatusIcon/StatusIcon.tsx b/packages/ibm-products/src/components/StatusIcon/StatusIcon.tsx new file mode 100644 index 0000000000..52b43eff43 --- /dev/null +++ b/packages/ibm-products/src/components/StatusIcon/StatusIcon.tsx @@ -0,0 +1,306 @@ +/** + * Copyright IBM Corp. 2021, 2022 + * + * 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 React, { + PropsWithChildren, + ReactSVGElement, + forwardRef, + Ref, +} from 'react'; +import PropTypes from 'prop-types'; +import cx from 'classnames'; + +import { + Misuse, + ErrorFilled, + WarningAltInvertedFilled, + WarningAltFilled, + UndefinedFilled, + UnknownFilled, + CheckmarkFilled, + InformationSquareFilled, + InProgress, + CheckmarkOutline, + Pending, +} from '@carbon/react/icons'; + +import { getDevtoolsProps } from '../../global/js/utils/devtools'; +import { pkg } from '../../settings'; + +const blockClass = `${pkg.prefix}--status-icon`; +const componentName = 'StatusIcon'; + +/** +The `StatusIcon` component follows the Carbon guidelines for status icons with +some added specifications around illustration usage. For additional usage +guidelines and documentation please refer to the links above. + +_Status icons_ are an important method of communicating severity level +information to users. The shapes and colors, communicate severity that enable +users to quickly assess and identify status and respond accordingly. + */ + +type Size = 'sm' | 'md' | 'lg' | 'xl'; +type Theme = 'light' | 'dark'; +type Kind = + | 'fatal' + | 'critical' + | 'major-warning' + | 'minor-warning' + | 'undefined' + | 'unknown' + | 'normal' + | 'info' + | 'in-progress' + | 'running' + | 'pending'; +interface StatusIconProps extends PropsWithChildren { + /** + * Provide an optional class to be applied to the modal root node. + */ + className?: string; + /** + * A required prop that provides a title element and tooltip for the icon for accessibility purposes + */ + iconDescription: string; + /** + * A required prop that displays the respective icon associated with the status + */ + kind: Kind; + /** + * A required prop that displays the size of the icon associate with the status + */ + size: Size; + /** + * A required prop that displays the theme of the icon associated with the status + */ + theme: Theme; +} +export let StatusIcon = forwardRef( + ( + { kind, theme, size, className, iconDescription, ...rest }: StatusIconProps, + ref + ) => { + const forwardedRef = ref as Ref; + + const icons = { + fatal: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + critical: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + 'major-warning': { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + 'minor-warning': { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + undefined: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + unknown: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + normal: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + info: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + 'in-progress': { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + running: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + pending: { + sm: forwardRef((props, _ref) => ( + + )), + md: forwardRef((props, _ref) => ( + + )), + lg: forwardRef((props, _ref) => ( + + )), + xl: forwardRef((props, _ref) => ( + + )), + }, + }; + + const IconComponent = icons[kind]?.[size]; + + const classNames = cx(className, blockClass, `${blockClass}--${theme}`, { + [`${blockClass}--${theme}-${kind}`]: kind, + }); + + return ( + IconComponent && ( + + {iconDescription} + + ) + ); + } +); + +StatusIcon = pkg.checkComponentEnabled(StatusIcon, componentName); + +StatusIcon.displayName = componentName; + +StatusIcon.propTypes = { + /** + * Provide an optional class to be applied to the modal root node. + */ + className: PropTypes.string, + /** + * A required prop that provides a title element and tooltip for the icon for accessibility purposes + */ + iconDescription: PropTypes.string.isRequired, + /** + * A required prop that displays the respective icon associated with the status + */ + kind: PropTypes.oneOf([ + 'fatal', + 'critical', + 'major-warning', + 'minor-warning', + 'undefined', + 'unknown', + 'normal', + 'info', + 'in-progress', + 'running', + 'pending', + ]).isRequired, + /** + * A required prop that displays the size of the icon associate with the status + */ + size: PropTypes.oneOf(['sm', 'md', 'lg', 'xl']).isRequired, + /** + * A required prop that displays the theme of the icon associated with the status + */ + theme: PropTypes.oneOf(['light', 'dark']).isRequired, +};