Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HTML data option [enhancement] #112

Closed
sanderjson opened this issue Aug 24, 2022 · 5 comments
Closed

Add HTML data option [enhancement] #112

sanderjson opened this issue Aug 24, 2022 · 5 comments

Comments

@sanderjson
Copy link
Contributor

I would love to be able to render my own HTML within custom nodes.

data: {
		label: "<p>my cool HTML string</p>"
                label_type: "HTML"
	}

image

@antl3x
Copy link

antl3x commented Sep 5, 2022

@sanderjson I think would be better to support Custom Svelte Components no?

We can render with <svelte:component this={customComponent} ... />

@sanderjson
Copy link
Contributor Author

Yes, this is great. Breaking change for 4.0?

@rchrdnsh
Copy link

Both html and svelte elements/components would make this infinitely more useful and awesome. I second this idea :-)

@ronvoluted
Copy link

If you're happy to use a hack until maintainers add it, you can modify node_modules to get this working. Add the following two lines at /node_modules/svelvet/Containers/GraphView/index.svelte#L75:

      {#if node.image && !node.data.label}
        <ImageNode {node} {key} />
+     {:else if node.data.html}
+       <Node {node} {key}>{@html node.data.html}</Node>
      {:else}
        <Node {node} {key}>{node.data.label}</Node>

Then use a html property instead of the usual label:

const nodes = [
  {
    id: 1,
    width: 100,
    height: 100,
    position: { x: 0, y: 250 },
    data: { html: `<p>This is <a href="https://html.com">HTML</a></p>` },
  },
];

Go wild!:
Screenshot 2022-10-12 at 7 56 57 pm

@sanderjson
Copy link
Contributor Author

This is great! I was previously using this code below. Great addition thank you 😀🎉

  <div class={`Node Node-${key}`}>
    {#each $nodesStore as node}
      {#if node.image && !node.data.label}
        <ImageNode {node} {key} />
      {:else}
      <Node {node} {key}>
        {#if node.data.label_type == 'HTML'}
          {@html node.data.label}
        {:else}
          {node.data.label}
        {/if}
        </Node>
      {/if}
    {/each}
  </div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants