mm
This commit is contained in:
@@ -7,49 +7,71 @@ import {
|
||||
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 { containerRecipe } from "../../styles/recipes/container-recipe";
|
||||
import { useThemeContext } from "../theme/use-theme-context";
|
||||
import type { CommonProps } from "../../utils/CommonProps";
|
||||
import { brandRecipe } from "../../styles/recipes/brand-recipe";
|
||||
|
||||
|
||||
export type MenuDropdownProps = ComponentPropsWithoutRef<"div"> & {
|
||||
export type MenuDropdownProps = CommonProps & {
|
||||
modal?: boolean;
|
||||
};
|
||||
|
||||
export const MenuDropdown = (props: MenuDropdownProps) => {
|
||||
const { modal = true, className = "", children, ...rest } = props;
|
||||
const { modal = true, className = "", children, style, ...rest } = props;
|
||||
|
||||
const { size } = useMenuContext()!
|
||||
const { refs, elementsRef, context, floatingStyles, getFloatingProps, isNested, isOpen } = useMenuFloatingContext()!;
|
||||
const { size } = useMenuContext()!;
|
||||
const {
|
||||
refs,
|
||||
elementsRef,
|
||||
context,
|
||||
floatingStyles,
|
||||
getFloatingProps,
|
||||
isNested,
|
||||
isOpen,
|
||||
} = useMenuFloatingContext()!;
|
||||
|
||||
// ==============================================================================================================
|
||||
|
||||
const { themeBaseClass, themeClass } = useThemeContext()!
|
||||
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 rootClass = mergeClass(
|
||||
containerRecipe({
|
||||
boxShadow: true,
|
||||
rounded: size == "sm" ? 4 : 8,
|
||||
padding: size == "sm" ? 4 : 8,
|
||||
background: "base",
|
||||
hasFocusOutline: "false",
|
||||
}),
|
||||
brandRecipe(),
|
||||
themeBaseClass,
|
||||
themeClass,
|
||||
className,
|
||||
);
|
||||
|
||||
const rootStyle: CSSProperties = {
|
||||
...floatingStyles,
|
||||
borderRadius: borderRadius,
|
||||
padding: padding,
|
||||
// invisable the outline
|
||||
outline: 0,
|
||||
background: "var(--base-bg)"
|
||||
...style,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
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 >
|
||||
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