"use client"; import cx from "classnames"; import type { ReactNode } from "react"; import React from "react"; import { useStatic } from "@/utils/hooks"; import { Bar, BarItem } from "../Bar"; import { IconButton } from "../Button"; import type { ButtonProps } from "../Button/Button"; import { CLASS_ROOT } from "./constants"; import DropdownButtonStatic from "./Dropdown.static"; import { DropdownToggleButton } from "./DropdownToggleButton"; export { CLASS_ROOT } from "./constants"; export type DropdownButtonProps = { className?: string; children?: ReactNode; iconName?: string; type?: ButtonProps["type"]; }; export type DropdownProps = { button: DropdownButtonProps; children: ReactNode; hasFocusTrap?: boolean; hasSpacing?: boolean; id: string; isInteractive?: boolean; placement?: "left" | "center" | "right"; className?: string; [key: string]: any; }; const placements: Record<"left" | "center" | "right", string> = { left: "bottom-start", center: "bottom", right: "bottom-end", }; const Dropdown: React.FC = ({ button, className, hasFocusTrap = false, hasSpacing = true, children, id, isInteractive = false, placement = "left", ...other }) => { const [dropdownRef] = useStatic(DropdownButtonStatic); const classes = cx( "dropdown", { [`${CLASS_ROOT}-spacing`]: hasSpacing, }, className, ); return ( <> {button && ( )}
{hasFocusTrap && ( )} {children}
); }; Dropdown.displayName = "Dropdown"; export { Dropdown };