File size: 1,143 Bytes
8a37e0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { IconButton, Tooltip } from '@invoke-ai/ui-library';
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { selectActiveTab } from 'features/ui/store/uiSelectors';
import { setActiveTab } from 'features/ui/store/uiSlice';
import type { TabName } from 'features/ui/store/uiTypes';
import { forwardRef, memo, type ReactElement, useCallback } from 'react';

export const TabButton = memo(
  forwardRef(({ tab, icon, label }: { tab: TabName; icon: ReactElement; label: string }, ref) => {
    const dispatch = useAppDispatch();
    const activeTabName = useAppSelector(selectActiveTab);
    const onClick = useCallback(() => {
      dispatch(setActiveTab(tab));
    }, [dispatch, tab]);

    return (
      <Tooltip label={label} placement="end">
        <IconButton
          ref={ref}
          p={0}
          onClick={onClick}
          icon={icon}
          size="md"
          fontSize="24px"
          variant="appTab"
          data-selected={activeTabName === tab}
          aria-label={label}
          data-testid={label}
        />
      </Tooltip>
    );
  })
);

TabButton.displayName = 'TabButton';