Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Patterns
Range Switcher
Previous and next arrows around a week or month.
import { useState } from "react"
import { RangeSwitcher, shiftWeek, weekLabel } from "@/registry/vcare/ui/range-switcher"
export default function RangeSwitcherDemo() {
const [start, setStart] = useState(() => new Date())
return <RangeSwitcher label={weekLabel(start, "en")} onPrevious={() => setStart((d) => shiftWeek(d, -1))} onNext={() => setStart((d) => shiftWeek(d, 1))} />
}Installation
npx shadcn@latest add @vcare/range-switcherOr install directly from the URL: https://ui.vcarehms.com/r/range-switcher.json
- Install the dependencies:
npm i date-fns lucide-react - Add the registry items it uses: calendar-locale, i18n, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/range-switcher.tsx
import { ChevronLeft, ChevronRight } from 'lucide-react';
import { addDays, addMonths, endOfWeek, format, startOfWeek } from 'date-fns';
import { useTranslation } from '@/registry/vcare/lib/i18n';
import { cn } from '@/registry/vcare/lib/utils';
import { calendarLocale } from '@/registry/vcare/lib/calendar-locale';
interface Props {
/** Text between the arrows, e.g. "29 Jun – 5 Jul". Use `weekLabel` or `monthLabel`. */
label: string;
onPrevious: () => void;
onNext: () => void;
/** Stop paging forward, for example when the range already reaches today. */
disableNext?: boolean;
disablePrevious?: boolean;
className?: string;
}
/** The pill with a chevron on each side that steps a card through weeks or months. */
export function RangeSwitcher({ label, onPrevious, onNext, disableNext, disablePrevious, className }: Props) {
const { t } = useTranslation();
const arrow =
'grid size-7 place-items-center rounded-full text-muted-foreground outline-none transition-colors duration-150 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-40 [&_svg]:size-4';
return (
<div data-slot="range-switcher" className={cn('inline-flex h-8 items-center gap-1 rounded-full bg-secondary px-0.5 shadow-raised', className)}>
<button
type="button"
className={arrow}
onClick={onPrevious}
disabled={disablePrevious}
aria-label={t('previous', { defaultValue: 'Previous' })}
>
<ChevronLeft />
</button>
<span className="min-w-20 px-1 text-center text-xs font-medium whitespace-nowrap tabular-nums" aria-live="polite">
{label}
</span>
<button type="button" className={arrow} onClick={onNext} disabled={disableNext} aria-label={t('next', { defaultValue: 'Next' })}>
<ChevronRight />
</button>
</div>
);
}
/** "29 Jun – 5 Jul" for the Monday-to-Sunday week containing `date`. */
export function weekLabel(date: Date, language: string) {
const locale = calendarLocale(language);
const start = startOfWeek(date, { weekStartsOn: 1, locale });
const end = endOfWeek(date, { weekStartsOn: 1, locale });
return `${format(start, 'd MMM', { locale })} – ${format(end, 'd MMM', { locale })}`;
}
export const shiftWeek = (date: Date, by: number) => addDays(date, by * 7);
export const shiftMonth = (date: Date, by: number) => addMonths(date, by);
export const monthLabel = (date: Date, language: string) => format(date, 'LLLL', { locale: calendarLocale(language) });Usage
import { RangeSwitcher } from "@/components/ui/range-switcher"Exports
RangeSwitcher
Dependencies
date-fns@^4.4.0(npm)lucide-react@^1.80.0(npm)@vcare/calendar-locale(registry)@vcare/i18n(registry)@vcare/utils(registry)
Raw item: /r/range-switcher.json