Skip to content

Commit 10ce554

Browse files
Merge pull request #341 from FormidableLabs/feature/docusarus-site
Added base docusaurus site
2 parents 4def191 + 697c272 commit 10ce554

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8556
-3284
lines changed

README.md

Lines changed: 8 additions & 224 deletions
Original file line numberDiff line numberDiff line change
@@ -22,236 +22,20 @@ The library is structured modularly and lets you style and compose its component
2222

2323
<p align="center"><img src="https://user-images.githubusercontent.com/17658189/63181897-1d67d380-c049-11e9-9dd2-7da2a3a57f05.gif" width=500></p>
2424

25-
## Usage
25+
Come learn more at our [docs site](https://formidable-react-live-docs.vercel.app)!
2626

27-
Install it with `npm install react-live` or `yarn add react-live` and try out this piece of JSX:
27+
## Support
2828

29-
```js
30-
import { LiveProvider, LiveEditor, LiveError, LivePreview } from "react-live";
29+
Have a question about react-live? Submit an issue in this repository using the
30+
["Question" template](https://github.com/FormidableLabs/react-live/issues/new?template=question.md).
3131

32-
<LiveProvider code="<strong>Hello World!</strong>">
33-
<LiveEditor />
34-
<LiveError />
35-
<LivePreview />
36-
</LiveProvider>;
37-
```
32+
Notice something inaccurate or confusing? Feel free to [open an issue](https://github.com/FormidableLabs/react-live/issues/new/choose) or [make a pull request](https://github.com/FormidableLabs/react-live/pulls) to help improve the documentation for everyone!
3833

39-
## Demo
34+
The source for our docs site lives in this repo in the [`docs`](https://github.com/FormidableLabs/react-live/blob/main/docs) folder.
4035

41-
[https://react-live.netlify.com/](https://react-live.netlify.com/)
36+
## Contributing
4237

43-
## FAQ
44-
45-
### How does it work?
46-
47-
It takes your code and transpiles it with [Sucrase](https://github.com/alangpierce/sucrase), while the code is displayed using [`use-editable`](https://github.com/FormidableLabs/use-editable) and the code is highlighted using [`prism-react-renderer`](https://github.com/FormidableLabs/prism-react-renderer).
48-
49-
The transpiled code is then rendered in the preview component (`LivePreview`), which does a fake mount if the code
50-
is a React component.
51-
52-
Prior to `v3.0.0`, earlier versions of the library used different internals. We recommend using the latest version you can.
53-
54-
| Version | Supported React version | Editor | Transpiler |
55-
| ------- | ----------------------- | -------------------------- | ---------- |
56-
| v3.x.x | v17.x.x | `use-editable` | `Sucrase` |
57-
| v2.x.x | v16.x.x | `react-simple-code-editor` | `Bublé` |
58-
59-
Please see also the related Formidable libraries:-
60-
61-
- [https://github.com/FormidableLabs/prism-react-renderer](https://github.com/FormidableLabs/prism-react-renderer)
62-
- [https://github.com/FormidableLabs/use-editable](https://github.com/FormidableLabs/use-editable)
63-
64-
### What code can I use?
65-
66-
The code can be one of the following things:
67-
68-
- React elements, e.g. `<strong>Hello World!</strong>`
69-
- React pure functional components, e.g. `() => <strong>Hello World!</strong>`
70-
- React functional components with Hooks
71-
- React component classes
72-
73-
If you enable the `noInline` prop on your `LiveProvider`, you’ll be able to write imperative code,
74-
and render one of the above things by calling `render`.
75-
76-
### How does the scope work?
77-
78-
The `scope` prop on the `LiveProvider` accepts additional globals. By default it injects `React` only, which
79-
means that the user can use it in their code like this:
80-
81-
```js
82-
// ↓↓↓↓↓
83-
class Example extends React.Component {
84-
render() {
85-
return <strong>Hello World!</strong>;
86-
}
87-
}
88-
```
89-
90-
But you can of course pass more things to the scope. They will be available as variables in the code. Here's an example using [styled components](https://github.com/styled-components/styled-components):
91-
92-
```js
93-
import styled from 'styled-components';
94-
95-
const headerProps = { text: 'I\'m styled!' };
96-
97-
const scope = {styled, headerProps};
98-
99-
const code = `
100-
const Header = styled.div\`
101-
color: palevioletred;
102-
font-size: 18px;
103-
\`
104-
105-
render(<Header>{headerProps.text}</Header>)
106-
`
107-
108-
<LiveProvider code={code} scope={scope} noInline={true}>
109-
<LiveEditor />
110-
<LiveError />
111-
<LivePreview />
112-
</LiveProvider>
113-
```
114-
115-
Here's an example using a custom component `<MyButton />`. This component lives in a different directory. It gets passed into the scope wrapped in an Object. Note that since we are not using `render()` in the code snippet we let `noInline` stay equal to the default of `false`:
116-
117-
```js
118-
119-
import { MyButton } from './components/MyButton';
120-
121-
const scope = { MyButton };
122-
123-
const code = `
124-
<MyButton />
125-
`
126-
127-
<LiveProvider code={code} scope={scope}>
128-
<LiveEditor />
129-
<LiveError />
130-
<LivePreview />
131-
</LiveProvider>
132-
```
133-
134-
### Using Hooks
135-
136-
React Live supports using Hooks, but you may need to be mindful of the scope. As mentioned above, only React is injected into scope by default.
137-
138-
This means that while you may be used to destructuring `useState` when importing React, to use hooks provided by React in React Live you will either need to stick to using `React.useState` or alternately you can set the scope up so that `useState` is provided separately.
139-
140-
```js
141-
() => {
142-
const [likes, increaseLikes] = React.useState(0);
143-
144-
return (
145-
<>
146-
<p>{`${likes} likes`}</p>
147-
<button onClick={() => increaseLikes(likes + 1)}>Like</button>
148-
</>
149-
);
150-
};
151-
```
152-
153-
### What bundle size can I expect?
154-
155-
Our reported bundle size badges don't give you the full picture of
156-
the kind of sizes you will get in a production app. The minified
157-
bundles we publish _exclude_ some dependencies that we depend
158-
on.
159-
160-
<img src="https://img.badgesize.io/https://unpkg.com/react-live/dist/react-live.min.js?compression=gzip&label=gzip%20size">
161-
162-
In an actual app when you use `react-live` you will also be bundling
163-
Sucrase for transpilation.
164-
165-
## API
166-
167-
### &lt;LiveProvider /&gt;
168-
169-
This component provides the `context` for all the other ones. It also transpiles the user’s code!
170-
It supports these props, while passing any others through to the `children`:
171-
172-
| Name | PropType | Description |
173-
| ------------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
174-
| code | PropTypes.string | The code that should be rendered, apart from the user’s edits |
175-
| scope | PropTypes.object | Accepts custom globals that the `code` can use |
176-
| noInline | PropTypes.bool | Doesn’t evaluate and mount the inline code (Default: `false`). Note: when using `noInline` whatever code you write must be a single expression (function, class component or some `jsx`) that can be returned immediately. If you'd like to render multiple components, use `noInline={true}` |
177-
| transformCode | PropTypes.func | Accepts and returns the code to be transpiled, affording an opportunity to first transform it |
178-
| language | PropTypes.string | What language you're writing for correct syntax highlighting. (Default: `jsx`) |
179-
| disabled | PropTypes.bool | Disable editing on the `<LiveEditor />` (Default: `false`) |
180-
| theme | PropTypes.object | A `prism-react-renderer` theme object. See more [here](https://github.com/FormidableLabs/prism-react-renderer#theming) |
181-
182-
All subsequent components must be rendered inside a provider, since they communicate
183-
using one.
184-
185-
The `noInline` option kicks the Provider into a different mode, where you can write imperative-style
186-
code and nothing gets evaluated and mounted automatically. Your example will need to call `render`
187-
with valid JSX elements.
188-
189-
### &lt;LiveEditor /&gt;
190-
191-
This component renders the editor that displays the code. It is a wrapper around [`react-simple-code-editor`](https://github.com/satya164/react-simple-code-editor) and the code highlighted using [`prism-react-renderer`](https://github.com/FormidableLabs/prism-react-renderer).
192-
193-
| Name | PropType | Description |
194-
| ------- | ----------------------------------------- | ----------------------------------------------------------------- |
195-
| style | PropTypes.object | Allows overriding default styles on the `LiveEditor` component. |
196-
| tabMode | PropTypes.oneOf(["indentation", "focus"]) | Sets how you want the tab key to work. (Default: `"indentation"`) |
197-
198-
### &lt;LiveError /&gt;
199-
200-
This component renders any error that occur while executing the code, or transpiling it.
201-
It passes through any props to a `pre`.
202-
203-
> Note: Right now when the component unmounts, when there’s no error to be shown.
204-
205-
### &lt;LivePreview /&gt;
206-
207-
This component renders the actual component that the code generates inside an error boundary.
208-
209-
| Name | PropType | Description |
210-
| --------- | -------------- | ------------------------------------------------------- |
211-
| Component | PropTypes.node | Element that wraps the generated code. (Default: `div`) |
212-
213-
### withLive
214-
215-
The `withLive` method creates a higher-order component, that injects the live-editing props provided
216-
by `LiveProvider` into a component.
217-
218-
Using this HOC allows you to add new components to react-live, or replace the default ones, with a new
219-
desired behavior.
220-
221-
The component wrapped with `withLive` gets injected the following props:
222-
223-
| Name | PropType | Description |
224-
| -------- | ---------------- | -------------------------------------------------------------------------------------- |
225-
| code | PropTypes.string | Reflects the code that is passed in as the `code` prop |
226-
| error | PropTypes.string | An error that the code has thrown when it was previewed |
227-
| onError | PropTypes.func | A callback that, when called, changes the error to what's passed as the first argument |
228-
| onChange | PropTypes.func | A callback that accepts new code and transpiles it |
229-
| element | React.Element | The result of the transpiled code that is previewed |
230-
231-
> Note: The code prop doesn't reflect the up-to-date code, but the `code` prop, that is passed to the `LiveProvider`.
232-
233-
## FAQ
234-
235-
> **I want to use experimental feature x but Sucrase doesn't support it! Can I use babel instead?**
236-
237-
`react-live` doesn't currently support configuring the transpiler and it ships with Sucrase. The current workaround for using some experimental features `Sucrase` doesn't support would be to use the `transformCode` prop on `LiveProvider` to transform your code with `babel` alongside `Sucrase`.
238-
239-
## Comparison to [component-playground](https://github.com/FormidableLabs/component-playground)
240-
241-
There are multiple options when it comes to live, editable React component environments. Formidable actually has **two** first class projects to help you out: [`component-playground`](https://github.com/FormidableLabs/component-playground) and [`react-live`](https://github.com/FormidableLabs/react-live). Let's briefly look at the libraries, use cases, and factors that might help in deciding which is right for you.
242-
243-
Here's a high-level decision tree:
244-
245-
- If you want **fast and easy** setup and integration, then `component-playground` may be the ticket!
246-
- If you want **a smaller bundle**, **SSR**, and **more flexibility**, then `react-live` is for you!
247-
248-
Here are the various factors at play:
249-
250-
- **Build**: `component-playground` uses `babel-standalone`, `react-live` uses `Sucrase`.
251-
- **Bundle size**: `component-playground` has a larger bundle, but uses a more familiar editor setup. `react-live` is smaller, but more customized editor around `prism`.
252-
- **Ease vs. flexibility**: `react-live` is more modular/customizable, while `component-playground` is easier/faster to set up.
253-
- **Extra features**: `component-playground` supports raw evaluation and pretty-printed output out-of-the-box, while `react-live` does not.
254-
- **Error handling**: `component-playground` might have more predictable error handling than `react-live` in some cases (due to `react-dom`).
38+
Please see our [contributing guide](CONTRIBUTING.md).
25539

25640
## Maintenance Status
25741

demo/.babelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

demo/.eslintrc.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

demo/components/GlobalStyle.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)