Skip to content

Commit 5e66949

Browse files
authored
feat: add circular text (#416)
1 parent a90caa0 commit 5e66949

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import CircularText from "@/animata/text/circular-text";
2+
import { Meta, StoryObj } from "@storybook/react";
3+
4+
const meta = {
5+
title: "Text/Circular Text",
6+
component: CircularText,
7+
parameters: {
8+
layout: "centered",
9+
},
10+
tags: ["autodocs"],
11+
argTypes: {},
12+
} satisfies Meta<typeof CircularText>;
13+
14+
export default meta;
15+
type Story = StoryObj<typeof meta>;
16+
17+
export const Primary: Story = {
18+
args: {
19+
text: "CIRCULAR•TEXT•COMPONENT•",
20+
},
21+
};

animata/text/circular-text.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { useMemo } from "react";
2+
import { motion } from "framer-motion";
3+
4+
import { cn } from "@/lib/utils";
5+
6+
export default function CircularText({
7+
text,
8+
spinDuration = 30,
9+
radius = 5,
10+
className = "",
11+
}: {
12+
text: string;
13+
spinDuration?: number;
14+
radius?: number;
15+
className?: string;
16+
}) {
17+
const characters = useMemo(() => [...text], [text]);
18+
return (
19+
<motion.div
20+
key={spinDuration}
21+
className={cn(
22+
"relative mx-auto flex h-[200px] w-[200px] origin-center cursor-pointer items-center justify-center rounded-full text-center font-bold text-foreground",
23+
className,
24+
)}
25+
initial={{ rotate: 0 }}
26+
animate={{ rotate: 360 }}
27+
transition={{
28+
ease: "linear",
29+
duration: spinDuration,
30+
repeat: Infinity,
31+
}}
32+
>
33+
{characters.map((char, index) => {
34+
const angle = (360 / characters.length) * index;
35+
const transform = `rotate(${angle}deg) translateY(-${radius}px)`;
36+
return (
37+
<span
38+
key={`${char}-${index}`}
39+
style={{ transform, WebkitTransform: transform }}
40+
className="absolute inset-0 inline-block font-medium"
41+
>
42+
{char}
43+
</span>
44+
);
45+
})}
46+
</motion.div>
47+
);
48+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: Circular Text
3+
description: Displays text arranged in a rotating circular path with customizable speed.
4+
author: Sanj__P
5+
---
6+
7+
<ComponentPreview name="text-circular-text--docs" />
8+
9+
## Installation
10+
11+
<Steps>
12+
<Step>Install dependencies</Step>
13+
14+
```bash
15+
npm install framer-motion
16+
```
17+
18+
<Step>Run the following command</Step>
19+
20+
It will create a new file `circular-text.tsx` inside the `components/animata/text` directory.
21+
22+
```bash
23+
mkdir -p components/animata/text && touch components/animata/text/circular-text.tsx
24+
```
25+
26+
<Step>Paste the code</Step>{" "}
27+
28+
Open the newly created file and paste the following code:
29+
30+
```jsx file=<rootDir>/animata/text/circular-text.tsx
31+
32+
```
33+
34+
</Steps>
35+
36+
## Credits
37+
38+
Built by [Sanjana Podduturi](https://github.com/P-Sanjana)

0 commit comments

Comments
 (0)