Skip to content

Commit

Permalink
feat(devtools): breadcrumb component for switch between tabs of react…
Browse files Browse the repository at this point in the history
… devtools
  • Loading branch information
Asuka109 committed Dec 5, 2023
1 parent 3fe4077 commit a24d022
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SelectLink } from '@/components/SelectLink';

export const handle = {
breadcrumb: [
{ title: 'React' },
{
title: (
<SelectLink
items={[
{ to: '/react/components', title: 'Components' },
{ to: '/react/profiler', title: 'Profiler' },
]}
/>
),
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Outlet } from '@modern-js/runtime/router';

export default function Layout() {
return <Outlet />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Box, useThemeContext } from '@radix-ui/themes';
import React from 'react';
import {
createBridge,
createStore,
initialize,
} from 'react-devtools-inline/frontend';
import { useAsync } from 'react-use';
import { useParams } from '@modern-js/runtime/router';
import { setupMountPointConnection } from '@/entries/client/rpc';

const connTask = setupMountPointConnection();

const Page: React.FC = () => {
const params = useParams();
const ctx = useThemeContext();
const browserTheme = ctx.appearance === 'light' ? 'light' : 'dark';

const { value: InnerView } = useAsync(async () => {
const { mountPoint, wall } = await connTask;
const bridge = createBridge(window.parent, wall);
const store = createStore(bridge);
const ret = initialize(window.parent, { bridge, store });
mountPoint.activateReactDevtools();
return ret;
}, []);

return (
<Box
style={{
position: 'fixed',
left: 'var(--navigator-width)',
top: 'var(--breadcrumb-height)',
bottom: 0,
right: 0,
}}
>
{InnerView && (
<InnerView
browserTheme={browserTheme}
overrideTab={params.tab === 'profiler' ? 'profiler' : 'components'}
hideSettings={false}
/>
)}
</Box>
);
};

export default Page;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { LoaderFunctionArgs, redirect } from '@modern-js/runtime/router';
import { resolveURL } from 'ufo';

export default ({ request }: LoaderFunctionArgs) => {
const target = resolveURL(request.url, './components');
return redirect(target);
};
Original file line number Diff line number Diff line change
@@ -1,43 +1 @@
import { Box, useThemeContext } from '@radix-ui/themes';
import React from 'react';
import {
createBridge,
createStore,
initialize,
} from 'react-devtools-inline/frontend';
import { useAsync } from 'react-use';
import { setupMountPointConnection } from '../../rpc';

const connTask = setupMountPointConnection();

const Page: React.FC = () => {
const ctx = useThemeContext();
const browserTheme = ctx.appearance === 'light' ? 'light' : 'dark';

const { value: InnerView } = useAsync(async () => {
const { mountPoint, wall } = await connTask;
const bridge = createBridge(window.parent, wall);
const store = createStore(bridge);
const ret = initialize(window.parent, { bridge, store });
mountPoint.activateReactDevtools();
return ret;
}, []);

return (
<Box
style={{
position: 'fixed',
left: 'var(--navigator-width)',
top: 'var(--breadcrumb-height)',
bottom: 0,
right: 0,
}}
>
{InnerView && (
<InnerView browserTheme={browserTheme} hideSettings={false} />
)}
</Box>
);
};

export default Page;
export default null;

0 comments on commit a24d022

Please sign in to comment.