umami/components/DateFilter.js
2020-07-28 19:04:45 -07:00

25 lines
571 B
JavaScript

import React, { useState } from 'react';
import { getDateRange } from 'lib/date';
const filterOptions = ['24h', '7d', '30d'];
export default function DateFilter({ onChange }) {
const [selected, setSelected] = useState('7d');
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} name={option}>
{option}
</option>
))}
</select>
);
}