collaboration Drawing app
 
 
 
Go to file
Steve Ruiz 6b4c2f0247 v0.1.20 2021-11-13 09:00:00 +00:00
.github
.husky
.vscode
electron v0.1.17 2021-11-12 22:30:04 +00:00
example v0.1.17 2021-11-12 22:30:04 +00:00
guides
packages/tldraw Update CHANGELOG.md 2021-11-12 22:30:35 +00:00
vscode v0.1.20 2021-11-13 09:00:00 +00:00
www v0.1.17 2021-11-12 22:30:04 +00:00
.eslintignore
.eslintrc
.gitignore
.npmignore
.prettierrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
card-repo.png
lerna.json v0.1.17 2021-11-12 22:30:04 +00:00
package.json [fix] vscode bugs (#271) 2021-11-13 08:49:34 +00:00
setupTests.ts
tsconfig.base.json
tsconfig.json
yarn.lock

README.md

@tldraw/tldraw

This package contains the TLDraw editor as a React component named <TLDraw>. You can use this package to embed the editor in any React application.

💕 Love this library? Consider becoming a sponsor.

🙌 Questions? Join the Discord channel or start a discussion.

🎨 Want to build your own TLDraw-ish app instead? Try @tldraw/core.

Installation

Use your package manager of choice to install @tldraw/tldraw and its peer dependencies.

yarn add @tldraw/tldraw
# or
npm i @tldraw/tldraw

Usage

Import the TLDraw React component and use it in your app.

import { TLDraw } from '@tldraw/tldraw'

function App() {
  return <TLDraw />
}

Persisting the State

You can use the id to persist the state in a user's browser storage.

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.

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.

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 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 for more.

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

See the project's documentation.

Contribution

See the contributing guide.

Development

See the development guide.

Example

See the example folder for examples of how to use the <TLDraw/> component.

Community

Support

Need help? Please open an issue for support.

Discussion

Want to connect with other devs? Visit the Discord channel.

License

This project is licensed under MIT.

If you're using the library in a commercial product, please consider becoming a sponsor.

Author