@wix/design-system
Version:
@wix/design-system
33 lines • 1.91 kB
JavaScript
import React, { useEffect } from 'react';
import { st, classes } from './StatusIndicator.st.css.js';
import Tooltip from '../Tooltip';
import deprecationLog from '../utils/deprecationLog';
import { FormFieldSuccessFilled, FormFieldWarningFilled, FormFieldErrorFilled, } from '@wix/wix-ui-icons-common/system';
import Loader from '../Loader';
import { dataHooks, STATUS, TOOLTIP_PLACEMENT, } from './StatusIndicator.constants';
const statusToIconMap = {
success: React.createElement(FormFieldSuccessFilled, null),
warning: React.createElement(FormFieldWarningFilled, null),
loading: React.createElement(Loader, { size: "tiny" }),
error: React.createElement(FormFieldErrorFilled, null),
};
const StatusIndicator = (props) => {
const { dataHook, status = STATUS.ERROR, message, tooltipPlacement = TOOLTIP_PLACEMENT.TOP, className, tooltipProps, } = props;
useEffect(() => {
if ('tooltipPlacement' in props) {
deprecationLog('<StatusIndicator/> - prop "tooltipPlacement" is deprecated and will be removed in next major release, please use "tooltipProps" instead.');
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const icon = statusToIconMap[status];
const renderIcon = () => {
if (message) {
return (React.createElement("span", { tabIndex: 0, className: classes.iconWrapper }, icon));
}
return icon;
};
return (React.createElement("div", { className: st(classes.root, { status }, className), "data-hook": dataHook, "data-status": status }, message ? (React.createElement(Tooltip, { dataHook: dataHooks.tooltip, appendTo: "window", placement: tooltipPlacement, exitDelay: 100, content: message, maxWidth: 250, ...tooltipProps }, renderIcon())) : (icon)));
};
StatusIndicator.displayName = 'StatusIndicator';
export default StatusIndicator;
//# sourceMappingURL=StatusIndicator.js.map