UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
feat: add number-ticker to accept decimal places (#308)
Singgih Adi Nugrohoc779f74e649b
diff --git a/content/docs/components/number-ticker.mdx b/content/docs/components/number-ticker.mdxindex 88ec28d3..6064a529 100644--- a/content/docs/components/number-ticker.mdx+++ b/content/docs/components/number-ticker.mdx@@ -41,9 +41,17 @@ npx magicui-cli add number-ticker</Tabs>+## Example++### Decimal++<ComponentPreview name="number-ticker-decimal-demo" />+## Props-| Prop | Type | Description | Default |-| --------- | ---------- | ------------------------- | ------- |-| value | int | The value to count to | 0 |-| direction | up \| down | The direction to count in | up |+| Prop | Type | Description | Default |+| ------------- | ---------- | ------------------------------------ | ------- |+| value | int | The value to count to | 0 |+| direction | up \| down | The direction to count in | up |+| delay | number | The delay before counting | 0 |+| decimalPlaces | number | The number of decimal places to show | 0 |diff --git a/registry/components/example/number-ticker-decimal-demo.tsx b/registry/components/example/number-ticker-decimal-demo.tsxnew file mode 100644index 00000000..bbed856c--- /dev/null+++ b/registry/components/example/number-ticker-decimal-demo.tsx@@ -0,0 +1,11 @@+import NumberTicker from "@/components/magicui/number-ticker";++const NumberTickerDemo = () => {+ return (+ <p className="whitespace-pre-wrap text-8xl font-medium tracking-tighter text-black dark:text-white">+ <NumberTicker value={5.67} decimalPlaces={2} />+ </p>+ );+};++export default NumberTickerDemo;diff --git a/registry/components/magicui/number-ticker.tsx b/registry/components/magicui/number-ticker.tsxindex f0dc6188..17db6c5a 100644--- a/registry/components/magicui/number-ticker.tsx+++ b/registry/components/magicui/number-ticker.tsx@@ -10,11 +10,13 @@ export default function NumberTicker({direction = "up",delay = 0,className,+ decimalPlaces = 0,}: {value: number;direction?: "up" | "down";className?: string;delay?: number; // delay in s+ decimalPlaces?: number;}) {const ref = useRef<HTMLSpanElement>(null);const motionValue = useMotionValue(direction === "down" ? value : 0);@@ -35,12 +37,13 @@ export default function NumberTicker({() =>springValue.on("change", (latest) => {if (ref.current) {- ref.current.textContent = Intl.NumberFormat("en-US").format(- Number(latest.toFixed(0)),- );+ ref.current.textContent = Intl.NumberFormat("en-US", {+ minimumFractionDigits: decimalPlaces,+ maximumFractionDigits: decimalPlaces,+ }).format(Number(latest.toFixed(decimalPlaces)));}}),- [springValue],+ [springValue, decimalPlaces],);return (diff --git a/registry/index.tsx b/registry/index.tsxindex 8a5be1a2..aad90955 100644--- a/registry/index.tsx+++ b/registry/index.tsx@@ -504,6 +504,15 @@ const example: Registry = {() => import("@/registry/components/example/number-ticker-demo"),),},+ "number-ticker-decimal-demo": {+ name: "number-ticker-decimal-demo",+ type: "components:example",+ registryDependencies: ["number-ticker"],+ files: ["registry/components/example/number-ticker-decimal-demo.tsx"],+ component: React.lazy(+ () => import("@/registry/components/example/number-ticker-decimal-demo"),+ ),+ },"ripple-demo": {name: "ripple-demo",type: "components:example",