Skip to content

Commit

Permalink
Up demo
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Aug 29, 2023
1 parent 69bc951 commit 96e6cae
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions docs/modules/Canvas.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ In the next section, we'll see how it's possible to reuse the built-in spots and

In the example below we'll see how to reuse the built-in `hover` canvas spot to render our custom highlighting rectangle (we'll disable the rendering of the default one) and create a new one in order to render a button below the selected `text` components.

[DEMO](https://jsfiddle.net/artur_arseniev/zdetbjsg/)

<demo-viewer value="zdetbjsg" height="500" darkcode/>

Worth noting a few important points:

* Our custom container has to be moved inside the GrapesJS spots container.
```js
editor.onReady(() => {
Canvas.getSpotsEl().appendChild(this.$el);
});
```
* We pass the `component` to our custom spot, in order to have the style coordinates properly updated when we scroll the page or update the component.
```js
Canvas.addSpot({ type: customSpotType, component });
```
* The single spot is placed properly with `spot.getStyle()`
```html
<div ... class="spot" :style="spot.getStyle()">...</div>
```
* The spots container, by default, relies on `pointer-events: none`, in order to prevent the spot from blocking the interaction with the components. This is why we have to re-enable the pointer event on the button in order to make it interactable.
```css
.spot-text-btn {
/*...*/
pointer-events: auto;
}
```

<!-- Demo template, here for reference
<style>
Expand Down

0 comments on commit 96e6cae

Please sign in to comment.