This commit is contained in:
eewing
2026-02-17 14:10:16 -06:00
parent 2bca5834c5
commit cf73cd3b4c
11246 changed files with 1690552 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { ToggleRootProps } from "../types.js";
import { ToggleRootState } from "../toggle.svelte.js";
import { createId } from "../../../internal/create-id.js";
import { noop } from "../../../internal/noop.js";
const uid = $props.id();
let {
ref = $bindable(null),
id = createId(uid),
pressed = $bindable(false),
onPressedChange = noop,
disabled = false,
type = "button",
children,
child,
...restProps
}: ToggleRootProps = $props();
const toggleState = ToggleRootState.create({
pressed: boxWith(
() => pressed,
(v) => {
pressed = v;
onPressedChange(v);
}
),
disabled: boxWith(() => disabled ?? false),
id: boxWith(() => id),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
});
const mergedProps = $derived(mergeProps(restProps, toggleState.props, { type }));
</script>
{#if child}
{@render child({ props: mergedProps, ...toggleState.snippetProps })}
{:else}
<button {...mergedProps}>
{@render children?.(toggleState.snippetProps)}
</button>
{/if}