@mskcc/carbon-react
Version:
Carbon react components for the MSKCC DSM
97 lines (93 loc) • 3.01 kB
JavaScript
/**
* MSKCC 2021, 2024
*/
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
import React__default from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { ErrorFilled, CheckmarkFilled } from '@carbon/icons-react';
import Loading from '../Loading/Loading.js';
import { usePrefix } from '../../internal/usePrefix.js';
const InlineLoading = _ref => {
let {
className,
status = 'active',
iconDescription,
description,
onSuccess,
successDelay = 1500,
...rest
} = _ref;
const prefix = usePrefix();
const loadingClasses = cx(`${prefix}--inline-loading`, className);
const getLoading = () => {
let iconLabel = iconDescription ? iconDescription : status;
if (status === 'error') {
return /*#__PURE__*/React__default.createElement(ErrorFilled, {
className: `${prefix}--inline-loading--error`
}, /*#__PURE__*/React__default.createElement("title", null, iconLabel));
}
if (status === 'finished') {
setTimeout(() => {
if (onSuccess) {
onSuccess();
}
}, successDelay);
return /*#__PURE__*/React__default.createElement(CheckmarkFilled, {
className: `${prefix}--inline-loading__checkmark-container`
}, /*#__PURE__*/React__default.createElement("title", null, iconLabel));
}
if (status === 'inactive' || status === 'active') {
if (!iconDescription) {
iconLabel = status === 'active' ? 'loading' : 'not loading';
}
return /*#__PURE__*/React__default.createElement(Loading, {
small: true,
description: iconLabel,
withOverlay: false,
active: status === 'active'
});
}
return undefined;
};
const loadingText = /*#__PURE__*/React__default.createElement("div", {
className: `${prefix}--inline-loading__text`
}, description);
const loading = getLoading();
const loadingAnimation = loading && /*#__PURE__*/React__default.createElement("div", {
className: `${prefix}--inline-loading__animation`
}, loading);
return /*#__PURE__*/React__default.createElement("div", _extends({
className: loadingClasses
}, rest, {
"aria-live": 'assertive'
}), loadingAnimation, description && loadingText);
};
InlineLoading.propTypes = {
/**
* Specify a custom className to be applied to the container node
*/
className: PropTypes.string,
/**
* Specify the description for the inline loading text
*/
description: PropTypes.node,
/**
* Specify the description for the inline loading text
*/
iconDescription: PropTypes.string,
/**
* Provide an optional handler to be invoked when <InlineLoading> is
* successful
*/
onSuccess: PropTypes.func,
/**
* Specify the loading status
*/
status: PropTypes.oneOf(['inactive', 'active', 'finished', 'error']),
/**
* Provide a delay for the `setTimeout` for success
*/
successDelay: PropTypes.number
};
export { InlineLoading as default };