import type { Meta, StoryObj } from "@storybook/react-native"; import { addDays, addMonths, endOfYear, startOfMonth, startOfYear, subMonths, } from "date-fns"; import { useCallback, useMemo, useRef, useState } from "react"; import { Button, Text, View } from "react-native"; import type { CalendarListProps, CalendarListRef } from "@/components"; import { Calendar } from "@/components"; import { HStack } from "@/components/HStack"; import { VStack } from "@/components/VStack"; import { paddingDecorator } from "@/developer/decorators"; import { loggingHandler } from "@/developer/loggginHandler"; import { fromDateId, toDateId } from "@/helpers/dates"; import type { CalendarActiveDateRange } from "@/hooks/useCalendar"; import { useDateRange } from "@/hooks/useDateRange"; import { useTheme } from "@/hooks/useTheme"; const today = new Date(); const startOfThisMonth = startOfMonth(today); const CalendarListMeta: Meta = { title: "Calendar.List", component: Calendar.List, argTypes: {}, args: { onCalendarDayPress: loggingHandler("onCalendarDayPress"), calendarRowVerticalSpacing: 8, calendarRowHorizontalSpacing: 8, calendarFutureScrollRangeInMonths: 12, calendarPastScrollRangeInMonths: 12, calendarFirstDayOfWeek: "sunday", calendarInitialMonthId: toDateId(startOfThisMonth), }, decorators: [paddingDecorator], }; export default CalendarListMeta; export const Default: StoryObj = {}; export const SpacingDense: StoryObj = { args: { calendarRowVerticalSpacing: 0, calendarRowHorizontalSpacing: 4, }, }; export const WithDateRangeAndDisabledDates: StoryObj = { args: { calendarActiveDateRanges: [ { startId: "2024-01-15", endId: "2024-01-28", }, ], calendarDisabledDateIds: ["2024-01-01", "2024-01-02"], calendarInitialMonthId: "2024-01-01", }, }; export const WithShortFutureScrollRange: StoryObj = { args: { calendarPastScrollRangeInMonths: 1, calendarFutureScrollRangeInMonths: 1, calendarInitialMonthId: "2024-02-01", }, }; export function SpacingSparse() { const [selectedDate, setSelectedDate] = useState( undefined ); const onCalendarDayPress = (dateId: string) => { setSelectedDate(dateId); }; return ( Selected date: {selectedDate} ); } export function ImperativeScrolling() { const [currentMonth, setCurrentMonth] = useState(startOfMonth(new Date())); const [activeDateId, setActiveDateId] = useState( toDateId(addDays(currentMonth, 3)) ); const calendarActiveDateRanges = useMemo(() => { if (!activeDateId) return []; return [{ startId: activeDateId, endId: activeDateId }]; }, [activeDateId]); const ref = useRef(null); const onCalendarDayPress = useCallback((dateId: string) => { ref.current?.scrollToDate(fromDateId(dateId), true); setActiveDateId(dateId); }, []); return (