@gravity-ui/uikit
Version:
Gravity UI base styling and components
25 lines (24 loc) • 941 B
JavaScript
import * as React from 'react';
import { bTabPanel } from "../constants.js";
import { TabContext } from "../contexts/TabContext.js";
export function useTabPanel(tabPanelProps) {
const tabContext = React.useContext(TabContext);
if (!tabContext) {
throw new Error('<TabPanel> must be used within <TabProvider>');
}
const currentValue = tabContext.value;
const parentId = tabContext.id;
const tabId = `${parentId}:t:${tabPanelProps.value}`;
const panelId = `${parentId}:p:${tabPanelProps.value}`;
const isSelected = currentValue === tabPanelProps.value;
const { value: _value, qa: _qa, ...htmlProps } = tabPanelProps;
return {
...htmlProps,
role: 'tabpanel',
'aria-labelledby': tabId,
id: panelId,
className: bTabPanel({ hidden: !isSelected }, tabPanelProps.className),
'data-qa': tabPanelProps.qa,
};
}
//# sourceMappingURL=useTabPanel.js.map