All files / src/components/RangeCalendar RangeCalendar.tsx

66.66% Statements 6/9
0% Branches 0/2
50% Functions 1/2
62.5% Lines 5/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30    12x                           12x   2x   2x           12x      
'use client';
 
import React from 'react';
 
import type {DateTime} from '@gravity-ui/date-utils';
 
import type {CalendarProps} from '../Calendar/Calendar';
import {CalendarView} from '../CalendarView/CalendarView';
import type {CalendarInstance} from '../CalendarView/CalendarView';
import {useRangeCalendarState} from '../CalendarView/hooks/useRangeCalendarState';
import type {RangeValue} from '../types';
 
import '../CalendarView/Calendar.scss';
 
export type RangeCalendarProps = CalendarProps<RangeValue<DateTime>>;
 
export const RangeCalendar = React.forwardRef<CalendarInstance, RangeCalendarProps>(
    function Calendar(props: RangeCalendarProps, ref) {
        const state = useRangeCalendarState(props);
 
        const handleBlur = (e: React.FocusEvent) => {
            if (state.anchorDate) {
                state.selectFocusedDate();
            }
            props.onBlur?.(e);
        };
        return <CalendarView ref={ref} {...props} state={state} onBlur={handleBlur} />;
    },
);