テキスト
Shimmer Text
CSS グラデーションアニメーションでキラキラと光るシマーエフェクトのテキストコンポーネント。
インストール
npx shadcn add https://d-ui.daigo-suhara.com/registry/shimmer-text.jsonサンプル
シマーエフェクト
使い方
import { ShimmerText } from "@/components/ui/shimmer-text"
export default function Example() {
return (
<ShimmerText as="h1" className="text-4xl font-bold">
Hello World
</ShimmerText>
)
}プロパティ
speed任意"slow" | "normal" | "fast"アニメーション速度
デフォルト:
"normal"colors必須stringTailwindのグラデーションクラス(from-* via-* to-*)
as任意"span" | "h1" | "h2" | "h3" | "p"レンダリングするHTML要素
デフォルト:
"span"className必須string追加のCSSクラス
| 名前 | 型 | デフォルト | 説明 | |
|---|---|---|---|---|
| 任意 | speed | "slow" | "normal" | "fast" | "normal" | アニメーション速度 |
| 必須 | colors | string | — | Tailwindのグラデーションクラス(from-* via-* to-*) |
| 任意 | as | "span" | "h1" | "h2" | "h3" | "p" | "span" | レンダリングするHTML要素 |
| 必須 | className | string | — | 追加のCSSクラス |
ソースコード
import * as React from "react";
import { cn } from "@/lib/utils";
interface ShimmerTextProps extends React.HTMLAttributes<HTMLSpanElement> {
speed?: "slow" | "normal" | "fast";
colors?: string;
as?: "span" | "h1" | "h2" | "h3" | "p";
}
const speeds = {
slow: "3s",
normal: "2s",
fast: "1s",
};
export function ShimmerText({
className,
speed = "normal",
colors = "from-foreground via-foreground/40 to-foreground",
as: Tag = "span",
style,
children,
...props
}: ShimmerTextProps) {
return (
<Tag
className={cn(
"inline-block bg-gradient-to-r bg-clip-text text-transparent bg-[length:200%_auto]",
"animate-[shimmer_var(--shimmer-speed)_linear_infinite]",
colors,
className
)}
style={{
"--shimmer-speed": speeds[speed],
...style,
} as React.CSSProperties}
{...props}
>
{children}
</Tag>
);
}