@neynar/ui 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/accordion.d.ts +1 -25
- package/dist/components/ui/accordion.d.ts.map +1 -1
- package/dist/components/ui/alert-dialog.d.ts +240 -46
- package/dist/components/ui/alert-dialog.d.ts.map +1 -1
- package/dist/components/ui/alert.d.ts +73 -11
- package/dist/components/ui/alert.d.ts.map +1 -1
- package/dist/components/ui/aspect-ratio.d.ts +44 -10
- package/dist/components/ui/aspect-ratio.d.ts.map +1 -1
- package/dist/components/ui/avatar.d.ts +117 -33
- package/dist/components/ui/avatar.d.ts.map +1 -1
- package/dist/components/ui/badge.d.ts +50 -71
- package/dist/components/ui/badge.d.ts.map +1 -1
- package/dist/components/ui/breadcrumb.d.ts +231 -49
- package/dist/components/ui/breadcrumb.d.ts.map +1 -1
- package/dist/components/ui/button.d.ts +189 -71
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/calendar.d.ts +197 -40
- package/dist/components/ui/calendar.d.ts.map +1 -1
- package/dist/components/ui/card.d.ts +7 -22
- package/dist/components/ui/card.d.ts.map +1 -1
- package/dist/components/ui/carousel.d.ts +369 -99
- package/dist/components/ui/carousel.d.ts.map +1 -1
- package/dist/components/ui/chart.d.ts.map +1 -1
- package/dist/components/ui/checkbox.d.ts +110 -38
- package/dist/components/ui/checkbox.d.ts.map +1 -1
- package/dist/components/ui/collapsible.d.ts +246 -61
- package/dist/components/ui/collapsible.d.ts.map +1 -1
- package/dist/components/ui/combobox.d.ts +207 -159
- package/dist/components/ui/combobox.d.ts.map +1 -1
- package/dist/components/ui/command.d.ts +336 -67
- package/dist/components/ui/command.d.ts.map +1 -1
- package/dist/components/ui/container.d.ts +159 -64
- package/dist/components/ui/container.d.ts.map +1 -1
- package/dist/components/ui/context-menu.d.ts +321 -39
- package/dist/components/ui/context-menu.d.ts.map +1 -1
- package/dist/components/ui/date-picker.d.ts +113 -86
- package/dist/components/ui/date-picker.d.ts.map +1 -1
- package/dist/components/ui/dialog.d.ts +106 -25
- package/dist/components/ui/dialog.d.ts.map +1 -1
- package/dist/components/ui/drawer.d.ts +388 -59
- package/dist/components/ui/drawer.d.ts.map +1 -1
- package/dist/components/ui/dropdown-menu.d.ts +521 -74
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -1
- package/dist/components/ui/empty-state.d.ts +148 -76
- package/dist/components/ui/empty-state.d.ts.map +1 -1
- package/dist/components/ui/hover-card.d.ts +253 -34
- package/dist/components/ui/hover-card.d.ts.map +1 -1
- package/dist/components/ui/input.d.ts +143 -44
- package/dist/components/ui/input.d.ts.map +1 -1
- package/dist/components/ui/label.d.ts +0 -8
- package/dist/components/ui/label.d.ts.map +1 -1
- package/dist/components/ui/menubar.d.ts +288 -46
- package/dist/components/ui/menubar.d.ts.map +1 -1
- package/dist/components/ui/navigation-menu.d.ts +444 -127
- package/dist/components/ui/navigation-menu.d.ts.map +1 -1
- package/dist/components/ui/pagination.d.ts +342 -66
- package/dist/components/ui/pagination.d.ts.map +1 -1
- package/dist/components/ui/popover.d.ts +0 -8
- package/dist/components/ui/popover.d.ts.map +1 -1
- package/dist/components/ui/progress.d.ts +88 -30
- package/dist/components/ui/progress.d.ts.map +1 -1
- package/dist/components/ui/radio-group.d.ts +189 -45
- package/dist/components/ui/radio-group.d.ts.map +1 -1
- package/dist/components/ui/resizable.d.ts +178 -62
- package/dist/components/ui/resizable.d.ts.map +1 -1
- package/dist/components/ui/scroll-area.d.ts +180 -21
- package/dist/components/ui/scroll-area.d.ts.map +1 -1
- package/dist/components/ui/select.d.ts +382 -60
- package/dist/components/ui/select.d.ts.map +1 -1
- package/dist/components/ui/separator.d.ts +52 -39
- package/dist/components/ui/separator.d.ts.map +1 -1
- package/dist/components/ui/sheet.d.ts +144 -27
- package/dist/components/ui/sheet.d.ts.map +1 -1
- package/dist/components/ui/sidebar.d.ts +81 -31
- package/dist/components/ui/sidebar.d.ts.map +1 -1
- package/dist/components/ui/skeleton.d.ts +94 -32
- package/dist/components/ui/skeleton.d.ts.map +1 -1
- package/dist/components/ui/slider.d.ts +37 -31
- package/dist/components/ui/slider.d.ts.map +1 -1
- package/dist/components/ui/sonner.d.ts +280 -46
- package/dist/components/ui/sonner.d.ts.map +1 -1
- package/dist/components/ui/stack.d.ts +289 -148
- package/dist/components/ui/stack.d.ts.map +1 -1
- package/dist/components/ui/stories/aspect-ratio.stories.d.ts +1 -2
- package/dist/components/ui/stories/aspect-ratio.stories.d.ts.map +1 -1
- package/dist/components/ui/stories/container.stories.d.ts +2 -3
- package/dist/components/ui/stories/container.stories.d.ts.map +1 -1
- package/dist/components/ui/stories/empty-state.stories.d.ts +2 -2
- package/dist/components/ui/stories/scroll-area.stories.d.ts +1 -2
- package/dist/components/ui/stories/scroll-area.stories.d.ts.map +1 -1
- package/dist/components/ui/stories/stack.stories.d.ts +1 -1
- package/dist/components/ui/stories/text-field.stories.d.ts +7 -1
- package/dist/components/ui/stories/text-field.stories.d.ts.map +1 -1
- package/dist/components/ui/switch.d.ts +44 -38
- package/dist/components/ui/switch.d.ts.map +1 -1
- package/dist/components/ui/table.d.ts +33 -0
- package/dist/components/ui/table.d.ts.map +1 -1
- package/dist/components/ui/tabs.d.ts +4 -22
- package/dist/components/ui/tabs.d.ts.map +1 -1
- package/dist/components/ui/text-field.d.ts +170 -84
- package/dist/components/ui/text-field.d.ts.map +1 -1
- package/dist/components/ui/textarea.d.ts +106 -29
- package/dist/components/ui/textarea.d.ts.map +1 -1
- package/dist/components/ui/theme-toggle.d.ts +190 -65
- package/dist/components/ui/theme-toggle.d.ts.map +1 -1
- package/dist/components/ui/theme.d.ts +107 -23
- package/dist/components/ui/theme.d.ts.map +1 -1
- package/dist/components/ui/toggle-group.d.ts +143 -67
- package/dist/components/ui/toggle-group.d.ts.map +1 -1
- package/dist/components/ui/toggle.d.ts +118 -30
- package/dist/components/ui/toggle.d.ts.map +1 -1
- package/dist/components/ui/tooltip.d.ts +152 -28
- package/dist/components/ui/tooltip.d.ts.map +1 -1
- package/dist/components/ui/typography.d.ts +452 -134
- package/dist/components/ui/typography.d.ts.map +1 -1
- package/dist/index.js +9388 -8281
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/llms.txt +173 -3
- package/package.json +5 -2
- package/src/components/ui/accordion.tsx +112 -27
- package/src/components/ui/alert-dialog.tsx +401 -46
- package/src/components/ui/alert.tsx +114 -11
- package/src/components/ui/aspect-ratio.tsx +69 -14
- package/src/components/ui/avatar.tsx +179 -33
- package/src/components/ui/badge.tsx +74 -75
- package/src/components/ui/breadcrumb.tsx +335 -50
- package/src/components/ui/button.tsx +198 -90
- package/src/components/ui/calendar.tsx +867 -43
- package/src/components/ui/card.tsx +140 -33
- package/src/components/ui/carousel.tsx +529 -98
- package/src/components/ui/chart.tsx +222 -1
- package/src/components/ui/checkbox.tsx +176 -38
- package/src/components/ui/collapsible.tsx +321 -67
- package/src/components/ui/combobox.tsx +284 -83
- package/src/components/ui/command.tsx +527 -67
- package/src/components/ui/container.tsx +217 -65
- package/src/components/ui/context-menu.tsx +716 -51
- package/src/components/ui/date-picker.tsx +228 -38
- package/src/components/ui/dialog.tsx +270 -33
- package/src/components/ui/drawer.tsx +546 -67
- package/src/components/ui/dropdown-menu.tsx +657 -74
- package/src/components/ui/empty-state.tsx +241 -82
- package/src/components/ui/hover-card.tsx +328 -39
- package/src/components/ui/input.tsx +207 -44
- package/src/components/ui/label.tsx +98 -8
- package/src/components/ui/menubar.tsx +587 -54
- package/src/components/ui/navigation-menu.tsx +557 -128
- package/src/components/ui/pagination.tsx +561 -79
- package/src/components/ui/popover.tsx +119 -8
- package/src/components/ui/progress.tsx +131 -29
- package/src/components/ui/radio-group.tsx +260 -51
- package/src/components/ui/resizable.tsx +289 -63
- package/src/components/ui/scroll-area.tsx +377 -66
- package/src/components/ui/select.tsx +545 -60
- package/src/components/ui/separator.tsx +146 -40
- package/src/components/ui/sheet.tsx +348 -31
- package/src/components/ui/sidebar.tsx +471 -29
- package/src/components/ui/skeleton.tsx +114 -32
- package/src/components/ui/slider.tsx +77 -31
- package/src/components/ui/sonner.tsx +574 -46
- package/src/components/ui/stack.tsx +423 -101
- package/src/components/ui/switch.tsx +78 -39
- package/src/components/ui/table.tsx +170 -4
- package/src/components/ui/tabs.tsx +108 -22
- package/src/components/ui/text-field.tsx +226 -81
- package/src/components/ui/textarea.tsx +180 -29
- package/src/components/ui/theme-toggle.tsx +313 -65
- package/src/components/ui/theme.tsx +117 -23
- package/src/components/ui/toggle-group.tsx +280 -69
- package/src/components/ui/toggle.tsx +124 -35
- package/src/components/ui/tooltip.tsx +239 -29
- package/src/components/ui/typography.tsx +1115 -165
|
@@ -8,82 +8,185 @@ import { Calendar } from "./calendar";
|
|
|
8
8
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Props for DatePicker component (Documentation only - NOT used in component implementation)
|
|
12
12
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* These types are for documentation generation and should not replace Calendar/Popover inferred types.
|
|
14
|
+
* Combines date selection functionality with popover positioning and calendar configuration.
|
|
15
|
+
* All props support both controlled and uncontrolled usage patterns for flexible integration
|
|
16
|
+
* with forms, state management, and validation systems.
|
|
17
|
+
*
|
|
18
|
+
* Extends the base date picker functionality with comprehensive prop documentation.
|
|
19
|
+
* This component is built on Radix UI Popover and Calendar primitives, inheriting
|
|
20
|
+
* their accessibility features while providing a simplified, opinionated interface
|
|
21
|
+
* for common date selection use cases.
|
|
22
|
+
*
|
|
23
|
+
* **Inherited Behavior:**
|
|
24
|
+
* - Popover positioning and collision detection from Radix UI Popover
|
|
25
|
+
* - Calendar navigation and accessibility from shadcn/ui Calendar
|
|
26
|
+
* - Button styling and interaction states from shadcn/ui Button
|
|
27
|
+
* - Portal rendering for proper z-index layering
|
|
28
|
+
* - Keyboard navigation and ARIA support
|
|
29
|
+
* - Automatic focus management and restoration
|
|
30
|
+
*
|
|
31
|
+
* **Key Features:**
|
|
32
|
+
* - Controlled and uncontrolled usage patterns
|
|
33
|
+
* - Automatic date formatting with internationalization
|
|
34
|
+
* - Form library integration support
|
|
35
|
+
* - Responsive design with customizable width
|
|
36
|
+
* - Touch-friendly mobile interface
|
|
37
|
+
* - High contrast accessibility compliance
|
|
15
38
|
*/
|
|
16
|
-
|
|
39
|
+
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
40
|
+
type DatePickerDocsProps = {
|
|
17
41
|
/**
|
|
18
|
-
* The currently selected date value
|
|
42
|
+
* The currently selected date value
|
|
43
|
+
*
|
|
44
|
+
* Controls the date selection state. When undefined, no date is selected and
|
|
45
|
+
* the placeholder text is displayed. Pass a Date object to show a selected date.
|
|
46
|
+
* For controlled usage, combine with onDateChange callback.
|
|
19
47
|
*
|
|
20
48
|
* @example
|
|
21
49
|
* ```tsx
|
|
50
|
+
* // Controlled usage
|
|
22
51
|
* const [selectedDate, setSelectedDate] = useState<Date>();
|
|
23
52
|
* <DatePicker date={selectedDate} onDateChange={setSelectedDate} />
|
|
53
|
+
*
|
|
54
|
+
* // Uncontrolled with default
|
|
55
|
+
* <DatePicker date={new Date()} /> // Shows today
|
|
56
|
+
*
|
|
57
|
+
* // No selection
|
|
58
|
+
* <DatePicker /> // Shows placeholder
|
|
24
59
|
* ```
|
|
25
60
|
*/
|
|
26
61
|
date?: Date;
|
|
27
62
|
|
|
28
63
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
64
|
+
* Event handler called when the date selection changes
|
|
65
|
+
*
|
|
66
|
+
* Invoked whenever the user selects a new date from the calendar or clears
|
|
67
|
+
* the current selection. Receives the new date or undefined if cleared.
|
|
68
|
+
* Essential for controlled usage and form integration.
|
|
31
69
|
*
|
|
32
|
-
* @param date - The newly selected date or undefined if cleared
|
|
70
|
+
* @param date - The newly selected date, or undefined if selection was cleared
|
|
33
71
|
*
|
|
34
72
|
* @example
|
|
35
73
|
* ```tsx
|
|
36
|
-
*
|
|
74
|
+
* // Basic usage with state
|
|
75
|
+
* <DatePicker onDateChange={(date) => {
|
|
76
|
+
* console.log('Selected:', date);
|
|
77
|
+
* setFormData(prev => ({ ...prev, selectedDate: date }));
|
|
78
|
+
* }} />
|
|
79
|
+
*
|
|
80
|
+
* // Form integration
|
|
81
|
+
* <DatePicker onDateChange={(date) => {
|
|
82
|
+
* setValue('birthDate', date); // React Hook Form
|
|
83
|
+
* validateField('birthDate'); // Validation
|
|
84
|
+
* }} />
|
|
85
|
+
*
|
|
86
|
+
* // Analytics tracking
|
|
87
|
+
* <DatePicker onDateChange={(date) => {
|
|
88
|
+
* if (date) {
|
|
89
|
+
* analytics.track('date_selected', { date: date.toISOString() });
|
|
90
|
+
* }
|
|
91
|
+
* }} />
|
|
37
92
|
* ```
|
|
38
93
|
*/
|
|
39
94
|
onDateChange?: (date: Date | undefined) => void;
|
|
40
95
|
|
|
41
96
|
/**
|
|
42
|
-
* Placeholder text displayed
|
|
43
|
-
*
|
|
97
|
+
* Placeholder text displayed when no date is selected
|
|
98
|
+
*
|
|
99
|
+
* Shows in the trigger button as a prompt to guide users about the expected
|
|
100
|
+
* date selection. Should be descriptive and context-appropriate to help users
|
|
101
|
+
* understand what kind of date they should choose.
|
|
44
102
|
*
|
|
45
103
|
* @default "Pick a date"
|
|
46
104
|
*
|
|
47
105
|
* @example
|
|
48
106
|
* ```tsx
|
|
107
|
+
* // Contextual placeholders
|
|
49
108
|
* <DatePicker placeholder="Select your birthday" />
|
|
109
|
+
* <DatePicker placeholder="Choose departure date" />
|
|
110
|
+
* <DatePicker placeholder="Pick appointment time" />
|
|
111
|
+
* <DatePicker placeholder="Select due date" />
|
|
112
|
+
*
|
|
113
|
+
* // With internationalization
|
|
114
|
+
* <DatePicker placeholder={t('datePicker.placeholder')} />
|
|
50
115
|
* ```
|
|
51
116
|
*/
|
|
52
117
|
placeholder?: string;
|
|
53
118
|
|
|
54
119
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
120
|
+
* Disables the entire date picker component
|
|
121
|
+
*
|
|
122
|
+
* When true, prevents all user interaction including clicking the trigger button,
|
|
123
|
+
* opening the calendar popover, and keyboard navigation. The component will appear
|
|
124
|
+
* visually disabled with reduced opacity and appropriate cursor states.
|
|
57
125
|
*
|
|
58
126
|
* @default false
|
|
59
127
|
*
|
|
60
128
|
* @example
|
|
61
129
|
* ```tsx
|
|
62
|
-
*
|
|
130
|
+
* // Form field disabling
|
|
131
|
+
* <DatePicker disabled={isSubmitting} placeholder="Loading..." />
|
|
132
|
+
*
|
|
133
|
+
* // Conditional disabling based on permissions
|
|
134
|
+
* <DatePicker disabled={!canEditDates} placeholder="Date locked" />
|
|
135
|
+
*
|
|
136
|
+
* // Loading state
|
|
137
|
+
* <DatePicker disabled={isLoadingData} placeholder="Loading available dates..." />
|
|
138
|
+
*
|
|
139
|
+
* // Past date selection disabled
|
|
140
|
+
* <DatePicker
|
|
141
|
+
* disabled={selectedDate && selectedDate < new Date()}
|
|
142
|
+
* placeholder="Future dates only"
|
|
143
|
+
* />
|
|
63
144
|
* ```
|
|
64
145
|
*/
|
|
65
146
|
disabled?: boolean;
|
|
66
147
|
|
|
67
148
|
/**
|
|
68
|
-
* Additional CSS classes
|
|
69
|
-
*
|
|
149
|
+
* Additional CSS classes for the trigger button
|
|
150
|
+
*
|
|
151
|
+
* Applies custom styling to the date picker's trigger button. Commonly used
|
|
152
|
+
* for width adjustments, spacing, alignment, or integration with form layouts.
|
|
153
|
+
* Classes are merged with the default button styling.
|
|
70
154
|
*
|
|
71
155
|
* @example
|
|
72
156
|
* ```tsx
|
|
157
|
+
* // Width customization
|
|
73
158
|
* <DatePicker className="w-full" /> // Full width
|
|
74
159
|
* <DatePicker className="w-[300px]" /> // Fixed width
|
|
160
|
+
* <DatePicker className="min-w-[200px]" /> // Minimum width
|
|
161
|
+
*
|
|
162
|
+
* // Form integration
|
|
163
|
+
* <DatePicker className="flex-1" /> // Flexible within flex container
|
|
164
|
+
* <DatePicker className="col-span-2" /> // Grid column spanning
|
|
165
|
+
*
|
|
166
|
+
* // Spacing and alignment
|
|
167
|
+
* <DatePicker className="ml-auto" /> // Right-aligned
|
|
168
|
+
* <DatePicker className="mx-auto" /> // Center-aligned
|
|
169
|
+
* <DatePicker className="mb-4" /> // Bottom margin
|
|
170
|
+
*
|
|
171
|
+
* // Custom styling
|
|
172
|
+
* <DatePicker className="border-2 border-blue-500 focus:border-blue-600" />
|
|
75
173
|
* ```
|
|
76
174
|
*/
|
|
77
175
|
className?: string;
|
|
78
176
|
};
|
|
79
177
|
|
|
80
178
|
/**
|
|
81
|
-
* A comprehensive date selection component
|
|
82
|
-
* with a full-featured calendar popover for intuitive date picking.
|
|
179
|
+
* DatePicker - A comprehensive date selection component with popover calendar interface
|
|
83
180
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
181
|
+
* A polished date selection component that combines an accessible trigger button with a
|
|
182
|
+
* full-featured calendar popover. Built on Radix UI Popover and Calendar primitives with
|
|
183
|
+
* shadcn/ui styling, providing intuitive date selection with proper accessibility,
|
|
184
|
+
* keyboard navigation, automatic positioning, and internationalization support.
|
|
185
|
+
*
|
|
186
|
+
* The component handles both controlled and uncontrolled usage patterns, integrates
|
|
187
|
+
* seamlessly with forms and validation systems, and provides consistent date formatting
|
|
188
|
+
* using date-fns. The popover automatically positions itself to stay within viewport
|
|
189
|
+
* bounds and includes smooth animations for a polished user experience.
|
|
87
190
|
*
|
|
88
191
|
* @component
|
|
89
192
|
* @example
|
|
@@ -133,24 +236,105 @@ type DatePickerProps = {
|
|
|
133
236
|
* ```
|
|
134
237
|
*
|
|
135
238
|
* @accessibility
|
|
136
|
-
* - **Keyboard Navigation**:
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
239
|
+
* - **Keyboard Navigation**:
|
|
240
|
+
* - Tab to focus the trigger button
|
|
241
|
+
* - Enter/Space to open calendar popover
|
|
242
|
+
* - Arrow keys for date navigation within calendar
|
|
243
|
+
* - Escape to close popover and return focus to trigger
|
|
244
|
+
* - Page Up/Down for month navigation
|
|
245
|
+
* - Home/End for week start/end navigation
|
|
246
|
+
* - **Screen Reader Support**:
|
|
247
|
+
* - Proper ARIA labels describing the date picker purpose
|
|
248
|
+
* - Live region announcements for date selection changes
|
|
249
|
+
* - Calendar grid structure announced correctly
|
|
250
|
+
* - Selected date clearly announced with full formatting
|
|
251
|
+
* - **Focus Management**:
|
|
252
|
+
* - Visible focus indicators with 3px ring on trigger button
|
|
253
|
+
* - Focus trapped within calendar when popover is open
|
|
254
|
+
* - Focus returns to trigger button when popover closes
|
|
255
|
+
* - Initial focus on today's date or selected date when opening
|
|
256
|
+
* - **Visual Indicators**:
|
|
257
|
+
* - Clear visual states for disabled, selected, and focused elements
|
|
258
|
+
* - High contrast borders and backgrounds meeting WCAG 2.1 AA standards
|
|
259
|
+
* - Consistent color coding for different date states
|
|
260
|
+
* - Reduced opacity for disabled state with appropriate cursor
|
|
261
|
+
* - **Date Formatting**:
|
|
262
|
+
* - Consistent date presentation using date-fns localized formatting
|
|
263
|
+
* - Full date format (e.g., "Wednesday, January 15, 2025") for clarity
|
|
264
|
+
* - Placeholder text provides clear guidance about expected input
|
|
141
265
|
*
|
|
142
266
|
* @features
|
|
143
|
-
* - Single date selection with visual confirmation
|
|
144
|
-
* - Popover-
|
|
145
|
-
* - Automatic
|
|
146
|
-
* -
|
|
147
|
-
* - Customizable trigger button
|
|
148
|
-
* - Date formatting
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
267
|
+
* - **Date Selection**: Single date selection with immediate visual confirmation
|
|
268
|
+
* - **Popover Interface**: Non-modal calendar popover that doesn't disrupt page layout
|
|
269
|
+
* - **Smart Positioning**: Automatic positioning with collision detection and boundary awareness
|
|
270
|
+
* - **State Management**: Flexible controlled/uncontrolled patterns with internal state fallback
|
|
271
|
+
* - **Customizable Styling**: Full control over trigger button appearance, width, and spacing
|
|
272
|
+
* - **Internationalization**: Date formatting with date-fns supporting multiple locales
|
|
273
|
+
* - **Form Integration**: Seamless integration with form libraries and validation systems
|
|
274
|
+
* - **Performance**: Optimized rendering with minimal re-renders and efficient state updates
|
|
275
|
+
* - **Animation**: Smooth open/close animations with proper state transitions
|
|
276
|
+
* - **Mobile Support**: Touch-friendly interface with appropriate sizing and spacing
|
|
277
|
+
*
|
|
278
|
+
* @implementation
|
|
279
|
+
* The DatePicker component is implemented as a composition of:
|
|
280
|
+
* - **Popover**: Radix UI primitive providing positioning, portal rendering, and focus management
|
|
281
|
+
* - **PopoverTrigger**: Button element that opens the calendar (uses asChild pattern)
|
|
282
|
+
* - **PopoverContent**: Container for the calendar with auto-positioning
|
|
283
|
+
* - **Calendar**: Full-featured calendar component with keyboard navigation
|
|
284
|
+
* - **Button**: Styled trigger with outline variant and calendar icon
|
|
285
|
+
*
|
|
286
|
+
* State is managed internally with React.useState hooks and synchronized with external
|
|
287
|
+
* props through React.useEffect. The component automatically handles date formatting
|
|
288
|
+
* using date-fns format function with "PPP" pattern for readable date display.
|
|
289
|
+
*
|
|
290
|
+
* @usage-patterns
|
|
291
|
+
* **Controlled Pattern** (Recommended):
|
|
292
|
+
* ```tsx
|
|
293
|
+
* const [date, setDate] = useState<Date>();
|
|
294
|
+
* <DatePicker date={date} onDateChange={setDate} />
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* **Form Library Integration**:
|
|
298
|
+
* ```tsx
|
|
299
|
+
* // React Hook Form
|
|
300
|
+
* <Controller render={({ field }) =>
|
|
301
|
+
* <DatePicker date={field.value} onDateChange={field.onChange} />
|
|
302
|
+
* } />
|
|
303
|
+
*
|
|
304
|
+
* // Formik
|
|
305
|
+
* <Field name="date">
|
|
306
|
+
* {({ field, form }) => (
|
|
307
|
+
* <DatePicker
|
|
308
|
+
* date={field.value}
|
|
309
|
+
* onDateChange={(date) => form.setFieldValue('date', date)}
|
|
310
|
+
* />
|
|
311
|
+
* )}
|
|
312
|
+
* </Field>
|
|
313
|
+
* ```
|
|
314
|
+
*
|
|
315
|
+
* **Validation Integration**:
|
|
316
|
+
* ```tsx
|
|
317
|
+
* const handleDateChange = (date: Date | undefined) => {
|
|
318
|
+
* // Validate date before setting
|
|
319
|
+
* if (date && isValidDate(date)) {
|
|
320
|
+
* setDate(date);
|
|
321
|
+
* clearError();
|
|
322
|
+
* } else {
|
|
323
|
+
* setError('Please select a valid date');
|
|
324
|
+
* }
|
|
325
|
+
* };
|
|
326
|
+
* ```
|
|
327
|
+
*
|
|
328
|
+
* @see {@link Calendar} The underlying calendar component with full date navigation
|
|
329
|
+
* @see {@link Popover} The popover container component for positioning and portal rendering
|
|
330
|
+
* @see {@link PopoverTrigger} Trigger element that opens the calendar popover
|
|
331
|
+
* @see {@link PopoverContent} Content container for the calendar with auto-positioning
|
|
332
|
+
* @see {@link Button} The styled trigger button with variant support
|
|
333
|
+
* @see {@link https://ui.shadcn.com/docs/components/date-picker} shadcn/ui Date Picker documentation
|
|
334
|
+
* @see {@link https://ui.shadcn.com/docs/components/calendar} shadcn/ui Calendar component
|
|
335
|
+
* @see {@link https://ui.shadcn.com/docs/components/popover} shadcn/ui Popover component
|
|
336
|
+
* @see {@link https://date-fns.org/docs/format} date-fns formatting documentation
|
|
337
|
+
* @see {@link https://www.radix-ui.com/primitives/docs/components/popover} Radix UI Popover primitives
|
|
154
338
|
*
|
|
155
339
|
* @since 1.0.0
|
|
156
340
|
*/
|
|
@@ -160,7 +344,13 @@ function DatePicker({
|
|
|
160
344
|
placeholder = "Pick a date",
|
|
161
345
|
disabled = false,
|
|
162
346
|
className,
|
|
163
|
-
}:
|
|
347
|
+
}: {
|
|
348
|
+
date?: Date;
|
|
349
|
+
onDateChange?: (date: Date | undefined) => void;
|
|
350
|
+
placeholder?: string;
|
|
351
|
+
disabled?: boolean;
|
|
352
|
+
className?: string;
|
|
353
|
+
}) {
|
|
164
354
|
// Internal state for uncontrolled usage and popover open/close
|
|
165
355
|
const [internalDate, setInternalDate] = React.useState<Date | undefined>(
|
|
166
356
|
date,
|