choigirang / portfolio

포트폴리오 v1
https://v1.choigirang-portfolio.site
0 stars 0 forks source link

Projects: data mapping 시 ref childrern #20

Open choigirang opened 5 months ago

choigirang commented 5 months ago
export default function AboutContent(props: ProjectDetailType) {
  const { projectName, description, github, stack, link } = props;
  const [isHover, setIsHover] = useState('');
  const [childWidth, setChildWidth] = useState(0);
  const txtBoxEl = useRef<HTMLDivElement | null>(null);
  const childEls = useRef<HTMLDivElement | null>(null);

  const floorItems = [
    { title: '프로젝트명', value: projectName },
    { title: '스택', value: [...stack.frontend, ...stack.backend] },
    { title: '링크', value: link },
    { title: '깃허브', value: github },
    { title: '설명', value: description },
  ];

  const handleImageInteraction = (event: React.MouseEvent<HTMLElement, MouseEvent>, el: string) => {
    event.stopPropagation();
    if (event.type === 'mouseenter') {
      setIsHover(el);
    } else if (event.type === 'mouseleave') {
      setIsHover('');
    }
  };

  useEffect(() => {
    const hideAndAddPlusBtn = () => {
      const txtBoxWidth = txtBoxEl.current?.getBoundingClientRect().width;

      if (!txtBoxEl.current) return;
      console.log(txtBoxEl);
      console.log('children', txtBoxEl.current.childNodes[0]);
    };

    const handleChildrenWidth = () => {
      hideAndAddPlusBtn();
    };

    window.addEventListener('resize', handleChildrenWidth);
    handleChildrenWidth();
    return () => {
      window.removeEventListener('resize', handleChildrenWidth);
    };
  }, [txtBoxEl.current]);

  return (
    <Container>
      {floorItems.map((items, index) => (
        <Floor key={index}>
          <Title>{items.title} :</Title>
          <Text id="txt Ref" ref={txtBoxEl} checkStack={items.title === '스택'} checkDes={items.title === '설명'}>
            {/* 스택 데이터 시 */}
            {items.title === '스택' &&
              Array.isArray(items.value) &&
              items.value.map(item => (
                <div id="span">{item.displayName}</div>
                // <DisplayImgWithTooltip
                //   onMouseEnter={e => handleImageInteraction(e, item.name)}
                //   onMouseLeave={e => handleImageInteraction(e, item.name)}
                //   variants={variants}
                //   role="button"
                //   key={item.displayName}
                //   ref={e => console.log(e)}>
                //   <img
                //     className="stack-img"
                //     src={`https://cdn.simpleicons.org/${item.name}/${item.color}`}
                //     alt="stack-icon"
                //     width="32"
                //     height="32"
                //   />
                //   <Tooltip
                //     show={isHover}
                //     name={item.name}
                //     displayName={item.displayName}
                //     color={item.color}
                //     horizon="center"
                //     vertical="bottom"
                //   />
                // </DisplayImgWithTooltip>
              ))}
            {/* 이외 데이터 */}
            {!Array.isArray(items.value) && <span ref={(e) => console.log(e)}>{items.value}</span>}
          </Text>
        </Floor>
      ))}
    </Container>
  );
}
choigirang commented 5 months ago
choigirang commented 5 months ago

// ProjectList.tsx export default function ProjectStackList(props: { isHover: string; setIsHover: Dispatch<SetStateAction>; value: StackInfoType[]; })

return (

{value.map(item => ( handleImageInteraction(e, item.name)} onMouseLeave={e => handleImageInteraction(e, item.name)} variants={variants} role="button" key={item.displayName}> stack-icon ))} ); ```