/* * React Fabric * @version: 1.0.0 * * * The MIT License (MIT) * Copyright (c) 2024 Adarsh Pastakia * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software * and associated documentation files (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or substantial * portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import { Format, cn } from "@react-fabric/utilities"; import { useMemoDebugger } from "../../hooks/useEffectDebugger"; import type { CustomColors } from "../../types"; import { getColor } from "../../utils"; export interface ProgressProps { /** * progress value (0-1) */ value: number; /** * size */ size?: "sm" | "md" | "lg" | "xl"; /** * color */ color?: CustomColors; } const SizeMap: KeyValue = { "": "1rem", sm: "0.875rem", md: "1.125rem", lg: "1.5rem", xl: "2rem", }; /** * A circular progress indicator that visually represents a percentage of completion. * It displays a circular track with a stroke that fills based on the `value` prop. * The component is customizable with size and color props. * * @example * ```jsx * * // Renders a circular progress indicator with 75% completion, medium size, and primary color. * * * // Renders a circular progress indicator with 50% completion, large size, and secondary color. * ``` */ export function ProgressCircle({ value = 0, size = "sm", color = "primary-500" }: ProgressProps) { /** ***************** make sure value is between 0 and 100 *******************/ const actualValue = useMemoDebugger(() => Math.min(Math.max(value, 0), 1), [value], "ProgressCirle value"); /** ***************** calculate stroke offset by actual value *******************/ const strokeDashoffset = useMemoDebugger( () => { const circumfrence = Math.PI * 2 * 44; return circumfrence * (1 - actualValue); }, [actualValue], "ProgressCirle dashOffset", ); /** ***************** component *******************/ return ( ); }