Skip to content

Commit d2e4159

Browse files
feat: add Calendar component and update DatePicker with latest shadcn/ui improvements
- Add standalone Calendar component following latest shadcn/ui patterns - Update DatePicker day_outside styling for better contrast (Nov 3, 2024 update) - Remove opacity-50 and aria-selected:opacity-30 from day_outside for improved accessibility - Export Calendar component in UI index - Maintain backward compatibility with existing DatePicker usage
1 parent 879e7e4 commit d2e4159

3 files changed

Lines changed: 58 additions & 1 deletion

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { ChevronLeft, ChevronRight } from 'lucide-react';
2+
import type * as React from 'react';
3+
import { type CustomComponents, DayPicker } from 'react-day-picker';
4+
import { buttonVariants } from './button';
5+
import { cn } from './utils';
6+
7+
export type CalendarProps = React.ComponentProps<typeof DayPicker>;
8+
9+
function Calendar({ className, classNames, showOutsideDays = true, ...props }: CalendarProps) {
10+
return (
11+
<DayPicker
12+
showOutsideDays={showOutsideDays}
13+
className={cn('p-3', className)}
14+
data-slot="calendar"
15+
classNames={{
16+
months: 'flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0',
17+
month: 'space-y-4',
18+
caption: 'flex justify-center pt-1 relative items-center',
19+
caption_label: 'text-sm font-medium',
20+
nav: 'space-x-1 flex items-center',
21+
nav_button: cn(
22+
buttonVariants({ variant: 'outline' }),
23+
'h-7 w-7 bg-transparent p-0 opacity-50 hover:opacity-100',
24+
),
25+
nav_button_previous: 'absolute left-1',
26+
nav_button_next: 'absolute right-1',
27+
table: 'w-full border-collapse space-y-1',
28+
head_row: 'flex',
29+
head_cell: 'text-muted-foreground rounded-md w-9 font-normal text-[0.8rem]',
30+
row: 'flex w-full mt-2',
31+
cell: 'h-9 w-9 text-center text-sm p-0 relative [&:has([aria-selected].day-range-end)]:rounded-r-md [&:has([aria-selected].day-outside)]:bg-accent/50 [&:has([aria-selected])]:bg-accent first:[&:has([aria-selected])]:rounded-l-md last:[&:has([aria-selected])]:rounded-r-md focus-within:relative focus-within:z-20',
32+
day: cn(buttonVariants({ variant: 'ghost' }), 'h-9 w-9 p-0 font-normal aria-selected:opacity-100'),
33+
day_range_end: 'day-range-end',
34+
day_selected:
35+
'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground',
36+
day_today: 'bg-accent text-accent-foreground',
37+
day_outside:
38+
'day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground',
39+
day_disabled: 'text-muted-foreground opacity-50',
40+
day_range_middle: 'aria-selected:bg-accent aria-selected:text-accent-foreground',
41+
day_hidden: 'invisible',
42+
...classNames,
43+
}}
44+
components={
45+
{
46+
IconLeft: ({ ...props }) => <ChevronLeft className="h-4 w-4" {...props} />,
47+
IconRight: ({ ...props }) => <ChevronRight className="h-4 w-4" {...props} />,
48+
} as Partial<CustomComponents>
49+
}
50+
{...props}
51+
/>
52+
);
53+
}
54+
55+
export { Calendar };
56+

packages/components/src/ui/date-picker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function DatePicker({ className, classNames, showOutsideDays = true, ...props }:
3535
'bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground',
3636
day_today: 'bg-accent text-accent-foreground',
3737
day_outside:
38-
'day-outside text-muted-foreground opacity-50 aria-selected:bg-accent/50 aria-selected:text-muted-foreground aria-selected:opacity-30',
38+
'day-outside text-muted-foreground aria-selected:bg-accent/50 aria-selected:text-muted-foreground',
3939
day_disabled: 'text-muted-foreground opacity-50',
4040
day_range_middle: 'aria-selected:bg-accent aria-selected:text-accent-foreground',
4141
day_hidden: 'invisible',

packages/components/src/ui/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './button';
2+
export * from './calendar';
23
export * from './checkbox-field';
34
export * from './date-picker';
45
export * from './date-picker-field';

0 commit comments

Comments
 (0)