Installation
Install the dependencies
pnpm add cn class-variance-authorityCopy the component
Copy the following files into src/lib/components/ui/label.
<script lang="ts">
import type { HTMLLabelAttributes } from 'svelte/elements';
import { cn } from 'cn';
let { children, class: classProp, ...props }: HTMLLabelAttributes = $props();
</script>
<label data-slot="label" {...props} class={cn('gap-2 text-sm leading-none font-medium group-data-[disabled=true]:opacity-50 peer-disabled:opacity-50 flex items-center select-none group-data-[disabled=true]:pointer-events-none peer-disabled:cursor-not-allowed', classProp)}>
{@render children?.()}
</label>export { default as Label } from './Label.svelte';Update the import paths
Change the imports to match your project setup.
Usage
<script lang="ts">
import { Label } from '$lib/components/ui/label';
</script><Label for="email">Your email address</Label>