Example of using custom element
See original GitHub issueHey @nathancahill, I like where Sveltik is headed, and I’d like to help out with the porting of Formik over to Svelte, but I was wanting to see if I could get you to provide an example of how you can use a custom element with Sveltik.
Here is a real-world element as an example
step-counter.svelte
<script>
export let value = 0
export let min = 0
export let max = 10
export let label = ''
export let name = ''
const decrement = () => { if (value > min) value -= 1 }
const increment = () => { if (value < max) value += 1 }
</script>
<template>
<div>
<button on:click={decrement}>Decrement</button>
<input type='number' {name} step='1' bind:value={value} readonly>
<button on:click={increment}>Increment</button>
{#if label}<p>{label}</p>{/if}
</div>
</template>
Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Using custom elements - Web Components | MDN
Let's have a look at an example of an autonomous custom element — <popup-info-box> (see a live example). This takes an image icon...
Read more >Custom elements - The Modern JavaScript Tutorial
Example : “time-formatted” · Observing attributes · Rendering order · Customized built-in elements · References · Summary · Tasks · Comments.
Read more >Custom Elements v1 - Reusable Web Components
Custom elements allow web developers to define new HTML tags, extend existing ones, and create reusable web components.
Read more >Creating a Custom Element from Scratch | CSS-Tricks
Essentially, a custom element consists of two pieces: a tag name and a class that extends the built-in HTMLElement class. The most basic...
Read more >Your First Custom Element | DigitalOcean
In this post we'll explore the basic syntax and concepts to allow you to start dabbling with Custom Elements and Shadow DOM.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Here’s an example with the step counter: https://svelte.dev/repl/38b0d1009d5b4041877b138809d421df?version=3
Responding on #9 to keep things organized.