@addsign/moje-agenda-shared-lib 2.0.20 → 2.0.22
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.
|
@@ -3,7 +3,7 @@ import { Button } from "./button.js";
|
|
|
3
3
|
import { f as format, C as Calendar$1, i as isValid } from "../../Calendar-DWT4e7Th.js";
|
|
4
4
|
import { P as Popover, a as PopoverTrigger, b as PopoverContent } from "../../popover-DpJhfyvx.js";
|
|
5
5
|
import { cn } from "../../utils/utils.js";
|
|
6
|
-
import
|
|
6
|
+
import { forwardRef, useState, useEffect } from "react";
|
|
7
7
|
import { Input } from "./input.js";
|
|
8
8
|
import { c as createLucideIcon } from "../../createLucideIcon-KSoQd4Wi.js";
|
|
9
9
|
import { X } from "../../x-DciOkaU0.js";
|
|
@@ -35,8 +35,9 @@ const DatePicker = forwardRef(
|
|
|
35
35
|
disabled,
|
|
36
36
|
...props
|
|
37
37
|
}, ref) => {
|
|
38
|
-
const [date, setDate] =
|
|
39
|
-
const [inputValue, setInputValue] =
|
|
38
|
+
const [date, setDate] = useState(value);
|
|
39
|
+
const [inputValue, setInputValue] = useState("");
|
|
40
|
+
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
40
41
|
useEffect(() => {
|
|
41
42
|
if (value) {
|
|
42
43
|
setDate(value);
|
|
@@ -80,6 +81,7 @@ const DatePicker = forwardRef(
|
|
|
80
81
|
onChange == null ? void 0 : onChange(selectedDate);
|
|
81
82
|
if (selectedDate) {
|
|
82
83
|
setInputValue(format(selectedDate, DATE_FORMAT));
|
|
84
|
+
setIsPopoverOpen(false);
|
|
83
85
|
} else {
|
|
84
86
|
setInputValue("");
|
|
85
87
|
}
|
|
@@ -89,50 +91,57 @@ const DatePicker = forwardRef(
|
|
|
89
91
|
setDate(void 0);
|
|
90
92
|
onChange == null ? void 0 : onChange(void 0);
|
|
91
93
|
};
|
|
92
|
-
return /* @__PURE__ */ jsxs(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
94
|
+
return /* @__PURE__ */ jsxs(
|
|
95
|
+
Popover,
|
|
96
|
+
{
|
|
97
|
+
open: !disabled && isPopoverOpen,
|
|
98
|
+
onOpenChange: setIsPopoverOpen,
|
|
99
|
+
children: [
|
|
100
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
|
|
101
|
+
/* @__PURE__ */ jsx(
|
|
102
|
+
Input,
|
|
103
|
+
{
|
|
104
|
+
type: "text",
|
|
105
|
+
value: inputValue,
|
|
106
|
+
onChange: handleInputChange,
|
|
107
|
+
onBlur: handleInputBlur,
|
|
108
|
+
placeholder,
|
|
109
|
+
className: cn(
|
|
110
|
+
"w-full pl-8 pr-8",
|
|
111
|
+
!date && "text-muted-foreground"
|
|
112
|
+
),
|
|
113
|
+
ref,
|
|
114
|
+
...props
|
|
115
|
+
}
|
|
105
116
|
),
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
) })
|
|
135
|
-
] });
|
|
117
|
+
/* @__PURE__ */ jsx(Calendar, { className: "absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" }),
|
|
118
|
+
clearable && !disabled && inputValue && /* @__PURE__ */ jsxs(
|
|
119
|
+
Button,
|
|
120
|
+
{
|
|
121
|
+
type: "button",
|
|
122
|
+
variant: "ghost",
|
|
123
|
+
size: "icon",
|
|
124
|
+
className: "absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 p-0",
|
|
125
|
+
onClick: handleClear,
|
|
126
|
+
children: [
|
|
127
|
+
/* @__PURE__ */ jsx(X, { className: "h-4 w-4 text-muted-foreground" }),
|
|
128
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Smazat datum" })
|
|
129
|
+
]
|
|
130
|
+
}
|
|
131
|
+
)
|
|
132
|
+
] }) }),
|
|
133
|
+
/* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", align: "start", children: /* @__PURE__ */ jsx(
|
|
134
|
+
Calendar$1,
|
|
135
|
+
{
|
|
136
|
+
mode: "single",
|
|
137
|
+
selected: date,
|
|
138
|
+
onSelect: handleCalendarSelect,
|
|
139
|
+
initialFocus: true
|
|
140
|
+
}
|
|
141
|
+
) })
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
);
|
|
136
145
|
}
|
|
137
146
|
);
|
|
138
147
|
DatePicker.displayName = "DatePicker";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.js","sources":["../../../node_modules/lucide-react/dist/esm/icons/calendar.js","../../../lib/components/ui/DatePicker.tsx"],"sourcesContent":["/**\n * @license lucide-react v0.456.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst Calendar = createLucideIcon(\"Calendar\", [\n [\"path\", { d: \"M8 2v4\", key: \"1cmpym\" }],\n [\"path\", { d: \"M16 2v4\", key: \"4m81vk\" }],\n [\"rect\", { width: \"18\", height: \"18\", x: \"3\", y: \"4\", rx: \"2\", key: \"1hopcy\" }],\n [\"path\", { d: \"M3 10h18\", key: \"8toen8\" }]\n]);\n\nexport { Calendar as default };\n//# sourceMappingURL=calendar.js.map\n","import { format, isValid, parse } from \"date-fns\";\r\nimport { CalendarIcon, XIcon } from \"lucide-react\";\r\n\r\nimport { Button } from \"./button\";\r\nimport { Calendar } from \"./Calendar\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\r\nimport { cn } from \"../../utils/utils\";\r\nimport React, { forwardRef, useEffect } from \"react\";\r\nimport { Input } from \"./input\";\r\n\r\nconst DATE_FORMAT = \"dd.MM.yyyy\";\r\n\r\ninterface DatePickerProps {\r\n value?: Date;\r\n onChange?: (date: Date | undefined) => void;\r\n className?: string;\r\n placeholder?: string;\r\n clearable?: boolean;\r\n disabled?: boolean;\r\n}\r\nconst validateDateFormat = (dateString: string): boolean => {\r\n // Regex for the desired date format dd.MM.yyyy\r\n const dateRegex =\r\n /^([0-9]|[0-2][0-9]|3[0-1])\\.([1-9]|0[1-9]|1[0-2])\\.(\\d{4})$/;\r\n return dateRegex.test(dateString);\r\n};\r\n\r\nconst DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(\r\n (\r\n {\r\n value,\r\n onChange,\r\n className,\r\n clearable = true,\r\n placeholder,\r\n disabled,\r\n ...props\r\n },\r\n ref\r\n ) => {\r\n const [date, setDate] =
|
|
1
|
+
{"version":3,"file":"DatePicker.js","sources":["../../../node_modules/lucide-react/dist/esm/icons/calendar.js","../../../lib/components/ui/DatePicker.tsx"],"sourcesContent":["/**\n * @license lucide-react v0.456.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst Calendar = createLucideIcon(\"Calendar\", [\n [\"path\", { d: \"M8 2v4\", key: \"1cmpym\" }],\n [\"path\", { d: \"M16 2v4\", key: \"4m81vk\" }],\n [\"rect\", { width: \"18\", height: \"18\", x: \"3\", y: \"4\", rx: \"2\", key: \"1hopcy\" }],\n [\"path\", { d: \"M3 10h18\", key: \"8toen8\" }]\n]);\n\nexport { Calendar as default };\n//# sourceMappingURL=calendar.js.map\n","import { format, isValid, parse } from \"date-fns\";\r\nimport { CalendarIcon, XIcon } from \"lucide-react\";\r\n\r\nimport { Button } from \"./button\";\r\nimport { Calendar } from \"./Calendar\";\r\nimport { Popover, PopoverContent, PopoverTrigger } from \"./popover\";\r\nimport { cn } from \"../../utils/utils\";\r\nimport React, { forwardRef, useEffect, useState } from \"react\";\r\nimport { Input } from \"./input\";\r\n\r\nconst DATE_FORMAT = \"dd.MM.yyyy\";\r\n\r\ninterface DatePickerProps {\r\n value?: Date;\r\n onChange?: (date: Date | undefined) => void;\r\n className?: string;\r\n placeholder?: string;\r\n clearable?: boolean;\r\n disabled?: boolean;\r\n}\r\nconst validateDateFormat = (dateString: string): boolean => {\r\n // Regex for the desired date format dd.MM.yyyy\r\n const dateRegex =\r\n /^([0-9]|[0-2][0-9]|3[0-1])\\.([1-9]|0[1-9]|1[0-2])\\.(\\d{4})$/;\r\n return dateRegex.test(dateString);\r\n};\r\n\r\nconst DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(\r\n (\r\n {\r\n value,\r\n onChange,\r\n className,\r\n clearable = true,\r\n placeholder,\r\n disabled,\r\n ...props\r\n },\r\n ref\r\n ) => {\r\n const [date, setDate] = useState<Date | undefined>(value);\r\n const [inputValue, setInputValue] = useState<string>(\"\");\r\n const [isPopoverOpen, setIsPopoverOpen] = useState(false);\r\n\r\n useEffect(() => {\r\n if (value) {\r\n setDate(value);\r\n setInputValue(format(value, DATE_FORMAT));\r\n } else {\r\n setDate(undefined);\r\n setInputValue(\"\");\r\n }\r\n }, [value]);\r\n\r\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {\r\n setInputValue(event.target.value);\r\n const parsedDate = parse(event.target.value, DATE_FORMAT, new Date());\r\n if (validateDateFormat(event.target.value) && isValid(parsedDate)) {\r\n handleCalendarSelect(parsedDate);\r\n } else {\r\n setInputValue(\"\");\r\n setDate(undefined);\r\n onChange?.(undefined);\r\n }\r\n };\r\n\r\n const handleInputBlur = () => {\r\n if (inputValue === \"\") {\r\n setDate(undefined);\r\n onChange?.(undefined);\r\n setInputValue(\"\");\r\n return;\r\n }\r\n\r\n const parsedDate = parse(inputValue, DATE_FORMAT, new Date());\r\n if (isValid(parsedDate)) {\r\n setDate(parsedDate);\r\n onChange?.(parsedDate);\r\n setInputValue(format(parsedDate, DATE_FORMAT));\r\n } else {\r\n setInputValue(\"\");\r\n setDate(undefined);\r\n onChange?.(undefined);\r\n }\r\n };\r\n\r\n const handleCalendarSelect = (selectedDate: Date | undefined) => {\r\n setDate(selectedDate);\r\n onChange?.(selectedDate);\r\n if (selectedDate) {\r\n setInputValue(format(selectedDate, DATE_FORMAT));\r\n setIsPopoverOpen(false); // Close the popover after a date is selected\r\n } else {\r\n setInputValue(\"\");\r\n }\r\n };\r\n\r\n const handleClear = () => {\r\n setInputValue(\"\");\r\n setDate(undefined);\r\n onChange?.(undefined);\r\n };\r\n\r\n return (\r\n <Popover\r\n open={!disabled && isPopoverOpen}\r\n onOpenChange={setIsPopoverOpen}\r\n >\r\n <PopoverTrigger asChild>\r\n <div className={cn(\"relative w-full\", className)}>\r\n <Input\r\n type=\"text\"\r\n value={inputValue}\r\n onChange={handleInputChange}\r\n onBlur={handleInputBlur}\r\n placeholder={placeholder}\r\n className={cn(\r\n \"w-full pl-8 pr-8\",\r\n !date && \"text-muted-foreground\"\r\n )}\r\n ref={ref}\r\n {...props}\r\n />\r\n <CalendarIcon className=\"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground\" />\r\n {clearable && !disabled && inputValue && (\r\n <Button\r\n type=\"button\"\r\n variant=\"ghost\"\r\n size=\"icon\"\r\n className=\"absolute right-2 top-1/2 -translate-y-1/2 h-4 w-4 p-0\"\r\n onClick={handleClear}\r\n >\r\n <XIcon className=\"h-4 w-4 text-muted-foreground\" />\r\n <span className=\"sr-only\">Smazat datum</span>\r\n </Button>\r\n )}\r\n </div>\r\n </PopoverTrigger>\r\n <PopoverContent className=\"w-auto p-0\" align=\"start\">\r\n <Calendar\r\n mode=\"single\"\r\n selected={date}\r\n onSelect={handleCalendarSelect}\r\n initialFocus\r\n />\r\n </PopoverContent>\r\n </Popover>\r\n );\r\n }\r\n);\r\n\r\nDatePicker.displayName = \"DatePicker\";\r\n\r\nexport default DatePicker;\r\n"],"names":["CalendarIcon","XIcon","Calendar"],"mappings":";;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,MAAM,WAAW,iBAAiB,YAAY;AAAA,EAC5C,CAAC,QAAQ,EAAE,GAAG,UAAU,KAAK,SAAQ,CAAE;AAAA,EACvC,CAAC,QAAQ,EAAE,GAAG,WAAW,KAAK,SAAQ,CAAE;AAAA,EACxC,CAAC,QAAQ,EAAE,OAAO,MAAM,QAAQ,MAAM,GAAG,KAAK,GAAG,KAAK,IAAI,KAAK,KAAK,SAAQ,CAAE;AAAA,EAC9E,CAAC,QAAQ,EAAE,GAAG,YAAY,KAAK,SAAQ,CAAE;AAC3C,CAAC;ACJD,MAAM,cAAc;AAUpB,MAAM,qBAAqB,CAAC,eAAgC;AAE1D,QAAM,YACJ;AACK,SAAA,UAAU,KAAK,UAAU;AAClC;AAEA,MAAM,aAAa;AAAA,EACjB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA,GAAG;AAAA,KAEL,QACG;AACH,UAAM,CAAC,MAAM,OAAO,IAAI,SAA2B,KAAK;AACxD,UAAM,CAAC,YAAY,aAAa,IAAI,SAAiB,EAAE;AACvD,UAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,KAAK;AAExD,cAAU,MAAM;AACd,UAAI,OAAO;AACT,gBAAQ,KAAK;AACC,sBAAA,OAAO,OAAO,WAAW,CAAC;AAAA,MAAA,OACnC;AACL,gBAAQ,MAAS;AACjB,sBAAc,EAAE;AAAA,MAClB;AAAA,IAAA,GACC,CAAC,KAAK,CAAC;AAEJ,UAAA,oBAAoB,CAAC,UAA+C;AAC1D,oBA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AAAA,gBACR;AAAA,gBACA,WAAW;AAAA,kBACT;AAAA,kBACA,CAAC,QAAQ;AAAA,gBACX;AAAA,gBACA;AAAA,gBACC,GAAG;AAAA,cAAA;AAAA,YACN;AAAA,YACA,oBAACA,UAAa,EAAA,WAAU,yEAAyE,CAAA;AAAA,YAChG,aAAa,CAAC,YAAY,cACzB;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,MAAK;AAAA,gBACL,SAAQ;AAAA,gBACR,MAAK;AAAA,gBACL,WAAU;AAAA,gBACV,SAAS;AAAA,gBAET,UAAA;AAAA,kBAAC,oBAAAC,GAAA,EAAM,WAAU,gCAAgC,CAAA;AAAA,kBAChD,oBAAA,QAAA,EAAK,WAAU,WAAU,UAAY,gBAAA;AAAA,gBAAA;AAAA,cAAA;AAAA,YACxC;AAAA,UAAA,EAAA,CAEJ,EACF,CAAA;AAAA,UACC,oBAAA,gBAAA,EAAe,WAAU,cAAa,OAAM,SAC3C,UAAA;AAAA,YAACC;AAAAA,YAAA;AAAA,cACC,MAAK;AAAA,cACL,UAAU;AAAA,cACV,UAAU;AAAA,cACV,cAAY;AAAA,YAAA;AAAA,UAAA,GAEhB;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,WAAW,cAAc;","x_google_ignoreList":[0]}
|
|
@@ -5,7 +5,7 @@ import { Button } from "./button";
|
|
|
5
5
|
import { Calendar } from "./Calendar";
|
|
6
6
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover";
|
|
7
7
|
import { cn } from "../../utils/utils";
|
|
8
|
-
import React, { forwardRef, useEffect } from "react";
|
|
8
|
+
import React, { forwardRef, useEffect, useState } from "react";
|
|
9
9
|
import { Input } from "./input";
|
|
10
10
|
|
|
11
11
|
const DATE_FORMAT = "dd.MM.yyyy";
|
|
@@ -38,8 +38,9 @@ const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(
|
|
|
38
38
|
},
|
|
39
39
|
ref
|
|
40
40
|
) => {
|
|
41
|
-
const [date, setDate] =
|
|
42
|
-
const [inputValue, setInputValue] =
|
|
41
|
+
const [date, setDate] = useState<Date | undefined>(value);
|
|
42
|
+
const [inputValue, setInputValue] = useState<string>("");
|
|
43
|
+
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
43
44
|
|
|
44
45
|
useEffect(() => {
|
|
45
46
|
if (value) {
|
|
@@ -88,6 +89,7 @@ const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(
|
|
|
88
89
|
onChange?.(selectedDate);
|
|
89
90
|
if (selectedDate) {
|
|
90
91
|
setInputValue(format(selectedDate, DATE_FORMAT));
|
|
92
|
+
setIsPopoverOpen(false); // Close the popover after a date is selected
|
|
91
93
|
} else {
|
|
92
94
|
setInputValue("");
|
|
93
95
|
}
|
|
@@ -100,7 +102,10 @@ const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(
|
|
|
100
102
|
};
|
|
101
103
|
|
|
102
104
|
return (
|
|
103
|
-
<Popover
|
|
105
|
+
<Popover
|
|
106
|
+
open={!disabled && isPopoverOpen}
|
|
107
|
+
onOpenChange={setIsPopoverOpen}
|
|
108
|
+
>
|
|
104
109
|
<PopoverTrigger asChild>
|
|
105
110
|
<div className={cn("relative w-full", className)}>
|
|
106
111
|
<Input
|