UNPKG

click-to-react-component-intellij

Version:

Option+Click your React components in your browser to open the source file in intellij

164 lines (116 loc) 3.38 kB
# <ClickToComponent /> <kbd>Option+Click</kbd> a Component in the browser to **instantly** goto the source in your editor. ![Next.js Demo](next.gif) ## Features - <kbd>Option+Click</kbd> opens a context menu with the parent Components' `props`, `fileName`, `columnNumber`, and `lineNumber` - <kbd>Option+Right-click</kbd> opens a context menu with the parent Components' `props`, `fileName`, `columnNumber`, and `lineNumber` > ![props](props.png) - Works with frameworks like [Next.js](https://nextjs.org/), [Create React App](https://create-react-app.dev/), & [Vite](https://github.com/vitejs/vite/tree/main/packages/plugin-react) that use [@babel/plugin-transform-react-jsx-source](https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-react-jsx-source) - Supports `vscode` & `vscode-insiders`' [URL handling](https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls) - Automatically **tree-shaken** from `production` builds - Keyboard navigation in context menu (e.g. <kbd></kbd>, <kbd></kbd>, <kbd></kbd>) - More context & faster than using React DevTools: > ![React DevTools](devtools.png) ## Installation <details> <summary>npm</summary> ```shell npm install click-to-react-component-intellij ``` </details> <details> <summary>pnpm</summary> ```shell pnpm add click-to-react-component-intellij ``` </details> <details> <summary>yarn</summary> ```shell yarn add click-to-react-component-intellij ``` </details> Even though `click-to-react-component` is added to `dependencies`, [tree-shaking](https://esbuild.github.io/api/#tree-shaking) will remove `click-to-react-component` from `production` builds. ## Usage <details> <summary>Create React App</summary> ```diff +import { ClickToComponent } from 'click-to-react-component'; import React from 'react'; import ReactDOM from 'react-dom/client'; import './index.css'; @@ -8,7 +7,6 @@ import reportWebVitals from './reportWebVitals'; const root = ReactDOM.createRoot(document.getElementById('root')); root.render( <React.StrictMode> + <ClickToComponent /> <App /> </React.StrictMode> ); ``` > ![Create React App Demo](cra.gif) </details> <details> <summary>Next.js</summary> ```diff +import { ClickToComponent } from 'click-to-react-component' import type { AppProps } from 'next/app' import '../styles/globals.css' function MyApp({ Component, pageProps }: AppProps) { return ( <> + <ClickToComponent /> <Component {...pageProps} /> </> ) ``` > ![Next.js Demo](next.gif) </details> <details> <summary>Vite</summary> ```diff +import { ClickToComponent } from "click-to-react-component"; import React from "react"; import ReactDOM from "react-dom/client"; import App from "./App"; import "./index.css"; ReactDOM.createRoot(document.getElementById("root")!).render( <React.StrictMode> <App /> + <ClickToComponent /> </React.StrictMode> ); ``` > ![Vite Demo](vite.gif) </details> ### `editor` ```diff -<ClickToComponent /> ``` ## Run Locally Go to the project directory ```shell cd click-to-component ``` Install dependencies ```shell pnpm install ``` Run one of the examples: <details> <summary>Create React App</summary> ```shell cd apps/cra pnpm start ``` </details> <details> <summary>Next.js</summary> ```shell cd apps/next pnpm dev ``` </details>