Ring
dashboardblocks/ringFreeComponent
A ring component.
Live preview
live · rendered by the registry
Rendered by dashboardblocks on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://dashboardblocks.com/r/ring.jsonSource
1'use client'23import { useInView } from '@/registry/hooks/use-in-view'4import { type ReactNode, type RefObject, useEffect, useState } from 'react'56import { cn } from '@/lib/utils'78export interface RingProps {9 ariaLabel?: string10 children?: ReactNode11 className?: string12 percentage: number13 radius?: number14 ringColor?: string15 ringTrackColor?: string16 strokeWidth?: number17}1819export const Ring = ({20 ariaLabel,21 children,22 className = '',23 percentage,24 radius = 40,25 ringColor = 'var(--color-primary)',26 ringTrackColor = 'var(--color-muted)',27 strokeWidth = 12,28}: RingProps) => {29 const [value, setValue] = useState(0)30 const { isInView, ref } = useInView()31 const circumference = 2 * Math.PI * radius32 const strokeDashoffset = circumference - (value / 100) * circumference3334 useEffect(() => {35 if (isInView) {36 // Small delay to ensure the initial render happens at 037 const timer = requestAnimationFrame(() => {38 setValue(percentage)39 })40 return () => cancelAnimationFrame(timer)41 }42 }, [isInView, percentage])4344 return (45 <div46 ref={ref as RefObject<HTMLDivElement>}47 className={cn('relative shrink-0', className)}48 aria-label={ariaLabel}49 role={ariaLabel ? 'img' : undefined}50 >51 <svg className='h-full w-full -rotate-90' viewBox='0 0 100 100'>52 <circle53 cx='50'54 cy='50'55 r={radius}56 fill='none'57 stroke={ringTrackColor}58 strokeWidth={strokeWidth}59 />60 <circle61 cx='50'62 cy='50'63 r={radius}64 fill='none'65 stroke={ringColor}66 strokeWidth={strokeWidth}67 strokeLinecap='round'68 strokeDasharray={circumference}69 strokeDashoffset={strokeDashoffset}70 className='transition-all duration-1000 ease-out-expo'71 />72 </svg>73 <div className='absolute inset-0 flex items-center justify-center'>{children}</div>74 </div>75 )76}
What it pulls in
Other registry items
Files it writes
More from dashboardblocks
All 36 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Activity Feedactivity-feed | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-01activity-feed-01 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-02activity-feed-02 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-03activity-feed-03 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-04activity-feed-04 | dashboardblocks | Components | Free | 1 dep | |
| activity-feed-05activity-feed-05 | dashboardblocks | Components | Free | 1 dep | |
| Animated Numberanimated-number | dashboardblocks | Components | Free | no deps | |
| Animated Waveanimated-wave | dashboardblocks | Components | Free | no deps |
