Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A circular progress bar component with animated transitions between primary and secondary colors.
0
animated-circular-progress-bar.svelte
<script lang="ts"> import { AnimatedCircularProgressBar } from "$lib/components/magic/animated-circular-progress-bar/index.js"; import { mode } from "mode-watcher"; import { onMount, onDestroy } from "svelte";
let value = $state(0); let interval: ReturnType<typeof setInterval>;
onMount(() => { const handleIncrement = () => { value = value === 100 ? 0 : value + 10; };
handleIncrement(); interval = setInterval(handleIncrement, 2000); });
onDestroy(() => { if (interval) { clearInterval(interval); } });</script>
<AnimatedCircularProgressBar {value} gaugePrimaryColor={mode.current === "dark" ? "#34d399" : "rgb(79 70 229)"} gaugeSecondaryColor={mode.current === "dark" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)"}/>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/animated-circular-progress-bar.json
Copy the Source Code
Copy and paste the following code into your project:
animated-circular-progress-bar.svelte
<script lang="ts"> import type { ClassValue } from "svelte/elements"; import { cn } from "#lib/utils.js";
interface AnimatedCircularProgressBarProps { max?: number; min?: number; value: number; gaugePrimaryColor: string; gaugeSecondaryColor: string; class?: ClassValue; }
let { max = 100, min = 0, value = 0, gaugePrimaryColor, gaugeSecondaryColor, class: className, }: AnimatedCircularProgressBarProps = $props();
const circumference = 2 * Math.PI * 45; const percentPx = circumference / 100;
const currentPercent = $derived(Math.round(((value - min) / (max - min)) * 100));</script>
<div class={cn("relative size-40 text-2xl font-semibold", className)} style=" --circle-size: 100px; --circumference: {circumference}; --percent-to-px: {percentPx}px; --gap-percent: 5; --offset-factor: 0; --transition-length: 1s; --transition-step: 200ms; --delay: 0s; --percent-to-deg: 3.6deg; transform: translateZ(0); "> <svg fill="none" class="size-full" stroke-width="2" viewBox="0 0 100 100"> {#if currentPercent <= 90 && currentPercent >= 0} <circle cx="50" cy="50" r="45" stroke-width="10" stroke-dashoffset="0" stroke-linecap="round" stroke-linejoin="round" class="opacity-100" style=" stroke: {gaugeSecondaryColor}; --stroke-percent: {90 - currentPercent}; --offset-factor-secondary: calc(1 - var(--offset-factor)); stroke-dasharray: calc(var(--stroke-percent) * var(--percent-to-px)) var(--circumference); transform: rotate(calc(1turn - 90deg - (var(--gap-percent) * var(--percent-to-deg) * var(--offset-factor-secondary)))) scaleY(-1); transition: all var(--transition-length) ease var(--delay); transform-origin: calc(var(--circle-size) / 2) calc(var(--circle-size) / 2); " /> {/if} <circle cx="50" cy="50" r="45" stroke-width="10" stroke-dashoffset="0" stroke-linecap="round" stroke-linejoin="round" class="opacity-100" style=" stroke: {gaugePrimaryColor}; --stroke-percent: {currentPercent}; stroke-dasharray: calc(var(--stroke-percent) * var(--percent-to-px)) var(--circumference); transition: var(--transition-length) ease var(--delay), stroke var(--transition-length) ease var(--delay); transition-property: stroke-dasharray, transform; transform: rotate(calc(-90deg + var(--gap-percent) * var(--offset-factor) * var(--percent-to-deg))); transform-origin: calc(var(--circle-size) / 2) calc(var(--circle-size) / 2); " /> </svg> <span data-current-value={currentPercent} class="animate-in fade-in absolute inset-0 m-auto size-fit delay-(--delay) duration-(--transition-length) ease-linear" > {currentPercent} </span></div> index.ts
import AnimatedCircularProgressBar from "./animated-circular-progress-bar.svelte";export { AnimatedCircularProgressBar };Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── animated-circular-progress-bar/ ├── animated-circular-progress-bar.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/animated-circular-progress-bar/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { AnimatedCircularProgressBar } from "#lib/components/magic/animated-circular-progress-bar/index.js"; import { mode } from "mode-watcher";</script>
<AnimatedCircularProgressBar value={75} gaugePrimaryColor={mode.current === "dark" ? "#34d399" : "#4f46e5"} gaugeSecondaryColor="#e5e7eb"/>Props
Animated Circular Progress Bar
A component for displaying animated circular progress.
| Name | Type | Default | Description |
|---|---|---|---|
max | number | 100 | The maximum value for the progress bar |
min | number | 0 | The minimum value for the progress bar |
value | number | 0 | The current value of the progress bar |
gaugePrimaryColor | string | required | The color for the progress portion of the bar |
gaugeSecondaryColor | string | required | The color for the remaining portion of the bar |
class | ClassValue | "" | Additional CSS classes to apply |