@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
65 lines (64 loc) • 2.37 kB
JavaScript
"use client";
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
import React, { useRef, useEffect } from 'react';
import { validateDOMAttributes } from "../../shared/component-helper.js";
function usePrevious(value) {
const ref = useRef();
useEffect(() => {
ref.current = value;
}, [value]);
return [ref.current, value];
}
function ProgressIndicatorLine(props) {
const {
size,
title,
progress,
visible,
onComplete,
callOnCompleteHandler,
customColors,
style,
...rest
} = props;
const onCompleteIsFn = typeof onComplete === 'function' && typeof callOnCompleteHandler === 'function';
const [visibleCurrent, visiblePrev] = usePrevious(visible);
if (onCompleteIsFn && !visibleCurrent && visiblePrev) {
callOnCompleteHandler();
}
const hasProgressValue = progress > -1;
const transform = `translateX(${(progress || 0) - 100}%)`;
if (hasProgressValue) {
rest.role = 'progressbar';
rest['aria-label'] = title;
rest['title'] = title;
} else {
rest.role = 'alert';
rest['aria-busy'] = true;
}
const remainingDOMAttributes = validateDOMAttributes(props, {
...rest
});
return React.createElement("span", _extends({
className: 'dnb-progress-indicator__linear' + (size ? ` dnb-progress-indicator__linear--${size}` : ""),
style: {
...style,
...((customColors === null || customColors === void 0 ? void 0 : customColors.shaft) && {
backgroundColor: customColors === null || customColors === void 0 ? void 0 : customColors.shaft
})
}
}, remainingDOMAttributes), React.createElement("span", {
className: "dnb-progress-indicator__linear__bar " + (hasProgressValue ? 'dnb-progress-indicator__linear__bar-transition' : 'dnb-progress-indicator__linear__bar1-animation'),
style: {
backgroundColor: customColors === null || customColors === void 0 ? void 0 : customColors.line,
transform: hasProgressValue ? transform : undefined
}
}), !hasProgressValue && React.createElement("span", {
className: "dnb-progress-indicator__linear__bar dnb-progress-indicator__linear__bar2-animation",
style: {
backgroundColor: customColors === null || customColors === void 0 ? void 0 : customColors.line
}
}));
}
export default ProgressIndicatorLine;
//# sourceMappingURL=ProgressIndicatorLinear.js.map