import { formatDate, Popover, PopoverContent, PopoverTrigger } from '@ballerine/ui'; import { CalendarIcon } from '@radix-ui/react-icons'; import dayjs from 'dayjs'; import { ComponentProps, useMemo } from 'react'; import { Button } from '@/common/components/atoms/Button/Button'; import { Calendar } from '@/common/components/molecules/Calendar/Calendar'; import { ctw } from '@/common/utils/ctw/ctw'; type TDateRangePickerProps = { onChange: NonNullable['onSelect']>; value: ComponentProps['selected']; placeholder?: string; className?: ComponentProps<'div'>['className']; }; export const DateRangePicker = ({ onChange, value, placeholder, className, ...props }: TDateRangePickerProps & Partial>) => { return (
} /> ); }; const DateRangePickerPlaceholder = ({ placeholder, value, }: Pick) => { const { text, shouldStyle } = useMemo(() => { if (!value || !value?.from) { return { text: placeholder ?? 'All Dates', shouldStyle: true }; } if ( dayjs(value.from).isSame(dayjs().subtract(1, 'month'), 'day') && value.to && dayjs().isSame(value.to, 'day') ) { return { text: 'Last 30 days', shouldStyle: true }; } if (value.from && value.to) { return { text: `${formatDate(value.from, 'LLL dd, y')} - ${formatDate(value.to, 'LLL dd, y')}`, shouldStyle: false, }; } return { text: formatDate(value.from, 'LLL dd, y'), shouldStyle: false }; }, [value, placeholder]); return ( {text} ); };