22 lines
3.5 KiB
JSON
22 lines
3.5 KiB
JSON
{
|
|
"$schema": "https://ui.shadcn.com/schema/registry-item.json",
|
|
"name": "base-progress",
|
|
"type": "registry:ui",
|
|
"title": "Base Progress",
|
|
"description": "Displays the status of a task that takes a long time.",
|
|
"dependencies": [
|
|
"motion",
|
|
"@base-ui-components/react"
|
|
],
|
|
"registryDependencies": [
|
|
"https://animate-ui.com/r/counting-number"
|
|
],
|
|
"files": [
|
|
{
|
|
"path": "registry/base/progress/index.tsx",
|
|
"content": "'use client';\n\nimport * as React from 'react';\nimport { Progress as ProgressPrimitives } from '@base-ui-components/react/progress';\nimport { motion, type Transition } from 'motion/react';\n\nimport { cn } from '@/lib/utils';\nimport {\n CountingNumber,\n type CountingNumberProps,\n} from '@/components/animate-ui/text/counting-number';\n\ntype ProgressContextType = {\n value: number | null;\n};\n\nconst ProgressContext = React.createContext<ProgressContextType | undefined>(\n undefined,\n);\n\nconst useProgress = (): ProgressContextType => {\n const context = React.useContext(ProgressContext);\n if (!context) {\n throw new Error('useProgress must be used within a Progress');\n }\n return context;\n};\n\ntype ProgressProps = React.ComponentProps<typeof ProgressPrimitives.Root>;\n\nconst Progress = ({ value, ...props }: ProgressProps) => {\n return (\n <ProgressContext.Provider value={{ value }}>\n <ProgressPrimitives.Root data-slot=\"progress\" value={value} {...props}>\n {props.children}\n </ProgressPrimitives.Root>\n </ProgressContext.Provider>\n );\n};\n\nconst MotionProgressIndicator = motion.create(ProgressPrimitives.Indicator);\n\ntype ProgressTrackProps = React.ComponentProps<\n typeof ProgressPrimitives.Track\n> & {\n transition?: Transition;\n};\n\nfunction ProgressTrack({\n className,\n transition = { type: 'spring', stiffness: 100, damping: 30 },\n ...props\n}: ProgressTrackProps) {\n const { value } = useProgress();\n\n return (\n <ProgressPrimitives.Track\n data-slot=\"progress-track\"\n className={cn(\n 'relative h-2 w-full overflow-hidden rounded-full bg-secondary',\n className,\n )}\n {...props}\n >\n <MotionProgressIndicator\n data-slot=\"progress-indicator\"\n className=\"h-full w-full flex-1 bg-primary rounded-full\"\n animate={{ width: `${value}%` }}\n transition={transition}\n />\n </ProgressPrimitives.Track>\n );\n}\n\ntype ProgressLabelProps = React.ComponentProps<typeof ProgressPrimitives.Label>;\n\nfunction ProgressLabel(props: ProgressLabelProps) {\n return <ProgressPrimitives.Label data-slot=\"progress-label\" {...props} />;\n}\n\ntype ProgressValueProps = Omit<\n React.ComponentProps<typeof ProgressPrimitives.Value>,\n 'render'\n> & {\n countingNumberProps?: CountingNumberProps;\n};\n\nfunction ProgressValue({ countingNumberProps, ...props }: ProgressValueProps) {\n const { value } = useProgress();\n\n return (\n <ProgressPrimitives.Value\n data-slot=\"progress-value\"\n render={\n <CountingNumber\n number={value ?? 0}\n transition={{ stiffness: 80, damping: 20 }}\n {...countingNumberProps}\n />\n }\n {...props}\n />\n );\n}\n\nexport {\n Progress,\n ProgressTrack,\n ProgressLabel,\n ProgressValue,\n useProgress,\n type ProgressProps,\n type ProgressTrackProps,\n type ProgressLabelProps,\n type ProgressValueProps,\n};\n",
|
|
"type": "registry:ui",
|
|
"target": "components/animate-ui/base/progress.tsx"
|
|
}
|
|
]
|
|
} |