gauge
diceui-radix/gaugeFreeComponent
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/gauge.jsonSource
1"use client";23import { Slot as SlotPrimitive } from "radix-ui";4import * as React from "react";5import { cn } from "@/lib/utils";67const GAUGE_NAME = "Gauge";8const INDICATOR_NAME = "GaugeIndicator";9const TRACK_NAME = "GaugeTrack";10const RANGE_NAME = "GaugeRange";11const VALUE_TEXT_NAME = "GaugeValueText";12const LABEL_NAME = "GaugeLabel";1314const DEFAULT_MAX = 100;15const DEFAULT_START_ANGLE = 0;16const DEFAULT_END_ANGLE = 360;1718type GaugeState = "indeterminate" | "complete" | "loading";1920interface DivProps extends React.ComponentProps<"div"> {21 asChild?: boolean;22}2324interface PathProps extends React.ComponentProps<"path"> {}2526function getGaugeState(27 value: number | undefined | null,28 maxValue: number,29): GaugeState {30 return value == null31 ? "indeterminate"32 : value === maxValue33 ? "complete"34 : "loading";35}3637function getIsValidNumber(value: unknown): value is number {38 return typeof value === "number" && Number.isFinite(value);39}4041function getIsValidMaxNumber(max: unknown): max is number {42 return getIsValidNumber(max) && max > 0;43}4445function getIsValidValueNumber(46 value: unknown,47 min: number,48 max: number,49): value is number {50 return getIsValidNumber(value) && value <= max && value >= min;51}5253function getDefaultValueText(value: number, min: number, max: number): string {54 const percentage = max === min ? 100 : ((value - min) / (max - min)) * 100;55 return Math.round(percentage).toString();56}5758function getInvalidValueError(59 propValue: string,60 componentName: string,61): string {62 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 state. The value will be clamped to the valid range.`;63}6465function getInvalidMaxError(propValue: string, componentName: string): string {66 return `Invalid prop \`max\` of value \`${propValue}\` supplied to \`${componentName}\`. Only numbers greater than 0 are valid. Defaulting to ${DEFAULT_MAX}.`;67}6869function getNormalizedAngle(angle: number) {70 return ((angle % 360) + 360) % 360;71}7273function polarToCartesian(74 centerX: number,75 centerY: number,76 radius: number,77 angleInDegrees: number,78) {79 const angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;80 return {81 x: centerX + radius * Math.cos(angleInRadians),82 y: centerY + radius * Math.sin(angleInRadians),83 };84}8586function describeArc(87 x: number,88 y: number,89// … 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 | |
| circular-progresscircular-progress | diceui/radix | Components | Free | 1 dep | |
| client-onlyclient-only | diceui/radix | Components | Free | no deps |
