@g4rcez/components 2.0.11 → 2.0.13

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.
@@ -1 +1 @@
1
- {"version":3,"file":"modal.d.ts","sourceRoot":"","sources":["../../../src/components/floating/modal.tsx"],"names":[],"mappings":"AACA,OAAO,EACH,KAAK,YAAY,EASpB,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAmB,eAAe,EAAqE,MAAM,cAAc,CAAC;AACnI,OAAO,KAAkH,MAAM,OAAO,CAAC;AAIvI,OAAO,EAAE,KAAK,EAAO,QAAQ,EAAE,MAAM,aAAa,CAAC;AAMnD,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,OAAO,CAAC;AAuD9C,MAAM,MAAM,UAAU,GAAG,QAAQ,CAC7B,eAAe,CAAC,KAAK,CAAC,EACtB,CAAC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,GAAG;IAC5E,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;CAC1C,GAAG,OAAO,CAAC;IACR,MAAM,EAAE,KAAK,CAAC;IACd,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACz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,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAA;CAAE,CAAC;AAI/D,eAAO,MAAM,KAAK;WAzGJ,KAAK;gBAAc,MAAM;;UACzB,OAAO;cACH,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI;;YAE9B,KAAK;UACP,SAAS;cACL,OAAO;aACR,OAAO;cACN,MAAM;aACP,OAAO;eACL,MAAM;cACP,OAAO;eACN,OAAO;mBACH,MAAM;sBACH,MAAM;cACd,cAAc;uBACL,OAAO;UACpB,QAAQ,GAAG,SAAS;kBACZ,YAAY,EAAE;aACnB,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC;;;;eAnBmB,MAAM;YAAU,KAAK;;UAChE,OAAO;cACH,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI;;YAE9B,KAAK;UACP,SAAS;cACL,OAAO;aACR,OAAO;cACN,MAAM;aACP,OAAO;eACL,MAAM;cACP,OAAO;eACN,OAAO;mBACH,MAAM;sBACH,MAAM;cACd,cAAc;uBACL,OAAO;UACpB,QAAQ,GAAG,SAAS;kBACZ,YAAY,EAAE;aACnB,KAAK,GAAG,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC;;;2CA4UrC,CAAC"}
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { FloatingFocusManager, FloatingOverlay, FloatingPortal, useClick, useDismiss, useFloating, useInteractions, useRole, } from "@floating-ui/react";
4
- import { Slot as RadixSlot } from "radix-ui";
5
4
  import { cva } from "class-variance-authority";
6
5
  import { XIcon } from "lucide-react";
7
6
  import { AnimatePresence, motion, useMotionValue } from "motion/react";
8
- import { forwardRef, Fragment, useId, useImperativeHandle, useEffect } from "react";
7
+ import { Slot as RadixSlot } from "radix-ui";
8
+ import { forwardRef, Fragment, useEffect, useId, useImperativeHandle, useRef } from "react";
9
9
  import { useMediaQuery } from "../../hooks/use-media-query";
10
10
  import { useRemoveScroll } from "../../hooks/use-remove-scroll";
11
11
  import { css, mergeRefs } from "../../lib/dom";
@@ -17,21 +17,21 @@ const drawerLeft = {
17
17
  initial: { x: ["-30%", "0%"], opacity: 0.8, animationDuration },
18
18
  };
19
19
  const drawerRight = {
20
- initial: { x: ["30%", "0%"], opacity: 0.8 },
21
20
  enter: { x: "0%", opacity: 1, animationDuration },
22
21
  exit: { x: ["0%", "30%"], opacity: 0, animationDuration },
22
+ initial: { x: ["30%", "0%"], opacity: 0.8, animationDuration },
23
23
  };
