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
@@ -0,0 +1,39 @@
<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { ToggleGroupItemProps } from "../types.js";
import { ToggleGroupItemState } from "../toggle-group.svelte.js";
import { createId } from "../../../internal/create-id.js";
const uid = $props.id();
let {
children,
child,
ref = $bindable(null),
value,
disabled = false,
id = createId(uid),
type = "button",
...restProps
}: ToggleGroupItemProps = $props();
const itemState = ToggleGroupItemState.create({
id: boxWith(() => id),
value: boxWith(() => value),
disabled: boxWith(() => disabled ?? false),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
});
const mergedProps = $derived(mergeProps(restProps, itemState.props, { type }));
</script>
{#if child}
{@render child({ props: mergedProps, ...itemState.snippetProps })}
{:else}
<button {...mergedProps}>
{@render children?.(itemState.snippetProps)}
</button>
{/if}
@@ -0,0 +1,4 @@
import type { ToggleGroupItemProps } from "../types.js";
declare const ToggleGroupItem: import("svelte").Component<ToggleGroupItemProps, {}, "ref">;
type ToggleGroupItem = ReturnType<typeof ToggleGroupItem>;
export default ToggleGroupItem;
@@ -0,0 +1,72 @@
<script lang="ts">
import { type WritableBox, boxWith } from "svelte-toolbelt";
import { mergeProps } from "svelte-toolbelt";
import type { ToggleGroupRootProps } from "../types.js";
import { ToggleGroupRootState } from "../toggle-group.svelte.js";
import { createId } from "../../../internal/create-id.js";
import { noop } from "../../../internal/noop.js";
import { watch } from "runed";
const uid = $props.id();
let {
id = createId(uid),
ref = $bindable(null),
value = $bindable(),
onValueChange = noop,
type,
disabled = false,
loop = true,
orientation = "horizontal",
rovingFocus = true,
child,
children,
...restProps
}: ToggleGroupRootProps = $props();
function handleDefaultValue() {
if (value !== undefined) return;
value = type === "single" ? "" : [];
}
// SSR
handleDefaultValue();
watch.pre(
() => value,
() => {
handleDefaultValue();
}
);
const rootState = ToggleGroupRootState.create({
id: boxWith(() => id),
value: boxWith(
() => value!,
(v) => {
value = v;
// @ts-expect-error - we know
onValueChange(v);
}
) as WritableBox<string> | WritableBox<string[]>,
disabled: boxWith(() => disabled),
loop: boxWith(() => loop),
orientation: boxWith(() => orientation),
rovingFocus: boxWith(() => rovingFocus),
type,
ref: boxWith(
() => ref,
(v) => (ref = v)
),
});
const mergedProps = $derived(mergeProps(restProps, rootState.props));
</script>
{#if child}
{@render child({ props: mergedProps })}
{:else}
<div {...mergedProps}>
{@render children?.()}
</div>
{/if}
@@ -0,0 +1,4 @@
import type { ToggleGroupRootProps } from "../types.js";
declare const ToggleGroup: import("svelte").Component<ToggleGroupRootProps, {}, "value" | "ref">;
type ToggleGroup = ReturnType<typeof ToggleGroup>;
export default ToggleGroup;