UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

71 lines (70 loc) 3.39 kB
"use strict"; "use client"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireWildcard(require("react")); var _componentHelper = require("../../shared/component-helper.js"); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function usePrevious(value) { const ref = (0, _react.useRef)(); (0, _react.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 = (0, _componentHelper.validateDOMAttributes)(props, { ...rest }); return _react.default.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.default.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.default.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 } })); } var _default = exports.default = ProgressIndicatorLine; //# sourceMappingURL=ProgressIndicatorLinear.js.map