2022-11-10 13:47:02 +01:00
|
|
|
import React, { useRef, useState } from 'react';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import TimezoneSetting from './TimezoneSetting';
|
|
|
|
import DateRangeSetting from './DateRangeSetting';
|
2022-12-27 01:57:59 +01:00
|
|
|
import { Button, Icon } from 'react-basics';
|
2022-11-10 13:47:02 +01:00
|
|
|
import styles from './SettingsButton.module.css';
|
|
|
|
import Gear from 'assets/gear.svg';
|
|
|
|
import useDocumentClick from '../../hooks/useDocumentClick';
|
|
|
|
|
|
|
|
export default function SettingsButton() {
|
|
|
|
const [show, setShow] = useState(false);
|
|
|
|
const ref = useRef();
|
|
|
|
|
|
|
|
function handleClick() {
|
|
|
|
setShow(state => !state);
|
|
|
|
}
|
|
|
|
|
|
|
|
useDocumentClick(e => {
|
|
|
|
if (!ref.current?.contains(e.target)) {
|
|
|
|
setShow(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.button} ref={ref}>
|
2022-12-27 01:57:59 +01:00
|
|
|
<Button variant="light" onClick={handleClick}>
|
|
|
|
<Icon>
|
|
|
|
<Gear />
|
|
|
|
</Icon>
|
|
|
|
</Button>
|
2022-11-10 13:47:02 +01:00
|
|
|
{show && (
|
|
|
|
<div className={styles.panel}>
|
|
|
|
<dt>
|
|
|
|
<FormattedMessage id="label.timezone" defaultMessage="Timezone" />
|
|
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
<TimezoneSetting />
|
|
|
|
</dd>
|
|
|
|
<dt>
|
|
|
|
<FormattedMessage id="label.default-date-range" defaultMessage="Default date range" />
|
|
|
|
</dt>
|
|
|
|
<dd>
|
|
|
|
<DateRangeSetting />
|
|
|
|
</dd>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|