@talend/react-components
Version:
Set of react components.
76 lines • 1.79 kB
JavaScript
import PropTypes from 'prop-types';
import classNames from 'classnames';
import TooltipTrigger from '../TooltipTrigger';
import theme from './Progress.module.scss';
import { jsx as _jsx } from "react/jsx-runtime";
function normalize(percent) {
if (percent > 100) {
return 100;
}
if (percent < 0) {
return 0;
}
return percent;
}
function Progress({
id,
percent,
tooltip,
infinite,
contained
}) {
const normalizedPercent = infinite ? 100 : normalize(percent);
const style = {
width: `${normalizedPercent}%`
};
const rootClassNames = classNames(theme.progress, {
[theme.hidden]: normalizedPercent === 0,
[theme.fixed]: !contained,
[theme.infinite]: infinite
});
let progress = /*#__PURE__*/_jsx("div", {
style: style,
className: theme['progress-percent'],
children: infinite && /*#__PURE__*/_jsx("div", {
className: theme['infinite-indicator']
})
});
if (tooltip) {
progress = /*#__PURE__*/_jsx(TooltipTrigger, {
label: tooltip,
tooltipPlacement: "bottom",
children: progress
});
}
let a11yProps;
if (!infinite) {
a11yProps = {
role: 'progressbar',
'aria-valuenow': normalizedPercent,
'aria-valuemin': 0,
'aria-valuemax': 100
};
} else {
a11yProps = {
role: 'status',
'aria-busy': true
};
}
return /*#__PURE__*/_jsx("div", {
id: id,
className: rootClassNames,
"aria-label": tooltip,
...a11yProps,
children: progress
});
}
Progress.displayName = 'Progress';
Progress.propTypes = {
id: PropTypes.string,
percent: PropTypes.number,
tooltip: PropTypes.string.isRequired,
infinite: PropTypes.bool,
contained: PropTypes.bool
};
export default Progress;
//# sourceMappingURL=Progress.component.js.map