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
+10
View File
@@ -0,0 +1,10 @@
<script lang="ts">
import HiddenInput from "../../utilities/hidden-input.svelte";
import { SwitchInputState } from "../switch.svelte.js";
const inputState = SwitchInputState.create();
</script>
{#if inputState.shouldRender}
<HiddenInput {...inputState.props} />
{/if}
@@ -0,0 +1,18 @@
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
$$bindings?: Bindings;
} & Exports;
(internal: unknown, props: {
$$events?: Events;
$$slots?: Slots;
}): Exports & {
$set?: any;
$on?: any;
};
z_$$bindings?: Bindings;
}
declare const SwitchInput: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
[evt: string]: CustomEvent<any>;
}, {}, {}, string>;
type SwitchInput = InstanceType<typeof SwitchInput>;
export default SwitchInput;
+34
View File
@@ -0,0 +1,34 @@
<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { SwitchThumbProps } from "../types.js";
import { SwitchThumbState } from "../switch.svelte.js";
import { createId } from "../../../internal/create-id.js";
const uid = $props.id();
let {
child,
children,
ref = $bindable(null),
id = createId(uid),
...restProps
}: SwitchThumbProps = $props();
const thumbState = SwitchThumbState.create({
id: boxWith(() => id),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
});
const mergedProps = $derived(mergeProps(restProps, thumbState.props));
</script>
{#if child}
{@render child({ props: mergedProps, ...thumbState.snippetProps })}
{:else}
<span {...mergedProps}>
{@render children?.(thumbState.snippetProps)}
</span>
{/if}
@@ -0,0 +1,4 @@
import type { SwitchThumbProps } from "../types.js";
declare const SwitchThumb: import("svelte").Component<SwitchThumbProps, {}, "ref">;
type SwitchThumb = ReturnType<typeof SwitchThumb>;
export default SwitchThumb;
+56
View File
@@ -0,0 +1,56 @@
<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { SwitchRootProps } from "../types.js";
import { SwitchRootState } from "../switch.svelte.js";
import SwitchInput from "./switch-input.svelte";
import { createId } from "../../../internal/create-id.js";
import { noop } from "../../../internal/noop.js";
const uid = $props.id();
let {
child,
children,
ref = $bindable(null),
id = createId(uid),
disabled = false,
required = false,
checked = $bindable(false),
value = "on",
name = undefined,
type = "button",
onCheckedChange = noop,
...restProps
}: SwitchRootProps = $props();
const rootState = SwitchRootState.create({
checked: boxWith(
() => checked,
(v) => {
checked = v;
onCheckedChange?.(v);
}
),
disabled: boxWith(() => disabled ?? false),
required: boxWith(() => required),
value: boxWith(() => value),
name: boxWith(() => name),
id: boxWith(() => id),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
});
const mergedProps = $derived(mergeProps(restProps, rootState.props, { type }));
</script>
{#if child}
{@render child({ props: mergedProps, ...rootState.snippetProps })}
{:else}
<button {...mergedProps}>
{@render children?.(rootState.snippetProps)}
</button>
{/if}
<SwitchInput />
+4
View File
@@ -0,0 +1,4 @@
import type { SwitchRootProps } from "../types.js";
declare const Switch: import("svelte").Component<SwitchRootProps, {}, "checked" | "ref">;
type Switch = ReturnType<typeof Switch>;
export default Switch;