[improvement] rename onEvent to onUiEvent (#1358)

This PR:
- renames `onEvent` to `onUiEvent`
- adds docs for `onUiEvent` to the docs site
- splits the `EventsExample` into `UiEventsExample` and
`StoreEventsExample`

### Change Type

- [x] `major` — Breaking Change

### Release Notes

- [docs] Adds docs for ui events
- [tldraw] Renames `onEvent` to `onUiEvent`
This commit is contained in:
Steve Ruiz 2023-05-12 10:05:56 +01:00 committed by GitHub
parent 8b6b244194
commit 9ccd0f480f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 19 deletions

View file

@ -15,6 +15,24 @@ keywords:
- styles
---
Coming soon.
## Events
The `<Tldraw>` component has a prop, `onUiEvent`, that the user interface will call when certain events occur.
```tsx
function Example() {
function handleEvent(name, data) {
// do something with the event
}
return (
<Tldraw onUiEvent={handleEvent}/>
)
}
```
The `onUiEvent` callback is called with the name of the event as a string and an object with information about the event's source (e.g. `menu` or `context-menu`) and possibly other data specific to each event, such as the direction in an `align-shapes` event.
Note that `onUiEvent` is only called when interacting with the user interface. It is not called when running commands manually against the app, e.g. `app.alignShapes()` will not call `onUiEvent`.
See the [tldraw repository](https://github.com/tldraw/tldraw) for an example of how to customize tldraw's user interface.