Duration Picker
rare-ui/duration-pickerFreeComponent
A gooey, spring-animated picker for entering a duration in hours and minutes.
Install it
npx shadcn@latest add https://rareui.com/r/duration-picker.jsonSource
1'use client'23import { Slot } from '@radix-ui/react-slot'4import { getSvgPath } from 'figma-squircle'5import { interpolate } from 'flubber'6import { motion, useMotionValue, useReducedMotion, useSpring, useTransform, useVelocity, type MotionStyle, type MotionValue } from 'motion/react'7import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'8import useMeasure from 'react-use-measure'910import { cn } from '@/lib/utils'1112const PEN_PATH = 'M3.78181 16.3092L3 21L7.69086 20.2182C8.50544 20.0825 9.25725 19.6956 9.84119 19.1116L20.4198 8.53288C21.1934 7.75922 21.1934 6.5049 20.4197 5.73126L18.2687 3.58024C17.495 2.80658 16.2406 2.80659 15.4669 3.58027L4.88841 14.159C4.30447 14.7429 3.91757 15.4947 3.78181 16.3092Z'13const TICK_PATH = 'M7.959 20.513L1.592 12.872L3.128 11.592L8.041 17.487L20.947 3.587L22.413 4.948L7.959 20.513Z'1415const OPEN_GAP = 816const CORNER_RADIUS = 1217const GAP_SPRING = { stiffness: 200, damping: 28, mass: 1 }18const ICON_SPRING = { stiffness: 200, damping: 28 }19const WIDTH_SPRING = { stiffness: 250, damping: 31 }20const SWAY_SPRING = { stiffness: 200, damping: 24 }21const ERROR_SPRING = { stiffness: 700, damping: 9 }2223export type DurationValue = {24 hours: number25 minutes: number26}2728export type DurationPickerProps = Omit<29 React.ComponentProps<'div'>,30 'onChange' | 'defaultValue' | 'onDrag' | 'onDragStart' | 'onDragEnd' | 'onAnimationStart' | 'onAnimationEnd'31> & {32 value?: DurationValue33 defaultValue?: DurationValue34 onChange?: (value: DurationValue) => void35 onConfirm?: (value: DurationValue) => void36 onEditingChange?: (editing: boolean) => void37 defaultEditing?: boolean38 maxHours?: number39 maxMinutes?: number40 hoursLabel?: string41 minutesLabel?: string42 disabled?: boolean43}4445type SquircleSegmentProps = {46 asChild?: boolean47 cornerSmoothing?: number48 leftRadius: number | MotionValue<number>49 rightRadius: number | MotionValue<number>50 className?: string51 style?: MotionStyle52 children: React.ReactNode53}5455const MotionSlot = motion.create(Slot)5657const radiusValue = (radius: number | MotionValue<number>) =>58 typeof radius === 'number' ? radius : radius.get()5960const SquircleSegment = ({ asChild, cornerSmoothing = 1, leftRadius, rightRadius, className, style, children }: SquircleSegmentProps) => {61 const Component = asChild ? MotionSlot : motion.div62 const [ref, bounds] = useMeasure()63 const width = useMotionValue(0)64 const height = useMotionValue(0)6566// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from rare-ui
All 13 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Bounce Sidebarbounce-sidebar | rare-ui | Components | Free | 1 dep | |
| Code Blockcode-block | rare-ui | Components | Free | 3 deps | |
| Emoji Reactionemoji-reaction | rare-ui | Components | Free | 4 deps | |
| Family Drawerfamily-drawer | rare-ui | Components | Free | 2 deps | |
| Fluid Orbfluid-orb | rare-ui | Components | Free | no deps | |
| Folder Componentfolder-component | rare-ui | Components | Free | 1 dep | |
| GitHub Activitygithub-activity | rare-ui | Components | Free | 1 dep | |
| Gravity Lettersgravity-letters | rare-ui | Components | Free | no deps |
