umami/components/DateFilter.js
2020-07-29 23:25:52 -07:00

25 lines
599 B
JavaScript

import React, { useState } from 'react';
import { getDateRange } from 'lib/date';
const filterOptions = ['24hour', '7day', '30day', '60day', '90day'];
export default function DateFilter({ onChange }) {
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 => (
<option key={option} value={option}>
{option}
</option>
))}
</select>
);
}