+
{children}
)
diff --git a/packages/core/src/components/handles/handle.test.tsx b/packages/core/src/components/handles/handle.test.tsx
new file mode 100644
index 000000000..658614cf5
--- /dev/null
+++ b/packages/core/src/components/handles/handle.test.tsx
@@ -0,0 +1,15 @@
+import * as React from 'react'
+import { renderWithContext } from '~test'
+import { screen } from '@testing-library/react'
+import { Handle } from './handle'
+
+describe('handle', () => {
+ test('mounts component without crashing', () => {
+ renderWithContext(
)
+ })
+ test('validate attributes for handle component', () => {
+ renderWithContext(
)
+ const handle = screen.getByLabelText('handle')
+ expect(handle.querySelectorAll('circle').length).toBe(2)
+ })
+})
diff --git a/packages/core/src/components/handles/handle.tsx b/packages/core/src/components/handles/handle.tsx
index bec9101e6..545c592c5 100644
--- a/packages/core/src/components/handles/handle.tsx
+++ b/packages/core/src/components/handles/handle.tsx
@@ -27,7 +27,7 @@ export const Handle = React.memo(function Handle({ id, point }: HandleProps) {
)}
>
-
+
diff --git a/packages/core/src/components/handles/handles.test.tsx b/packages/core/src/components/handles/handles.test.tsx
index 84bc392df..52be3ed51 100644
--- a/packages/core/src/components/handles/handles.test.tsx
+++ b/packages/core/src/components/handles/handles.test.tsx
@@ -2,9 +2,48 @@ import * as React from 'react'
import { renderWithContext } from '~test'
import { Handles } from './handles'
import { boxShape } from '~shape-utils/TLShapeUtil.spec'
+import { screen } from '@testing-library/react'
describe('handles', () => {
test('mounts component without crashing', () => {
renderWithContext()
})
+ test('validate attributes for handles component', () => {
+ const boxShapeWithHandles = {
+ ...boxShape,
+ handles: {
+ 'handle-1': {
+ id: 'handle-1',
+ index: 0,
+ point: [10, 10],
+ },
+ 'handle-2': {
+ id: 'handle-2',
+ index: 1,
+ point: [200, 200],
+ },
+ },
+ }
+
+ renderWithContext()
+ const containers = screen.getAllByLabelText('container')
+ const handles = screen.getAllByLabelText('handle')
+
+ expect(containers.length).toBe(2)
+ expect(handles.length).toBe(2)
+ })
+
+ test.todo('Expect transform to match.')
+
+ // Due to whitespaces, the below compare is failing
+ // Custom matcher should be explored to make below works
+ // expect(containers[0]).toHaveAttribute(
+ // 'style',
+ // `transform:
+ // translate(
+ // calc(10px - var(--tl-padding)),
+ // calc(10px - var(--tl-padding))
+ // )
+ // rotate(0rad);`
+ // )
})
diff --git a/packages/tldraw/README.md b/packages/tldraw/README.md
index 9c78304f2..ee39f6fbb 100644
--- a/packages/tldraw/README.md
+++ b/packages/tldraw/README.md
@@ -6,8 +6,126 @@
This package contains the [tldraw](https://tldraw.com) editor as a React component named ``. You can use this package to embed the editor in any React application.
-🎨 Want to build your own tldraw-ish app instead? Try [@tldraw/core](https://github.com/tldraw/core).
-
💕 Love this library? Consider [becoming a sponsor](https://github.com/sponsors/steveruizok?frequency=recurring&sponsor=steveruizok).
-For documentation, see the [tldraw](https://github.com/tldraw) repository.
+🙌 Questions? Join the [Discord channel](https://discord.gg/SBBEVCA4PG) or start a [discussion](https://github.com/tldraw/tldraw/discussions/new).
+
+🎨 Want to build your own tldraw-ish app instead? Try the **@tldraw/core** folder instead.
+
+## Installation
+
+Use your package manager of choice to install `@tldraw/tldraw` and its peer dependencies.
+
+```bash
+yarn add @tldraw/tldraw
+# or
+npm i @tldraw/tldraw
+```
+
+## Usage
+
+Import the `tldraw` React component and use it in your app.
+
+```tsx
+import { Tldraw } from '@tldraw/tldraw'
+
+function App() {
+ return
+}
+```
+
+### 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
+}
+```
+
+### Controlling the Component through Props
+
+You can control the `` component through its props.
+
+```tsx
+import { Tldraw, TDDocument } from '@tldraw/tldraw'
+
+function App() {
+ const myDocument: TDDocument = {}
+
+ return
+}
+```
+
+### Controlling the Component through the tldrawApp API
+
+You can also control the `` component imperatively through the `TldrawApp` API.
+
+```tsx
+import { Tldraw, tldrawApp } from '@tldraw/tldraw'
+
+function App() {
+ const handleMount = React.useCallback((app: TldrawApp) => {
+ app.selectAll()
+ }, [])
+
+ return
+}
+```
+
+Internally, the `` component's user interface uses this API to make changes to the component's state. See the `tldrawApp` 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, TldrawApp } from '@tldraw/tldraw'
+
+function App() {
+ const handleChange = React.useCallback((app: TldrawApp, reason: string) => {
+ // Do something with the change
+ }, [])
+
+ return
+}
+```
+
+## Documentation
+
+See the project's [documentation](/packages/tldraw/guides/documentation.md).
+
+## Contribution
+
+See the [contributing guide](/CONTRIBUTING.md).
+
+## Development
+
+See the [development guide](/packages/tldraw/guides/development.md).
+
+## Example
+
+See the `example` folder for examples of how to use the `` 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/SBBEVCA4PG).
+
+### 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)
diff --git a/guides/development.md b/packages/tldraw/guides/development.md
similarity index 100%
rename from guides/development.md
rename to packages/tldraw/guides/development.md
diff --git a/guides/documentation.md b/packages/tldraw/guides/documentation.md
similarity index 100%
rename from guides/documentation.md
rename to packages/tldraw/guides/documentation.md
diff --git a/guides/publishing.md b/packages/tldraw/guides/publishing.md
similarity index 100%
rename from guides/publishing.md
rename to packages/tldraw/guides/publishing.md
diff --git a/tsconfig.base.json b/tsconfig.base.json
index beda42fbd..c055d1da9 100644
--- a/tsconfig.base.json
+++ b/tsconfig.base.json
@@ -29,6 +29,6 @@
"stripInternal": true,
"target": "es6",
"typeRoots": ["node_modules/@types", "node_modules/jest"],
- "types": ["node", "jest"]
+ "types": ["node", "jest", "@testing-library/jest-dom", "@testing-library/react"]
}
}