-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c512d9
commit 97841ae
Showing
6 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
This directory contains utility files which enable some visual features of the | ||
[React Buddy](https://plugins.jetbrains.com/plugin/17467-react-buddy/) plugin. | ||
Files in the directory should be committed to source control. | ||
|
||
React Buddy palettes describe reusable components and building blocks. `React Palette` tool window becomes available | ||
when an editor with React components is active. You can drag and drop items from the tool window to the code editor or | ||
JSX Outline. Alternatively, you can insert components from the palette using code generation | ||
action (`alt+insert` / `⌘ N`). | ||
|
||
Add components to the palette using `Add to React Palette` intention or via palette editor (look for the corresponding | ||
link in `palette.tsx`). There are some ready-to-use palettes for popular React libraries which are published as npm | ||
packages and can be added as a dependency: | ||
|
||
```jsx | ||
import AntdPalette from "@react-buddy/palette-antd"; | ||
import ReactIntlPalette from "@react-buddy/palette-react-intl"; | ||
|
||
export const PaletteTree = () => ( | ||
<Palette> | ||
<AntdPalette/> | ||
<ReactIntlPalette/> | ||
<Category name="App templates"> | ||
<Component name="Card"> | ||
<Variant name="Loading"> | ||
<Card title="Card title"> | ||
<Skeleton loading={true} avatar active> | ||
Card content | ||
</Skeleton> | ||
</Card> | ||
</Variant> | ||
</Component> | ||
<Component name="Form"> | ||
<Variant proto={FormTemplate}/> | ||
</Component> | ||
</Category> | ||
</Palette> | ||
) | ||
``` | ||
|
||
React Buddy explicitly registers any previewed component in the `previews.tsx` file so that you can specify required | ||
props. | ||
|
||
```jsx | ||
<ComponentPreview path="/Page"> | ||
<Page title={'Hello'}/> | ||
</ComponentPreview> | ||
``` | ||
|
||
You can add some global initialization logic for the preview mode in `useInitital.ts`, | ||
e.g. implicitly obtain user session: | ||
|
||
```typescript | ||
export const useInitial: () => InitialHookStatus = () => { | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const [error, setError] = useState<boolean>(false); | ||
|
||
useEffect(() => { | ||
setLoading(true); | ||
async function login() { | ||
const response = await loginRequest(DEV_LOGIN, DEV_PASSWORD); | ||
if (response?.status !== 200) { | ||
setError(true); | ||
} | ||
setLoading(false); | ||
} | ||
login(); | ||
}, []); | ||
return { loading, error }; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from "react" | ||
import {useInitial} from "./useInitial" | ||
|
||
const ComponentPreviews = React.lazy(() => import("./previews")) | ||
|
||
export { | ||
ComponentPreviews, | ||
useInitial | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {Fragment} from "react" | ||
import { | ||
Category, | ||
Component, | ||
Variant, | ||
Palette, | ||
} from "@react-buddy/ide-toolbox" | ||
import MUIPalette from "@react-buddy/palette-mui"; | ||
|
||
export const PaletteTree = () => ( | ||
<Palette> | ||
<Category name="App"> | ||
<Component name="Loader"> | ||
<Variant> | ||
<ExampleLoaderComponent/> | ||
</Variant> | ||
</Component> | ||
</Category> | ||
<MUIPalette/> | ||
</Palette> | ||
) | ||
|
||
export function ExampleLoaderComponent() { | ||
return ( | ||
<Fragment>Loading...</Fragment> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {Previews} from '@react-buddy/ide-toolbox' | ||
import {PaletteTree} from './palette' | ||
|
||
const ComponentPreviews = () => { | ||
return ( | ||
<Previews palette={<PaletteTree/>}> | ||
</Previews> | ||
) | ||
} | ||
|
||
export default ComponentPreviews |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import React from "react"; | ||
import { createRoot } from "react-dom/client"; | ||
import {createRoot} from "react-dom/client"; | ||
import "./index.css"; | ||
import App from "./App"; | ||
import {DevSupport} from "@react-buddy/ide-toolbox"; | ||
import {ComponentPreviews, useInitial} from "./dev/index.js"; | ||
|
||
const root = createRoot(document.getElementById("root")); | ||
root.render(<App />); | ||
root.render(<DevSupport ComponentPreviews={ComponentPreviews} | ||
useInitialHook={useInitial} | ||
> | ||
<App/> | ||
</DevSupport>); |