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,34 @@
<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { CheckboxGroupLabelProps } from "../types.js";
import { CheckboxGroupLabelState } from "../checkbox.svelte.js";
import { createId } from "../../../internal/create-id.js";
const uid = $props.id();
let {
ref = $bindable(null),
id = createId(uid),
child,
children,
...restProps
}: CheckboxGroupLabelProps = $props();
const labelState = CheckboxGroupLabelState.create({
id: boxWith(() => id),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
});
const mergedProps = $derived(mergeProps(restProps, labelState.props));
</script>
{#if child}
{@render child({ props: mergedProps })}
{:else}
<span {...mergedProps}>
{@render children?.()}
</span>
{/if}
@@ -0,0 +1,4 @@
import type { CheckboxGroupLabelProps } from "../types.js";
declare const CheckboxGroupLabel: import("svelte").Component<CheckboxGroupLabelProps, {}, "ref">;
type CheckboxGroupLabel = ReturnType<typeof CheckboxGroupLabel>;
export default CheckboxGroupLabel;
@@ -0,0 +1,55 @@
<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { CheckboxGroupProps } from "../types.js";
import { CheckboxGroupState } from "../checkbox.svelte.js";
import { noop } from "../../../internal/noop.js";
import { createId } from "../../../internal/create-id.js";
import { arraysAreEqual } from "../../../internal/arrays.js";
const uid = $props.id();
let {
ref = $bindable(null),
id = createId(uid),
value = $bindable([]),
onValueChange = noop,
name,
required,
disabled,
children,
child,
readonly,
...restProps
}: CheckboxGroupProps = $props();
const groupState = CheckboxGroupState.create({
id: boxWith(() => id),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
disabled: boxWith(() => Boolean(disabled)),
required: boxWith(() => Boolean(required)),
readonly: boxWith(() => Boolean(readonly)),
name: boxWith(() => name),
value: boxWith(
() => $state.snapshot(value),
(v) => {
if (arraysAreEqual(value, v)) return;
value = $state.snapshot(v);
onValueChange(v);
}
),
onValueChange: boxWith(() => onValueChange),
});
const mergedProps = $derived(mergeProps(restProps, groupState.props));
</script>
{#if child}
{@render child({ props: mergedProps })}
{:else}
<div {...mergedProps}>
{@render children?.()}
</div>
{/if}
@@ -0,0 +1,4 @@
import type { CheckboxGroupProps } from "../types.js";
declare const CheckboxGroup: import("svelte").Component<CheckboxGroupProps, {}, "value" | "ref">;
type CheckboxGroup = ReturnType<typeof CheckboxGroup>;
export default CheckboxGroup;
@@ -0,0 +1,10 @@
<script lang="ts">
import { CheckboxInputState } from "../checkbox.svelte.js";
import HiddenInput from "../../utilities/hidden-input.svelte";
const inputState = CheckboxInputState.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 CheckboxInput: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
[evt: string]: CustomEvent<any>;
}, {}, {}, string>;
type CheckboxInput = InstanceType<typeof CheckboxInput>;
export default CheckboxInput;
+97
View File
@@ -0,0 +1,97 @@
<script lang="ts">
import { boxWith, mergeProps } from "svelte-toolbelt";
import type { CheckboxRootProps } from "../types.js";
import { CheckboxGroupContext, CheckboxRootState } from "../checkbox.svelte.js";
import CheckboxInput from "./checkbox-input.svelte";
import { createId } from "../../../internal/create-id.js";
import { watch } from "runed";
const uid = $props.id();
let {
checked = $bindable(false),
ref = $bindable(null),
onCheckedChange,
children,
disabled = false,
required = false,
name = undefined,
value = "on",
id = createId(uid),
indeterminate = $bindable(false),
onIndeterminateChange,
child,
type = "button",
readonly,
...restProps
}: CheckboxRootProps = $props();
const group = CheckboxGroupContext.getOr(null);
if (group && value) {
if (group.opts.value.current.includes(value)) {
checked = true;
} else {
checked = false;
}
}
watch.pre(
() => value,
() => {
if (group && value) {
if (group.opts.value.current.includes(value)) {
checked = true;
} else {
checked = false;
}
}
}
);
const rootState = CheckboxRootState.create(
{
checked: boxWith(
() => checked,
(v) => {
checked = v;
onCheckedChange?.(v);
}
),
disabled: boxWith(() => disabled ?? false),
required: boxWith(() => required),
name: boxWith(() => name),
value: boxWith(() => value),
id: boxWith(() => id),
ref: boxWith(
() => ref,
(v) => (ref = v)
),
indeterminate: boxWith(
() => indeterminate,
(v) => {
indeterminate = v;
onIndeterminateChange?.(v);
}
),
type: boxWith(() => type),
readonly: boxWith(() => Boolean(readonly)),
},
group
);
const mergedProps = $derived(mergeProps({ ...restProps }, rootState.props));
</script>
{#if child}
{@render child({
props: mergedProps,
...rootState.snippetProps,
})}
{:else}
<button {...mergedProps}>
{@render children?.(rootState.snippetProps)}
</button>
{/if}
<CheckboxInput />
@@ -0,0 +1,4 @@
import type { CheckboxRootProps } from "../types.js";
declare const Checkbox: import("svelte").Component<CheckboxRootProps, {}, "checked" | "indeterminate" | "ref">;
type Checkbox = ReturnType<typeof Checkbox>;
export default Checkbox;