site/components/collapsable-box.js
Alice ac6e2ac349
Update /team and use JSON instead of Airtable (#1452)
* Added collapsable-box, added team json and modified the api to fetch
from it

* Removed yarn from the package.json

* Moved departments to Array and fixed the await in a forEach

* fix

* another fix

* should fix smth

* fix: /api/team

* fix: clean up team.json

* fix: final fixes for team page

* Make TypeScript great again

* fix: nora's pfp on /team

* chore: apply biome recommendations

* fix: ts-ify /team

* things

* Fix lint

* Update Mahad's team role

* Delete bun.lock

* should fix hopefully

---------

Co-authored-by: Mahad Kalam <mahadkalam1@proton.me>
Co-authored-by: Mahad Kalam <55807755+SkyfallWasTaken@users.noreply.github.com>
Co-authored-by: aqua <84078890+phthallo@users.noreply.github.com>
2025-04-16 09:20:45 -04:00

64 lines
1.4 KiB
JavaScript

import { useState, useRef, useEffect } from 'react'
import { Box, Text } from 'theme-ui'
// Not used atm, but keeping around in case we want to add back in
const CollapsableBox = ({
title,
children,
backgroundColor,
isOpen: isOpenProp
}) => {
const [isOpen, setIsOpen] = useState(isOpenProp || false)
const [height, setHeight] = useState(0)
const contentRef = useRef(null)
useEffect(() => {
if (contentRef.current) {
setHeight(isOpen ? contentRef.current.scrollHeight : 0)
}
}, [isOpen])
const toggleOpen = () => {
setIsOpen(prev => !prev)
}
return (
<Box
bg={backgroundColor}
sx={{
borderRadius: 'default',
boxShadow: 'default',
overflow: 'hidden'
}}
mb={2}
>
<div
onClick={toggleOpen}
onKeyDown={event => event.key === 'Enter' && toggleOpen()}
style={{ cursor: 'pointer', fontWeight: 'bold' }}
>
<Text
variant="headline"
as="h4"
sx={{ textAlign: 'center', fontSize: 3 }}
>
{title}
</Text>
</div>
<div
ref={contentRef}
style={{
height: `${height}px`,
overflow: 'hidden',
transition: 'height 0.3s ease',
margin: '0 1rem',
marginBottom: isOpen ? '1rem' : '0'
}}
>
{children}
</div>
</Box>
)
}
export default CollapsableBox