-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* π§ update biome configuration to include noUndeclaredDependencies and format ignore list * β¨ add trigger-on-scroll component with animated number functionality * π update changelog for the trigger on scroll component
- Loading branch information
1 parent
9122ea3
commit 4de290c
Showing
7 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
title: Animated numbers triggered on scroll | ||
--- | ||
|
||
#### New component | ||
|
||
- A new component has been added to the website that animates numbers when they come into view. | ||
> This component was requested for displaying statistics or other numerical data in a marketing section. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/ui/cuicui/marketing-ui/statistics/trigger-on-scroll/component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import PreviewTriggerOnScroll from "@/cuicui/marketing-ui/statistics/trigger-on-scroll/preview"; | ||
import type { ComponentType } from "@/lib/types/component"; | ||
|
||
export const triggerOnScrollComponent: ComponentType = { | ||
sizePreview: "sm", | ||
slug: "trigger-on-scroll", | ||
// isIframed: true, | ||
rerenderButton: true, | ||
name: "Number trigger on scroll", | ||
description: "Show numbers that animate when they appear on the screen.", | ||
variantList: [ | ||
{ | ||
name: "Animated Number", | ||
component: PreviewTriggerOnScroll, | ||
slugPreviewFile: "preview", | ||
}, | ||
], | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/ui/cuicui/marketing-ui/statistics/trigger-on-scroll/preview.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { TriggerOnScroll } from "@/cuicui/marketing-ui/statistics/trigger-on-scroll/trigger-on-scroll"; | ||
|
||
export default function PreviewTriggerOnScroll() { | ||
return ( | ||
<div className="h-[200dvh] flex flex-col items-center justify-evenly"> | ||
<p className="text-neutral-500">Scroll to see the number reveal</p> | ||
<TriggerOnScroll>{252}</TriggerOnScroll> | ||
<TriggerOnScroll>{5120}</TriggerOnScroll> | ||
<TriggerOnScroll>{12300}</TriggerOnScroll> | ||
<TriggerOnScroll>{14}</TriggerOnScroll> | ||
</div> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
packages/ui/cuicui/marketing-ui/statistics/trigger-on-scroll/trigger-on-scroll.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"use client"; | ||
|
||
import { cn } from "@/cuicui/utils/cn/cn"; | ||
import NumberFlow from "@number-flow/react"; | ||
import { useState, useRef, useEffect } from "react"; | ||
import { useInView } from "framer-motion"; | ||
|
||
type NumberProps = number | `${number}`; | ||
|
||
export function TriggerOnScroll({ | ||
className, | ||
children, | ||
delayInMs = 100, | ||
}: { className?: string; children: NumberProps; delayInMs?: number }) { | ||
const [number, setNumber] = useState<NumberProps>(0); | ||
const ref = useRef(null); | ||
const isInView = useInView(ref, { margin: "0px 0px -100px 0px" }); | ||
|
||
useEffect(() => { | ||
if (isInView) { | ||
setTimeout(() => setNumber(children), delayInMs); | ||
} else { | ||
setNumber(0); | ||
} | ||
}, [isInView, children, delayInMs]); | ||
|
||
return ( | ||
<NumberFlow | ||
ref={ref} | ||
value={Number(number)} | ||
isolate={true} | ||
spinTiming={{ duration: 1200, easing: "ease-in-out" }} | ||
className={cn( | ||
"z-20 dark:text-neutral-300 text-neutral-700 text-4xl font-medium tracking-tighter", | ||
className, | ||
)} | ||
/> | ||
); | ||
} |