Skip to content

Modern Docker Management, Designed for Everyone

1.1 KB
Raw Blame
<script lang="ts">
	import { mergeProps } from 'bits-ui';

	import { Label } from '#lib/components/ui/label/index.js';
	import { Switch } from '#lib/components/ui/switch/index.js';

	let {
		id,
		checked = $bindable(),
		label,
		description,
		error,
		disabled = false,
		onCheckedChange,
		triggerProps
	}: {
		id: string;
		checked: boolean;
		label: string;
		description?: string;
		error?: string | null;
		disabled?: boolean;
		onCheckedChange?: (checked: boolean) => void;
		triggerProps?: Record<string, unknown>;
	} = $props();
	void checked;

	const switchProps = $derived(
		mergeProps(triggerProps ?? {}, {
			id,
			disabled,
			onCheckedChange: (value: boolean) => onCheckedChange?.(value === true)
		})
	);
</script>

<div class="flex items-center space-x-2">
	<Switch {...switchProps} bind:checked />
	<div class="grid gap-1.5 leading-none">
		<Label for={id} class="mb-0">
			{label}
		</Label>
		{#if error}
			<p class="text-xs font-medium text-destructive">
				{error}
			</p>
		{/if}
		{#if description}
			<p class="text-xs text-muted-foreground">
				{description}
			</p>
		{/if}
	</div>
</div>