mirror of
https://github.com/umami-software/umami.git
synced 2026-02-06 13:47:15 +01:00
Add quick filter buttons.
This commit is contained in:
parent
9beec1b50e
commit
ff4492ffb5
10 changed files with 80 additions and 25 deletions
33
components/QuickButtons.js
Normal file
33
components/QuickButtons.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import React, { useState } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { getDateRange } from 'lib/date';
|
||||
import styles from './QuickButtons.module.css';
|
||||
|
||||
const options = {
|
||||
'24hour': '24h',
|
||||
'7day': '7d',
|
||||
'30day': '30d',
|
||||
};
|
||||
|
||||
export default function QuickButtons({ onChange }) {
|
||||
const [active, setActive] = useState('7day');
|
||||
|
||||
function handleClick(value) {
|
||||
setActive(value);
|
||||
onChange(getDateRange(value));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.buttons}>
|
||||
{Object.keys(options).map(key => (
|
||||
<div
|
||||
key={key}
|
||||
className={classNames(styles.button, { [styles.active]: active === key })}
|
||||
onClick={() => handleClick(key)}
|
||||
>
|
||||
{options[key]}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue