umami/components/common/Menu.js

47 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-08-06 08:03:07 +02:00
import React from 'react';
import classNames from 'classnames';
import styles from './Menu.module.css';
2020-08-10 00:13:38 +02:00
export default function Menu({
options = [],
selectedOption,
className,
float,
align = 'left',
optionClassName,
selectedClassName,
onSelect = () => {},
}) {
2020-08-06 08:03:07 +02:00
return (
<div
className={classNames(styles.menu, className, {
2020-08-10 00:13:38 +02:00
[styles.float]: float,
[styles.top]: float === 'top',
[styles.bottom]: float === 'bottom',
2020-08-06 08:03:07 +02:00
[styles.left]: align === 'left',
[styles.right]: align === 'right',
})}
>
{options
.filter(({ hidden }) => !hidden)
.map(option => {
const { label, value, className: customClassName, render } = option;
2020-08-10 00:13:38 +02:00
return render ? (
render(option)
) : (
<div
key={value}
className={classNames(styles.option, optionClassName, customClassName, {
[selectedClassName]: selectedOption === value,
})}
onClick={e => onSelect(value, e)}
>
{label}
</div>
);
})}
2020-08-06 08:03:07 +02:00
</div>
);
}