-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDropdownSubMenu.tsx
More file actions
33 lines (29 loc) · 1.02 KB
/
DropdownSubMenu.tsx
File metadata and controls
33 lines (29 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import { useState, useEffect, useContext, useRef } from 'react';
import * as Style from '../style';
import { DropdownContext, DropdownSubContext } from '../context';
import type { DropdownSubMenuProps } from '../types';
export const SubMenu = (props: DropdownSubMenuProps) => {
const { children, ...restProps } = props;
const { width } = useContext(DropdownContext);
const { subOpen } = useContext(DropdownSubContext);
const [menuStyle, setMenuStyle] = useState<ReturnType<typeof css>>();
const menuRef = useRef<HTMLUListElement>(null);
useEffect(() => {
setMenuStyle(css({ ...Style.createDropdownSubLocation(menuRef, width) }, { ...Style.dropdownMenu }));
}, [width]);
return (
<ul
role="menu"
ref={menuRef}
aria-orientation="vertical"
css={menuStyle}
className={`${subOpen ? 'sub_open' : 'sub_close'}`}
{...restProps}
>
{children}
</ul>
);
};
SubMenu.displayName = 'Dropdown.SubMenu';