Help forum

How to locally use custom elements

  • Emilien

    11 months ago

    Hello, I am currently testing Nordcraft locally and wanted to know if it is possible to use custom elements when self-hosting a project. I see that it was possible at one point, because there is an example in examples/custom-element on GitHub. But how can this be done now?
  • Lucas G

    11 months ago

    You still can
  • When you add an event to an element just type in the name of it
  • 1445834933561196614-image.png
  • Emilien

    11 months ago

    Sorry, I meant custom element, not custom event! 🥹
    One that I can use like this:
    <toddle-counter>
    <script
    type="module"
    src="http://localhost:3030/.toddle/custom-element/counter.js"
    ></script>
    <strong>This text should be replaced by a counter component</strong>
    </toddle-counter>
  • Lucas G

    11 months ago

    How exactly are you trying to use it?
  • Custom elements are basically non-standard HTML tags
  • 1445838455979511990-image.png
  • Lucas G

    11 months ago

    You can add that script to any element though, it wouldn't have to be a custom element unless you're trying to target it from something else. Could also probably just give it an element id
  • Emilien

    11 months ago

    I'm not sure we're talking about the same thing. I'm referring to the concept of creating web components/widgets in Nordcraft as you can see on my screenshot.

    I call it a custom element because that's what it seems to be called on the GitHub repository.
    1446031780351049768-image.png
  • Emilien

    11 months ago

    I'm trying to use the same system but locally. Except that instead of putting https://project.toddle.site/.toddle/custom-element/MyForm.js, you would need to put localhost:8989/.toddle/custom-element/MyForm.js.
  • Emilien

    11 months ago

    I saw a commit made by @Erik Beuschau called “Add support for serving custom elements (#81)” earlier this year that seems to add the ability to do this. But the project has changed since then, and I'm wondering if it's still possible to do it today and, if so, how?
  • Erik Beuschau

    11 months ago

    Let me get back to you later today on this 👍
  • Erik Beuschau

    11 months ago

    I currently have a PR in review that should enable this 🙏 I'll keep you posted when it's ready
  • Emilien

    11 months ago

    Thank you very much! I'll wait until it's merged to test all this 😮
    👍1
  • Tod

    11 months ago

    Great job @Emilien! Your contribution to the Nordcraft Community just made you advance to Community Level 2! 🌲
  • Erik Beuschau

    11 months ago

    It has been merged now, but we have not released it in an actual release yet. You can still try it out if you want 👍
    💪1
  • Emilien

    11 months ago

    i will try it thank you