Advertisement
leoanjos

TOC

Jun 21st, 2022 (edited)
1,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // index.tsx
  2.     <Box sx={styles.itemsContainer}>
  3.       {headings.map((item) => (
  4.         <Box key={item.slug}>
  5.           <Item
  6.             title={item.title}
  7.             slug={item.slug}
  8.             level={1}
  9.             active={item.slug === activeItem.item}
  10.           />
  11.           <Box
  12.             sx={styles.subItemsContainer(
  13.               item.slug === activeItem.item,
  14.               item.children.length
  15.             )}
  16.           >
  17.             {item.children.map((subItem) => (
  18.               <Item
  19.                 key={subItem.slug}
  20.                 title={subItem.title}
  21.                 slug={subItem.slug}
  22.                 level={2}
  23.                 active={subItem.slug === activeItem.subItem}
  24.               />
  25.             ))}
  26.           </Box>
  27.         </Box>
  28.       ))}
  29.     </Box>
  30.  
  31. // styles.ts
  32. const subItemsContainer: (
  33.   active: boolean,
  34.   subItemsCount: number
  35. ) => SxStyleProp = (active, subItemsCount) => {
  36.   return {
  37.     ml: '16px',
  38.     overflow: 'hidden',
  39.     borderLeft: '1px solid #E7E9EE',
  40.     // maxHeight: active ? `${subItemsCount * 40}px` : '0',
  41.     transform: active ? 'scaleY(1)' : 'scaleY(0)',
  42.     transition: 'transform 0.3s ease-in-out',
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement