feat(component): mobile menu support (#7892)

This commit is contained in:
Cats Juice
2024-08-21 17:05:05 +08:00
committed by GitHub
parent 182b2fd62d
commit 23b0db36b9
57 changed files with 988 additions and 1482 deletions
@@ -0,0 +1,55 @@
import { ArrowRightSmallPlusIcon } from '@blocksuite/icons/rc';
import { Slot } from '@radix-ui/react-slot';
import { type MouseEvent, useCallback, useContext } from 'react';
import type { MenuSubProps } from '../menu.types';
import { useMenuItem } from '../use-menu-item';
import { MobileMenuContext } from './context';
export const MobileMenuSub = ({
children: propsChildren,
items,
triggerOptions,
subContentOptions: contentOptions = {},
}: MenuSubProps) => {
const {
className,
children,
otherProps: { onClick, ...otherTriggerOptions },
} = useMenuItem({
...triggerOptions,
children: propsChildren,
suffixIcon: <ArrowRightSmallPlusIcon />,
});
return (
<MobileMenuSubRaw
onClick={onClick}
items={items}
subContentOptions={contentOptions}
>
<div className={className} {...otherTriggerOptions}>
{children}
</div>
</MobileMenuSubRaw>
);
};
export const MobileMenuSubRaw = ({
onClick,
children,
items,
subContentOptions: contentOptions = {},
}: MenuSubProps & { onClick?: (e: MouseEvent<HTMLDivElement>) => void }) => {
const { setSubMenus } = useContext(MobileMenuContext);
const onItemClick = useCallback(
(e: MouseEvent<HTMLDivElement>) => {
onClick?.(e);
setSubMenus(prev => [...prev, { items, contentOptions }]);
},
[contentOptions, items, onClick, setSubMenus]
);
return <Slot onClick={onItemClick}>{children}</Slot>;
};