This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarCellState } from "../calendar.svelte.js";
|
||||
import type { CalendarCellProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
date,
|
||||
month,
|
||||
...restProps
|
||||
}: CalendarCellProps = $props();
|
||||
|
||||
const cellState = CalendarCellState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
date: boxWith(() => date),
|
||||
month: boxWith(() => month),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, cellState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({
|
||||
props: mergedProps,
|
||||
...cellState.snippetProps,
|
||||
})}
|
||||
{:else}
|
||||
<td {...mergedProps}>
|
||||
{@render children?.(cellState.snippetProps)}
|
||||
</td>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarCellProps } from "../types.js";
|
||||
declare const CalendarCell: import("svelte").Component<CalendarCellProps, {}, "ref">;
|
||||
type CalendarCell = ReturnType<typeof CalendarCell>;
|
||||
export default CalendarCell;
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarDayState } from "../calendar.svelte.js";
|
||||
import type { CalendarDayProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarDayProps = $props();
|
||||
|
||||
const dayState = CalendarDayState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, dayState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({
|
||||
props: mergedProps,
|
||||
...dayState.snippetProps,
|
||||
})}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{#if children}
|
||||
{@render children?.(dayState.snippetProps)}
|
||||
{:else}
|
||||
{dayState.cell.opts.date.current.day}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarDayProps } from "../types.js";
|
||||
declare const CalendarDay: import("svelte").Component<CalendarDayProps, {}, "ref">;
|
||||
type CalendarDay = ReturnType<typeof CalendarDay>;
|
||||
export default CalendarDay;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { CalendarGridBodyProps } from "../types.js";
|
||||
import { CalendarGridBodyState } from "../calendar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarGridBodyProps = $props();
|
||||
|
||||
const gridBodyState = CalendarGridBodyState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, gridBodyState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<tbody {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</tbody>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarGridBodyProps } from "../types.js";
|
||||
declare const CalendarGridBody: import("svelte").Component<CalendarGridBodyProps, {}, "ref">;
|
||||
type CalendarGridBody = ReturnType<typeof CalendarGridBody>;
|
||||
export default CalendarGridBody;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarGridHeadState } from "../calendar.svelte.js";
|
||||
import type { CalendarGridHeadProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarGridHeadProps = $props();
|
||||
|
||||
const gridHeadState = CalendarGridHeadState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, gridHeadState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<thead {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</thead>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarGridHeadProps } from "../types.js";
|
||||
declare const CalendarGridHead: import("svelte").Component<CalendarGridHeadProps, {}, "ref">;
|
||||
type CalendarGridHead = ReturnType<typeof CalendarGridHead>;
|
||||
export default CalendarGridHead;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarGridRowState } from "../calendar.svelte.js";
|
||||
import type { CalendarGridRowProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarGridRowProps = $props();
|
||||
|
||||
const gridRowState = CalendarGridRowState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, gridRowState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<tr {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</tr>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarGridRowProps } from "../types.js";
|
||||
declare const CalendarGridRow: import("svelte").Component<CalendarGridRowProps, {}, "ref">;
|
||||
type CalendarGridRow = ReturnType<typeof CalendarGridRow>;
|
||||
export default CalendarGridRow;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarGridState } from "../calendar.svelte.js";
|
||||
import type { CalendarGridProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarGridProps = $props();
|
||||
|
||||
const gridState = CalendarGridState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, gridState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<table {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</table>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarGridProps } from "../types.js";
|
||||
declare const CalendarGrid: import("svelte").Component<CalendarGridProps, {}, "ref">;
|
||||
type CalendarGrid = ReturnType<typeof CalendarGrid>;
|
||||
export default CalendarGrid;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarHeadCellState } from "../calendar.svelte.js";
|
||||
import type { CalendarHeadCellProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarHeadCellProps = $props();
|
||||
|
||||
const headCellState = CalendarHeadCellState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, headCellState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<th {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</th>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarHeadCellProps } from "../types.js";
|
||||
declare const CalendarHeadCell: import("svelte").Component<CalendarHeadCellProps, {}, "ref">;
|
||||
type CalendarHeadCell = ReturnType<typeof CalendarHeadCell>;
|
||||
export default CalendarHeadCell;
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarHeaderState } from "../calendar.svelte.js";
|
||||
import type { CalendarHeaderProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarHeaderProps = $props();
|
||||
|
||||
const headerState = CalendarHeaderState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, headerState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<header {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</header>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarHeaderProps } from "../types.js";
|
||||
declare const CalendarHeader: import("svelte").Component<CalendarHeaderProps, {}, "ref">;
|
||||
type CalendarHeader = ReturnType<typeof CalendarHeader>;
|
||||
export default CalendarHeader;
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { CalendarHeadingProps } from "../types.js";
|
||||
import { CalendarHeadingState } from "../calendar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
...restProps
|
||||
}: CalendarHeadingProps = $props();
|
||||
|
||||
const headingState = CalendarHeadingState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, headingState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps, headingValue: headingState.root.headingValue })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{#if children}
|
||||
{@render children?.({ headingValue: headingState.root.headingValue })}
|
||||
{:else}
|
||||
{headingState.root.headingValue}
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarHeadingProps } from "../types.js";
|
||||
declare const CalendarHeading: import("svelte").Component<CalendarHeadingProps, {}, "ref">;
|
||||
type CalendarHeading = ReturnType<typeof CalendarHeading>;
|
||||
export default CalendarHeading;
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { CalendarMonthSelectProps } from "../types.js";
|
||||
import { CalendarMonthSelectState } from "../calendar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||
monthFormat = "long",
|
||||
disabled = false,
|
||||
"aria-label": ariaLabel = "Select a month",
|
||||
...restProps
|
||||
}: CalendarMonthSelectProps = $props();
|
||||
|
||||
const monthSelectState = CalendarMonthSelectState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
months: boxWith(() => months),
|
||||
monthFormat: boxWith(() => monthFormat),
|
||||
disabled: boxWith(() => Boolean(disabled)),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(
|
||||
mergeProps(restProps, monthSelectState.props, { "aria-label": ariaLabel })
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps, ...monthSelectState.snippetProps })}
|
||||
{:else}
|
||||
<select {...mergedProps}>
|
||||
{#if children}
|
||||
{@render children?.(monthSelectState.snippetProps)}
|
||||
{:else}
|
||||
{#each monthSelectState.monthItems as month (month.value)}
|
||||
<option
|
||||
value={month.value}
|
||||
selected={month.value === monthSelectState.currentMonth}
|
||||
>
|
||||
{month.label}
|
||||
</option>
|
||||
{/each}
|
||||
{/if}
|
||||
</select>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarMonthSelectProps } from "../types.js";
|
||||
declare const CalendarMonthSelect: import("svelte").Component<CalendarMonthSelectProps, {}, "ref">;
|
||||
type CalendarMonthSelect = ReturnType<typeof CalendarMonthSelect>;
|
||||
export default CalendarMonthSelect;
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { CalendarNextButtonState } from "../calendar.svelte.js";
|
||||
import type { CalendarNextButtonProps } from "../types.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
// for safari
|
||||
tabindex = 0,
|
||||
...restProps
|
||||
}: CalendarNextButtonProps = $props();
|
||||
|
||||
const nextButtonState = CalendarNextButtonState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, nextButtonState.props, { tabindex }));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<button {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</button>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarNextButtonProps } from "../types.js";
|
||||
declare const CalendarNextButton: import("svelte").Component<CalendarNextButtonProps, {}, "ref">;
|
||||
type CalendarNextButton = ReturnType<typeof CalendarNextButton>;
|
||||
export default CalendarNextButton;
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { CalendarPrevButtonProps } from "../types.js";
|
||||
import { CalendarPrevButtonState } from "../calendar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
id = createId(uid),
|
||||
ref = $bindable(null),
|
||||
// for safari
|
||||
tabindex = 0,
|
||||
...restProps
|
||||
}: CalendarPrevButtonProps = $props();
|
||||
|
||||
const prevButtonState = CalendarPrevButtonState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, prevButtonState.props, { tabindex }));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps })}
|
||||
{:else}
|
||||
<button {...mergedProps}>
|
||||
{@render children?.()}
|
||||
</button>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarPrevButtonProps } from "../types.js";
|
||||
declare const CalendarPrevButton: import("svelte").Component<CalendarPrevButtonProps, {}, "ref">;
|
||||
type CalendarPrevButton = ReturnType<typeof CalendarPrevButton>;
|
||||
export default CalendarPrevButton;
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<script lang="ts">
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import type { CalendarYearSelectProps } from "../types.js";
|
||||
import { CalendarYearSelectState } from "../calendar.svelte.js";
|
||||
import { createId } from "../../../internal/create-id.js";
|
||||
|
||||
const uid = $props.id();
|
||||
|
||||
let {
|
||||
children,
|
||||
child,
|
||||
ref = $bindable(null),
|
||||
id = createId(uid),
|
||||
years,
|
||||
yearFormat = "numeric",
|
||||
disabled = false,
|
||||
"aria-label": ariaLabel = "Select a year",
|
||||
...restProps
|
||||
}: CalendarYearSelectProps = $props();
|
||||
|
||||
const yearSelectState = CalendarYearSelectState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
years: boxWith(() => years),
|
||||
yearFormat: boxWith(() => yearFormat),
|
||||
disabled: boxWith(() => Boolean(disabled)),
|
||||
});
|
||||
|
||||
const mergedProps = $derived(
|
||||
mergeProps(restProps, yearSelectState.props, { "aria-label": ariaLabel })
|
||||
);
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps, ...yearSelectState.snippetProps })}
|
||||
{:else}
|
||||
<select {...mergedProps}>
|
||||
{#if children}
|
||||
{@render children?.(yearSelectState.snippetProps)}
|
||||
{:else}
|
||||
{#each yearSelectState.yearItems as year (year.value)}
|
||||
<option value={year.value} selected={year.value === yearSelectState.currentYear}>
|
||||
{year.label}
|
||||
</option>
|
||||
{/each}
|
||||
{/if}
|
||||
</select>
|
||||
{/if}
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarYearSelectProps } from "../types.js";
|
||||
declare const CalendarYearSelect: import("svelte").Component<CalendarYearSelectProps, {}, "ref">;
|
||||
type CalendarYearSelect = ReturnType<typeof CalendarYearSelect>;
|
||||
export default CalendarYearSelect;
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
<script lang="ts">
|
||||
import { watch } from "runed";
|
||||
import { boxWith, mergeProps } from "svelte-toolbelt";
|
||||
import { type DateValue } from "@internationalized/date";
|
||||
import { CalendarRootState } from "../calendar.svelte.js";
|
||||
import type { CalendarRootProps } from "../types.js";
|
||||
import { useId } from "../../../internal/use-id.js";
|
||||
import { noop } from "../../../internal/noop.js";
|
||||
import { getDefaultDate } from "../../../internal/date-time/utils.js";
|
||||
import { resolveLocaleProp } from "../../utilities/config/prop-resolvers.js";
|
||||
|
||||
let {
|
||||
child,
|
||||
children,
|
||||
id = useId(),
|
||||
ref = $bindable(null),
|
||||
value = $bindable(),
|
||||
onValueChange = noop,
|
||||
placeholder = $bindable(),
|
||||
onPlaceholderChange = noop,
|
||||
weekdayFormat = "narrow",
|
||||
weekStartsOn,
|
||||
pagedNavigation = false,
|
||||
isDateDisabled = () => false,
|
||||
isDateUnavailable = () => false,
|
||||
fixedWeeks = false,
|
||||
numberOfMonths = 1,
|
||||
locale,
|
||||
calendarLabel = "Event",
|
||||
disabled = false,
|
||||
readonly = false,
|
||||
minValue = undefined,
|
||||
maxValue = undefined,
|
||||
preventDeselect = false,
|
||||
type,
|
||||
disableDaysOutsideMonth = true,
|
||||
initialFocus = false,
|
||||
maxDays,
|
||||
monthFormat = "long",
|
||||
yearFormat = "numeric",
|
||||
...restProps
|
||||
}: CalendarRootProps = $props();
|
||||
|
||||
const defaultPlaceholder = getDefaultDate({
|
||||
defaultValue: value,
|
||||
minValue,
|
||||
maxValue,
|
||||
});
|
||||
|
||||
function handleDefaultPlaceholder() {
|
||||
if (placeholder !== undefined) return;
|
||||
placeholder = defaultPlaceholder;
|
||||
}
|
||||
|
||||
// SSR
|
||||
handleDefaultPlaceholder();
|
||||
|
||||
watch.pre(
|
||||
() => placeholder,
|
||||
() => {
|
||||
handleDefaultPlaceholder();
|
||||
}
|
||||
);
|
||||
|
||||
function handleDefaultValue() {
|
||||
if (value !== undefined) return;
|
||||
value = type === "single" ? undefined : [];
|
||||
}
|
||||
|
||||
// SSR
|
||||
handleDefaultValue();
|
||||
|
||||
watch.pre(
|
||||
() => value,
|
||||
() => {
|
||||
handleDefaultValue();
|
||||
}
|
||||
);
|
||||
|
||||
const rootState = CalendarRootState.create({
|
||||
id: boxWith(() => id),
|
||||
ref: boxWith(
|
||||
() => ref,
|
||||
(v) => (ref = v)
|
||||
),
|
||||
weekdayFormat: boxWith(() => weekdayFormat),
|
||||
weekStartsOn: boxWith(() => weekStartsOn),
|
||||
pagedNavigation: boxWith(() => pagedNavigation),
|
||||
isDateDisabled: boxWith(() => isDateDisabled),
|
||||
isDateUnavailable: boxWith(() => isDateUnavailable),
|
||||
fixedWeeks: boxWith(() => fixedWeeks),
|
||||
numberOfMonths: boxWith(() => numberOfMonths),
|
||||
locale: resolveLocaleProp(() => locale),
|
||||
calendarLabel: boxWith(() => calendarLabel),
|
||||
readonly: boxWith(() => readonly),
|
||||
disabled: boxWith(() => disabled),
|
||||
minValue: boxWith(() => minValue),
|
||||
maxValue: boxWith(() => maxValue),
|
||||
disableDaysOutsideMonth: boxWith(() => disableDaysOutsideMonth),
|
||||
initialFocus: boxWith(() => initialFocus),
|
||||
maxDays: boxWith(() => maxDays),
|
||||
placeholder: boxWith(
|
||||
() => placeholder as DateValue,
|
||||
(v) => {
|
||||
placeholder = v;
|
||||
onPlaceholderChange(v as DateValue);
|
||||
}
|
||||
),
|
||||
preventDeselect: boxWith(() => preventDeselect),
|
||||
value: boxWith(
|
||||
() => value,
|
||||
(v) => {
|
||||
value = v;
|
||||
// oxlint-disable-next-line no-explicit-any
|
||||
onValueChange(v as any);
|
||||
}
|
||||
),
|
||||
type: boxWith(() => type),
|
||||
monthFormat: boxWith(() => monthFormat),
|
||||
yearFormat: boxWith(() => yearFormat),
|
||||
defaultPlaceholder,
|
||||
});
|
||||
|
||||
const mergedProps = $derived(mergeProps(restProps, rootState.props));
|
||||
</script>
|
||||
|
||||
{#if child}
|
||||
{@render child({ props: mergedProps, ...rootState.snippetProps })}
|
||||
{:else}
|
||||
<div {...mergedProps}>
|
||||
{@render children?.(rootState.snippetProps)}
|
||||
</div>
|
||||
{/if}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { CalendarRootProps } from "../types.js";
|
||||
declare const Calendar: import("svelte").Component<CalendarRootProps, {}, "value" | "placeholder" | "ref">;
|
||||
type Calendar = ReturnType<typeof Calendar>;
|
||||
export default Calendar;
|
||||
Reference in New Issue
Block a user