import React, { type ButtonHTMLAttributes, forwardRef, useEffect, useRef } from 'react'; import mergeRefs from 'react-merge-refs'; import cn from 'classnames'; import { Skeleton, type SkeletonProps } from '@alfalab/core-components-skeleton'; import { type Styles, type TabListTitle } from '../../typings'; type Props = TabListTitle & Styles & Omit, 'id' | 'title'> & { focused?: boolean; isOption?: boolean; showSkeleton?: boolean; skeletonProps?: Omit; onResize?: () => void; }; export const Title = forwardRef( ( { id, toggleClassName, title, styles = {}, rightAddons = null, hidden = false, selected = false, disabled = false, collapsed = false, focused = false, isOption = false, showSkeleton = false, skeletonProps, onResize, dataTestId, className, ...restProps }, ref, ) => { const buttonRef = useRef(null); const titleClassName = cn(styles.content, { [styles.focused]: focused, }); useEffect(() => { const resizeObserver = new ResizeObserver(() => { if (onResize) { onResize(); } }); const button = buttonRef.current; if (button) { resizeObserver.observe(button); } return () => { if (button) { resizeObserver.unobserve(button); } }; }, [onResize]); return hidden ? null : ( ); }, );