-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
5,028 additions
and
994 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 23 additions & 24 deletions
47
packages/bits-ui/src/lib/bits/date-field/components/date-field-input.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import { getCtx } from "../ctx.js"; | ||
import { useId } from "$lib/internal/useId.svelte.js"; | ||
import { box } from "svelte-toolbelt"; | ||
import { useDateFieldInput } from "../date-field.svelte.js"; | ||
import type { InputProps } from "../index.js"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
type $$Props = InputProps; | ||
let { | ||
id = useId(), | ||
ref = $bindable(null), | ||
asChild, | ||
children, | ||
child, | ||
...restProps | ||
}: InputProps = $props(); | ||
export let asChild: $$Props["asChild"] = false; | ||
export let id: $$Props["id"] = undefined; | ||
export let el: $$Props["el"] = undefined; | ||
const inputState = useDateFieldInput({ | ||
id: box.with(() => id), | ||
ref: box.with( | ||
() => ref, | ||
(v) => (ref = v) | ||
), | ||
}); | ||
const { | ||
elements: { field }, | ||
states: { segmentContents }, | ||
ids, | ||
getAttrs, | ||
} = getCtx(); | ||
$: if (id) { | ||
ids.field.set(id); | ||
} | ||
const attrs = getAttrs("input"); | ||
$: builder = $field; | ||
$: Object.assign(builder, attrs); | ||
const mergedProps = $derived(mergeProps(restProps, inputState.props)); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} segments={$segmentContents} /> | ||
{@render child?.({ props: mergedProps, segments: inputState.root.segmentContents })} | ||
{:else} | ||
<div bind:this={ref} use:melt={builder} {...$$restProps}> | ||
<slot {builder} segments={$segmentContents} /> | ||
<div {...mergedProps}> | ||
{@render children?.({ segments: inputState.root.segmentContents })} | ||
</div> | ||
{/if} |
48 changes: 24 additions & 24 deletions
48
packages/bits-ui/src/lib/bits/date-field/components/date-field-label.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import { getCtx } from "../ctx.js"; | ||
import { useId } from "$lib/internal/useId.svelte.js"; | ||
import { box } from "svelte-toolbelt"; | ||
import { useDateFieldLabel } from "../date-field.svelte.js"; | ||
import type { LabelProps } from "../index.js"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
type $$Props = LabelProps; | ||
let { | ||
id = useId(), | ||
ref = $bindable(null), | ||
asChild, | ||
children, | ||
child, | ||
...restProps | ||
}: LabelProps = $props(); | ||
export let asChild: $$Props["asChild"] = false; | ||
export let id: $$Props["id"] = undefined; | ||
export let el: $$Props["el"] = undefined; | ||
const labelState = useDateFieldLabel({ | ||
id: box.with(() => id), | ||
ref: box.with( | ||
() => ref, | ||
(v) => (ref = v) | ||
), | ||
}); | ||
const { | ||
elements: { label }, | ||
ids, | ||
getAttrs, | ||
} = getCtx(); | ||
if (id) { | ||
ids.label.set(id); | ||
} | ||
const attrs = getAttrs("label"); | ||
$: builder = $label; | ||
$: Object.assign(builder, attrs); | ||
const mergedProps = $derived(mergeProps(restProps, labelState.props)); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} /> | ||
{@render child?.({ props: mergedProps })} | ||
{:else} | ||
<span bind:this={ref} use:melt={builder} {...$$restProps}> | ||
<slot {builder} /> | ||
</span> | ||
<div {...mergedProps}> | ||
{@render children?.()} | ||
</div> | ||
{/if} |
64 changes: 28 additions & 36 deletions
64
packages/bits-ui/src/lib/bits/date-field/components/date-field-segment.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,37 @@ | ||
<script lang="ts"> | ||
import { melt } from "@melt-ui/svelte"; | ||
import { getCtx } from "../ctx.js"; | ||
import type { SegmentEvents, SegmentProps } from "../index.js"; | ||
import { createDispatcher } from "$lib/internal/events.js"; | ||
import { useId } from "$lib/internal/useId.svelte.js"; | ||
import { box } from "svelte-toolbelt"; | ||
import { useDateFieldSegment } from "../date-field.svelte.js"; | ||
import type { SegmentProps } from "../index.js"; | ||
import { mergeProps } from "$lib/internal/mergeProps.js"; | ||
type $$Props = SegmentProps; | ||
type $$Events = SegmentEvents; | ||
let { | ||
id = useId(), | ||
ref = $bindable(null), | ||
asChild, | ||
children, | ||
child, | ||
part, | ||
...restProps | ||
}: SegmentProps = $props(); | ||
export let asChild: $$Props["asChild"] = false; | ||
export let id: $$Props["id"] = undefined; | ||
export let part: $$Props["part"]; | ||
export let el: $$Props["el"] = undefined; | ||
const segmentState = useDateFieldSegment(part, { | ||
id: box.with(() => id), | ||
ref: box.with( | ||
() => ref, | ||
(v) => (ref = v) | ||
), | ||
}); | ||
const { | ||
elements: { segment }, | ||
ids, | ||
getAttrs, | ||
} = getCtx(); | ||
$: if (id && part !== "literal") { | ||
ids[part].set(id); | ||
} | ||
const attrs = getAttrs("segment"); | ||
const dispatch = createDispatcher(); | ||
$: builder = $segment(part); | ||
$: Object.assign(builder, attrs); | ||
const mergedProps = $derived( | ||
mergeProps(restProps, segmentState.props as Record<string, unknown>) | ||
); | ||
</script> | ||
|
||
{#if asChild} | ||
<slot {builder} /> | ||
{@render child?.({ props: mergedProps })} | ||
{:else} | ||
<div | ||
bind:this={ref} | ||
use:melt={builder} | ||
{...$$restProps} | ||
on:m-click={dispatch} | ||
on:m-focusout={dispatch} | ||
on:m-keydown={dispatch} | ||
> | ||
<slot {builder} /> | ||
</div> | ||
<span {...mergedProps}> | ||
{@render children?.()} | ||
</span> | ||
{/if} |
Oops, something went wrong.