importtype{ ReactElement }from"react";import{ useState }from"react";import{ AppBar, AppBarAction, AppBarNav }from"@react-md/app-bar";import{ Avatar }from"@react-md/avatar";import avatarVariables from"@react-md/avatar/dist/scssVariables";import{ List, ListItem }from"@react-md/list";import{ MenuSVGIcon, MoreVertSVGIcon }from"@react-md/material-icons";import people from"./people";import AppBarTitle from"./AppBarTitle";import styles from"./AnimatingAppBar.module.scss";typeCSSProperties= React.CSSProperties &{"--offset":string;};constCOLORS= Object.keys(avatarVariables["rmd-avatar-colors"]);const transformedPeople = people.map((name, i)=>({
id: name.toLowerCase().replace(//g,"-"),
name,
avatar: name.substring(0,1),
color:COLORS[i %COLORS.length],}));constHEIGHT=96;// this is used along with the current `scrollTop` value to make// the animation happen a bit slower. The number has no real significance// and just looked "decent"constSCROLL_MULTIPLIER=0.314;exportdefaultfunctionDemo(): ReactElement {const[height, setHeight]=useState(`${HEIGHT}px`);const style: CSSProperties ={"--offset": height,};return(<divstyle={style}className={styles.container}><AppBarid="animating-app-bar"className={styles.header}fixedtheme="clear"><AppBarNavid="animating-app-bar-nav"aria-label="Navigation"><MenuSVGIcon/></AppBarNav><AppBarTitleclassName={styles.title}>Animating App Bar</AppBarTitle><AppBarActionid="animating-app-bar-kebab"aria-label="Actions"first><MoreVertSVGIcon/></AppBarAction></AppBar><divclassName={styles.content}onScroll={(event)=>{const{ scrollTop }= event.currentTarget;const remaining = Math.min(
Math.max(HEIGHT- scrollTop *SCROLL_MULTIPLIER,0),HEIGHT);const nextHeight =`${remaining}px`;if(height !== nextHeight){setHeight(nextHeight);}}}><List>{transformedPeople.map(({ id, name, avatar, color }, i)=>(<ListItemid={`person-${i}`}key={id}leftAddon={<Avatarcolor={color}>{avatar}</Avatar>}leftAddonType="avatar">{name}</ListItem>))}</List></div></div>);}