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',
|
|
|
|
})}
|
|
|
|
>
|
2020-08-11 04:54:03 +02:00
|
|
|
{options
|
|
|
|
.filter(({ hidden }) => !hidden)
|
|
|
|
.map(option => {
|
|
|
|
const { label, value, className: customClassName, render } = option;
|
2020-08-10 00:13:38 +02:00
|
|
|
|
2020-08-11 04:54:03 +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>
|
|
|
|
);
|
|
|
|
}
|