// @flow strict import * as React from 'react'; import {TEXT_COLORS} from '../../../types/typography'; import {classify} from '../../../utils/classify'; import {UnstyledButton} from '../../Button'; import type {IconType} from '../../Icon'; import {Icon} from '../../Icon'; import {ButtonTextMedium, ButtonTextSmall} from '../../Text'; import css from './Tab.module.css'; type ClassNames = $ReadOnly<{wrapper?: string, iconTextWrap?: string}>; export const TAB_SIZE = Object.freeze({ small: 'small', medium: 'medium', }); export const tabSizeOptions: Array = [...Object.keys(TAB_SIZE)]; export type TabSize = $Keys; export type TabProps = { classNames?: ClassNames, onSelect?: ({tabId?: string, label?: string}) => mixed, size?: TabSize, selectedTab?: {tabId?: string, label?: string}, disabled?: boolean, tabId?: string, label?: string, iconName?: string, iconType?: IconType, width?: string, onClick?: ?(SyntheticEvent) => mixed, }; export const Tab: React$AbstractComponent = React.forwardRef( ( { classNames, onSelect, size = 'medium', selectedTab, disabled = false, tabId, label, iconName, iconType, onClick, width, ...props }: TabProps, forwardRef, ) => { const tabRef = React.useRef(null); React.useImperativeHandle(forwardRef, () => tabRef.current); const selected = tabId && tabId === selectedTab?.tabId; const onClickHandler = (e) => { if (!disabled) { e.preventDefault(); onSelect && onSelect({tabId, label}); onClick && onClick(e); tabRef.current?.blur(); } }; return ( {iconName ? ( ) : null} {label && ( <> {size === TAB_SIZE.medium ? ( {label} ) : ( {label} )} )} ); }, ); Tab.displayName = 'Tab';