MCPcopy
hub / github.com/facebook/react / Header

Function Header

compiler/apps/playground/components/Header.tsx:24–123  ·  compiler/apps/playground/components/Header.tsx::Header
()

Source from the content-addressed store, hash-verified

22import {TOGGLE_INTERNALS_TRANSITION} from '../lib/transitionTypes';
23
24export default function Header(): JSX.Element {
25 const [showCheck, setShowCheck] = useState(false);
26 const store = useStore();
27 const dispatchStore = useStoreDispatch();
28 const {enqueueSnackbar, closeSnackbar} = useSnackbar();
29
30 const handleReset: () => void = () => {
31 if (confirm('Are you sure you want to reset the playground?')) {
32 /**
33 * Close open snackbars if any. This is necessary because when displaying
34 * outputs (Preview or not), we only close previous snackbars if we received
35 * new messages, which is needed in order to display "Bad URL" or success
36 * messages when loading Playground for the first time. Otherwise, messages
37 * such as "Bad URL" will be closed by the outputs calling `closeSnackbar`.
38 */
39 closeSnackbar();
40 dispatchStore({type: 'setStore', payload: {store: defaultStore}});
41 }
42 };
43
44 const handleShare: () => void = () => {
45 navigator.clipboard.writeText(location.href).then(() => {
46 enqueueSnackbar('URL copied to clipboard');
47 setShowCheck(true);
48 // Show the check mark icon briefly after URL is copied
49 setTimeout(() => setShowCheck(false), 1000);
50 });
51 };
52
53 return (
54 <div className="fixed z-10 flex items-center justify-between w-screen px-5 py-3 bg-white border-b border-gray-200 h-14">
55 <div className="flex items-center flex-none h-full gap-2 text-lg">
56 <Logo
57 className={clsx(
58 'w-8 h-8 text-link',
59 process.env.NODE_ENV === 'development' && 'text-yellow-600',
60 )}
61 />
62 <p className="hidden select-none sm:block">React Compiler Playground</p>
63 </div>
64 <div className="flex items-center text-[15px] gap-4">
65 <div className="flex items-center gap-2">
66 <label className="show-internals relative inline-block w-[34px] h-5">
67 <input
68 type="checkbox"
69 checked={store.showInternals}
70 onChange={() =>
71 startTransition(() => {
72 addTransitionType(TOGGLE_INTERNALS_TRANSITION);
73 dispatchStore({type: 'toggleInternals'});
74 })
75 }
76 className="absolute opacity-0 cursor-pointer h-full w-full m-0"
77 />
78 <span
79 className={clsx(
80 'absolute inset-0 rounded-full cursor-pointer transition-all duration-250',
81 "before:content-[''] before:absolute before:w-4 before:h-4 before:left-0.5 before:bottom-0.5",

Callers

nothing calls this directly

Calls 4

useStateFunction · 0.90
startTransitionFunction · 0.90
useStoreFunction · 0.85
addTransitionTypeFunction · 0.85

Tested by

no test coverage detected