Index of every page on this site: llms.txt
All skills
spences10 avatar

/svelte-components

@5fe4989
Run it yourself

Svelte component patterns. Use for web components, component libraries (Bits UI, Ark UI, Melt UI), form patterns, or third-party integration.

Use this Skill: https://skilld.dev/gh/spences10/svelte-skills-kit/svelte-components

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesweb-components.md

≈555 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Web Components with Svelte

Basic Setup

// svelte.config.js
export default {
	compilerOptions: {
		customElement: true, // Enable for entire project
	},
};

Or per-component:

<svelte:options customElement="my-element" />

<script>
	let { name = 'World' } = $props();
</script>

<p>Hello {name}!</p>

Gotchas

1. Self-Closing Tags

Svelte 5 requires closing tags. This affects custom elements:

<!-- WRONG -->
<my-element />

<!-- RIGHT -->
<my-element></my-element>

2. Nested HTML in Options

<option> with nested HTML causes compiler errors:

<!-- WRONG - compiler error -->
<select>
	<option><div>Rich content</div></option>
</select>

<!-- WORKAROUND - use snippets -->
{#snippet optionContent()}
	<div>Rich content</div>
{/snippet}

<select>
	<option>{@render optionContent()}</option>
</select>

3. Shadow DOM Styling

Styles are scoped to shadow DOM by default:

<svelte:options customElement="styled-button" />

<button>
	<slot />
</button>

<style>
	/* Only affects this component's shadow DOM */
	button {
		background: blue;
	}
</style>

Exposing Props as Attributes

<svelte:options
	customElement={{
		tag: 'my-counter',
		props: {
			count: { reflect: true, type: 'Number' },
		},
	}}
/>

<script>
	let { count = 0 } = $props();
</script>

<button onclick={() => count++}>{count}</button>

Events

Dispatch custom events:

<svelte:options customElement="event-button" />

<script>
	import { createEventDispatcher } from 'svelte';
	const dispatch = createEventDispatcher();
</script>

<button onclick={() => dispatch('clicked', { time: Date.now() })}>
	Click me
</button>
<!-- Usage -->
<event-button></event-button>
<script>
	document
		.querySelector('event-button')
		.addEventListener('clicked', (e) => console.log(e.detail));
</script>

Library Distribution

For library authors:

// package.json
{
	"svelte": "./dist/index.js",
	"exports": {
		".": {
			"svelte": "./dist/index.js"
		}
	},
	"keywords": ["svelte"],
	"peerDependencies": {
		"svelte": "^5.0.0"
	}
}

Important: Always include svelte in keywords and peerDependencies.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning2mo4 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides educational content and best practices for building web components and forms using Svelte. It includes references to popular, well-maintained UI libraries like Bits UI, Ark UI, and Melt UI. No security risks were identified.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

  • Runlayer9mo

    4/4 files flagged

Signed by skilld at 5fe4989. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago

README badge

README badge for spences10/svelte-skills-kit/svelte-components