24
24
  const animations = {
25
25
  drawer: (type) => (type === "left" ? drawerLeft : drawerRight),
26
26
  sheet: {
27
- initial: { opacity: 0.5, y: "25%", animationDuration, transformOrigin: "bottom" },
28
27
  enter: { opacity: 1, y: "0%", animationDuration, transformOrigin: "bottom" },
29
- exit: { opacity: 0.1, y: "50%", animationDuration, transformOrigin: "bottom" },
28
+ exit: { opacity: 0.4, y: "10%", animationDuration, transformOrigin: "bottom" },
29
+ initial: { opacity: 0.7, y: "10%", animationDuration, transformOrigin: "bottom" },
30
30
  },
31
31
  dialog: {
32
32
  exit: { opacity: 0, scale: 0.95, animationDuration },
33
- initial: { opacity: 0.5, scale: 0.95, animationDuration, transition: { duration: 0.5, ease: "easeInOut" } },
34
33
  enter: { opacity: 1, scale: [1.05, 1], animationDuration },
34
+ initial: { opacity: 0.5, scale: 0.95, animationDuration, transition: { duration: 0.5, ease: "easeInOut" } },
35
35
  },
36
36
  };
37
37
  const variants = cva("z-floating border border-card-border ring-0 outline-0 appearance-none flex flex-col gap-4 flex-nowrap min-w-xs bg-floating-background", {
@@ -52,31 +52,33 @@ const variants = cva("z-floating border border-card-border ring-0 outline-0 appe
52
52
  const dragConstraints = { top: 0, left: 0, right: 0, bottom: 0 };
53
53
  const calculateClose = (n) => n * 0.6;
54
54
  const Draggable = (props) => {
55
- const onDrag = (_, info) => {
55
+ const onDrag = (e, info) => {
56
56
  if (props.parent.current) {
57
- if (!props.sheet) {
57
+ e.stopPropagation();
58
+ e.stopImmediatePropagation();
59
+ if (props.sheet) {
58
60
  const div = props.parent.current;
59
- const v = props.value.get() || div.getBoundingClientRect().width;
60
- const delta = props.position === "right" ? -info.delta.x : info.delta.x;
61
- const value = Math.abs(v + delta);
62
- return props.value.set(value);
61
+ const rect = div.getBoundingClientRect();
62
+ const v = props.value.get() || rect.height;
63
+ const result = Math.abs(v - info.delta.y);
64
+ const max = window.outerHeight;
65
+ const screenHeightToClose = calculateClose(max);
66
+ if (result >= screenHeightToClose)
67
+ return props.value.set(result);
68
+ if (document.activeElement instanceof HTMLElement) {
69
+ document.activeElement?.blur();
70
+ }
71
+ props.onChange(false);
72
+ return setTimeout(() => props.value.set(undefined), 350);
63
73
  }
64
74
  const div = props.parent.current;
65
- const rect = div.getBoundingClientRect();
66
- const v = props.value.get() || rect.height;
67
- const result = Math.abs(v - info.delta.y);
68
- const max = window.outerHeight;
69
- const screenHeightToClose = calculateClose(max);
70
- if (result >= screenHeightToClose)
71
- return props.value.set(result);
72
- if (document.activeElement instanceof HTMLElement) {
73
- document.activeElement?.blur();
74
- }
75
- props.onChange(false);
76
- return setTimeout(() => props.value.set(undefined), 350);
75
+ const v = props.value.get() || div.getBoundingClientRect().width;
76
+ const delta = props.position === "right" ? -info.delta.x : info.delta.x;
77
+ const value = Math.abs(v + delta);
78
+ return props.value.set(value);
77
79
  }
78
80
  };
79
- return (_jsx(motion.div, { draggable: true, dragMomentum: true, dragListener: true, dragPropagation: true, onDrag: onDrag, animate: false, initial: false, dragElastic: 0, dragDirectionLock: true, dragSnapToOrigin: true, drag: props.sheet ? "y" : "x", dragConstraints: dragConstraints, whileDrag: { cursor: "grabbing" }, className: css("absolute rounded-lg", props.sheet ? "cursor-row-resize" : "cursor-col-resize bg-floating-border", props.sheet
81
+ return (_jsx(motion.button, { draggable: true, dragListener: true, dragMomentum: true, type: "button", animate: false, dragElastic: 0, dragPropagation: true, initial: false, onDrag: onDrag, dragSnapToOrigin: true, dragDirectionLock: true, drag: props.sheet ? "y" : "x", dragConstraints: dragConstraints, whileDrag: { cursor: "grabbing" }, className: css("absolute rounded-lg isolate z-calendar", props.sheet ? "cursor-row-resize" : "cursor-col-resize bg-floating-border", props.sheet
80
82
  ? "top-1 flex h-3 w-full justify-center py-2"
81
83
  : props.position === "left"
82
84
  ? "right-5 top-1/2 h-10 w-2"
@@ -91,6 +93,7 @@ const fetchPosition = (isDesktop, forceType, propsType, propsPosition) => {
91
93
  };
92
94
  const noop = [];
93
95
  export const Modal = forwardRef(({ open, title, footer, asChild, trigger, children, onChange, ariaTitle, className, bodyClassName, resizer = true, animated = true, closable = true, forceType = false, layoutId = undefined, overlayClassName = "", type: _type = "dialog", position: propsPosition, overlayClickClose = false, role: roleName = "dialog", interactions: outInteractions = noop, ...props }, externalRef) => {
96
+ const innerContent = useRef(null);
94
97
  const removeScrollRef = useRemoveScroll(open, "block-only");
95
98
  const headingId = useId();
96
99
  const descriptionId = useId();
@@ -110,52 +113,62 @@ export const Modal = forwardRef(({ open, title, footer, asChild, trigger, childr
110
113
  const interactions = useInteractions([click, role, dismiss].concat(outInteractions));
111
114
  const Trigger = trigger;
112
115
  const floatingSize = useMotionValue(undefined);
113
- useEffect(() => {
114
- floatingSize.set(undefined);
115
- }, [type]);
116
+ useEffect(() => floatingSize.set(undefined), [type]);
116
117
  const onClose = () => onChange(false);
117
- useImperativeHandle(externalRef, () => {
118
- return { context: floating.context, floating: removeScrollRef.current };
119
- }, [floating.context, removeScrollRef]);
120
- const onDrag = (_, info) => {
121
- const parent = floating.refs.floating;
122
- if (parent.current && type === "sheet") {
123
- const div = parent.current;
124
- const rect = div.getBoundingClientRect();
125
- const v = floatingSize.get() || rect.height;
126
- const result = Math.abs(v - info.delta.y);
127
- const screenHeightToClose = calculateClose(window.outerHeight);
128
- if (result < screenHeightToClose) {
129
- onClose();
130
- return setTimeout(() => floatingSize.set(window.outerHeight), 350);
131
- }
118
+ useImperativeHandle(externalRef, () => ({ context: floating.context, floating: removeScrollRef.current }), [floating.context, removeScrollRef]);
119
+ const onDragHeader = (_, info) => {
120
+ const div = floating.refs.floating.current;
121
+ const rect = div.getBoundingClientRect();
122
+ const v = floatingSize.get() || rect.height;
123
+ const result = Math.abs(v - info.delta.y);
124
+ const max = window.outerHeight;
125
+ const screenHeightToClose = calculateClose(max);
126
+ console.log({ max, result, v, screenHeightToClose });
127
+ if (result >= screenHeightToClose)
132
128
  return floatingSize.set(result);
129
+ if (document.activeElement instanceof HTMLElement) {
130
+ document.activeElement?.blur();
133
131
  }
132
+ onChange?.(false);
133
+ return setTimeout(() => floatingSize.set(undefined), 350);
134
134
  };
135
- const commonAnimated = {
136
- layoutId,
137
- layout: true,
138
- exit: "exit",
139
- animate: "enter",
140
- initial: "initial",
141
- variants: animation,
142
- };
143
- const animationProps = animated && type === "sheet"
144
- ? {
145
- ...commonAnimated,
146
- dragElastic: 0,
147
- onDrag: onDrag,
148
- dragConstraints,
149
- dragListener: true,
150
- dragMomentum: true,
151
- dragPropagation: true,
152
- dragSnapToOrigin: true,
153
- dragDirectionLock: true,
154
- draggable: type === "sheet",
155
- drag: type === "sheet" ? "y" : "x",
135
+ const onDragBody = (_, info) => {
136
+ const div = floating.refs.floating.current;
137
+ if (info.delta.y < 0 && info.offset.y < 0) {
138
+ div.scrollTo({ top: div.scrollTop + Math.abs(info.offset.y), behavior: "smooth" });
139
+ return;
156
140
  }
157
- : commonAnimated;
158
- return (_jsxs(Fragment, { children: [trigger ? (_jsx(Fragment, { children: asChild ? (_jsx(Slot, { ref: floating.refs.setReference, ...interactions.getReferenceProps({ layoutId: layoutId }), children: Trigger })) : (_jsx(motion.button, { ref: floating.refs.setReference, ...interactions.getReferenceProps(), layoutId: layoutId, type: "button", children: Trigger })) })) : null, _jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(AnimatePresence, { propagate: true, mode: "wait", initial: false, children: open ? (_jsx(FloatingOverlay, { lockScroll: true, className: css("inset-0 isolate z-overlay h-[100dvh] !overflow-clip bg-floating-overlay/70", type === "drawer" ? "" : "flex items-start justify-center p-10", overlayClassName), children: _jsx(FloatingFocusManager, { guards: true, visuallyHiddenDismiss: true, modal: true, closeOnFocusOut: true, context: floating.context, children: _jsxs(motion.div, { ...props, ...animationProps, ...(title
141
+ const rect = div.getBoundingClientRect();
142
+ const v = floatingSize.get() || rect.height;
143
+ const result = Math.abs(v - info.delta.y);
144
+ const max = window.outerHeight;
145
+ const screenHeightToClose = calculateClose(max);
146
+ if (result >= screenHeightToClose)
147
+ return floatingSize.set(result);
148
+ if (document.activeElement instanceof HTMLElement) {
149
+ document.activeElement?.blur();
150
+ }
151
+ onChange?.(false);
152
+ return setTimeout(() => floatingSize.set(undefined), 350);
153
+ };
154
+ const draggableMotionProps = type === "sheet" ? {
155
+ drag: "y",
156
+ animate: false,
157
+ dragElastic: 0,
158
+ initial: false,
159
+ dragConstraints,
160
+ draggable: true,
161
+ dragListener: true,
162
+ dragMomentum: true,
163
+ onDrag: onDragHeader,
164
+ dragPropagation: true,
165
+ dragSnapToOrigin: true,
166
+ dragDirectionLock: true,
167
+ whileDrag: { cursor: "grabbing" },
168
+ } : { animate: animated, initial: false };
169
+ const scrollInitial = useMotionValue(undefined);
170
+ const scroll = useMotionValue(undefined);
171
+ return (_jsxs(Fragment, { children: [trigger ? (_jsx(Fragment, { children: asChild ? (_jsx(Slot, { ref: floating.refs.setReference, ...interactions.getReferenceProps({ layoutId: layoutId }), children: Trigger })) : (_jsx(motion.button, { ref: floating.refs.setReference, ...interactions.getReferenceProps(), layoutId: layoutId, type: "button", children: Trigger })) })) : null, _jsx(FloatingPortal, { preserveTabOrder: true, children: _jsx(AnimatePresence, { propagate: true, mode: "wait", initial: false, children: open ? (_jsx(FloatingOverlay, { lockScroll: true, className: css("inset-0 isolate z-overlay h-[100dvh] !overflow-clip bg-floating-overlay/70", type === "drawer" ? "" : "flex items-start justify-center p-10", overlayClassName), children: _jsx(FloatingFocusManager, { guards: true, visuallyHiddenDismiss: true, modal: true, closeOnFocusOut: true, context: floating.context, children: _jsxs(motion.div, { ...props, ...(title
159
172
  ? {
160
173
  "aria-labelledby": headingId,
161
174
  "aria-describedby": descriptionId,
@@ -163,9 +176,33 @@ export const Modal = forwardRef(({ open, title, footer, asChild, trigger, childr
163
176
  : { "aria-label": ariaTitle }), ...interactions.getFloatingProps({
164
177
  "aria-modal": open,
165
178
  ref: mergeRefs(floating.refs.setFloating, removeScrollRef),
166
- className: css(variants({
167
- position,
168
- type,
169
- }), className, "overscroll-contain"),
170
- }), "data-component": "modal", style: type === "drawer" ? { width: floatingSize } : { height: floatingSize }, children: [title ? (_jsx("header", { className: "relative w-full", children: title ? (_jsx("h2", { id: headingId, className: "select-text border-b border-floating-border px-8 pb-2 text-3xl font-medium leading-relaxed", children: title })) : null })) : null, _jsx("section", { "data-component": "modal-body", className: css("flex-1 select-text overflow-y-auto px-8 py-1", bodyClassName), children: children }), footer ? (_jsx("footer", { className: "w-full select-text border-t border-floating-border px-8 pt-4", children: footer })) : null, closable ? (_jsx("nav", { className: "absolute right-4 top-1 z-floating", children: _jsx("button", { type: "button", onClick: onClose, className: "p-1 opacity-70 transition-colors hover:text-danger hover:opacity-100 focus:text-danger", children: _jsx(XIcon, {}) }) })) : null, useResizer && resizer ? (_jsx(Draggable, { onChange: onChange, value: floatingSize, sheet: type === "sheet", position: position, parent: floating.refs.floating })) : null] }) }) })) : null }, headingId) })] }));
179
+ className: css(variants({ position, type }), className, "isolate overscroll-contain"),
180
+ }), exit: "exit", layout: true, animate: "enter", initial: "initial", layoutId: layoutId, variants: animation, "data-component": "modal", style: type === "drawer" ? { width: floatingSize } : { height: floatingSize }, children: [useResizer && resizer ? (_jsx(Draggable, { onChange: onChange, value: floatingSize, sheet: type === "sheet", position: position, parent: floating.refs.floating })) : null, title ? (_jsx(motion.header, { ...draggableMotionProps, className: "relative isolate w-full", children: title ? (_jsx("h2", { id: headingId, className: "select-text border-b border-floating-border px-8 pb-2 text-3xl font-medium leading-relaxed block", children: title })) : null })) : null, _jsx(motion.section, { ref: innerContent, "data-component": "modal-body", dragConstraints: dragConstraints, drag: isDesktop ? "y" : undefined, onDrag: type === "sheet" ? (isDesktop ? onDragBody : undefined) : undefined, className: css("flex-1 select-text overflow-y-auto px-8 py-1", bodyClassName), onTouchEnd: () => {
181
+ scroll.set(undefined);
182
+ scrollInitial.set(undefined);
183
+ }, onTouchStart: e => {
184
+ const touch = e.changedTouches[0];
185
+ scrollInitial.set(touch.pageY);
186
+ scroll.set(touch.pageY);
187
+ }, onTouchMove: e => {
188
+ const touch = e.changedTouches[0];
189
+ const y = touch.pageY;
190
+ const initial = scrollInitial.get();
191
+ if (initial < y) {
192
+ const distanceFromTop = innerContent.current?.scrollTop;
193
+ if (distanceFromTop === 0) {
194
+ const div = floating.refs.floating.current;
195
+ const rect = div.getBoundingClientRect();
196
+ const v = floatingSize.get() || rect.height;
197
+ const diff = (initial - y) / 10;
198
+ const down = v + diff;
199
+ const max = window.outerHeight;
200
+ const screenHeightToClose = calculateClose(max);
201
+ if (down < screenHeightToClose)
202
+ onChange?.(false);
203
+ floatingSize.set(down);
204
+ }
205
+ }
206
+ scroll.set(touch.pageY);
207
+ }, children: children }), footer ? (_jsx("footer", { className: "w-full select-text border-t border-floating-border px-8 pt-4", children: footer })) : null, closable ? (_jsx("nav", { className: "absolute right-4 top-1 z-floating", children: _jsx("button", { type: "button", onClick: onClose, className: "p-1 opacity-70 transition-colors hover:text-danger hover:opacity-100 focus:text-danger", children: _jsx(XIcon, {}) }) })) : null] }) }) })) : null }, headingId) })] }));
171
208
  });
@@ -1 +1 @@
1
- {"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../../src/components/form/date-picker.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAyD,MAAM,OAAO,CAAC;AAI9E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAY,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAS,UAAU,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,aAAa,GAAG;IACpE,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB,CAAC,EAAE,UAAU,CAAC,CAAA;AAiDf,eAAO,MAAM,UAAU,uGA8GtB,CAAC"}
1
+ {"version":3,"file":"date-picker.d.ts","sourceRoot":"","sources":["../../../src/components/form/date-picker.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAoE,MAAM,OAAO,CAAC;AAIzF,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAY,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAS,UAAU,EAAE,MAAM,SAAS,CAAC;AAE5C,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,aAAa,GAAG;IACpE,YAAY,CAAC,EAAE,OAAO,CAAA;CACzB,CAAC,EAAE,UAAU,CAAC,CAAA;AAiDf,eAAO,MAAM,UAAU,uGAyHtB,CAAC"}
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { format, isValid, parse, startOfDay } from "date-fns";
4
4
  import { CalendarIcon } from "lucide-react";
5
- import { forwardRef, Fragment, useId, useMemo, useState } from "react";
5
+ import { forwardRef, Fragment, useEffect, useId, useMemo, useState } from "react";
6
6
  import { Is } from "sidekicker";
7
7
  import { useLocale } from "../../hooks/use-locale";
8
8
  import { useTranslations } from "../../hooks/use-translations";
@@ -58,6 +58,7 @@ export const DatePicker = forwardRef(({ date, locale: inputLocal, disabledDate,
58
58
  const [open, setOpen] = useState(false);
59
59
  const mask = formatParts(datetimeFormat, fixedDate).flatMap((x) => (Is.keyof(parts, x.type) ? parts[x.type](x.value) : []));
60
60
  const placeholder = formatParts(datetimeFormat, fixedDate).reduce((acc, x) => acc + (Is.keyof(placeholders, x.type) ? placeholders[x.type](x.value) : ""), "");
61
+ const isoDateEffect = date?.toISOString();
61
62
  const [value, setValue] = useState(!innerDate
62
63
  ? ""
63
64
  : formatParts(datetimeFormat, innerDate).reduce((acc, x) => acc + (Is.keyof(parts, x.type) ? partValues[x.type](innerDate, x.value) : ""), ""));
@@ -79,6 +80,12 @@ export const DatePicker = forwardRef(({ date, locale: inputLocal, disabledDate,
79
80
  setInnerDate(undefined);
80
81
  return onChange?.(undefined);
81
82
  };
83
+ useEffect(() => {
84
+ if (isValid(date)) {
85
+ setInnerDate(date);
86
+ setValue(format(date, placeholder));
87
+ }
88
+ }, [isoDateEffect]);
82
89
  const onChangeDate = (d) => {
83
90
  setInnerDate(d);
84
91
  onChange?.(d);