UNPKG

@arolariu/components

Version:

🎨 60+ beautiful, accessible React components built on Radix UI. TypeScript-first, tree-shakeable, SSR-ready. Perfect for modern web apps, design systems & rapid prototyping. Zero config, maximum flexibility! ⚡

95 lines (94 loc) • 4.09 kB
"use client"; "use strict"; var __webpack_require__ = {}; (()=>{ __webpack_require__.d = (exports1, definition)=>{ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, { enumerable: true, get: definition[key] }); }; })(); (()=>{ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop); })(); (()=>{ __webpack_require__.r = (exports1)=>{ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, { value: 'Module' }); Object.defineProperty(exports1, '__esModule', { value: true }); }; })(); var __webpack_exports__ = {}; __webpack_require__.r(__webpack_exports__); __webpack_require__.d(__webpack_exports__, { CountingNumber: ()=>CountingNumber }); const jsx_runtime_namespaceObject = require("react/jsx-runtime"); const external_react_namespaceObject = require("react"); const react_namespaceObject = require("motion/react"); const CountingNumber = /*#__PURE__*/ external_react_namespaceObject.forwardRef(({ number, fromNumber = 0, padStart = false, inView = false, inViewMargin = "0px", inViewOnce = true, decimalSeparator = ".", transition = { stiffness: 90, damping: 50 }, decimalPlaces = 0, className, ...props }, ref)=>{ const localRef = external_react_namespaceObject.useRef(null); external_react_namespaceObject.useImperativeHandle(ref, ()=>localRef.current); const numberStr = number.toString(); const decimals = "number" == typeof decimalPlaces ? decimalPlaces : numberStr.includes(".") ? numberStr.split(".")[1].length : 0; const motionVal = (0, react_namespaceObject.useMotionValue)(fromNumber); const springVal = (0, react_namespaceObject.useSpring)(motionVal, transition); const inViewResult = (0, react_namespaceObject.useInView)(localRef, { once: inViewOnce, margin: inViewMargin }); const isInView = !inView || inViewResult; external_react_namespaceObject.useEffect(()=>{ if (isInView) motionVal.set(number); }, [ isInView, number, motionVal ]); external_react_namespaceObject.useEffect(()=>{ const unsubscribe = springVal.on("change", (latest)=>{ if (localRef.current) { let formatted = decimals > 0 ? latest.toFixed(decimals) : Math.round(latest).toString(); if (decimals > 0) formatted = formatted.replace(".", decimalSeparator); if (padStart) { const finalIntLength = Math.floor(Math.abs(number)).toString().length; const [intPart, fracPart] = formatted.split(decimalSeparator); const paddedInt = intPart.padStart(finalIntLength, "0"); formatted = fracPart ? `${paddedInt}${decimalSeparator}${fracPart}` : paddedInt; } localRef.current.textContent = formatted; } }); return ()=>unsubscribe(); }, [ springVal, decimals, padStart, number, decimalSeparator ]); const finalIntLength = Math.floor(Math.abs(number)).toString().length; const initialText = padStart ? "0".padStart(finalIntLength, "0") + (decimals > 0 ? decimalSeparator + "0".repeat(decimals) : "") : "0" + (decimals > 0 ? decimalSeparator + "0".repeat(decimals) : ""); return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", { ref: localRef, className: className, ...props, children: initialText }); }); CountingNumber.displayName = "CountingNumber"; exports.CountingNumber = __webpack_exports__.CountingNumber; for(var __webpack_i__ in __webpack_exports__)if (-1 === [ "CountingNumber" ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__]; Object.defineProperty(exports, '__esModule', { value: true }); //# sourceMappingURL=counting-number.cjs.map