circular-progress
diceui-base/circular-progressFreeComponent
diceui/base publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/sadmann7/diceui/HEAD/docs/public/r/styles/base-vega/circular-progress.jsonSource
1"use client";23import { mergeProps } from "@base-ui/react/merge-props";4import { useRender } from "@base-ui/react/use-render";5import * as React from "react";6import { cn } from "@/lib/utils";78const CIRCULAR_PROGRESS_NAME = "CircularProgress";9const INDICATOR_NAME = "CircularProgressIndicator";10const TRACK_NAME = "CircularProgressTrack";11const RANGE_NAME = "CircularProgressRange";12const VALUE_TEXT_NAME = "CircularProgressValueText";1314const DEFAULT_MAX = 100;1516type ProgressState = "indeterminate" | "complete" | "loading";1718function getProgressState(19 value: number | undefined | null,20 maxValue: number,21): ProgressState {22 return value == null23 ? "indeterminate"24 : value === maxValue25 ? "complete"26 : "loading";27}2829function getIsValidNumber(value: unknown): value is number {30 return typeof value === "number" && Number.isFinite(value);31}3233function getIsValidMaxNumber(max: unknown): max is number {34 return getIsValidNumber(max) && max > 0;35}3637function getIsValidValueNumber(38 value: unknown,39 min: number,40 max: number,41): value is number {42 return getIsValidNumber(value) && value <= max && value >= min;43}4445function getDefaultValueText(value: number, min: number, max: number): string {46 const percentage = max === min ? 100 : ((value - min) / (max - min)) * 100;47 return `${Math.round(percentage)}%`;48}4950function getInvalidValueError(51 propValue: string,52 componentName: string,53): string {54 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.`;55}5657function getInvalidMaxError(propValue: string, componentName: string): string {58 return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid. Defaulting to ${DEFAULT_MAX}.`;59}6061interface CircularProgressContextValue {62 value: number | null;63 valueText: string | undefined;64 max: number;65 min: number;66 state: ProgressState;67 radius: number;68 thickness: number;69 size: number;70 center: number;71 circumference: number;72 percentage: number | null;73 valueTextId?: string;74}7576const CircularProgressContext =77 React.createContext<CircularProgressContextValue | null>(null);7879function useCircularProgressContext(consumerName: string) {80 const context = React.useContext(CircularProgressContext);81 if (!context) {82// … truncated
What it pulls in
npm packages
Files it writes
More from diceui/base
All 192 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| action-baraction-bar | diceui/base | Components | Free | 1 dep | |
| angle-sliderangle-slider | diceui/base | Components | Free | 1 dep · 3 files | |
| avatar-groupavatar-group | diceui/base | Components | Free | 1 dep | |
| badge-overflowbadge-overflow | diceui/base | Components | Free | 1 dep · 2 files | |
| bannerbanner | diceui/base | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/base | Components | Free | no deps | |
| color-pickercolor-picker | diceui/base | Components | Free | 1 dep · 2 files | |
| color-swatchcolor-swatch | diceui/base | Components | Free | 1 dep |
