storyblok / storyblok-svelte

Svelte SDK for Storyblok CMS
MIT License
83 stars 12 forks source link

How to use visual editor with custom components? #901

Open abranhe opened 8 months ago

abranhe commented 8 months ago

Description

The library has the storyblokEditable action which allow the component to be used in the visual editor by adding this:

node.setAttribute("data-blok-c", options["data-blok-c"]);
node.setAttribute("data-blok-uid", options["data-blok-uid"]);
node.classList.add("storyblok__outline");

to the HTML element.

If the person wants to use a custom UI library, storyblokEditable won't work because actions cannot be used on components. There for something like this won't work:

<script lang="ts">
import { storyblokEditable } from '@storyblok/svelte';
import { Button } from 'my-reusable-ui-library';

export let block;
</script>

<Button use:storyblokEditable={blok} title={blok.title}/>

Is there a workaround for this, or another way to implement it on custom components?

Additional context

No response

Validations

josefineschaefer commented 7 months ago

Hi @abranhe, Thank you for your message and sorry for the delay. We will get back to you shortly.

HalCodes commented 6 months ago

My workaround is using a wrapper div

<div use:storyblokEditable={blok}>
  <Button title={blok.title}/>
</div>
josefineschaefer commented 6 months ago

Thanks for sharing @HalCodes!

roberto-butti commented 6 months ago

Hi @abranhe , I see your question here, I just had the same problem with another framework (not Svelte, but the concept is the same), I solved it as shown by @HalCodes (super!), putting a div wrapper. The problem here is that the custom component provided by the library doesn't pass and render in the HTML element the extra parameters.