umami/components/metrics/QuickButtons.js

31 lines
717 B
JavaScript
Raw Normal View History

2020-07-31 03:11:43 +00:00
import React from 'react';
2020-08-23 05:01:14 +00:00
import ButtonGroup from 'components/common/ButtonGroup';
2020-07-30 08:08:21 +00:00
import { getDateRange } from 'lib/date';
import styles from './QuickButtons.module.css';
const options = {
2020-08-23 05:01:14 +00:00
'24h': '24hour',
'7d': '7day',
'30d': '30day',
2020-07-30 08:08:21 +00:00
};
2020-07-31 03:11:43 +00:00
export default function QuickButtons({ value, onChange }) {
2020-08-23 05:01:14 +00:00
const selectedItem = Object.keys(options).find(key => options[key] === value);
2020-08-31 21:11:30 +00:00
function handleClick(selected) {
if (options[selected] !== value) {
onChange(getDateRange(options[selected]));
}
2020-07-30 08:08:21 +00:00
}
return (
2020-08-23 05:01:14 +00:00
<ButtonGroup
size="xsmall"
className={styles.buttons}
items={Object.keys(options)}
selectedItem={selectedItem}
onClick={handleClick}
/>
2020-07-30 08:08:21 +00:00
);
}