@epilot/spark-ui 0.32.1 → 0.32.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{button-i1Bgbw4p.d.ts → button-4QGaO78M.d.ts} +2 -2
- package/dist/{button-CT39v1M3.d.cts → button-C-KeUy2j.d.cts} +2 -2
- package/dist/components/alert-dialog.d.cts +1 -1
- package/dist/components/alert-dialog.d.ts +1 -1
- package/dist/components/attachment.d.cts +3 -3
- package/dist/components/attachment.d.ts +3 -3
- package/dist/components/bubble.d.cts +1 -1
- package/dist/components/bubble.d.ts +1 -1
- package/dist/components/button.d.cts +1 -1
- package/dist/components/button.d.ts +1 -1
- package/dist/components/callout.d.cts +1 -1
- package/dist/components/callout.d.ts +1 -1
- package/dist/components/dropzone.d.cts +1 -1
- package/dist/components/dropzone.d.ts +1 -1
- package/dist/components/empty-state.d.cts +1 -1
- package/dist/components/empty-state.d.ts +1 -1
- package/dist/components/image-carousel.d.cts +1 -1
- package/dist/components/image-carousel.d.ts +1 -1
- package/dist/components/marker.d.cts +1 -1
- package/dist/components/marker.d.ts +1 -1
- package/dist/components/message-scroller.d.cts +1 -1
- package/dist/components/message-scroller.d.ts +1 -1
- package/dist/components/page-header.d.cts +2 -2
- package/dist/components/page-header.d.ts +2 -2
- package/dist/components/pagination.d.cts +1 -1
- package/dist/components/pagination.d.ts +1 -1
- package/dist/components/period-tabs.d.cts +1 -1
- package/dist/components/period-tabs.d.ts +1 -1
- package/dist/components/pill.d.cts +1 -1
- package/dist/components/pill.d.ts +1 -1
- package/dist/components/toggle.d.cts +1 -1
- package/dist/components/toggle.d.ts +1 -1
- package/dist/lib/date-field.cjs +6 -5
- package/dist/lib/date-field.cjs.map +1 -1
- package/dist/lib/date-field.d.cts +7 -1
- package/dist/lib/date-field.d.ts +7 -1
- package/dist/lib/date-field.js +6 -5
- package/dist/lib/date-field.js.map +1 -1
- package/dist/lib/toggle-group-context.d.cts +1 -1
- package/dist/lib/toggle-group-context.d.ts +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
10
10
|
declare const buttonVariants: (props?: ({
|
|
11
11
|
variant?: "primary" | "destructive" | "secondary" | "tertiary" | "bare" | null | undefined;
|
|
12
12
|
color?: "accent" | "primary" | "neutral" | "danger" | "destructive" | null | undefined;
|
|
13
|
-
size?: "
|
|
13
|
+
size?: "small" | "default" | "icon" | "medium" | "icon-small" | "icon-medium" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
interface ButtonLookProps extends Omit<VariantProps<typeof buttonVariants>, 'variant' | 'color'> {
|
|
16
16
|
/**
|
|
@@ -49,4 +49,4 @@ declare function useButtonLook({
|
|
|
49
49
|
declare const Button$1: React$1.ForwardRefExoticComponent<ButtonProps & React$1.RefAttributes<HTMLButtonElement>>;
|
|
50
50
|
//#endregion
|
|
51
51
|
export { useButtonLook as a, buttonVariants as i, ButtonLookProps as n, ButtonProps as r, Button$1 as t };
|
|
52
|
-
//# sourceMappingURL=button-
|
|
52
|
+
//# sourceMappingURL=button-4QGaO78M.d.ts.map
|
|
@@ -10,7 +10,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
10
10
|
declare const buttonVariants: (props?: ({
|
|
11
11
|
variant?: "primary" | "destructive" | "secondary" | "tertiary" | "bare" | null | undefined;
|
|
12
12
|
color?: "accent" | "primary" | "neutral" | "danger" | "destructive" | null | undefined;
|
|
13
|
-
size?: "
|
|
13
|
+
size?: "small" | "default" | "icon" | "medium" | "icon-small" | "icon-medium" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
interface ButtonLookProps extends Omit<VariantProps<typeof buttonVariants>, 'variant' | 'color'> {
|
|
16
16
|
/**
|
|
@@ -49,4 +49,4 @@ declare function useButtonLook({
|
|
|
49
49
|
declare const Button$1: React$1.ForwardRefExoticComponent<ButtonProps & React$1.RefAttributes<HTMLButtonElement>>;
|
|
50
50
|
//#endregion
|
|
51
51
|
export { useButtonLook as a, buttonVariants as i, ButtonLookProps as n, ButtonProps as r, Button$1 as t };
|
|
52
|
-
//# sourceMappingURL=button-
|
|
52
|
+
//# sourceMappingURL=button-C-KeUy2j.d.cts.map
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-C-KeUy2j.cjs";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { VariantProps } from "class-variance-authority";
|
|
6
6
|
import { useRender } from "@base-ui/react/use-render";
|
|
7
7
|
|
|
8
8
|
//#region src/components/attachment.d.ts
|
|
9
9
|
declare const attachmentVariants: (props?: ({
|
|
10
|
-
size?: "
|
|
10
|
+
size?: "default" | "sm" | "xs" | null | undefined;
|
|
11
11
|
orientation?: "horizontal" | "vertical" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
declare function Attachment({
|
|
@@ -20,7 +20,7 @@ declare function Attachment({
|
|
|
20
20
|
state?: 'idle' | 'uploading' | 'processing' | 'error' | 'done';
|
|
21
21
|
}): import("react/jsx-runtime").JSX.Element;
|
|
22
22
|
declare const attachmentMediaVariants: (props?: ({
|
|
23
|
-
variant?: "
|
|
23
|
+
variant?: "image" | "icon" | null | undefined;
|
|
24
24
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
25
25
|
declare function AttachmentMedia({
|
|
26
26
|
className,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-4QGaO78M.js";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { VariantProps } from "class-variance-authority";
|
|
6
6
|
import { useRender } from "@base-ui/react/use-render";
|
|
7
7
|
|
|
8
8
|
//#region src/components/attachment.d.ts
|
|
9
9
|
declare const attachmentVariants: (props?: ({
|
|
10
|
-
size?: "
|
|
10
|
+
size?: "default" | "sm" | "xs" | null | undefined;
|
|
11
11
|
orientation?: "horizontal" | "vertical" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
declare function Attachment({
|
|
@@ -20,7 +20,7 @@ declare function Attachment({
|
|
|
20
20
|
state?: 'idle' | 'uploading' | 'processing' | 'error' | 'done';
|
|
21
21
|
}): import("react/jsx-runtime").JSX.Element;
|
|
22
22
|
declare const attachmentMediaVariants: (props?: ({
|
|
23
|
-
variant?: "
|
|
23
|
+
variant?: "image" | "icon" | null | undefined;
|
|
24
24
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
25
25
|
declare function AttachmentMedia({
|
|
26
26
|
className,
|
|
@@ -10,7 +10,7 @@ declare function BubbleGroup({
|
|
|
10
10
|
...props
|
|
11
11
|
}: React$1.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
declare const bubbleVariants: (props?: ({
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "destructive" | "default" | "secondary" | "muted" | "tinted" | "outline" | "ghost" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
declare function Bubble({
|
|
16
16
|
variant,
|
|
@@ -10,7 +10,7 @@ declare function BubbleGroup({
|
|
|
10
10
|
...props
|
|
11
11
|
}: React$1.ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element;
|
|
12
12
|
declare const bubbleVariants: (props?: ({
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "destructive" | "default" | "secondary" | "muted" | "tinted" | "outline" | "ghost" | null | undefined;
|
|
14
14
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
15
15
|
declare function Bubble({
|
|
16
16
|
variant,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { i as SparkButtonDesignVariant, n as SparkButtonColor, s as SparkButtonVariant } from "../theme-types-CHl-L2F-.cjs";
|
|
4
|
-
import { a as useButtonLook, i as buttonVariants, n as ButtonLookProps, r as ButtonProps, t as Button } from "../button-
|
|
4
|
+
import { a as useButtonLook, i as buttonVariants, n as ButtonLookProps, r as ButtonProps, t as Button } from "../button-C-KeUy2j.cjs";
|
|
5
5
|
export { Button, ButtonLookProps, ButtonProps, type SparkButtonColor, type SparkButtonDesignVariant, type SparkButtonVariant, buttonVariants, useButtonLook };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { i as SparkButtonDesignVariant, n as SparkButtonColor, s as SparkButtonVariant } from "../theme-types-CHl-L2F-.js";
|
|
4
|
-
import { a as useButtonLook, i as buttonVariants, n as ButtonLookProps, r as ButtonProps, t as Button } from "../button-
|
|
4
|
+
import { a as useButtonLook, i as buttonVariants, n as ButtonLookProps, r as ButtonProps, t as Button } from "../button-4QGaO78M.js";
|
|
5
5
|
export { Button, ButtonLookProps, ButtonProps, type SparkButtonColor, type SparkButtonDesignVariant, type SparkButtonVariant, buttonVariants, useButtonLook };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-C-KeUy2j.cjs";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { VariantProps } from "class-variance-authority";
|
|
6
6
|
import { SparkIcon } from "@epilot/spark-icons";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-4QGaO78M.js";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { SparkIcon } from "@epilot/spark-icons";
|
|
6
6
|
import { VariantProps } from "class-variance-authority";
|
|
@@ -7,7 +7,7 @@ import { SparkIcon } from "@epilot/spark-icons";
|
|
|
7
7
|
//#region src/components/empty-state.d.ts
|
|
8
8
|
declare const emptyStateVariants: (props?: ({
|
|
9
9
|
variant?: "ghost" | "dashed" | null | undefined;
|
|
10
|
-
size?: "
|
|
10
|
+
size?: "default" | "sm" | null | undefined;
|
|
11
11
|
layout?: "inline" | "stacked" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
type EmptyStateVariants = VariantProps<typeof emptyStateVariants>;
|
|
@@ -7,7 +7,7 @@ import { VariantProps } from "class-variance-authority";
|
|
|
7
7
|
//#region src/components/empty-state.d.ts
|
|
8
8
|
declare const emptyStateVariants: (props?: ({
|
|
9
9
|
variant?: "ghost" | "dashed" | null | undefined;
|
|
10
|
-
size?: "
|
|
10
|
+
size?: "default" | "sm" | null | undefined;
|
|
11
11
|
layout?: "inline" | "stacked" | null | undefined;
|
|
12
12
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
13
13
|
type EmptyStateVariants = VariantProps<typeof emptyStateVariants>;
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "
|
|
9
|
+
variant?: "separator" | "default" | "border" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render";
|
|
|
6
6
|
|
|
7
7
|
//#region src/components/marker.d.ts
|
|
8
8
|
declare const markerVariants: (props?: ({
|
|
9
|
-
variant?: "
|
|
9
|
+
variant?: "separator" | "default" | "border" | null | undefined;
|
|
10
10
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
11
11
|
declare function Marker({
|
|
12
12
|
className,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-C-KeUy2j.cjs";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { MessageScroller as MessageScroller$1, useMessageScroller, useMessageScrollerScrollable, useMessageScrollerVisibility } from "@shadcn/react/message-scroller";
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-4QGaO78M.js";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { MessageScroller as MessageScroller$1, useMessageScroller, useMessageScrollerScrollable, useMessageScrollerVisibility } from "@shadcn/react/message-scroller";
|
|
6
6
|
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-C-KeUy2j.cjs";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { useRender } from "@base-ui/react/use-render";
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "size" | "styleVariant"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-4QGaO78M.js";
|
|
4
4
|
import * as React$1 from "react";
|
|
5
5
|
import { useRender } from "@base-ui/react/use-render";
|
|
6
6
|
|
|
7
7
|
//#region src/components/page-header.d.ts
|
|
8
8
|
declare const PageHeader: React$1.ForwardRefExoticComponent<React$1.HTMLAttributes<HTMLElement> & React$1.RefAttributes<HTMLElement>>;
|
|
9
|
-
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "
|
|
9
|
+
declare const PageHeaderBackButton: React$1.ForwardRefExoticComponent<Omit<ButtonProps, "color" | "size" | "styleVariant"> & React$1.RefAttributes<HTMLButtonElement>>;
|
|
10
10
|
declare const PageHeaderTitle: ({
|
|
11
11
|
className,
|
|
12
12
|
...props
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-C-KeUy2j.cjs";
|
|
4
4
|
|
|
5
5
|
//#region src/components/period-tabs.d.ts
|
|
6
6
|
type PeriodStepperButtonProps = Omit<ButtonProps, 'styleVariant' | 'color' | 'size' | 'children' | 'aria-label'> & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { r as ButtonProps } from "../button-
|
|
3
|
+
import { r as ButtonProps } from "../button-4QGaO78M.js";
|
|
4
4
|
|
|
5
5
|
//#region src/components/period-tabs.d.ts
|
|
6
6
|
type PeriodStepperButtonProps = Omit<ButtonProps, 'styleVariant' | 'color' | 'size' | 'children' | 'aria-label'> & {
|
|
@@ -27,7 +27,7 @@ type PillButtonProps = Omit<React$1.ComponentProps<typeof Button>, 'ref' | 'clas
|
|
|
27
27
|
'aria-label': string;
|
|
28
28
|
};
|
|
29
29
|
/** A button inside a static `Pill` (no `onClick`); it is disabled with the pill. */
|
|
30
|
-
declare const PillButton: React$1.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ButtonProps, "ref"> & React$1.RefAttributes<HTMLElement>, "
|
|
30
|
+
declare const PillButton: React$1.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ButtonProps, "ref"> & React$1.RefAttributes<HTMLElement>, "className" | "ref" | "aria-label"> & {
|
|
31
31
|
className?: string; /** Names the button; the icon inside is decorative. */
|
|
32
32
|
'aria-label': string;
|
|
33
33
|
} & React$1.RefAttributes<HTMLButtonElement>>;
|
|
@@ -27,7 +27,7 @@ type PillButtonProps = Omit<React$1.ComponentProps<typeof Button>, 'ref' | 'clas
|
|
|
27
27
|
'aria-label': string;
|
|
28
28
|
};
|
|
29
29
|
/** A button inside a static `Pill` (no `onClick`); it is disabled with the pill. */
|
|
30
|
-
declare const PillButton: React$1.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ButtonProps, "ref"> & React$1.RefAttributes<HTMLElement>, "
|
|
30
|
+
declare const PillButton: React$1.ForwardRefExoticComponent<Omit<Omit<import("@base-ui/react").ButtonProps, "ref"> & React$1.RefAttributes<HTMLElement>, "className" | "ref" | "aria-label"> & {
|
|
31
31
|
className?: string; /** Names the button; the icon inside is decorative. */
|
|
32
32
|
'aria-label': string;
|
|
33
33
|
} & React$1.RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { n as SparkButtonColor, v as SparkStyle } from "../theme-types-CHl-L2F-.cjs";
|
|
4
|
-
import { i as buttonVariants } from "../button-
|
|
4
|
+
import { i as buttonVariants } from "../button-C-KeUy2j.cjs";
|
|
5
5
|
import * as React$1 from "react";
|
|
6
6
|
import { VariantProps } from "class-variance-authority";
|
|
7
7
|
import { Toggle as Toggle$1 } from "@base-ui/react/toggle";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { n as SparkButtonColor, v as SparkStyle } from "../theme-types-CHl-L2F-.js";
|
|
4
|
-
import { i as buttonVariants } from "../button-
|
|
4
|
+
import { i as buttonVariants } from "../button-4QGaO78M.js";
|
|
5
5
|
import * as React$1 from "react";
|
|
6
6
|
import { VariantProps } from "class-variance-authority";
|
|
7
7
|
import { Toggle as Toggle$1 } from "@base-ui/react/toggle";
|
package/dist/lib/date-field.cjs
CHANGED
|
@@ -31,7 +31,7 @@ function isOutOfRange(date, { max, min, withTime }) {
|
|
|
31
31
|
const to = max && (withTime ? max : startOfDay(max));
|
|
32
32
|
return from !== void 0 && at < from || to !== void 0 && at > to;
|
|
33
33
|
}
|
|
34
|
-
function DateFieldRoot({ children, className, defaultOpen, defaultValue = "", disabled = false, max, min, onOpenChange, onValueChange, open, separator = ".", slot, value, withTime }) {
|
|
34
|
+
function DateFieldRoot({ children, className, defaultDay: defaultDayProp, defaultOpen, defaultValue = "", disabled = false, max, min, onOpenChange, onValueChange, open, separator = ".", slot, value, withTime }) {
|
|
35
35
|
const [text, setText] = useControllableState({
|
|
36
36
|
defaultProp: defaultValue,
|
|
37
37
|
prop: value
|
|
@@ -61,10 +61,10 @@ function DateFieldRoot({ children, className, defaultOpen, defaultValue = "", di
|
|
|
61
61
|
});
|
|
62
62
|
},
|
|
63
63
|
defaultDay: () => {
|
|
64
|
-
const
|
|
65
|
-
if (min &&
|
|
66
|
-
if (max &&
|
|
67
|
-
return
|
|
64
|
+
const day = startOfDay(defaultDayProp?.() ?? /* @__PURE__ */ new Date());
|
|
65
|
+
if (min && day < startOfDay(min)) return startOfDay(min);
|
|
66
|
+
if (max && day > startOfDay(max)) return startOfDay(max);
|
|
67
|
+
return day;
|
|
68
68
|
},
|
|
69
69
|
disabled,
|
|
70
70
|
handle,
|
|
@@ -79,6 +79,7 @@ function DateFieldRoot({ children, className, defaultOpen, defaultValue = "", di
|
|
|
79
79
|
triggerId,
|
|
80
80
|
withTime
|
|
81
81
|
}), [
|
|
82
|
+
defaultDayProp,
|
|
82
83
|
disabled,
|
|
83
84
|
handle,
|
|
84
85
|
max,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-field.cjs","names":["React","PopoverPrimitive","parseDateTime","Popover","PopoverAnchor","InputGroup","InputGroupAddon","PopoverTrigger","Button","CalendarMonth","parseDatePart","withDay","PopoverContent","CalendarFieldContext"],"sources":["../../src/lib/date-field.tsx"],"sourcesContent":["'use client'\n\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover'\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { Button } from '../components/button'\nimport { InputGroup, InputGroupAddon } from '../components/input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from '../components/popover'\nimport { cn } from '../utils/cn'\nimport { type CalendarField, CalendarFieldContext } from './calendar-field'\nimport { parseDatePart, parseDateTime, withDay } from './date-time-mask'\n\nexport type DateFieldDetails = {\n date: Date | undefined\n outOfRange: boolean\n}\n\ntype DateFieldContextValue = {\n commit: (next: string) => void\n defaultDay: () => Date\n disabled: boolean\n handle: PopoverPrimitive.Handle<unknown>\n inputRef: React.RefObject<HTMLInputElement | null>\n max: Date | undefined\n min: Date | undefined\n outOfRange: boolean\n separator: string\n slot: string\n text: string\n timeList: React.RefObject<{ defaultTime: string } | null>\n triggerId: string\n withTime: boolean\n}\n\nconst DateFieldContext = React.createContext<DateFieldContextValue | null>(null)\n\nexport function useDateField(part: string) {\n const context = React.useContext(DateFieldContext)\n if (!context)\n throw new Error(\n `${part} must be placed inside its InputDate or InputDateTime root.`,\n )\n return context\n}\n\nfunction useControllableState<T>({\n defaultProp,\n prop,\n}: {\n defaultProp: T\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n return [prop ?? uncontrolled, setUncontrolled] as const\n}\n\nconst startOfDay = (date: Date) =>\n new Date(date.getFullYear(), date.getMonth(), date.getDate())\n\nfunction isOutOfRange(\n date: Date,\n { max, min, withTime }: { max?: Date; min?: Date; withTime: boolean },\n) {\n const at = withTime ? date : startOfDay(date)\n const from = min && (withTime ? min : startOfDay(min))\n const to = max && (withTime ? max : startOfDay(max))\n return (from !== undefined && at < from) || (to !== undefined && at > to)\n}\n\nexport type DateFieldRootProps = Pick<\n React.ComponentProps<typeof Popover>,\n 'defaultOpen' | 'onOpenChange' | 'open'\n> & {\n children: React.ReactNode\n className?: string\n defaultValue?: string\n disabled?: boolean\n max?: Date\n min?: Date\n onValueChange?: (value: string, details: DateFieldDetails) => void\n separator?: string\n value?: string\n}\n\nexport function DateFieldRoot({\n children,\n className,\n defaultOpen,\n defaultValue = '',\n disabled = false,\n max,\n min,\n onOpenChange,\n onValueChange,\n open,\n separator = '.',\n slot,\n value,\n withTime,\n}: DateFieldRootProps & { slot: string; withTime: boolean }) {\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n prop: value,\n })\n const [handle] = React.useState(() => PopoverPrimitive.createHandle())\n const inputRef = React.useRef<HTMLInputElement>(null)\n const timeList = React.useRef<{ defaultTime: string } | null>(null)\n const triggerId = React.useId()\n const date = parseDateTime(text, withTime)\n const outOfRange =\n date !== undefined && isOutOfRange(date, { max, min, withTime })\n\n const context = React.useMemo<DateFieldContextValue>(\n () => ({\n commit: (next) => {\n if (next === text) return\n setText(next)\n const nextDate = parseDateTime(next, withTime)\n onValueChange?.(next, {\n date: nextDate,\n outOfRange:\n nextDate !== undefined &&\n isOutOfRange(nextDate, { max, min, withTime }),\n })\n },\n defaultDay: () => {\n const today = startOfDay(new Date())\n if (min && today < startOfDay(min)) return startOfDay(min)\n if (max && today > startOfDay(max)) return startOfDay(max)\n return today\n },\n disabled,\n handle,\n inputRef,\n max,\n min,\n outOfRange,\n separator,\n slot,\n text,\n timeList,\n triggerId,\n withTime,\n }),\n [\n disabled,\n handle,\n max,\n min,\n onValueChange,\n outOfRange,\n separator,\n setText,\n slot,\n text,\n triggerId,\n withTime,\n ],\n )\n\n return (\n <DateFieldContext.Provider value={context}>\n <Popover\n defaultOpen={defaultOpen}\n handle={handle}\n onOpenChange={onOpenChange}\n open={open}\n >\n <PopoverAnchor render={<div className=\"min-w-0\" data-slot={slot} />}>\n <InputGroup className={className}>{children}</InputGroup>\n </PopoverAnchor>\n </Popover>\n </DateFieldContext.Provider>\n )\n}\n\nexport type DateFieldTriggerProps = Omit<\n React.ComponentProps<typeof Button>,\n 'aria-label'\n> & { 'aria-label': string }\n\nexport function DateFieldTrigger({\n children,\n ...props\n}: DateFieldTriggerProps) {\n const { disabled, slot, triggerId } = useDateField(\n 'InputDateTrigger / InputDateTimeTrigger',\n )\n return (\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n id={triggerId}\n render={\n <Button\n color=\"neutral\"\n data-slot={`${slot}-trigger`}\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n {...props}\n >\n {children ?? <CalendarMonth />}\n </Button>\n }\n />\n </InputGroupAddon>\n )\n}\n\nexport function DateFieldContent({\n children,\n className,\n ...props\n}: React.ComponentProps<typeof PopoverContent>) {\n const field = useDateField('InputDateContent / InputDateTimeContent')\n const { commit, handle, max, min, separator, text, withTime } = field\n const selected = withTime ? parseDatePart(text) : parseDateTime(text)\n\n const calendar: CalendarField = {\n defaultMonth: selected ?? field.defaultDay(),\n disabled: [\n ...(min ? [{ before: min }] : []),\n ...(max ? [{ after: max }] : []),\n ],\n endMonth: max,\n onSelect: (day) => {\n if (!day) {\n if (withTime) return\n commit('')\n handle.close()\n return\n }\n const timeList = field.timeList.current\n commit(\n withDay(text, day, {\n separator,\n time: timeList?.defaultTime,\n withTime,\n }),\n )\n if (timeList) return\n handle.close()\n if (withTime) field.inputRef.current?.focus({ preventScroll: true })\n },\n selected,\n startMonth: min,\n }\n\n return (\n <PopoverContent\n align=\"start\"\n aria-labelledby={field.triggerId}\n collisionAvoidance={{ side: 'flip', fallbackAxisSide: 'none' }}\n data-slot={`${field.slot}-content`}\n {...props}\n className={cn(\n 'flex w-auto p-0 max-sm:flex-col has-[[data-slot=calendar-list]]:[&>[data-slot=input-date-time-time-list]]:hidden',\n className,\n )}\n >\n <CalendarFieldCont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tB;GAA+B,OAAO;GACnC;EAC4B,CAAA;CACjB,CAAA;AAEpB"}
|
|
1
|
+
{"version":3,"file":"date-field.cjs","names":["React","PopoverPrimitive","parseDateTime","Popover","PopoverAnchor","InputGroup","InputGroupAddon","PopoverTrigger","Button","CalendarMonth","parseDatePart","withDay","PopoverContent","CalendarFieldContext"],"sources":["../../src/lib/date-field.tsx"],"sourcesContent":["'use client'\n\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover'\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { Button } from '../components/button'\nimport { InputGroup, InputGroupAddon } from '../components/input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from '../components/popover'\nimport { cn } from '../utils/cn'\nimport { type CalendarField, CalendarFieldContext } from './calendar-field'\nimport { parseDatePart, parseDateTime, withDay } from './date-time-mask'\n\nexport type DateFieldDetails = {\n date: Date | undefined\n outOfRange: boolean\n}\n\ntype DateFieldContextValue = {\n commit: (next: string) => void\n defaultDay: () => Date\n disabled: boolean\n handle: PopoverPrimitive.Handle<unknown>\n inputRef: React.RefObject<HTMLInputElement | null>\n max: Date | undefined\n min: Date | undefined\n outOfRange: boolean\n separator: string\n slot: string\n text: string\n timeList: React.RefObject<{ defaultTime: string } | null>\n triggerId: string\n withTime: boolean\n}\n\nconst DateFieldContext = React.createContext<DateFieldContextValue | null>(null)\n\nexport function useDateField(part: string) {\n const context = React.useContext(DateFieldContext)\n if (!context)\n throw new Error(\n `${part} must be placed inside its InputDate or InputDateTime root.`,\n )\n return context\n}\n\nfunction useControllableState<T>({\n defaultProp,\n prop,\n}: {\n defaultProp: T\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n return [prop ?? uncontrolled, setUncontrolled] as const\n}\n\nconst startOfDay = (date: Date) =>\n new Date(date.getFullYear(), date.getMonth(), date.getDate())\n\nfunction isOutOfRange(\n date: Date,\n { max, min, withTime }: { max?: Date; min?: Date; withTime: boolean },\n) {\n const at = withTime ? date : startOfDay(date)\n const from = min && (withTime ? min : startOfDay(min))\n const to = max && (withTime ? max : startOfDay(max))\n return (from !== undefined && at < from) || (to !== undefined && at > to)\n}\n\nexport type DateFieldRootProps = Pick<\n React.ComponentProps<typeof Popover>,\n 'defaultOpen' | 'onOpenChange' | 'open'\n> & {\n children: React.ReactNode\n className?: string\n /**\n * The day an empty field opens on, and the day a time picked before any date applies to;\n * today by default. Kept within `min` and `max`.\n */\n defaultDay?: () => Date\n defaultValue?: string\n disabled?: boolean\n max?: Date\n min?: Date\n onValueChange?: (value: string, details: DateFieldDetails) => void\n separator?: string\n value?: string\n}\n\nexport function DateFieldRoot({\n children,\n className,\n defaultDay: defaultDayProp,\n defaultOpen,\n defaultValue = '',\n disabled = false,\n max,\n min,\n onOpenChange,\n onValueChange,\n open,\n separator = '.',\n slot,\n value,\n withTime,\n}: DateFieldRootProps & { slot: string; withTime: boolean }) {\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n prop: value,\n })\n const [handle] = React.useState(() => PopoverPrimitive.createHandle())\n const inputRef = React.useRef<HTMLInputElement>(null)\n const timeList = React.useRef<{ defaultTime: string } | null>(null)\n const triggerId = React.useId()\n const date = parseDateTime(text, withTime)\n const outOfRange =\n date !== undefined && isOutOfRange(date, { max, min, withTime })\n\n const context = React.useMemo<DateFieldContextValue>(\n () => ({\n commit: (next) => {\n if (next === text) return\n setText(next)\n const nextDate = parseDateTime(next, withTime)\n onValueChange?.(next, {\n date: nextDate,\n outOfRange:\n nextDate !== undefined &&\n isOutOfRange(nextDate, { max, min, withTime }),\n })\n },\n defaultDay: () => {\n const day = startOfDay(defaultDayProp?.() ?? new Date())\n if (min && day < startOfDay(min)) return startOfDay(min)\n if (max && day > startOfDay(max)) return startOfDay(max)\n return day\n },\n disabled,\n handle,\n inputRef,\n max,\n min,\n outOfRange,\n separator,\n slot,\n text,\n timeList,\n triggerId,\n withTime,\n }),\n [\n defaultDayProp,\n disabled,\n handle,\n max,\n min,\n onValueChange,\n outOfRange,\n separator,\n setText,\n slot,\n text,\n triggerId,\n withTime,\n ],\n )\n\n return (\n <DateFieldContext.Provider value={context}>\n <Popover\n defaultOpen={defaultOpen}\n handle={handle}\n onOpenChange={onOpenChange}\n open={open}\n >\n <PopoverAnchor render={<div className=\"min-w-0\" data-slot={slot} />}>\n <InputGroup className={className}>{children}</InputGroup>\n </PopoverAnchor>\n </Popover>\n </DateFieldContext.Provider>\n )\n}\n\nexport type DateFieldTriggerProps = Omit<\n React.ComponentProps<typeof Button>,\n 'aria-label'\n> & { 'aria-label': string }\n\nexport function DateFieldTrigger({\n children,\n ...props\n}: DateFieldTriggerProps) {\n const { disabled, slot, triggerId } = useDateField(\n 'InputDateTrigger / InputDateTimeTrigger',\n )\n return (\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n id={triggerId}\n render={\n <Button\n color=\"neutral\"\n data-slot={`${slot}-trigger`}\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n {...props}\n >\n {children ?? <CalendarMonth />}\n </Button>\n }\n />\n </InputGroupAddon>\n )\n}\n\nexport function DateFieldContent({\n children,\n className,\n ...props\n}: React.ComponentProps<typeof PopoverContent>) {\n const field = useDateField('InputDateContent / InputDateTimeContent')\n const { commit, handle, max, min, separator, text, withTime } = field\n const selected = withTime ? parseDatePart(text) : parseDateTime(text)\n\n const calendar: CalendarField = {\n defaultMonth: selected ?? field.defaultDay(),\n disabled: [\n ...(min ? [{ before: min }] : []),\n ...(max ? [{ after: max }] : []),\n ],\n endMonth: max,\n onSelect: (day) => {\n if (!day) {\n if (withTime) return\n commit('')\n handle.close()\n return\n }\n const timeList = field.timeList.current\n commit(\n withDay(text, day, {\n separator,\n time: timeList?.defaultTime,\n withTime,\n }),\n )\n if (timeList) return\n handle.close()\n if (withTime) field.inputRef.current?.focus({ preventScroll: true })\n },\n selected,\n startMonth: min,\n }\n\n return (\n <PopoverContent\n align=\"start\"\n aria-labelledby={field.triggerId}\n collisionAvoidance={{ side: 'flip', fallbackAxisSide: 'none' }}\n data-slot={`${field.slot}-content`}\n {...props}\n className={cn(\n 'flex w-auto p-0 max-sm:flex-col has-[[data-slot=calendar-list]]:[&>[data-slot=input-date-time-time-list]]:hidden',\n className,\n )}\n >\n <CalendarFieldContext.Provider value={calendar}>\n {children}\n </CalendarFieldContext.Provider>\n </PopoverContent>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuCA,MAAM,mBAAmBA,MAAM,cAA4C,IAAI;AAE/E,SAAgB,aAAa,MAAc;CACzC,MAAM,UAAUA,MAAM,WAAW,gBAAgB;CACjD,IAAI,CAAC,SACH,MAAM,IAAI,MACR,GAAG,KAAK,4DACV;CACF,OAAO;AACT;AAEA,SAAS,qBAAwB,EAC/B,aACA,QAIC;CACD,MAAM,CAAC,cAAc,mBAAmBA,MAAM,SAAS,WAAW;CAClE,OAAO,CAAC,QAAQ,cAAc,eAAe;AAC/C;AAEA,MAAM,cAAc,SAClB,IAAI,KAAK,KAAK,YAAY,GAAG,KAAK,SAAS,GAAG,KAAK,QAAQ,CAAC;AAE9D,SAAS,aACP,MACA,EAAE,KAAK,KAAK,YACZ;CACA,MAAM,KAAK,WAAW,OAAO,WAAW,IAAI;CAC5C,MAAM,OAAO,QAAQ,WAAW,MAAM,WAAW,GAAG;CACpD,MAAM,KAAK,QAAQ,WAAW,MAAM,WAAW,GAAG;CAClD,OAAQ,SAAS,KAAA,KAAa,KAAK,QAAU,OAAO,KAAA,KAAa,KAAK;AACxE;AAsBA,SAAgB,cAAc,EAC5B,UACA,WACA,YAAY,gBACZ,aACA,eAAe,IACf,WAAW,OACX,KACA,KACA,cACA,eACA,MACA,YAAY,KACZ,MACA,OACA,YAC2D;CAC3D,MAAM,CAAC,MAAM,WAAW,qBAAqB;EAC3C,aAAa;EACb,MAAM;CACR,CAAC;CACD,MAAM,CAAC,UAAUA,MAAM,eAAeC,uBAAAA,QAAiB,aAAa,CAAC;CACrE,MAAM,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gBAAD;EACE,OAAM;EACN,mBAAiB,MAAM;EACvB,oBAAoB;GAAE,MAAM;GAAQ,kBAAkB;EAAO;EAC7D,aAAW,GAAG,MAAM,KAAK;EACzB,GAAI;EACJ,YAAA,GAAA,GAAA,IACE,oHACA,SACF;YAEA,iBAAA,GAAA,kBAAA,KAACC,2BAAAA,qBAAqB,UAAtB;GAA+B,OAAO;GACnC;EAC4B,CAAA;CACjB,CAAA;AAEpB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { t as Button } from "../button-
|
|
3
|
+
import { t as Button } from "../button-C-KeUy2j.cjs";
|
|
4
4
|
import { i as PopoverContent, t as Popover$1 } from "../popover-DmcqNOkO.cjs";
|
|
5
5
|
import * as React$1 from "react";
|
|
6
6
|
import { Popover } from "@base-ui/react/popover";
|
|
@@ -32,6 +32,11 @@ declare function useDateField(part: string): DateFieldContextValue;
|
|
|
32
32
|
type DateFieldRootProps = Pick<React$1.ComponentProps<typeof Popover$1>, 'defaultOpen' | 'onOpenChange' | 'open'> & {
|
|
33
33
|
children: React$1.ReactNode;
|
|
34
34
|
className?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The day an empty field opens on, and the day a time picked before any date applies to;
|
|
37
|
+
* today by default. Kept within `min` and `max`.
|
|
38
|
+
*/
|
|
39
|
+
defaultDay?: () => Date;
|
|
35
40
|
defaultValue?: string;
|
|
36
41
|
disabled?: boolean;
|
|
37
42
|
max?: Date;
|
|
@@ -43,6 +48,7 @@ type DateFieldRootProps = Pick<React$1.ComponentProps<typeof Popover$1>, 'defaul
|
|
|
43
48
|
declare function DateFieldRoot({
|
|
44
49
|
children,
|
|
45
50
|
className,
|
|
51
|
+
defaultDay: defaultDayProp,
|
|
46
52
|
defaultOpen,
|
|
47
53
|
defaultValue,
|
|
48
54
|
disabled,
|
package/dist/lib/date-field.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { t as Button } from "../button-
|
|
3
|
+
import { t as Button } from "../button-4QGaO78M.js";
|
|
4
4
|
import { i as PopoverContent, t as Popover$1 } from "../popover-DmcqNOkO.js";
|
|
5
5
|
import * as React$1 from "react";
|
|
6
6
|
import { Popover } from "@base-ui/react/popover";
|
|
@@ -32,6 +32,11 @@ declare function useDateField(part: string): DateFieldContextValue;
|
|
|
32
32
|
type DateFieldRootProps = Pick<React$1.ComponentProps<typeof Popover$1>, 'defaultOpen' | 'onOpenChange' | 'open'> & {
|
|
33
33
|
children: React$1.ReactNode;
|
|
34
34
|
className?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The day an empty field opens on, and the day a time picked before any date applies to;
|
|
37
|
+
* today by default. Kept within `min` and `max`.
|
|
38
|
+
*/
|
|
39
|
+
defaultDay?: () => Date;
|
|
35
40
|
defaultValue?: string;
|
|
36
41
|
disabled?: boolean;
|
|
37
42
|
max?: Date;
|
|
@@ -43,6 +48,7 @@ type DateFieldRootProps = Pick<React$1.ComponentProps<typeof Popover$1>, 'defaul
|
|
|
43
48
|
declare function DateFieldRoot({
|
|
44
49
|
children,
|
|
45
50
|
className,
|
|
51
|
+
defaultDay: defaultDayProp,
|
|
46
52
|
defaultOpen,
|
|
47
53
|
defaultValue,
|
|
48
54
|
disabled,
|
package/dist/lib/date-field.js
CHANGED
|
@@ -28,7 +28,7 @@ function isOutOfRange(date, { max, min, withTime }) {
|
|
|
28
28
|
const to = max && (withTime ? max : startOfDay(max));
|
|
29
29
|
return from !== void 0 && at < from || to !== void 0 && at > to;
|
|
30
30
|
}
|
|
31
|
-
function DateFieldRoot({ children, className, defaultOpen, defaultValue = "", disabled = false, max, min, onOpenChange, onValueChange, open, separator = ".", slot, value, withTime }) {
|
|
31
|
+
function DateFieldRoot({ children, className, defaultDay: defaultDayProp, defaultOpen, defaultValue = "", disabled = false, max, min, onOpenChange, onValueChange, open, separator = ".", slot, value, withTime }) {
|
|
32
32
|
const [text, setText] = useControllableState({
|
|
33
33
|
defaultProp: defaultValue,
|
|
34
34
|
prop: value
|
|
@@ -58,10 +58,10 @@ function DateFieldRoot({ children, className, defaultOpen, defaultValue = "", di
|
|
|
58
58
|
});
|
|
59
59
|
},
|
|
60
60
|
defaultDay: () => {
|
|
61
|
-
const
|
|
62
|
-
if (min &&
|
|
63
|
-
if (max &&
|
|
64
|
-
return
|
|
61
|
+
const day = startOfDay(defaultDayProp?.() ?? /* @__PURE__ */ new Date());
|
|
62
|
+
if (min && day < startOfDay(min)) return startOfDay(min);
|
|
63
|
+
if (max && day > startOfDay(max)) return startOfDay(max);
|
|
64
|
+
return day;
|
|
65
65
|
},
|
|
66
66
|
disabled,
|
|
67
67
|
handle,
|
|
@@ -76,6 +76,7 @@ function DateFieldRoot({ children, className, defaultOpen, defaultValue = "", di
|
|
|
76
76
|
triggerId,
|
|
77
77
|
withTime
|
|
78
78
|
}), [
|
|
79
|
+
defaultDayProp,
|
|
79
80
|
disabled,
|
|
80
81
|
handle,
|
|
81
82
|
max,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-field.js","names":["React","PopoverPrimitive","Popover"],"sources":["../../src/lib/date-field.tsx"],"sourcesContent":["'use client'\n\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover'\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { Button } from '../components/button'\nimport { InputGroup, InputGroupAddon } from '../components/input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from '../components/popover'\nimport { cn } from '../utils/cn'\nimport { type CalendarField, CalendarFieldContext } from './calendar-field'\nimport { parseDatePart, parseDateTime, withDay } from './date-time-mask'\n\nexport type DateFieldDetails = {\n date: Date | undefined\n outOfRange: boolean\n}\n\ntype DateFieldContextValue = {\n commit: (next: string) => void\n defaultDay: () => Date\n disabled: boolean\n handle: PopoverPrimitive.Handle<unknown>\n inputRef: React.RefObject<HTMLInputElement | null>\n max: Date | undefined\n min: Date | undefined\n outOfRange: boolean\n separator: string\n slot: string\n text: string\n timeList: React.RefObject<{ defaultTime: string } | null>\n triggerId: string\n withTime: boolean\n}\n\nconst DateFieldContext = React.createContext<DateFieldContextValue | null>(null)\n\nexport function useDateField(part: string) {\n const context = React.useContext(DateFieldContext)\n if (!context)\n throw new Error(\n `${part} must be placed inside its InputDate or InputDateTime root.`,\n )\n return context\n}\n\nfunction useControllableState<T>({\n defaultProp,\n prop,\n}: {\n defaultProp: T\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n return [prop ?? uncontrolled, setUncontrolled] as const\n}\n\nconst startOfDay = (date: Date) =>\n new Date(date.getFullYear(), date.getMonth(), date.getDate())\n\nfunction isOutOfRange(\n date: Date,\n { max, min, withTime }: { max?: Date; min?: Date; withTime: boolean },\n) {\n const at = withTime ? date : startOfDay(date)\n const from = min && (withTime ? min : startOfDay(min))\n const to = max && (withTime ? max : startOfDay(max))\n return (from !== undefined && at < from) || (to !== undefined && at > to)\n}\n\nexport type DateFieldRootProps = Pick<\n React.ComponentProps<typeof Popover>,\n 'defaultOpen' | 'onOpenChange' | 'open'\n> & {\n children: React.ReactNode\n className?: string\n defaultValue?: string\n disabled?: boolean\n max?: Date\n min?: Date\n onValueChange?: (value: string, details: DateFieldDetails) => void\n separator?: string\n value?: string\n}\n\nexport function DateFieldRoot({\n children,\n className,\n defaultOpen,\n defaultValue = '',\n disabled = false,\n max,\n min,\n onOpenChange,\n onValueChange,\n open,\n separator = '.',\n slot,\n value,\n withTime,\n}: DateFieldRootProps & { slot: string; withTime: boolean }) {\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n prop: value,\n })\n const [handle] = React.useState(() => PopoverPrimitive.createHandle())\n const inputRef = React.useRef<HTMLInputElement>(null)\n const timeList = React.useRef<{ defaultTime: string } | null>(null)\n const triggerId = React.useId()\n const date = parseDateTime(text, withTime)\n const outOfRange =\n date !== undefined && isOutOfRange(date, { max, min, withTime })\n\n const context = React.useMemo<DateFieldContextValue>(\n () => ({\n commit: (next) => {\n if (next === text) return\n setText(next)\n const nextDate = parseDateTime(next, withTime)\n onValueChange?.(next, {\n date: nextDate,\n outOfRange:\n nextDate !== undefined &&\n isOutOfRange(nextDate, { max, min, withTime }),\n })\n },\n defaultDay: () => {\n const today = startOfDay(new Date())\n if (min && today < startOfDay(min)) return startOfDay(min)\n if (max && today > startOfDay(max)) return startOfDay(max)\n return today\n },\n disabled,\n handle,\n inputRef,\n max,\n min,\n outOfRange,\n separator,\n slot,\n text,\n timeList,\n triggerId,\n withTime,\n }),\n [\n disabled,\n handle,\n max,\n min,\n onValueChange,\n outOfRange,\n separator,\n setText,\n slot,\n text,\n triggerId,\n withTime,\n ],\n )\n\n return (\n <DateFieldContext.Provider value={context}>\n <Popover\n defaultOpen={defaultOpen}\n handle={handle}\n onOpenChange={onOpenChange}\n open={open}\n >\n <PopoverAnchor render={<div className=\"min-w-0\" data-slot={slot} />}>\n <InputGroup className={className}>{children}</InputGroup>\n </PopoverAnchor>\n </Popover>\n </DateFieldContext.Provider>\n )\n}\n\nexport type DateFieldTriggerProps = Omit<\n React.ComponentProps<typeof Button>,\n 'aria-label'\n> & { 'aria-label': string }\n\nexport function DateFieldTrigger({\n children,\n ...props\n}: DateFieldTriggerProps) {\n const { disabled, slot, triggerId } = useDateField(\n 'InputDateTrigger / InputDateTimeTrigger',\n )\n return (\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n id={triggerId}\n render={\n <Button\n color=\"neutral\"\n data-slot={`${slot}-trigger`}\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n {...props}\n >\n {children ?? <CalendarMonth />}\n </Button>\n }\n />\n </InputGroupAddon>\n )\n}\n\nexport function DateFieldContent({\n children,\n className,\n ...props\n}: React.ComponentProps<typeof PopoverContent>) {\n const field = useDateField('InputDateContent / InputDateTimeContent')\n const { commit, handle, max, min, separator, text, withTime } = field\n const selected = withTime ? parseDatePart(text) : parseDateTime(text)\n\n const calendar: CalendarField = {\n defaultMonth: selected ?? field.defaultDay(),\n disabled: [\n ...(min ? [{ before: min }] : []),\n ...(max ? [{ after: max }] : []),\n ],\n endMonth: max,\n onSelect: (day) => {\n if (!day) {\n if (withTime) return\n commit('')\n handle.close()\n return\n }\n const timeList = field.timeList.current\n commit(\n withDay(text, day, {\n separator,\n time: timeList?.defaultTime,\n withTime,\n }),\n )\n if (timeList) return\n handle.close()\n if (withTime) field.inputRef.current?.focus({ preventScroll: true })\n },\n selected,\n startMonth: min,\n }\n\n return (\n <PopoverContent\n align=\"start\"\n aria-labelledby={field.triggerId}\n collisionAvoidance={{ side: 'flip', fallbackAxisSide: 'none' }}\n data-slot={`${field.slot}-content`}\n {...props}\n className={cn(\n 'flex w-auto p-0 max-sm:flex-col has-[[data-slot=calendar-list]]:[&>[data-slot=input-date-time-time-list]]:hidden',\n className,\n )}\n >\n <CalendarFieldContext.Provider value={calendar}>\n {children}\n </CalendarFieldContext.Provider>\n </PopoverContent>\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,MAAM,mBAAmBA,QAAM,cAA4C,IAAI;AAE/E,SAAgB,aAAa,MAAc;CACzC,MAAM,UAAUA,QAAM,WAAW,gBAAgB;CACjD,IAAI,CAAC,SACH,MAAM,IAAI,MACR,GAAG,KAAK,4DACV;CACF,OAAO;AACT;AAEA,SAAS,qBAAwB,EAC/B,aACA,QAIC;CACD,MAAM,CAAC,cAAc,mBAAmBA,QAAM,SAAS,WAAW;CAClE,OAAO,CAAC,QAAQ,cAAc,eAAe;AAC/C;AAEA,MAAM,cAAc,SAClB,IAAI,KAAK,KAAK,YAAY,GAAG,KAAK,SAAS,GAAG,KAAK,QAAQ,CAAC;AAE9D,SAAS,aACP,MACA,EAAE,KAAK,KAAK,YACZ;CACA,MAAM,KAAK,WAAW,OAAO,WAAW,IAAI;CAC5C,MAAM,OAAO,QAAQ,WAAW,MAAM,WAAW,GAAG;CACpD,MAAM,KAAK,QAAQ,WAAW,MAAM,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CACd;CAEA,OACE,oBAAC,gBAAD;EACE,OAAM;EACN,mBAAiB,MAAM;EACvB,oBAAoB;GAAE,MAAM;GAAQ,kBAAkB;EAAO;EAC7D,aAAW,GAAG,MAAM,KAAK;EACzB,GAAI;EACJ,WAAW,GACT,oHACA,SACF;YAEA,oBAAC,qBAAqB,UAAtB;GAA+B,OAAO;GACnC;EAC4B,CAAA;CACjB,CAAA;AAEpB"}
|
|
1
|
+
{"version":3,"file":"date-field.js","names":["React","PopoverPrimitive","Popover"],"sources":["../../src/lib/date-field.tsx"],"sourcesContent":["'use client'\n\nimport { Popover as PopoverPrimitive } from '@base-ui/react/popover'\nimport { CalendarMonth } from '@epilot/spark-icons'\nimport * as React from 'react'\nimport { Button } from '../components/button'\nimport { InputGroup, InputGroupAddon } from '../components/input-group'\nimport {\n Popover,\n PopoverAnchor,\n PopoverContent,\n PopoverTrigger,\n} from '../components/popover'\nimport { cn } from '../utils/cn'\nimport { type CalendarField, CalendarFieldContext } from './calendar-field'\nimport { parseDatePart, parseDateTime, withDay } from './date-time-mask'\n\nexport type DateFieldDetails = {\n date: Date | undefined\n outOfRange: boolean\n}\n\ntype DateFieldContextValue = {\n commit: (next: string) => void\n defaultDay: () => Date\n disabled: boolean\n handle: PopoverPrimitive.Handle<unknown>\n inputRef: React.RefObject<HTMLInputElement | null>\n max: Date | undefined\n min: Date | undefined\n outOfRange: boolean\n separator: string\n slot: string\n text: string\n timeList: React.RefObject<{ defaultTime: string } | null>\n triggerId: string\n withTime: boolean\n}\n\nconst DateFieldContext = React.createContext<DateFieldContextValue | null>(null)\n\nexport function useDateField(part: string) {\n const context = React.useContext(DateFieldContext)\n if (!context)\n throw new Error(\n `${part} must be placed inside its InputDate or InputDateTime root.`,\n )\n return context\n}\n\nfunction useControllableState<T>({\n defaultProp,\n prop,\n}: {\n defaultProp: T\n prop?: T\n}) {\n const [uncontrolled, setUncontrolled] = React.useState(defaultProp)\n return [prop ?? uncontrolled, setUncontrolled] as const\n}\n\nconst startOfDay = (date: Date) =>\n new Date(date.getFullYear(), date.getMonth(), date.getDate())\n\nfunction isOutOfRange(\n date: Date,\n { max, min, withTime }: { max?: Date; min?: Date; withTime: boolean },\n) {\n const at = withTime ? date : startOfDay(date)\n const from = min && (withTime ? min : startOfDay(min))\n const to = max && (withTime ? max : startOfDay(max))\n return (from !== undefined && at < from) || (to !== undefined && at > to)\n}\n\nexport type DateFieldRootProps = Pick<\n React.ComponentProps<typeof Popover>,\n 'defaultOpen' | 'onOpenChange' | 'open'\n> & {\n children: React.ReactNode\n className?: string\n /**\n * The day an empty field opens on, and the day a time picked before any date applies to;\n * today by default. Kept within `min` and `max`.\n */\n defaultDay?: () => Date\n defaultValue?: string\n disabled?: boolean\n max?: Date\n min?: Date\n onValueChange?: (value: string, details: DateFieldDetails) => void\n separator?: string\n value?: string\n}\n\nexport function DateFieldRoot({\n children,\n className,\n defaultDay: defaultDayProp,\n defaultOpen,\n defaultValue = '',\n disabled = false,\n max,\n min,\n onOpenChange,\n onValueChange,\n open,\n separator = '.',\n slot,\n value,\n withTime,\n}: DateFieldRootProps & { slot: string; withTime: boolean }) {\n const [text, setText] = useControllableState({\n defaultProp: defaultValue,\n prop: value,\n })\n const [handle] = React.useState(() => PopoverPrimitive.createHandle())\n const inputRef = React.useRef<HTMLInputElement>(null)\n const timeList = React.useRef<{ defaultTime: string } | null>(null)\n const triggerId = React.useId()\n const date = parseDateTime(text, withTime)\n const outOfRange =\n date !== undefined && isOutOfRange(date, { max, min, withTime })\n\n const context = React.useMemo<DateFieldContextValue>(\n () => ({\n commit: (next) => {\n if (next === text) return\n setText(next)\n const nextDate = parseDateTime(next, withTime)\n onValueChange?.(next, {\n date: nextDate,\n outOfRange:\n nextDate !== undefined &&\n isOutOfRange(nextDate, { max, min, withTime }),\n })\n },\n defaultDay: () => {\n const day = startOfDay(defaultDayProp?.() ?? new Date())\n if (min && day < startOfDay(min)) return startOfDay(min)\n if (max && day > startOfDay(max)) return startOfDay(max)\n return day\n },\n disabled,\n handle,\n inputRef,\n max,\n min,\n outOfRange,\n separator,\n slot,\n text,\n timeList,\n triggerId,\n withTime,\n }),\n [\n defaultDayProp,\n disabled,\n handle,\n max,\n min,\n onValueChange,\n outOfRange,\n separator,\n setText,\n slot,\n text,\n triggerId,\n withTime,\n ],\n )\n\n return (\n <DateFieldContext.Provider value={context}>\n <Popover\n defaultOpen={defaultOpen}\n handle={handle}\n onOpenChange={onOpenChange}\n open={open}\n >\n <PopoverAnchor render={<div className=\"min-w-0\" data-slot={slot} />}>\n <InputGroup className={className}>{children}</InputGroup>\n </PopoverAnchor>\n </Popover>\n </DateFieldContext.Provider>\n )\n}\n\nexport type DateFieldTriggerProps = Omit<\n React.ComponentProps<typeof Button>,\n 'aria-label'\n> & { 'aria-label': string }\n\nexport function DateFieldTrigger({\n children,\n ...props\n}: DateFieldTriggerProps) {\n const { disabled, slot, triggerId } = useDateField(\n 'InputDateTrigger / InputDateTimeTrigger',\n )\n return (\n <InputGroupAddon align=\"inline-end\">\n <PopoverTrigger\n id={triggerId}\n render={\n <Button\n color=\"neutral\"\n data-slot={`${slot}-trigger`}\n disabled={disabled}\n size=\"icon-small\"\n styleVariant=\"ghost\"\n {...props}\n >\n {children ?? <CalendarMonth />}\n </Button>\n }\n />\n </InputGroupAddon>\n )\n}\n\nexport function DateFieldContent({\n children,\n className,\n ...props\n}: React.ComponentProps<typeof PopoverContent>) {\n const field = useDateField('InputDateContent / InputDateTimeContent')\n const { commit, handle, max, min, separator, text, withTime } = field\n const selected = withTime ? parseDatePart(text) : parseDateTime(text)\n\n const calendar: CalendarField = {\n defaultMonth: selected ?? field.defaultDay(),\n disabled: [\n ...(min ? [{ before: min }] : []),\n ...(max ? [{ after: max }] : []),\n ],\n endMonth: max,\n onSelect: (day) => {\n if (!day) {\n if (withTime) return\n commit('')\n handle.close()\n return\n }\n const timeList = field.timeList.current\n commit(\n withDay(text, day, {\n separator,\n time: timeList?.defaultTime,\n withTime,\n }),\n )\n if (timeList) return\n handle.close()\n if (withTime) field.inputRef.current?.focus({ preventScroll: true })\n },\n selected,\n startMonth: min,\n }\n\n return (\n <PopoverContent\n align=\"start\"\n aria-labelledby={field.triggerId}\n collisionAvoidance={{ side: 'flip', fallbackAxisSide: 'none' }}\n data-slot={`${field.slot}-content`}\n {...props}\n className={cn(\n 'flex w-auto p-0 max-sm:flex-col has-[[data-slot=calendar-list]]:[&>[data-slot=input-date-time-time-list]]:hidden',\n className,\n )}\n >\n <CalendarFieldContext.Provider value={calendar}>\n {children}\n </CalendarFieldContext.Provider>\n </PopoverContent>\n )\n}\n"],"mappings":";;;;;;;;;;;;;AAuCA,MAAM,mBAAmBA,QAAM,cAA4C,IAAI;AAE/E,SAAgB,aAAa,MAAc;CACzC,MAAM,UAAUA,QAAM,WAAW,gBAAgB;CACjD,IAAI,CAAC,SACH,MAAM,IAAI,MACR,GAAG,KAAK,4DACV;CACF,OAAO;AACT;AAEA,SAAS,qBAAwB,EAC/B,aACA,QAIC;CACD,MAAM,CAAC,cAAc,mBAAmBA,QAAM,SAAS,WAAW;CAClE,OAAO,CAAC,QAAQ,cAAc,eAAe;AAC/C;AAEA,MAAM,cAAc,SAClB,IAAI,KAAK,KAAK,YAAY,GAAG,KAAK,SAAS,GAAG,KAAK,QAAQ,CAAC;AAE9D,SAAS,aACP,MACA,EAAE,KAAK,KAAK,YACZ;CACA,MAAM,KAAK,WAAW,OAAO,WAAW,IAAI;CAC5C,MAAM,OAAO,QAAQ,WAAW,MAAM,WAAW,GAAG;CACpD,MAAM,KAAK,QAAQ,WAAW,MAAM,WAAW,GAAG;CAClD,OAAQ,SAAS,KAAA,KAAa,KAAK,QAAU,OAAO,KAAA,KAAa,KAAK;AACxE;AAsBA,SAAgB,cAAc,EAC5B,UACA,WACA,YAAY,gBACZ,aACA,eAAe,IACf,WAAW,OACX,KACA,KACA,cACA,eACA,MACA,YAAY,KACZ,MACA,OACA,YAC2D;CAC3D,MAAM,CAAC,MAAM,WAAW,qBAAqB;EAC3C,a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CAAA;CACjB,CAAA;AAEpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { n as SparkButtonColor } from "../theme-types-CHl-L2F-.cjs";
|
|
4
|
-
import { r as ButtonProps } from "../button-
|
|
4
|
+
import { r as ButtonProps } from "../button-C-KeUy2j.cjs";
|
|
5
5
|
import { ToggleStyle } from "../components/toggle.cjs";
|
|
6
6
|
import * as React$1 from "react";
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { n as SparkButtonColor } from "../theme-types-CHl-L2F-.js";
|
|
4
|
-
import { r as ButtonProps } from "../button-
|
|
4
|
+
import { r as ButtonProps } from "../button-4QGaO78M.js";
|
|
5
5
|
import { ToggleStyle } from "../components/toggle.js";
|
|
6
6
|
import * as React$1 from "react";
|
|
7
7
|
|