INIT
This commit is contained in:
+10
@@ -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}
|
||||
+18
@@ -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
@@ -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}
|
||||
+4
@@ -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
@@ -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
@@ -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;
|
||||
Reference in New Issue
Block a user