UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

68 lines (67 loc) 2.16 kB
"use client"; import { useRef, useEffect } from 'react'; import { clsx } from 'clsx'; import { validateDOMAttributes } from "../../shared/component-helper.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; function usePrevious(value) { const ref = useRef(undefined); useEffect(() => { ref.current = value; }, [value]); return [ref.current, value]; } function ProgressIndicatorLine(props) { const { size, title, progress, show, onComplete, callOnCompleteHandler, customColors, style, ...rest } = props; const onCompleteIsFn = typeof onComplete === 'function' && typeof callOnCompleteHandler === 'function'; const [showCurrent, showPrev] = usePrevious(show); if (onCompleteIsFn && !showCurrent && showPrev) { 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 _jsxs("span", { className: clsx('dnb-progress-indicator__linear', size && `dnb-progress-indicator__linear--${size}`), style: { ...style, ...(customColors?.shaft && { backgroundColor: customColors?.shaft }) }, ...remainingDOMAttributes, children: [_jsx("span", { className: clsx('dnb-progress-indicator__linear__bar', hasProgressValue && 'dnb-progress-indicator__linear__bar-transition', !hasProgressValue && 'dnb-progress-indicator__linear__bar1-animation'), style: { backgroundColor: customColors?.line, transform: hasProgressValue ? transform : undefined } }), !hasProgressValue && _jsx("span", { className: clsx('dnb-progress-indicator__linear__bar', 'dnb-progress-indicator__linear__bar2-animation'), style: { backgroundColor: customColors?.line } })] }); } export default ProgressIndicatorLine; //# sourceMappingURL=ProgressIndicatorLinear.js.map