Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.
TypeScript analyticsaudience-segmentationchartscohort-analysisgoogle-analyticsproduct-analyticsstatisticsuser-journeyweb-analytics
import { ListItem, Row, Select } from '@umami/react-zen';
import { useLocale } from '@/components/hooks';
import { formatDate } from '@/lib/date';
export function MonthSelect({ date = new Date(), onChange }) {
const { locale } = useLocale();
const month = date.getMonth();
const year = date.getFullYear();
const currentYear = new Date().getFullYear();
const months = [...Array(12)].map((_, i) => i);
const years = [...Array(10)].map((_, i) => currentYear - i);
const handleMonthChange = (month: number) => {
const d = new Date(date);
d.setMonth(month);
onChange?.(d);
};
const handleYearChange = (year: number) => {
const d = new Date(date);
d.setFullYear(year);
onChange?.(d);
};
return (
<Row gap>
<Select value={month} onChange={value => handleMonthChange(value as number)}>
{months.map(m => {
return (
<ListItem id={m} key={m}>
{formatDate(new Date(year, m, 1), 'MMMM', locale)}
</ListItem>
);
})}
</Select>
<Select value={year} onChange={value => handleYearChange(value as number)}>
{years.map(y => {
return (
<ListItem id={y} key={y}>
{y}
</ListItem>
);
})}
</Select>
</Row>
);
}