import React, { ReactNode } from "react"; import { withTheme } from "styled-components"; import { Popover, IconName, PopoverPosition, Classes, PopoverInteractionKind, Icon, } from "@blueprintjs/core"; import { IconNames } from "@blueprintjs/icons"; import { MenuIcons } from "icons/MenuIcons"; import { Intent, IntentColors } 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; disabled?: boolean; }; export type CustomizedDropdownProps = { sections: CustomizedDropdownOptionSection[]; trigger: ButtonProps & { content?: ReactNode; size?: "large" | "small"; }; openDirection: Direction; openOnHover?: boolean; usePortal?: boolean; themeType?: string; }; const getIcon = (icon?: string, intent?: Intent) => { if (icon) { if (MenuIcons[icon]) { return MenuIcons[icon]({ color: IntentColors[intent || "secondary"], width: 16, height: 16, }); } const iconNames = Object.values({ ...IconNames }); if (iconNames.indexOf(icon as IconName) > -1) { return ( ); } } }; const getContentSection = ( section: CustomizedDropdownOptionSection, themeType: string, ) => { return ( {section.options && section.options.map((option, index) => { const shouldClose = option.shouldCloseDropdown === undefined || option.shouldCloseDropdown; return ( ); })} ); }; export const CustomizedDropdown = ( props: CustomizedDropdownProps & { theme: Theme }, ) => { const themeType = props.themeType ? props.themeType : "light"; const icon = getIcon(props.trigger.icon, props.trigger.intent); const trigger = ( {icon &&
{icon}
} {props.trigger.content || (