MCPcopy Index your code
hub / github.com/react/react / TabbedWindow

Function TabbedWindow

compiler/apps/playground/components/TabbedWindow.tsx:16–77  ·  view source on GitHub ↗
({
  tabs,
  activeTab,
  onTabChange,
}: {
  tabs: Map<string, React.ReactNode>;
  activeTab: string;
  onTabChange: (tab: string) => void;
})

Source from the content-addressed store, hash-verified

14import {TOGGLE_TAB_TRANSITION} from '../lib/transitionTypes';
15
16export default function TabbedWindow({
17 tabs,
18 activeTab,
19 onTabChange,
20}: {
21 tabs: Map<string, React.ReactNode>;
22 activeTab: string;
23 onTabChange: (tab: string) => void;
24}): React.ReactElement {
25 const id = useId();
26 const transitionName = `tab-highlight-${id}`;
27
28 const handleTabChange = (tab: string): void => {
29 startTransition(() => {
30 addTransitionType(TOGGLE_TAB_TRANSITION);
31 onTabChange(tab);
32 });
33 };
34
35 return (
36 <div className="flex-1 min-w-[550px] sm:min-w-0">
37 <div className="flex flex-col h-full max-w-full">
38 <div className="flex p-2 flex-shrink-0">
39 {Array.from(tabs.keys()).map(tab => {
40 const isActive = activeTab === tab;
41 return (
42 <button
43 key={tab}
44 onClick={() => handleTabChange(tab)}
45 className={clsx(
46 'transition-transform py-1.5 px-1.5 xs:px-3 sm:px-4 rounded-full text-sm relative',
47 isActive ? 'text-link' : 'hover:bg-primary/5',
48 )}>
49 {isActive && (
50 <ViewTransition
51 name={transitionName}
52 share={{
53 [TOGGLE_TAB_TRANSITION]: 'tab-highlight',
54 default: 'none',
55 }}
56 update={{default: 'none'}}>
57 <div className="absolute inset-0 bg-highlight rounded-full" />
58 </ViewTransition>
59 )}
60 <ViewTransition
61 update={{
62 [TOGGLE_TAB_TRANSITION]: 'tab-text',
63 default: 'none',
64 }}>
65 <span className="relative z-1">{tab}</span>
66 </ViewTransition>
67 </button>
68 );
69 })}
70 </div>
71 <div className="flex-1 overflow-hidden w-full h-full">
72 {tabs.get(activeTab)}
73 </div>

Callers

nothing calls this directly

Calls 5

useIdFunction · 0.90
handleTabChangeFunction · 0.85
keysMethod · 0.80
mapMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected