import { type MouseEvent, useState } from 'react'; import { type RowPinningPosition } from '@tanstack/react-table'; import { ActionIcon, type ActionIconProps, Tooltip } from '@mantine/core'; import { type MRT_Row, type MRT_RowData, type MRT_TableInstance, } from '../../types'; interface Props extends ActionIconProps { pinningPosition: RowPinningPosition; row: MRT_Row; table: MRT_TableInstance; } export const MRT_RowPinButton = ({ pinningPosition, row, table, ...rest }: Props) => { 'use no memo'; const { options: { icons: { IconPinned, IconX }, localization, rowPinningDisplayMode, }, } = table; const isPinned = row.getIsPinned(); const [tooltipOpened, setTooltipOpened] = useState(false); const handleTogglePin = (event: MouseEvent) => { setTooltipOpened(false); event.stopPropagation(); row.pin(isPinned ? false : pinningPosition); }; return ( setTooltipOpened(true)} onMouseLeave={() => setTooltipOpened(false)} size="xs" style={{ height: '24px', width: '24px', }} variant="subtle" {...rest} > {isPinned ? ( ) : ( )} ); };