仕組み
The phrase sits in an inline block and the stars are placed around it in percentages: within its width, and mostly above and below the letters rather than across them, so the words stay readable. Each star grows from nothing while turning, peaks, shrinks away and rests for the last third of its cycle, so only some are lit at any moment; when a twinkle ends the star moves to a new random spot, so the pattern never visibly repeats. The first layout is seeded, so server and browser render the same. The phrase takes a gradient of the same palette, mixed with the text colour so it keeps its contrast.
向いている場面
- Celebrating a milestone, a reward or a new feature in a short phrase.
- A single word or figure that deserves delight on a quiet page.
向かない場面
- Long text or several places per screen.
- Serious contexts such as errors, billing or legal text.
使い方
import { SparklesText } from './SparklesText.jsx'
export function Milestone() {
return (
<h2>
Your newsletter just passed <SparklesText palette="gold" count={8}>1,000 readers</SparklesText>
</h2>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
children | ReactNode | — | The phrase to highlight; keep it short. |
count | number | 8 | Number of stars (0 to 24). |
palette | 'gold' | 'accent' | 'rainbow' | 'gold' | Star and highlight colours. |
size | number | 16 | Largest star size in px. |
speed | number | 1 | Twinkle pace multiplier. |
highlight | boolean | true | Gives the phrase a matching gradient fill. |
as | ElementType | 'span' | Element to render. |
アクセシビリティ
- The stars are aria-hidden SVGs; screen readers read only the phrase.
- The gradient fill mixes each colour with the body text colour, keeping large text above 3:1 in both themes; forced-colors mode shows plain text without stars.
- Stars avoid sitting across the letters, so the phrase is never obscured.
- Reduced motion freezes four small stars around the phrase and hides the rest.
モーション
Each twinkle lasts 1.6–2.8s (divided by speed) with an ease-in-out: it grows while turning 45° to its peak at 45% of the cycle, shrinks while turning another 45° by 70%, then rests.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
SparklesText.jsxsparkles-text.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。



