Tldraw/README.md

130 wiersze
3.2 KiB
Markdown
Czysty Zwykły widok Historia

<div style="text-align: center; transform: scale(.5);">
<img src="card-repo.png"/>
</div>
# @tldraw/tldraw
2021-05-09 12:03:39 +00:00
This package contains the [TLDraw](https://tldraw.com) editor as a React component named `<TLDraw>`. You can use this package to embed the editor in any React application.
2021-07-01 16:46:01 +00:00
🎨 Want to build your own TLDraw-ish app instead? Try [@tldraw/core](https://github.com/tldraw/core).
2021-07-01 16:46:01 +00:00
💕 Love this library? Consider [becoming a sponsor](https://github.com/sponsors/steveruizok?frequency=recurring&sponsor=steveruizok).
2021-07-08 08:39:27 +00:00
## Installation
2021-07-08 08:39:27 +00:00
Use your package manager of choice to install `@tldraw/tldraw` and its peer dependencies.
2021-07-01 16:46:01 +00:00
```bash
yarn add @tldraw/tldraw
# or
npm i @tldraw/tldraw
```
2021-07-01 16:46:01 +00:00
## Usage
2021-08-13 13:31:27 +00:00
Import the `TLDraw` React component and use it in your app.
2021-07-01 16:46:01 +00:00
```tsx
import { TLDraw } from '@tldraw/tldraw'
2021-07-01 16:46:01 +00:00
function App() {
return <TLDraw />
}
```
2021-07-01 16:46:01 +00:00
### Persisting the State
You can use the `id` to persist the state in a user's browser storage.
```tsx
import { TLDraw } from '@tldraw/tldraw'
function App() {
return <TLDraw id="myState" />
}
```
### Controlling the Component through Props
You can control the `TLDraw` component through its props.
```tsx
import { TLDraw, TLDrawDocument } from '@tldraw/tldraw'
function App() {
const myDocument: TLDrawDocument = {}
return <TLDraw document={document} />
}
```
### Controlling the Component through the TLDrawState API
You can also control the `TLDraw` component imperatively through the `TLDrawState` API.
```tsx
import { TLDraw, TLDrawState } from '@tldraw/tldraw'
function App() {
const handleMount = React.useCallback((state: TLDrawState) => {
state.selectAll()
}, [])
return <TLDraw onMount={handleMount} />
}
```
Internally, the `TLDraw` component's user interface uses this API to make changes to the component's state. See the `TLDrawState` section of the [documentation](guides/documentation) for more on this API.
### Responding to Changes
You can respond to changes and user actions using the `onChange` callback. For more specific changes, you can also use the `onPatch`, `onCommand`, or `onPersist` callbacks. See the [documentation](guides/documentation) for more.
```tsx
import { TLDraw, TLDrawState } from '@tldraw/tldraw'
function App() {
const handleChange = React.useCallback((state: TLDrawState, reason: string) => {
// Do something with the change
}, [])
return <TLDraw onMount={handleMount} />
}
```
## Documentation
2021-07-01 16:46:01 +00:00
See the project's [documentation](/guides/documentation).
## Contribution
See the [contributing guide](/CONTRIBUTING.md).
## Development
See the [development guide](/guides/development.md).
## Example
See the `example` folder for examples of how to use the `<TLDraw/>` component.
## Community
### Support
Need help? Please [open an issue](https://github.com/tldraw/tldraw/issues/new) for support.
### Discussion
Want to connect with other devs? Visit the [Discord channel](https://discord.gg/s4FXZ6fppJ).
### License
This project is licensed under MIT.
If you're using the library in a commercial product, please consider [becoming a sponsor](https://github.com/sponsors/steveruizok?frequency=recurring&sponsor=steveruizok).
## Author
- [@steveruizok](https://twitter.com/steveruizok)