umami/components/QuickButtons.js

31 lines
688 B
JavaScript
Raw Normal View History

2020-07-31 05:11:43 +02:00
import React from 'react';
2020-07-30 10:08:21 +02:00
import classNames from 'classnames';
import { getDateRange } from 'lib/date';
import styles from './QuickButtons.module.css';
const options = {
'24hour': '24h',
'7day': '7d',
'30day': '30d',
};
2020-07-31 05:11:43 +02:00
export default function QuickButtons({ value, onChange }) {
2020-07-30 10:08:21 +02:00
function handleClick(value) {
onChange(getDateRange(value));
}
return (
<div className={styles.buttons}>
{Object.keys(options).map(key => (
<div
key={key}
2020-07-31 05:11:43 +02:00
className={classNames(styles.button, { [styles.active]: value === key })}
2020-07-30 10:08:21 +02:00
onClick={() => handleClick(key)}
>
{options[key]}
</div>
))}
</div>
);
}