INIT
This commit is contained in:
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { DateFieldHiddenInputState } from "../date-field.svelte.js";
|
||||
import HiddenInput from "../../utilities/hidden-input.svelte";
|
||||
|
||||
const hiddenInputState = DateFieldHiddenInputState.create();
|
||||
</script>
|
||||
|
||||
{#if hiddenInputState.shouldRender}
|
||||
<HiddenInput {...hiddenInputState.props} />
|
||||
{/if}
|
||||
Generated
Vendored
+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 DateFieldHiddenInput: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
|
||||
[evt: string]: CustomEvent<any>;
|
||||
}, {}, {}, string>;
|
||||
type DateFieldHiddenInput = InstanceType<typeof DateFieldHiddenInput>;
|
||||
export default DateFieldHiddenInput;
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { DateFieldInputState } from "../date-field.svelte.js";
|
||||
import type { DateFieldInputProps } from "../types.js";
|
||||
import DateFieldHiddenInput from "./date-field-hidden-input.svelte";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
name = "",
|
||||
children,
|
||||
child,
|
||||
...restProps
|
||||
}: DateFieldInputProps = $props();
|
||||
|
||||
const inputState = DateFieldInputState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
name: boxWith(() => name),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, inputState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps, segments: inputState.root.segmentContents })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.({ segments: inputState.root.segmentContents })}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<DateFieldHiddenInput />
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DateFieldInputProps } from "../types.js";
|
||||
declare const DateFieldInput: import("svelte").Component<DateFieldInputProps, {}, "ref">;
|
||||
type DateFieldInput = ReturnType<typeof DateFieldInput>;
|
||||
export default DateFieldInput;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { DateFieldLabelState } from "../date-field.svelte.js";
|
||||
import type { DateFieldLabelProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
children,
|
||||
child,
|
||||
...restProps
|
||||
}: DateFieldLabelProps = $props();
|
||||
|
||||
const labelState = DateFieldLabelState.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}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DateFieldLabelProps } from "../types.js";
|
||||
declare const DateFieldLabel: import("svelte").Component<DateFieldLabelProps, {}, "ref">;
|
||||
type DateFieldLabel = ReturnType<typeof DateFieldLabel>;
|
||||
export default DateFieldLabel;
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { DateFieldSegmentState } from "../date-field.svelte.js";
|
||||
import type { DateFieldSegmentProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
children,
|
||||
child,
|
||||
part,
|
||||
...restProps
|
||||
}: DateFieldSegmentProps = $props();
|
||||
|
||||
const segmentState = DateFieldSegmentState.create(part, {
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(
|
||||
mergeProps(restProps, segmentState.props as Record<string, unknown>)
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<span {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</span>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DateFieldSegmentProps } from "../types.js";
|
||||
declare const DateFieldSegment: import("svelte").Component<DateFieldSegmentProps, {}, "ref">;
|
||||
type DateFieldSegment = ReturnType<typeof DateFieldSegment>;
|
||||
export default DateFieldSegment;
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
<script lang="ts">
|
||||
import { watch } from "runed";
|
||||
import { boxWith } from "svelte-toolbelt";
|
||||
import { DateFieldRootState } from "../date-field.svelte.js";
|
||||
import type { DateFieldRootProps } from "../types.js";
|
||||
import { noop } from "../../../internal/noop.js";
|
||||
import { getDefaultDate } from "../../../internal/date-time/utils.js";
|
||||
import { resolveLocaleProp } from "../../utilities/config/prop-resolvers.js";
|
||||
|
||||
let {
|
||||
disabled = false,
|
||||
granularity,
|
||||
hideTimeZone = false,
|
||||
hourCycle,
|
||||
locale,
|
||||
maxValue,
|
||||
minValue,
|
||||
onPlaceholderChange = noop,
|
||||
onValueChange = noop,
|
||||
validate = noop,
|
||||
onInvalid = noop,
|
||||
placeholder = $bindable(),
|
||||
value = $bindable(),
|
||||
readonly = false,
|
||||
readonlySegments = [],
|
||||
required = false,
|
||||
errorMessageId,
|
||||
children,
|
||||
}: DateFieldRootProps = $props();
|
||||
|
||||
function handleDefaultPlaceholder(setPlaceholder = true) {
|
||||
if (placeholder !== undefined) return placeholder;
|
||||
|
||||
const defaultPlaceholder = getDefaultDate({
|
||||
granularity,
|
||||
defaultValue: value,
|
||||
minValue,
|
||||
maxValue,
|
||||
});
|
||||
|
||||
if (setPlaceholder) {
|
||||
placeholder = defaultPlaceholder;
|
||||
}
|
||||
|
||||
return defaultPlaceholder;
|
||||
}
|
||||
|
||||
// SSR
|
||||
handleDefaultPlaceholder();
|
||||
|
||||
/**
|
||||
* Covers an edge case where when a spread props object is reassigned,
|
||||
* the props are reset to their default values, which would make placeholder
|
||||
* undefined which causes errors to be thrown.
|
||||
*/
|
||||
watch.pre(
|
||||
() => placeholder,
|
||||
() => {
|
||||
handleDefaultPlaceholder();
|
||||
}
|
||||
);
|
||||
|
||||
DateFieldRootState.create({
|
||||
value: boxWith(
|
||||
() => value,
|
||||
(v) => {
|
||||
value = v;
|
||||
onValueChange(v);
|
||||
}
|
||||
),
|
||||
placeholder: boxWith(
|
||||
() => {
|
||||
if (placeholder === undefined) return handleDefaultPlaceholder(false);
|
||||
return placeholder;
|
||||
},
|
||||
(v) => {
|
||||
if (v === undefined) return;
|
||||
placeholder = v;
|
||||
onPlaceholderChange(v);
|
||||
}
|
||||
),
|
||||
disabled: boxWith(() => disabled),
|
||||
granularity: boxWith(() => granularity),
|
||||
hideTimeZone: boxWith(() => hideTimeZone),
|
||||
hourCycle: boxWith(() => hourCycle),
|
||||
locale: resolveLocaleProp(() => locale),
|
||||
maxValue: boxWith(() => maxValue),
|
||||
minValue: boxWith(() => minValue),
|
||||
validate: boxWith(() => validate),
|
||||
readonly: boxWith(() => readonly),
|
||||
readonlySegments: boxWith(() => readonlySegments),
|
||||
required: boxWith(() => required),
|
||||
onInvalid: boxWith(() => onInvalid),
|
||||
errorMessageId: boxWith(() => errorMessageId),
|
||||
isInvalidProp: boxWith(() => undefined),
|
||||
});
|
||||
</script>
|
||||
|
||||
{@render children?.()}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
declare const DateField: import("svelte").Component<import("../types.js").DateFieldRootPropsWithoutHTML, {}, "value" | "placeholder">;
|
||||
type DateField = ReturnType<typeof DateField>;
|
||||
export default DateField;
|
||||
Reference in New Issue
Block a user