import React, { HTMLAttributes, useContext, useEffect, useRef } from 'react'; import styled from 'styled-components'; import classNames from 'classnames'; import RightIcon from '../icons/right2.svg'; import { ctx } from './Collapse'; export interface PanelProps extends HTMLAttributes { children?: React.ReactNode; header: string; order: string; } const PanelStyled = styled.div` display: flex; flex-direction: column; > .header { padding: 12px 16px; border-top: 1px solid rgba(0, 0, 0, 0.1); display: flex; gap: 10px; align-items: center; background-color: #fafafa; > span { display: flex; align-items: center; } } > .body { line-height: 1.5em; background-color: #ffffff; height: 0; overflow: hidden; transition: all 300ms; } `; const Panel: React.FC = (props) => { const { children, header, order, ...rest } = props; const { currentOrder, setOrder } = useContext(ctx); const divRef = useRef(null); const divRef2 = useRef(null); useEffect(() => { if (currentOrder === order) { divRef2.current!.style.height = `${divRef.current!.getBoundingClientRect().height}px`; } else { divRef2.current!.style.height = `${0}px`; } }, [currentOrder]); return ( { if (currentOrder !== order) { setOrder(order); } else { setOrder('null'); } }} > {header} {children} ); }; Panel.defaultProps = { children: '' }; export default Panel;
{header}