umami/components/DateFilter.js

25 lines
599 B
JavaScript
Raw Normal View History

import React, { useState } from 'react';
import { getDateRange } from 'lib/date';
2020-07-30 08:25:52 +02:00
const filterOptions = ['24hour', '7day', '30day', '60day', '90day'];
export default function DateFilter({ onChange }) {
2020-07-30 08:25:52 +02:00
const [selected, setSelected] = useState('7day');
function handleChange(e) {
const value = e.target.value;
setSelected(value);
onChange(getDateRange(value));
}
return (
<select value={selected} onChange={handleChange}>
{filterOptions.map(option => (
2020-07-30 08:25:52 +02:00
<option key={option} value={option}>
{option}
</option>
))}
</select>
);
}