import { Activity } from 'react'; import { Box, BoxProps, CompoundStylesApiProps, ElementProps, factory, Factory, useMantineEnv, useProps, } from '../../../core'; import { useTabsContext } from '../Tabs.context'; import classes from '../Tabs.module.css'; export type TabsPanelStylesNames = 'panel'; export interface TabsPanelProps extends BoxProps, CompoundStylesApiProps, ElementProps<'div'> { /** Panel content */ children: React.ReactNode; /** If set, the content is kept mounted, even if `keepMounted` is set `false` in the parent `Tabs` component */ keepMounted?: boolean; /** Value of associated control */ value: string; } export type TabsPanelFactory = Factory<{ props: TabsPanelProps; ref: HTMLDivElement; stylesNames: TabsPanelStylesNames; compound: true; }>; export const TabsPanel = factory((_props) => { const props = useProps('TabsPanel', null, _props); const { children, className, value, classNames, styles, style, mod, keepMounted, ...others } = props; const env = useMantineEnv(); const ctx = useTabsContext(); const active = ctx.value === value; const shouldKeepMounted = ctx.keepMounted || keepMounted; const content = shouldKeepMounted && env !== 'test' ? ( {children} ) : shouldKeepMounted ? ( children ) : active ? ( children ) : null; return ( {content} ); }); TabsPanel.classes = classes; TabsPanel.displayName = '@mantine/core/TabsPanel';