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