diff --git a/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx b/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx index 5092491b6..1b865aa8e 100644 --- a/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx +++ b/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx @@ -210,7 +210,7 @@ const LinkExpiration: React.FC<{ return createDayjsDate(new Date()).add(2, 'year'); }, []); - const onSelect: SelectSingleEventHandler = useMemoizedFn((date) => { + const onSelect = useMemoizedFn((date: Date | undefined) => { onChangeLinkExpiry(date || null); }); @@ -219,7 +219,7 @@ const LinkExpiration: React.FC<{ Link expiration = { + title: 'UI/Date/DatePicker', + component: DatePicker, + tags: ['autodocs'], + argTypes: { + dateFormat: { + control: 'text', + description: 'Format for displaying the selected date' + }, + placeholder: { + control: 'text', + description: 'Text to display when no date is selected' + }, + selected: { + control: 'date', + description: 'The currently selected date' + }, + onSelect: { + action: 'date selected', + description: 'Callback when a date is selected' + }, + mode: { + control: 'select', + options: ['single', 'range', 'multiple'], + description: 'Selection mode for the calendar' + }, + disabled: { + control: 'boolean', + description: 'Whether the date picker is disabled' + }, + fromDate: { + control: 'date', + description: 'Minimum selectable date' + }, + toDate: { + control: 'date', + description: 'Maximum selectable date' + } + } +}; + +export default meta; +type Story = StoryObj; + +// Create interactive wrappers for each story +const InteractiveDatePicker = ({ initialDate, ...args }: any) => { + const [date, setDate] = useState(initialDate); + + const handleDateSelect = (newDate: Date | undefined) => { + setDate(newDate); + action('onSelect')(newDate); + }; + + return ; +}; + +export const Default: Story = { + render: (args) => , + args: { + placeholder: 'Select a date' + } +}; + +export const WithSelectedDate: Story = { + render: (args) => , + args: { + placeholder: 'Select a date' + } +}; + +export const CustomDateFormat: Story = { + render: (args) => , + args: { + dateFormat: 'MMMM dd, yyyy', + placeholder: 'Select a date' + } +}; + +export const Disabled: Story = { + render: (args) => , + args: { + disabled: true, + placeholder: 'Date selection disabled' + } +}; + +export const WithDateRange: Story = { + render: (args) => , + args: { + fromDate: new Date(new Date().setDate(new Date().getDate() - 30)), + toDate: new Date(new Date().setDate(new Date().getDate() + 30)), + placeholder: 'Select within 30 day range' + } +}; diff --git a/web/src/components/ui/date/DatePicker.tsx b/web/src/components/ui/date/DatePicker.tsx index eb9b72d7b..97bedaf17 100644 --- a/web/src/components/ui/date/DatePicker.tsx +++ b/web/src/components/ui/date/DatePicker.tsx @@ -12,18 +12,19 @@ import { PopoverTrigger } from '@/components/ui/tooltip/PopoverBase'; import { formatDate } from '@/lib'; -import { DayPickerProps } from 'react-day-picker'; -export type DatePickerProps = CalendarProps & { +export type DatePickerProps = Omit & { dateFormat?: string; placeholder?: string; + selected?: Date; + onSelect: (date: Date | undefined) => void; }; export function DatePicker({ dateFormat = 'lll', placeholder = 'Pick a date', selected, - + onSelect, ...props }: DatePickerProps) { return ( @@ -47,7 +48,7 @@ export function DatePicker({ - + );