@addsign/moje-agenda-shared-lib 2.0.20 → 2.0.21
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,7 +91,7 @@ const DatePicker = forwardRef(
|
|
|
89
91
|
setDate(void 0);
|
|
90
92
|
onChange == null ? void 0 : onChange(void 0);
|
|
91
93
|
};
|
|
92
|
-
return /* @__PURE__ */ jsxs(Popover, { children: [
|
|
94
|
+
return /* @__PURE__ */ jsxs(Popover, { open: isPopoverOpen, onOpenChange: setIsPopoverOpen, children: [
|
|
93
95
|
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
|
|
94
96
|
/* @__PURE__ */ jsx(
|
|
95
97
|
Input,
|
|
@@ -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 open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>\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,SAA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AU,cAAa,OAAM,SAC3C,UAAA;AAAA,QAACC;AAAAA,QAAA;AAAA,UACC,MAAK;AAAA,UACL,UAAU;AAAA,UACV,UAAU;AAAA,UACV,cAAY;AAAA,QAAA;AAAA,MAAA,GAEhB;AAAA,IACF,EAAA,CAAA;AAAA,EAEJ;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,7 @@ const DatePicker = forwardRef<HTMLInputElement, DatePickerProps>(
|
|
|
100
102
|
};
|
|
101
103
|
|
|
102
104
|
return (
|
|
103
|
-
<Popover>
|
|
105
|
+
<Popover open={isPopoverOpen} onOpenChange={setIsPopoverOpen}>
|
|
104
106
|
<PopoverTrigger asChild>
|
|
105
107
|
<div className={cn("relative w-full", className)}>
|
|
106
108
|
<Input
|