2023-02-18 12:40:37 +03:00
|
|
|
import type { FC } from 'react';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { DropdownItem } from 'reactstrap';
|
2023-07-31 19:10:34 +03:00
|
|
|
import type { DateInterval } from './helpers/dateIntervals';
|
|
|
|
import { DATE_INTERVALS, rangeOrIntervalToString } from './helpers/dateIntervals';
|
2021-03-06 18:54:43 +03:00
|
|
|
|
|
|
|
export interface DateIntervalDropdownProps {
|
|
|
|
active?: DateInterval;
|
2021-10-03 22:07:07 +03:00
|
|
|
allText: string;
|
2021-03-06 18:54:43 +03:00
|
|
|
onChange: (interval: DateInterval) => void;
|
|
|
|
}
|
|
|
|
|
2021-10-03 22:07:07 +03:00
|
|
|
export const DateIntervalDropdownItems: FC<DateIntervalDropdownProps> = ({ active, allText, onChange }) => (
|
2021-03-06 18:54:43 +03:00
|
|
|
<>
|
2021-10-03 22:07:07 +03:00
|
|
|
<DropdownItem active={active === 'all'} onClick={() => onChange('all')}>
|
|
|
|
{allText}
|
|
|
|
</DropdownItem>
|
|
|
|
<DropdownItem divider />
|
2021-03-06 18:54:43 +03:00
|
|
|
{DATE_INTERVALS.map(
|
|
|
|
(interval) => (
|
|
|
|
<DropdownItem key={interval} active={active === interval} onClick={() => onChange(interval)}>
|
|
|
|
{rangeOrIntervalToString(interval)}
|
|
|
|
</DropdownItem>
|
|
|
|
),
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|