INIT
This commit is contained in:
Generated
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { DateRangeFieldInputProps } from "../types.js";
|
||||
import { DateRangeFieldInputState } from "../date-range-field.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
import DateFieldHiddenInput from "../../date-field/components/date-field-hidden-input.svelte";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
name = "",
|
||||
child,
|
||||
children,
|
||||
type,
|
||||
...restProps
|
||||
}: DateRangeFieldInputProps = $props();
|
||||
|
||||
const inputState = DateRangeFieldInputState.create(
|
||||
{
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
name: boxWith(() => name),
|
||||
},
|
||||
type
|
||||
);
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, inputState.props, { role: "presentation" }));
|
||||
</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 { DateRangeFieldInputProps } from "../types.js";
|
||||
declare const DateRangeFieldInput: import("svelte").Component<DateRangeFieldInputProps, {}, "ref">;
|
||||
type DateRangeFieldInput = ReturnType<typeof DateRangeFieldInput>;
|
||||
export default DateRangeFieldInput;
|
||||
Generated
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { DateRangeFieldLabelState } from "../date-range-field.svelte.js";
|
||||
import type { DateRangeFieldLabelProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
children,
|
||||
child,
|
||||
...restProps
|
||||
}: DateRangeFieldLabelProps = $props();
|
||||
|
||||
const labelState = DateRangeFieldLabelState.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}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DateRangeFieldLabelProps } from "../types.js";
|
||||
declare const DateRangeFieldLabel: import("svelte").Component<DateRangeFieldLabelProps, {}, "ref">;
|
||||
type DateRangeFieldLabel = ReturnType<typeof DateRangeFieldLabel>;
|
||||
export default DateRangeFieldLabel;
|
||||
Generated
Vendored
+145
@@ -0,0 +1,145 @@
|
||||
<script lang="ts">
|
||||
import { watch } from "runed";
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import { DateRangeFieldRootState } from "../date-range-field.svelte.js";
|
||||
import type { DateRangeFieldRootProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
import { noop } from "../../../internal/noop.js";
|
||||
import type { DateRange } from "../../../shared/index.js";
|
||||
import { getDefaultDate } from "../../../internal/date-time/utils.js";
|
||||
import { resolveLocaleProp } from "../../utilities/config/prop-resolvers.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
value = $bindable(),
|
||||
onValueChange = noop,
|
||||
placeholder = $bindable(),
|
||||
onPlaceholderChange = noop,
|
||||
disabled = false,
|
||||
readonly = false,
|
||||
required = false,
|
||||
hourCycle,
|
||||
granularity,
|
||||
locale,
|
||||
hideTimeZone = false,
|
||||
validate = noop,
|
||||
onInvalid = noop,
|
||||
maxValue,
|
||||
minValue,
|
||||
readonlySegments = [],
|
||||
children,
|
||||
child,
|
||||
onStartValueChange = noop,
|
||||
onEndValueChange = noop,
|
||||
errorMessageId,
|
||||
...restProps
|
||||
}: DateRangeFieldRootProps = $props();
|
||||
|
||||
let startValue = $state<DateValue | undefined>(value?.start);
|
||||
let endValue = $state<DateValue | undefined>(value?.end);
|
||||
|
||||
function handleDefaultPlaceholder() {
|
||||
if (placeholder !== undefined) return;
|
||||
const defaultPlaceholder = getDefaultDate({
|
||||
granularity,
|
||||
defaultValue: value?.start,
|
||||
minValue,
|
||||
maxValue,
|
||||
});
|
||||
placeholder = defaultPlaceholder;
|
||||
}
|
||||
|
||||
// SSR
|
||||
handleDefaultPlaceholder();
|
||||
|
||||
watch.pre(
|
||||
() => placeholder,
|
||||
() => {
|
||||
handleDefaultPlaceholder();
|
||||
}
|
||||
);
|
||||
|
||||
function handleDefaultValue() {
|
||||
if (value !== undefined) return;
|
||||
const defaultValue = { start: undefined, end: undefined };
|
||||
value = defaultValue;
|
||||
}
|
||||
|
||||
// SSR
|
||||
handleDefaultValue();
|
||||
|
||||
/**
|
||||
* Covers an edge case where when a spread props object is reassigned,
|
||||
* the props are reset to their default values, which would make value
|
||||
* undefined which causes errors to be thrown.
|
||||
*/
|
||||
watch.pre(
|
||||
() => value,
|
||||
() => {
|
||||
handleDefaultValue();
|
||||
}
|
||||
);
|
||||
|
||||
const rootState = DateRangeFieldRootState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
disabled: boxWith(() => disabled),
|
||||
readonly: boxWith(() => readonly),
|
||||
required: boxWith(() => required),
|
||||
hourCycle: boxWith(() => hourCycle),
|
||||
granularity: boxWith(() => granularity),
|
||||
locale: resolveLocaleProp(() => locale),
|
||||
hideTimeZone: boxWith(() => hideTimeZone),
|
||||
validate: boxWith(() => validate),
|
||||
maxValue: boxWith(() => maxValue),
|
||||
minValue: boxWith(() => minValue),
|
||||
placeholder: boxWith(
|
||||
() => placeholder as DateValue,
|
||||
(v) => {
|
||||
placeholder = v;
|
||||
onPlaceholderChange(v);
|
||||
}
|
||||
),
|
||||
readonlySegments: boxWith(() => readonlySegments),
|
||||
value: boxWith(
|
||||
() => value as DateRange,
|
||||
(v) => {
|
||||
value = v;
|
||||
onValueChange(v);
|
||||
}
|
||||
),
|
||||
startValue: boxWith(
|
||||
() => startValue,
|
||||
(v) => {
|
||||
startValue = v;
|
||||
onStartValueChange(v);
|
||||
}
|
||||
),
|
||||
endValue: boxWith(
|
||||
() => endValue,
|
||||
(v) => {
|
||||
endValue = v;
|
||||
onEndValueChange(v);
|
||||
}
|
||||
),
|
||||
onInvalid: boxWith(() => onInvalid),
|
||||
errorMessageId: boxWith(() => errorMessageId),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, rootState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { DateRangeFieldRootProps } from "../types.js";
|
||||
declare const DateRangeField: import("svelte").Component<DateRangeFieldRootProps, {}, "value" | "placeholder" | "ref">;
|
||||
type DateRangeField = ReturnType<typeof DateRangeField>;
|
||||
export default DateRangeField;
|
||||
Reference in New Issue
Block a user