Giter VIP home page Giter VIP logo

tldraw-examples's Introduction

Signia

tldraw-examples

Welcome to the tldraw example repository. Here you will find examples of using the new tldraw v2 library. Each example is organized as a route in the src/examples folder.

๐Ÿ‘‰ Try it on CodeSandbox

Local Development

This repository contains a regular Vite app.

To run the project locally, first fork and clone this repo.

Install dependencies:

yarn
# or
npm i

Then start the local development server.

yarn dev
# or
npm run dev

Each individual example is found in the examples folder.

Happy hacking!

Using Tldraw in a different app

You should be able to use the <Tldraw/> component in any React app.

First install the @tldraw/tldraw package using @alpha for the latest alpha release.

yarn add @tldraw/tldraw@alpha
# or
npm install @tldraw/tldraw@alpha

Next, create a file like this one:

import { Tldraw } from '@tldraw/tldraw'
import '@tldraw/tldraw/editor.css'
import '@tldraw/tldraw/ui.css'

export default function () {
	return (
		<div
			style={{
				position: 'fixed',
				inset: 0,
			}}
		>
			<Tldraw />
		</div>
	)
}

In addition to the component, you will also need to:

  • import the CSS files for the editor and UI
  • have the library's assets available on the same host
  • probably set a viewport meta tag in your html.

See below for more detail on these.

A note on next.js / server-rendered react

The <Tldraw/> component cannot be server-rendered. If you're using the component in a Next.js app, you will need to import it dynamically. The code to do that will look something like this:

import dynamic from "next/dynamic"

const Editor = dynamic(
	async () => import('../components/Editor')),
	{ ssr: false }
)

export default function MyPage() {
	return <Editor/>
}

<Tldraw/>

The <Tldraw/> component combines several other pieces:

  • the tldraw editor (@tldraw/editor)
  • the tldraw UI (@tldraw/ui)
  • an engine (@tldraw/sync-client) for persistence and cross-tab syncronization

Note: In the future, this library will also include an engine for using our collaboration services.

If you wanted to have more granular control, you could also use those subcomponents directly. See the Exploded example for what that would look like.

Assets

In order for this app to work, the app must be able to find certain assets on the host. These are contained in the embed-icons, fonts, icons, and translations folders. If you are using the <Tldraw/> component in your app, you must also copy these folders into your public path.

Note: This requirement is very likely to change in the near future.

While these files must be available, you can overwrite the individual files: for example, by placing different icons under the same name or modifying / adding translations.

CSS

In order for the <Tldraw/> component to work, you must also import a CSS file from the library @tldraw/editor library (automatically installed with @tldraw/tldraw):

import '@tldraw/tldraw/editor.css'
import '@tldraw/tldraw/ui.css'

You can overwrite these files with other CSS, customize the styles via package patches, or copy the contents into a different file and import that instead.

In addition to these stylesheets, the root project imports the src/index.css file, so its styles are used for every example. Be sure to take a look at this file: you may find some of these styles necessary in your own usage of the <Tldraw/> component.

HTML

The index.html's meta viewport element for some important settings. These may not be critical to <Tldraw/> performing correctly, however some features (such as safe area positioning) may not work correctly if these are not set.

<meta
	name="viewport"
	content="width=device-width, initial-scale=1, viewport-fit=cover"
/>

License

The code in this repo is licensed under MIT.

The various tldraw libraries are licensed mostly under Apache 2.0.

tldraw-examples's People

Contributors

steveruizok avatar somehats avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.