import React, { forwardRef } from "react"; import { BodyShort } from "../../../typography"; import type { OverridableComponent } from "../../../utils-external"; import { cl } from "../../../utils/helpers"; import { useTabsContext } from "../../Tabs.context"; import { useTab } from "./useTab"; export interface TabProps extends Omit< React.ButtonHTMLAttributes, "children" > { /** * Tab label. */ label?: React.ReactNode; /** * Tab Icon. */ icon?: React.ReactNode; /** * Value for state-handling. */ value: string; /** * Overrides auto-generated id. * * **Warning**: Tab generates an id if not provided. If you need to override it, * make sure to also include the correct `aria-controls` id for the TabPanel it controls. */ id?: string; } export const Tab: OverridableComponent = forwardRef( ( { className, as: Component = "button", label, icon, value, onClick, onFocus, disabled, id, ...rest }, ref: React.ForwardedRef, ) => { const tabCtx = useTab({ value, onClick, onFocus, disabled }, ref); const ctx = useTabsContext(); if (!label && !icon) { console.error(" needs label and/or icon"); return null; } return ( {icon} {label} ); }, ); export default Tab;