import React, { ReactNode } from "react";
import { withTheme } from "styled-components";
import {
Popover,
IconName,
PopoverPosition,
Classes,
PopoverInteractionKind,
} from "@blueprintjs/core";
import { MenuIcons } from "icons/MenuIcons";
import { Intent } from "constants/DefaultTheme";
import { Direction, Directions } from "utils/helpers";
import { getDirectionBased } from "./dropdownHelpers";
import { Theme } from "constants/DefaultTheme";
import {
Option,
DropdownContentSection,
DropdownContent,
DropdownTrigger,
} from "./StyledComponents";
import Button, { ButtonProps } from "components/editorComponents/Button";
export type CustomizedDropdownOptionSection = {
isSticky?: boolean;
options?: CustomizedDropdownOption[];
};
export type CustomizedDropdownOption = {
content: ReactNode;
active?: boolean;
onSelect?: () => void;
intent?: Intent;
shouldCloseDropdown?: boolean;
};
export type CustomizedDropdownProps = {
sections: CustomizedDropdownOptionSection[];
trigger: ButtonProps & {
content?: ReactNode;
};
openDirection: Direction;
openOnHover?: boolean;
};
const getContentSection = (section: CustomizedDropdownOptionSection) => {
return (
{section.options &&
section.options.map((option, index) => {
const shouldClose =
option.shouldCloseDropdown === undefined ||
option.shouldCloseDropdown;
return (
);
})}
);
};
export const CustomizedDropdown = (
props: CustomizedDropdownProps & { theme: Theme },
) => {
const icon =
props.trigger.icon &&
MenuIcons[props.trigger.icon]({
color: props.theme.colors.info,
width: 16,
height: 16,
});
const trigger = (
{icon && {icon}
}
{props.trigger.content || (
)}
);
const content = props.sections.map((section, index) => (
{getContentSection(section)}
));
return (
{trigger}
{content}
);
};
export default withTheme(CustomizedDropdown);