circular-progress
diceui-radix/circular-progressFreeComponent
diceui/radix publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/radix-nova/circular-progress.jsonSource
1"use client";23import { Slot as SlotPrimitive } from "radix-ui";4import * as React from "react";5import { cn } from "@/lib/utils";67const CIRCULAR_PROGRESS_NAME = "CircularProgress";8const INDICATOR_NAME = "CircularProgressIndicator";9const TRACK_NAME = "CircularProgressTrack";10const RANGE_NAME = "CircularProgressRange";11const VALUE_TEXT_NAME = "CircularProgressValueText";1213const DEFAULT_MAX = 100;1415type ProgressState = "indeterminate" | "complete" | "loading";1617function getProgressState(18 value: number | undefined | null,19 maxValue: number,20): ProgressState {21 return value == null22 ? "indeterminate"23 : value === maxValue24 ? "complete"25 : "loading";26}2728function getIsValidNumber(value: unknown): value is number {29 return typeof value === "number" && Number.isFinite(value);30}3132function getIsValidMaxNumber(max: unknown): max is number {33 return getIsValidNumber(max) && max > 0;34}3536function getIsValidValueNumber(37 value: unknown,38 min: number,39 max: number,40): value is number {41 return getIsValidNumber(value) && value <= max && value >= min;42}4344function getDefaultValueText(value: number, min: number, max: number): string {45 const percentage = max === min ? 100 : ((value - min) / (max - min)) * 100;46 return `${Math.round(percentage)}%`;47}4849function getInvalidValueError(50 propValue: string,51 componentName: string,52): string {53 return `Invalid prop \`value\` of value \`${propValue}\` supplied to \`${componentName}\`. The \`value\` prop must be a number between \`min\` and \`max\` (inclusive), or \`null\`/\`undefined\` for indeterminate progress. The value will be clamped to the valid range.`;54}5556function getInvalidMaxError(propValue: string, componentName: string): string {57 return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid. Defaulting to ${DEFAULT_MAX}.`;58}5960interface CircularProgressContextValue {61 value: number | null;62 valueText: string | undefined;63 max: number;64 min: number;65 state: ProgressState;66 radius: number;67 thickness: number;68 size: number;69 center: number;70 circumference: number;71 percentage: number | null;72 valueTextId?: string;73}7475const CircularProgressContext =76 React.createContext<CircularProgressContextValue | null>(null);7778function useCircularProgressContext(consumerName: string) {79 const context = React.useContext(CircularProgressContext);80 if (!context) {81 throw new Error(82// … truncated
What it pulls in
npm packages
Files it writes
More from diceui/radix
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/radix | Components | Free | 1 dep · 2 files | |
| angle-sliderangle-slider | diceui/radix | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/radix | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/radix | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/radix | Components | Free | 1 dep | |
| checkbox-groupcheckbox-group | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps | |
| color-pickercolor-picker | diceui/radix | Components | Free | 1 dep · 3 files |
