importtype{ CSSProperties, ReactElement }from"react";import{ useCallback, useRef, useState }from"react";import{ Button }from"@react-md/button";import{ TextIconSpacing }from"@react-md/icon";import{ List, ListItem }from"@react-md/list";import{ ArrowDropDownSVGIcon }from"@react-md/material-icons";import{ Overlay }from"@react-md/overlay";import{ Typography }from"@react-md/typography";import{ getFixedPosition, ScrollListener, useToggle }from"@react-md/utils";import styles from"./SimpleExample.module.scss";exportdefaultfunctionDemo(): ReactElement {const[visible,, hide, toggle]=useToggle(false);const[style, setStyle]=useState<CSSProperties |undefined>();const buttonRef =useRef<HTMLButtonElement |null>(null);const listRef =useRef<HTMLUListElement |null>(null);const updatePosition =useCallback(()=>{setStyle(getFixedPosition({
container: buttonRef.current,
element: listRef.current,}).style
);},[]);const listRefCB =useCallback((list: HTMLUListElement |null)=>{
listRef.current = list;updatePosition();// only want to call this once on mount// eslint-disable-next-line react-hooks/exhaustive-deps},[]);return(<divclassName={styles.container}><Buttonid="portal-button"theme="secondary"themeType="outline"aria-haspopup="true"aria-expanded={visible}onClick={toggle}ref={buttonRef}><TextIconSpacingicon={<ArrowDropDownSVGIcon/>}iconAfter>
Options...
</TextIconSpacing></Button><Overlayid="portal-menu-overlay"className={styles.overlay}visible={visible}onRequestClose={hide}><Listrole="menu"id="portal-menu"aria-labelledby="portal-button"tabIndex={-1}ref={listRefCB}style={style}className={styles.menu}onClick={(event)=>{if(event.currentTarget !== event.target){hide();}}}><ScrollListeneronScroll={updatePosition}/>{Array.from({ length:6}).map((_, i)=>(<ListItemid={`menu-item-${i}`}key={i}role="menuitem">{`Option ${i +1}`}</ListItem>))}</List></Overlay><Typography>
In condimentum ultrices metus ut viverra. In faucibus erat eu massa
tincidunt finibus. Donec eget quam venenatis, venenatis arcu sed, mollis
tellus. Mauris massa nunc, condimentum quis nisi vel, fermentum
pellentesque est. Pellentesque varius rhoncus dui. Donec suscipit
gravida justo eu pharetra. Donec suscipit neque a orci bibendum, a
consectetur ipsum finibus. Aenean est ligula, aliquet ut nunc vitae,
volutpat pharetra tortor. Cras ipsum mi, posuere eu diam a, cursus
euismod mi. Ut vitae eros nibh.
</Typography></div>);}