2020-12-25 10:29:25 +01:00
|
|
|
import { FC } from 'react';
|
2020-12-25 10:43:36 +01:00
|
|
|
import { Dropdown, DropdownMenu, DropdownToggle } from 'reactstrap';
|
2020-12-25 10:29:25 +01:00
|
|
|
import { useToggle } from './helpers/hooks';
|
2020-12-25 11:21:39 +01:00
|
|
|
import './DropdownBtn.scss';
|
2020-12-25 10:29:25 +01:00
|
|
|
|
2020-12-25 10:43:36 +01:00
|
|
|
export interface DropdownBtnProps {
|
2020-12-25 10:29:25 +01:00
|
|
|
text: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
className?: string;
|
2021-03-28 17:45:47 +02:00
|
|
|
dropdownClassName?: string;
|
|
|
|
right?: boolean;
|
2021-06-22 20:34:28 +02:00
|
|
|
minWidth?: number;
|
2020-12-25 10:29:25 +01:00
|
|
|
}
|
|
|
|
|
2021-03-28 17:45:47 +02:00
|
|
|
export const DropdownBtn: FC<DropdownBtnProps> = (
|
2021-06-22 20:34:28 +02:00
|
|
|
{ text, disabled = false, className = '', children, dropdownClassName, right = false, minWidth },
|
2021-03-28 17:45:47 +02:00
|
|
|
) => {
|
2020-12-25 10:29:25 +01:00
|
|
|
const [ isOpen, toggle ] = useToggle();
|
2020-12-25 10:54:49 +01:00
|
|
|
const toggleClasses = `dropdown-btn__toggle btn-block ${className}`;
|
2021-06-22 20:34:28 +02:00
|
|
|
const style = { minWidth: minWidth && `${minWidth}px` };
|
2020-12-25 10:29:25 +01:00
|
|
|
|
|
|
|
return (
|
2021-03-28 17:45:47 +02:00
|
|
|
<Dropdown isOpen={isOpen} toggle={toggle} disabled={disabled} className={dropdownClassName}>
|
2020-12-25 10:39:54 +01:00
|
|
|
<DropdownToggle caret className={toggleClasses} color="primary">{text}</DropdownToggle>
|
2021-06-22 20:34:28 +02:00
|
|
|
<DropdownMenu className="w-100" right={right} style={style}>{children}</DropdownMenu>
|
2020-12-25 10:43:36 +01:00
|
|
|
</Dropdown>
|
2020-12-25 10:29:25 +01:00
|
|
|
);
|
|
|
|
};
|