umami/components/metrics/QuickButtons.js

31 lines
733 B
JavaScript
Raw Normal View History

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';
2020-09-06 02:27:01 +02:00
const options = [
{ label: '24h', value: '24hour' },
{ label: '7d', value: '7day' },
{ label: '30d', value: '30day' },
];
2020-07-30 10:08:21 +02:00
2020-07-31 05:11:43 +02:00
export default function QuickButtons({ value, onChange }) {
2020-09-06 02:27:01 +02:00
const selectedItem = options.find(item => item.value === value)?.value;
2020-08-23 07:01:14 +02:00
2020-08-31 23:11:30 +02:00
function handleClick(selected) {
2020-09-06 02:27:01 +02:00
if (selected !== value) {
onChange(getDateRange(selected));
2020-08-31 23:11:30 +02:00
}
2020-07-30 10:08:21 +02:00
}
return (
2020-08-23 07:01:14 +02:00
<ButtonGroup
size="xsmall"
className={styles.buttons}
2020-09-06 02:27:01 +02:00
items={options}
2020-08-23 07:01:14 +02:00
selectedItem={selectedItem}
onClick={handleClick}
/>
2020-07-30 10:08:21 +02:00
);
}