Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions animata/text/circular-text.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import CircularText from "@/animata/text/circular-text";
import { Meta, StoryObj } from "@storybook/react";

const meta = {
title: "Text/Circular Text",
component: CircularText,
parameters: {
layout: "centered",
},
tags: ["autodocs"],
argTypes: {},
} satisfies Meta<typeof CircularText>;

export default meta;
type Story = StoryObj<typeof meta>;

export const Primary: Story = {
args: {
text: "CIRCULAR•TEXT•COMPONENT•",
},
};
48 changes: 48 additions & 0 deletions animata/text/circular-text.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { useMemo } from "react";
import { motion } from "framer-motion";

import { cn } from "@/lib/utils";

export default function CircularText({
text,
spinDuration = 30,
radius = 5,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default radius value too small for visible circle

High Severity

The default radius = 5 is far too small for the 200x200px container. With translateY(-5px), all characters will be positioned only 5 pixels from the center, causing them to overlap and the circular text effect to be essentially invisible. For a 200px container, the radius should be closer to 80-100px to properly display text in a circle.

Fix in Cursor Fix in Web

className = "",
}: {
text: string;
spinDuration?: number;
radius?: number;
className?: string;
}) {
const characters = useMemo(() => [...text], [text]);
return (
<motion.div
key={spinDuration}
className={cn(
"relative mx-auto flex h-[200px] w-[200px] origin-center cursor-pointer items-center justify-center rounded-full text-center font-bold text-foreground",
className,
)}
initial={{ rotate: 0 }}
animate={{ rotate: 360 }}
transition={{
ease: "linear",
duration: spinDuration,
repeat: Infinity,
}}
>
{characters.map((char, index) => {
const angle = (360 / characters.length) * index;
const transform = `rotate(${angle}deg) translateY(-${radius}px)`;
return (
<span
key={`${char}-${index}`}
style={{ transform, WebkitTransform: transform }}
className="absolute inset-0 inline-block font-medium"
>
{char}
</span>
);
})}
</motion.div>
);
}
38 changes: 38 additions & 0 deletions content/docs/text/circular-text.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Circular Text
description: Displays text arranged in a rotating circular path with customizable speed.
author: Sanj__P
---

<ComponentPreview name="text-circular-text--docs" />

## Installation

<Steps>
<Step>Install dependencies</Step>

```bash
npm install framer-motion
```

<Step>Run the following command</Step>

It will create a new file `circular-text.tsx` inside the `components/animata/text` directory.

```bash
mkdir -p components/animata/text && touch components/animata/text/circular-text.tsx
```

<Step>Paste the code</Step>{" "}

Open the newly created file and paste the following code:

```jsx file=<rootDir>/animata/text/circular-text.tsx

```

</Steps>

## Credits

Built by [Sanjana Podduturi](https://github.com/P-Sanjana)
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"lodash.startcase": "^4.4.0",
"lucide-react": "^0.390.0",
"mdast-util-toc": "^7.1.0",
"next": "14.2.26",
"next": "14.2.35",
"next-contentlayer": "^0.3.4",
"next-themes": "^0.3.0",
"ora": "^8.0.1",
Expand Down Expand Up @@ -108,11 +108,11 @@
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"react-docgen": "^7.0.3",
"storybook": "^8.1.6",
"storybook": "^8.6.15",
"storybook-dark-mode": "^4.0.1",
"tailwindcss": "^3.4.1",
"typescript": "^5",
"wrangler": "^3.79.0"
"wrangler": "^3.114.17"
},
"packageManager": "yarn@4.2.2",
"lint-staged": {
Expand Down
Loading