mm
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import type { ComponentPropsWithoutRef, CSSProperties } from "react";
|
||||
import {
|
||||
FloatingFocusManager,
|
||||
FloatingList,
|
||||
FloatingPortal,
|
||||
} from "@floating-ui/react";
|
||||
import { useMenuFloatingContext } from "./use-menu-floating-context";
|
||||
import { useMenuContext } from "./use-menu-context";
|
||||
import { mergeClass } from "../../styles/utils/merge-class";
|
||||
import { containerRecipe } from "../../styles/recipes/container-recipe"
|
||||
import { useThemeContext } from "../theme/use-theme-context";
|
||||
|
||||
|
||||
export type MenuDropdownProps = ComponentPropsWithoutRef<"div"> & {
|
||||
modal?: boolean;
|
||||
};
|
||||
|
||||
export const MenuDropdown = (props: MenuDropdownProps) => {
|
||||
const { modal = true, className = "", children, ...rest } = props;
|
||||
|
||||
const { size } = useMenuContext()!
|
||||
const { refs, elementsRef, context, floatingStyles, getFloatingProps, isNested, isOpen } = useMenuFloatingContext()!;
|
||||
|
||||
// ==============================================================================================================
|
||||
|
||||
const { themeBaseClass, themeClass } = useThemeContext()!
|
||||
|
||||
// ===============================================================================================================
|
||||
|
||||
const rootClass = mergeClass(themeBaseClass, themeClass, containerRecipe(), className);
|
||||
|
||||
const padding = size == "sm" ? "4px" : (size == "md" ? "8px" : undefined);
|
||||
const borderRadius = size == "sm" ? "4px" : (size == "md" ? "8px" : undefined);
|
||||
|
||||
const rootStyle: CSSProperties = {
|
||||
...floatingStyles,
|
||||
borderRadius: borderRadius,
|
||||
padding: padding,
|
||||
// invisable the outline
|
||||
outline: 0,
|
||||
background: "var(--base-bg)"
|
||||
|
||||
}
|
||||
|
||||
return <FloatingList elementsRef={elementsRef}>
|
||||
{isOpen && <FloatingPortal >
|
||||
<FloatingFocusManager context={context} modal={modal} >
|
||||
<div {...rest} className={rootClass} style={rootStyle} ref={refs.setFloating} {...getFloatingProps()} >
|
||||
{children}
|
||||
</div>
|
||||
</FloatingFocusManager>
|
||||
</FloatingPortal>
|
||||
}
|
||||
</FloatingList >
|
||||
};
|
||||
Reference in New Issue
Block a user