thailife-react 0.0.19 → 0.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.
- package/README.md +1 -19
- package/dist/components/DatePicker/DatePicker.d.ts +38 -0
- package/dist/components/DatePicker/DatePicker.d.ts.map +1 -0
- package/dist/components/DatePicker/DatePicker.stories.d.ts +17 -0
- package/dist/components/DatePicker/DatePicker.stories.d.ts.map +1 -0
- package/dist/components/DatePicker/examples.d.ts +4 -0
- package/dist/components/DatePicker/examples.d.ts.map +1 -0
- package/dist/components/DatePicker/index.d.ts +4 -0
- package/dist/components/DatePicker/index.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +555 -16
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +554 -14
- package/dist/index.js.map +1 -1
- package/dist/styles/index.css +6 -5
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1532,7 +1532,7 @@ const cssClasses = {
|
|
|
1532
1532
|
shadowXl: "shadow-xl"
|
|
1533
1533
|
};
|
|
1534
1534
|
|
|
1535
|
-
const _excluded$
|
|
1535
|
+
const _excluded$8 = ["className", "color", "variant", "size", "fullWidth", "loading", "disabled", "children"];
|
|
1536
1536
|
const Button = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1537
1537
|
let {
|
|
1538
1538
|
className,
|
|
@@ -1544,7 +1544,7 @@ const Button = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1544
1544
|
disabled,
|
|
1545
1545
|
children
|
|
1546
1546
|
} = _ref,
|
|
1547
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1547
|
+
props = _objectWithoutProperties(_ref, _excluded$8);
|
|
1548
1548
|
const baseClass = cssClasses.button;
|
|
1549
1549
|
const variantClass = variant === "contained" ? cssClasses.buttonContained : variant === "outlined" ? cssClasses.buttonOutlined : cssClasses.buttonLink;
|
|
1550
1550
|
const sizeClass = size === "sm" ? cssClasses.buttonSmall : size === "md" ? cssClasses.buttonMedium : cssClasses.buttonLarge;
|
|
@@ -1561,7 +1561,7 @@ const Button = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1561
1561
|
});
|
|
1562
1562
|
Button.displayName = "Button";
|
|
1563
1563
|
|
|
1564
|
-
const _excluded$
|
|
1564
|
+
const _excluded$7 = ["className", "type", "label", "error", "helperText", "size", "fullWidth", "id"];
|
|
1565
1565
|
const Input = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1566
1566
|
let {
|
|
1567
1567
|
className,
|
|
@@ -1573,7 +1573,7 @@ const Input = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1573
1573
|
fullWidth = false,
|
|
1574
1574
|
id
|
|
1575
1575
|
} = _ref,
|
|
1576
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1576
|
+
props = _objectWithoutProperties(_ref, _excluded$7);
|
|
1577
1577
|
const inputId = id || "input-".concat(Math.random().toString(36).substr(2, 9));
|
|
1578
1578
|
const containerClass = fullWidth ? cssClasses.inputContainerFullWidth : cssClasses.inputContainer;
|
|
1579
1579
|
const inputClass = error ? "".concat(cssClasses.input, " ").concat(cssClasses.inputError) : cssClasses.input;
|
|
@@ -1598,7 +1598,7 @@ const Input = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1598
1598
|
});
|
|
1599
1599
|
Input.displayName = "Input";
|
|
1600
1600
|
|
|
1601
|
-
const _excluded$
|
|
1601
|
+
const _excluded$6 = ["className", "label", "error", "helperText", "size", "fullWidth", "rows", "id"];
|
|
1602
1602
|
const Textarea = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1603
1603
|
let {
|
|
1604
1604
|
className,
|
|
@@ -1610,7 +1610,7 @@ const Textarea = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1610
1610
|
rows = 3,
|
|
1611
1611
|
id
|
|
1612
1612
|
} = _ref,
|
|
1613
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1613
|
+
props = _objectWithoutProperties(_ref, _excluded$6);
|
|
1614
1614
|
const textareaId = id || "textarea-".concat(Math.random().toString(36).substr(2, 9));
|
|
1615
1615
|
const containerClass = fullWidth ? cssClasses.textareaContainerFullWidth : cssClasses.textareaContainer;
|
|
1616
1616
|
const textareaClass = error ? "".concat(cssClasses.textarea, " ").concat(cssClasses.textareaError) : cssClasses.textarea;
|
|
@@ -1635,7 +1635,7 @@ const Textarea = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1635
1635
|
});
|
|
1636
1636
|
Textarea.displayName = "Textarea";
|
|
1637
1637
|
|
|
1638
|
-
const _excluded$
|
|
1638
|
+
const _excluded$5 = ["className", "label", "error", "helperText", "size", "fullWidth", "multiple", "accept", "buttonText", "id"];
|
|
1639
1639
|
const InputFile = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1640
1640
|
let {
|
|
1641
1641
|
className,
|
|
@@ -1649,7 +1649,7 @@ const InputFile = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1649
1649
|
buttonText = "Choose File",
|
|
1650
1650
|
id
|
|
1651
1651
|
} = _ref,
|
|
1652
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1652
|
+
props = _objectWithoutProperties(_ref, _excluded$5);
|
|
1653
1653
|
const inputId = id || "input-file-".concat(Math.random().toString(36).substr(2, 9));
|
|
1654
1654
|
const containerClass = fullWidth ? cssClasses.inputFileContainerFullWidth : cssClasses.inputFileContainer;
|
|
1655
1655
|
const uploadAreaClass = error ? "".concat(cssClasses.inputFileUploadArea, " ").concat(cssClasses.inputFileUploadAreaError) : cssClasses.inputFileUploadArea;
|
|
@@ -1688,7 +1688,7 @@ const InputFile = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1688
1688
|
});
|
|
1689
1689
|
InputFile.displayName = "InputFile";
|
|
1690
1690
|
|
|
1691
|
-
const _excluded$
|
|
1691
|
+
const _excluded$4 = ["className", "label", "error", "helperText", "size", "fullWidth", "indeterminate", "id"];
|
|
1692
1692
|
const Checkbox = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1693
1693
|
let {
|
|
1694
1694
|
className,
|
|
@@ -1700,7 +1700,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1700
1700
|
indeterminate = false,
|
|
1701
1701
|
id
|
|
1702
1702
|
} = _ref,
|
|
1703
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1703
|
+
props = _objectWithoutProperties(_ref, _excluded$4);
|
|
1704
1704
|
const checkboxId = id || "checkbox-".concat(Math.random().toString(36).substr(2, 9));
|
|
1705
1705
|
React.useEffect(() => {
|
|
1706
1706
|
if (ref && typeof ref === "object" && ref.current) {
|
|
@@ -1735,7 +1735,7 @@ const Checkbox = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1735
1735
|
});
|
|
1736
1736
|
Checkbox.displayName = "Checkbox";
|
|
1737
1737
|
|
|
1738
|
-
const _excluded$
|
|
1738
|
+
const _excluded$3 = ["className", "label", "error", "helperText", "size", "fullWidth", "id"];
|
|
1739
1739
|
const Radio = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1740
1740
|
let {
|
|
1741
1741
|
className,
|
|
@@ -1746,7 +1746,7 @@ const Radio = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1746
1746
|
fullWidth = false,
|
|
1747
1747
|
id
|
|
1748
1748
|
} = _ref,
|
|
1749
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1749
|
+
props = _objectWithoutProperties(_ref, _excluded$3);
|
|
1750
1750
|
const radioId = id || "radio-".concat(Math.random().toString(36).substr(2, 9));
|
|
1751
1751
|
const containerClass = fullWidth ? cssClasses.radioContainerFullWidth : cssClasses.radioContainer;
|
|
1752
1752
|
const radioClass = error ? "".concat(cssClasses.radio, " ").concat(cssClasses.radioError) : cssClasses.radio;
|
|
@@ -1776,7 +1776,7 @@ const Radio = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1776
1776
|
});
|
|
1777
1777
|
Radio.displayName = "Radio";
|
|
1778
1778
|
|
|
1779
|
-
const _excluded = ["className", "label", "error", "helperText", "size", "fullWidth", "options", "placeholder", "id"];
|
|
1779
|
+
const _excluded$2 = ["className", "label", "error", "helperText", "size", "fullWidth", "options", "placeholder", "id"];
|
|
1780
1780
|
const Select = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1781
1781
|
let {
|
|
1782
1782
|
className,
|
|
@@ -1789,7 +1789,7 @@ const Select = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1789
1789
|
placeholder,
|
|
1790
1790
|
id
|
|
1791
1791
|
} = _ref,
|
|
1792
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
1792
|
+
props = _objectWithoutProperties(_ref, _excluded$2);
|
|
1793
1793
|
const selectId = id || "select-".concat(Math.random().toString(36).substr(2, 9));
|
|
1794
1794
|
const containerClass = fullWidth ? cssClasses.selectContainerFullWidth : cssClasses.selectContainer;
|
|
1795
1795
|
const selectClass = error ? "".concat(cssClasses.select, " ").concat(cssClasses.selectError) : cssClasses.select;
|
|
@@ -1844,12 +1844,552 @@ const Select = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
|
1844
1844
|
});
|
|
1845
1845
|
Select.displayName = "Select";
|
|
1846
1846
|
|
|
1847
|
+
/**
|
|
1848
|
+
* @license lucide-react v0.542.0 - ISC
|
|
1849
|
+
*
|
|
1850
|
+
* This source code is licensed under the ISC license.
|
|
1851
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
1852
|
+
*/
|
|
1853
|
+
|
|
1854
|
+
const toKebabCase = string => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1855
|
+
const toCamelCase = string => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase());
|
|
1856
|
+
const toPascalCase = string => {
|
|
1857
|
+
const camelCase = toCamelCase(string);
|
|
1858
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
1859
|
+
};
|
|
1860
|
+
const mergeClasses = function () {
|
|
1861
|
+
for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1862
|
+
classes[_key] = arguments[_key];
|
|
1863
|
+
}
|
|
1864
|
+
return classes.filter((className, index, array) => {
|
|
1865
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
1866
|
+
}).join(" ").trim();
|
|
1867
|
+
};
|
|
1868
|
+
const hasA11yProp = props => {
|
|
1869
|
+
for (const prop in props) {
|
|
1870
|
+
if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
|
|
1871
|
+
return true;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
};
|
|
1875
|
+
|
|
1876
|
+
/**
|
|
1877
|
+
* @license lucide-react v0.542.0 - ISC
|
|
1878
|
+
*
|
|
1879
|
+
* This source code is licensed under the ISC license.
|
|
1880
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
1881
|
+
*/
|
|
1882
|
+
|
|
1883
|
+
var defaultAttributes = {
|
|
1884
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1885
|
+
width: 24,
|
|
1886
|
+
height: 24,
|
|
1887
|
+
viewBox: "0 0 24 24",
|
|
1888
|
+
fill: "none",
|
|
1889
|
+
stroke: "currentColor",
|
|
1890
|
+
strokeWidth: 2,
|
|
1891
|
+
strokeLinecap: "round",
|
|
1892
|
+
strokeLinejoin: "round"
|
|
1893
|
+
};
|
|
1894
|
+
|
|
1895
|
+
const _excluded$1 = ["color", "size", "strokeWidth", "absoluteStrokeWidth", "className", "children", "iconNode"];
|
|
1896
|
+
const Icon = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1897
|
+
let {
|
|
1898
|
+
color = "currentColor",
|
|
1899
|
+
size = 24,
|
|
1900
|
+
strokeWidth = 2,
|
|
1901
|
+
absoluteStrokeWidth,
|
|
1902
|
+
className = "",
|
|
1903
|
+
children,
|
|
1904
|
+
iconNode
|
|
1905
|
+
} = _ref,
|
|
1906
|
+
rest = _objectWithoutProperties(_ref, _excluded$1);
|
|
1907
|
+
return /*#__PURE__*/React.createElement("svg", _objectSpread2(_objectSpread2(_objectSpread2({
|
|
1908
|
+
ref
|
|
1909
|
+
}, defaultAttributes), {}, {
|
|
1910
|
+
width: size,
|
|
1911
|
+
height: size,
|
|
1912
|
+
stroke: color,
|
|
1913
|
+
strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
|
|
1914
|
+
className: mergeClasses("lucide", className)
|
|
1915
|
+
}, !children && !hasA11yProp(rest) && {
|
|
1916
|
+
"aria-hidden": "true"
|
|
1917
|
+
}), rest), [...iconNode.map(_ref2 => {
|
|
1918
|
+
let [tag, attrs] = _ref2;
|
|
1919
|
+
return /*#__PURE__*/React.createElement(tag, attrs);
|
|
1920
|
+
}), ...(Array.isArray(children) ? children : [children])]);
|
|
1921
|
+
});
|
|
1922
|
+
|
|
1923
|
+
const _excluded = ["className"];
|
|
1924
|
+
const createLucideIcon = (iconName, iconNode) => {
|
|
1925
|
+
const Component = /*#__PURE__*/React.forwardRef((_ref, ref) => {
|
|
1926
|
+
let {
|
|
1927
|
+
className
|
|
1928
|
+
} = _ref,
|
|
1929
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
1930
|
+
return /*#__PURE__*/React.createElement(Icon, _objectSpread2({
|
|
1931
|
+
ref,
|
|
1932
|
+
iconNode,
|
|
1933
|
+
className: mergeClasses("lucide-".concat(toKebabCase(toPascalCase(iconName))), "lucide-".concat(iconName), className)
|
|
1934
|
+
}, props));
|
|
1935
|
+
});
|
|
1936
|
+
Component.displayName = toPascalCase(iconName);
|
|
1937
|
+
return Component;
|
|
1938
|
+
};
|
|
1939
|
+
|
|
1940
|
+
/**
|
|
1941
|
+
* @license lucide-react v0.542.0 - ISC
|
|
1942
|
+
*
|
|
1943
|
+
* This source code is licensed under the ISC license.
|
|
1944
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
1945
|
+
*/
|
|
1946
|
+
|
|
1947
|
+
const __iconNode = [["path", {
|
|
1948
|
+
d: "M8 2v4",
|
|
1949
|
+
key: "1cmpym"
|
|
1950
|
+
}], ["path", {
|
|
1951
|
+
d: "M16 2v4",
|
|
1952
|
+
key: "4m81vk"
|
|
1953
|
+
}], ["rect", {
|
|
1954
|
+
width: "18",
|
|
1955
|
+
height: "18",
|
|
1956
|
+
x: "3",
|
|
1957
|
+
y: "4",
|
|
1958
|
+
rx: "2",
|
|
1959
|
+
key: "1hopcy"
|
|
1960
|
+
}], ["path", {
|
|
1961
|
+
d: "M3 10h18",
|
|
1962
|
+
key: "8toen8"
|
|
1963
|
+
}], ["path", {
|
|
1964
|
+
d: "M8 14h.01",
|
|
1965
|
+
key: "6423bh"
|
|
1966
|
+
}], ["path", {
|
|
1967
|
+
d: "M12 14h.01",
|
|
1968
|
+
key: "1etili"
|
|
1969
|
+
}], ["path", {
|
|
1970
|
+
d: "M16 14h.01",
|
|
1971
|
+
key: "1gbofw"
|
|
1972
|
+
}], ["path", {
|
|
1973
|
+
d: "M8 18h.01",
|
|
1974
|
+
key: "lrp35t"
|
|
1975
|
+
}], ["path", {
|
|
1976
|
+
d: "M12 18h.01",
|
|
1977
|
+
key: "mhygvu"
|
|
1978
|
+
}], ["path", {
|
|
1979
|
+
d: "M16 18h.01",
|
|
1980
|
+
key: "kzsmim"
|
|
1981
|
+
}]];
|
|
1982
|
+
const CalendarDays = createLucideIcon("calendar-days", __iconNode);
|
|
1983
|
+
|
|
1984
|
+
// Translations
|
|
1985
|
+
const translations = {
|
|
1986
|
+
th: {
|
|
1987
|
+
months: ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม'],
|
|
1988
|
+
weekdaysShort: ['อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'],
|
|
1989
|
+
today: 'วันนี้',
|
|
1990
|
+
clear: 'ล้าง',
|
|
1991
|
+
ok: 'ตกลง',
|
|
1992
|
+
hour: 'ชั่วโมง',
|
|
1993
|
+
minute: 'นาที'
|
|
1994
|
+
},
|
|
1995
|
+
en: {
|
|
1996
|
+
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
|
1997
|
+
weekdaysShort: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
|
1998
|
+
today: 'Today',
|
|
1999
|
+
clear: 'Clear',
|
|
2000
|
+
ok: 'OK',
|
|
2001
|
+
hour: 'Hour',
|
|
2002
|
+
minute: 'Minute'
|
|
2003
|
+
}
|
|
2004
|
+
};
|
|
2005
|
+
// Utility functions
|
|
2006
|
+
const convertYear = (year, fromType, toType) => {
|
|
2007
|
+
return year + 543;
|
|
2008
|
+
};
|
|
2009
|
+
const formatDate = (date, format, yearType) => {
|
|
2010
|
+
if (!date || isNaN(date.getTime())) return '';
|
|
2011
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
2012
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
2013
|
+
const year = yearType === 'be' ? convertYear(date.getFullYear()) : date.getFullYear();
|
|
2014
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
2015
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
2016
|
+
let formatted = format.replace('DD', day).replace('MM', month).replace('YYYY', year.toString()).replace('HH', hours).replace('mm', minutes);
|
|
2017
|
+
return formatted;
|
|
2018
|
+
};
|
|
2019
|
+
const isSameDay = (date1, date2) => {
|
|
2020
|
+
return date1.getDate() === date2.getDate() && date1.getMonth() === date2.getMonth() && date1.getFullYear() === date2.getFullYear();
|
|
2021
|
+
};
|
|
2022
|
+
// New utility function to check for disabled dates
|
|
2023
|
+
const isDisabled = (date, disabledPast, disabledFuture) => {
|
|
2024
|
+
const today = new Date();
|
|
2025
|
+
const dateOnly = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
2026
|
+
const todayOnly = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
2027
|
+
if (disabledPast && dateOnly < todayOnly) {
|
|
2028
|
+
return true;
|
|
2029
|
+
}
|
|
2030
|
+
if (disabledFuture && dateOnly > todayOnly) {
|
|
2031
|
+
return true;
|
|
2032
|
+
}
|
|
2033
|
+
return false;
|
|
2034
|
+
};
|
|
2035
|
+
const DatePicker = _ref => {
|
|
2036
|
+
let {
|
|
2037
|
+
format = 'DD/MM/YYYY',
|
|
2038
|
+
language = 'en',
|
|
2039
|
+
yearType = 'ad',
|
|
2040
|
+
value = null,
|
|
2041
|
+
onChange,
|
|
2042
|
+
placeholder = '',
|
|
2043
|
+
disabled = false,
|
|
2044
|
+
className = '',
|
|
2045
|
+
showClear = true,
|
|
2046
|
+
showToday = true,
|
|
2047
|
+
disabledPast = false,
|
|
2048
|
+
// Default to false
|
|
2049
|
+
disabledFuture = false // Default to false
|
|
2050
|
+
} = _ref;
|
|
2051
|
+
// State
|
|
2052
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
2053
|
+
const [selectedDate, setSelectedDate] = React.useState(null);
|
|
2054
|
+
const [currentMonth, setCurrentMonth] = React.useState(new Date().getMonth());
|
|
2055
|
+
const [currentYear, setCurrentYear] = React.useState(new Date().getFullYear());
|
|
2056
|
+
const [inputValue, setInputValue] = React.useState('');
|
|
2057
|
+
const [timeHour, setTimeHour] = React.useState(0);
|
|
2058
|
+
const [timeMinute, setTimeMinute] = React.useState(0);
|
|
2059
|
+
// Refs
|
|
2060
|
+
const containerRef = React.useRef(null);
|
|
2061
|
+
// Constants
|
|
2062
|
+
const includeTime = format.includes('HH:mm');
|
|
2063
|
+
const t = translations[language];
|
|
2064
|
+
// Initialize from value prop
|
|
2065
|
+
React.useEffect(() => {
|
|
2066
|
+
if (value) {
|
|
2067
|
+
const date = new Date(value);
|
|
2068
|
+
if (!isNaN(date.getTime())) {
|
|
2069
|
+
setSelectedDate(date);
|
|
2070
|
+
setCurrentMonth(date.getMonth());
|
|
2071
|
+
setCurrentYear(date.getFullYear());
|
|
2072
|
+
setTimeHour(date.getHours());
|
|
2073
|
+
setTimeMinute(date.getMinutes());
|
|
2074
|
+
setInputValue(formatDate(date, format, yearType));
|
|
2075
|
+
}
|
|
2076
|
+
} else {
|
|
2077
|
+
setSelectedDate(null);
|
|
2078
|
+
setInputValue('');
|
|
2079
|
+
}
|
|
2080
|
+
}, [value, format, yearType]);
|
|
2081
|
+
// Handle date selection
|
|
2082
|
+
const handleDateSelect = (day, year, month) => {
|
|
2083
|
+
const newDate = new Date(year, month, day, timeHour, timeMinute);
|
|
2084
|
+
// Check if the selected date is disabled before proceeding
|
|
2085
|
+
if (isDisabled(newDate, disabledPast, disabledFuture)) {
|
|
2086
|
+
return;
|
|
2087
|
+
}
|
|
2088
|
+
setSelectedDate(newDate);
|
|
2089
|
+
setInputValue(formatDate(newDate, format, yearType));
|
|
2090
|
+
onChange === null || onChange === void 0 || onChange(newDate);
|
|
2091
|
+
if (!includeTime) {
|
|
2092
|
+
setIsOpen(false);
|
|
2093
|
+
}
|
|
2094
|
+
};
|
|
2095
|
+
// Handle time change
|
|
2096
|
+
const handleTimeChange = (type, newValue) => {
|
|
2097
|
+
if (type === 'hour') {
|
|
2098
|
+
setTimeHour(newValue);
|
|
2099
|
+
} else {
|
|
2100
|
+
setTimeMinute(newValue);
|
|
2101
|
+
}
|
|
2102
|
+
if (selectedDate) {
|
|
2103
|
+
const newDate = new Date(selectedDate);
|
|
2104
|
+
if (type === 'hour') {
|
|
2105
|
+
newDate.setHours(newValue);
|
|
2106
|
+
} else {
|
|
2107
|
+
newDate.setMinutes(newValue);
|
|
2108
|
+
}
|
|
2109
|
+
setSelectedDate(newDate);
|
|
2110
|
+
setInputValue(formatDate(newDate, format, yearType));
|
|
2111
|
+
onChange === null || onChange === void 0 || onChange(newDate);
|
|
2112
|
+
}
|
|
2113
|
+
};
|
|
2114
|
+
// Handle today button
|
|
2115
|
+
const handleToday = () => {
|
|
2116
|
+
const today = new Date();
|
|
2117
|
+
if (isDisabled(today, disabledPast, disabledFuture)) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
setSelectedDate(today);
|
|
2121
|
+
setCurrentMonth(today.getMonth());
|
|
2122
|
+
setCurrentYear(today.getFullYear());
|
|
2123
|
+
setTimeHour(today.getHours());
|
|
2124
|
+
setTimeMinute(today.getMinutes());
|
|
2125
|
+
setInputValue(formatDate(today, format, yearType));
|
|
2126
|
+
onChange === null || onChange === void 0 || onChange(today);
|
|
2127
|
+
if (!includeTime) {
|
|
2128
|
+
setIsOpen(false);
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
// Handle clear button
|
|
2132
|
+
const handleClear = () => {
|
|
2133
|
+
setSelectedDate(null);
|
|
2134
|
+
setInputValue('');
|
|
2135
|
+
onChange === null || onChange === void 0 || onChange(null);
|
|
2136
|
+
setIsOpen(false);
|
|
2137
|
+
};
|
|
2138
|
+
// Handle confirm (for time picker)
|
|
2139
|
+
const handleConfirm = () => {
|
|
2140
|
+
setIsOpen(false);
|
|
2141
|
+
};
|
|
2142
|
+
// Navigation handlers
|
|
2143
|
+
const goToPreviousMonth = () => {
|
|
2144
|
+
if (currentMonth === 0) {
|
|
2145
|
+
setCurrentMonth(11);
|
|
2146
|
+
setCurrentYear(currentYear - 1);
|
|
2147
|
+
} else {
|
|
2148
|
+
setCurrentMonth(currentMonth - 1);
|
|
2149
|
+
}
|
|
2150
|
+
};
|
|
2151
|
+
const goToNextMonth = () => {
|
|
2152
|
+
if (currentMonth === 11) {
|
|
2153
|
+
setCurrentMonth(0);
|
|
2154
|
+
setCurrentYear(currentYear + 1);
|
|
2155
|
+
} else {
|
|
2156
|
+
setCurrentMonth(currentMonth + 1);
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
const goToPreviousYear = () => {
|
|
2160
|
+
setCurrentYear(currentYear - 1);
|
|
2161
|
+
};
|
|
2162
|
+
const goToNextYear = () => {
|
|
2163
|
+
setCurrentYear(currentYear + 1);
|
|
2164
|
+
};
|
|
2165
|
+
// Generate calendar days
|
|
2166
|
+
const generateCalendarDays = () => {
|
|
2167
|
+
const firstDayOfMonth = new Date(currentYear, currentMonth, 1);
|
|
2168
|
+
const lastDayOfMonth = new Date(currentYear, currentMonth + 1, 0);
|
|
2169
|
+
const firstDayOfWeek = firstDayOfMonth.getDay();
|
|
2170
|
+
const daysInMonth = lastDayOfMonth.getDate();
|
|
2171
|
+
const days = [];
|
|
2172
|
+
// Previous month days
|
|
2173
|
+
const prevMonth = new Date(currentYear, currentMonth - 1, 0);
|
|
2174
|
+
const daysFromPrevMonth = firstDayOfWeek;
|
|
2175
|
+
for (let i = daysFromPrevMonth - 1; i >= 0; i--) {
|
|
2176
|
+
days.push({
|
|
2177
|
+
day: prevMonth.getDate() - i,
|
|
2178
|
+
isCurrentMonth: false,
|
|
2179
|
+
isOtherMonth: true,
|
|
2180
|
+
month: currentMonth - 1,
|
|
2181
|
+
year: currentYear
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
// Current month days
|
|
2185
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
2186
|
+
days.push({
|
|
2187
|
+
day,
|
|
2188
|
+
isCurrentMonth: true,
|
|
2189
|
+
isOtherMonth: false,
|
|
2190
|
+
month: currentMonth,
|
|
2191
|
+
year: currentYear
|
|
2192
|
+
});
|
|
2193
|
+
}
|
|
2194
|
+
// Next month days
|
|
2195
|
+
const remainingDays = 42 - days.length;
|
|
2196
|
+
for (let day = 1; day <= remainingDays; day++) {
|
|
2197
|
+
days.push({
|
|
2198
|
+
day,
|
|
2199
|
+
isCurrentMonth: false,
|
|
2200
|
+
isOtherMonth: true,
|
|
2201
|
+
month: currentMonth + 1,
|
|
2202
|
+
year: currentYear
|
|
2203
|
+
});
|
|
2204
|
+
}
|
|
2205
|
+
return days;
|
|
2206
|
+
};
|
|
2207
|
+
// Click outside handler
|
|
2208
|
+
React.useEffect(() => {
|
|
2209
|
+
const handleClickOutside = event => {
|
|
2210
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
2211
|
+
setIsOpen(false);
|
|
2212
|
+
}
|
|
2213
|
+
};
|
|
2214
|
+
if (isOpen) {
|
|
2215
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
2216
|
+
}
|
|
2217
|
+
return () => {
|
|
2218
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
2219
|
+
};
|
|
2220
|
+
}, [isOpen]);
|
|
2221
|
+
const calendarDays = generateCalendarDays();
|
|
2222
|
+
const today = new Date();
|
|
2223
|
+
const displayYear = yearType === 'be' ? convertYear(currentYear) : currentYear;
|
|
2224
|
+
return jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
|
|
2225
|
+
children: [jsxRuntimeExports.jsx("style", {
|
|
2226
|
+
children: "\n .datetime-picker {\n position: relative;\n display: inline-block;\n width: 100%;\n max-width: 300px;\n}\n\n.datetime-picker-input-wrapper {\n position: relative;\n display: flex;\n align-items: center;\n}\n\n.datetime-picker-input {\n width: 100%;\n padding: 8px 40px 8px 12px;\n border: 1px solid #e1e5e9;\n font-size: 14px;\n background-color: #ffffff;\n cursor: pointer;\n transition: border-color 0.2s ease;\n box-sizing: border-box;\n}\n\n.datetime-picker-input:hover {\n border-color: #d1d5db;\n}\n\n.datetime-picker-input:focus {\n outline: none;\n border-color: #3b82f6;\n}\n\n.datetime-picker-input:disabled {\n background-color: #f9fafb;\n cursor: not-allowed;\n opacity: 0.6;\n}\n\n.datetime-picker-icon {\n position: absolute;\n right: 6px;\n top: 6px;\n font-size: 16px;\n pointer-events: none;\n color: #666666;\n}\n\n.datetime-picker-dropdown {\n position: absolute;\n top: 100%;\n left: 0;\n z-index: 1000;\n margin-top: 4px;\n background: #ffffff;\n border: 1px solid #e1e5e9;\n /* border-radius: 8px; */\n box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);\n padding: 16px;\n min-width: 320px;\n}\n\n.calendar-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n margin-bottom: 16px;\n}\n\n.nav-button {\n background: none;\n border: none;\n padding: 8px;\n /* border-radius: 4px; */\n cursor: pointer;\n font-size: 18px;\n color: #6b7280;\n transition: all 0.2s ease;\n}\n\n.nav-button:hover {\n background-color: #f3f4f6;\n color: #374151;\n}\n\n.current-month-year {\n font-size: 16px;\n font-weight: 600;\n color: #374151;\n min-width: 140px;\n text-align: center;\n}\n\n.weekdays {\n display: grid;\n grid-template-columns: repeat(7, 1fr);\n gap: 2px;\n margin-bottom: 8px;\n}\n\n.weekday {\n text-align: center;\n padding: 8px 4px;\n font-size: 12px;\n font-weight: 600;\n color: #6b7280;\n text-transform: uppercase;\n}\n\n.calendar-days {\n display: grid;\n grid-template-columns: repeat(7, 1fr);\n gap: 2px;\n margin-bottom: 16px;\n}\n\n.calendar-day {\n background: none;\n border: none;\n padding: 8px;\n text-align: center;\n cursor: pointer;\n /* border-radius: 4px; */\n font-size: 14px;\n color: #374151;\n transition: all 0.2s ease;\n min-height: 32px;\n}\n\n.calendar-day:hover {\n background-color: #f3f4f6;\n}\n\n.calendar-day.other-month {\n color: #9ca3af;\n}\n\n.calendar-day.selected {\n background-color: #007ac2;\n color: #ffffff;\n}\n\n.calendar-day.today {\n background-color: #e2f3fe;\n color: #007ac2;\n font-weight: 600;\n}\n\n.calendar-day.selected.today {\n background-color: #007ac2;\n color: #ffffff;\n}\n\n.calendar-day.disabled {\n color: #dcdcdc;\n cursor: not-allowed;\n}\n\n.calendar-day:hover.disabled {\n background-color: none;\n}\n\n.time-picker {\n display: flex;\n gap: 16px;\n padding: 16px 0;\n border-top: 1px solid #e5e7eb;\n border-bottom: 1px solid #e5e7eb;\n margin: 16px 0;\n}\n\n.time-picker-section {\n flex: 1;\n}\n\n.time-picker-section label {\n display: block;\n font-size: 12px;\n font-weight: 600;\n color: #6b7280;\n margin-bottom: 4px;\n}\n\n.time-select {\n width: 100%;\n padding: 6px 8px;\n border: 1px solid #d1d5db;\n /* border-radius: 4px; */\n font-size: 14px;\n background-color: #ffffff;\n box-sizing: border-box;\n}\n\n.calendar-footer {\n display: flex;\n justify-content: space-between;\n gap: 8px;\n}\n\n.footer-button {\n padding: 6px 12px;\n border: 1px solid #d1d5db;\n /* border-radius: 4px; */\n background: #ffffff;\n cursor: pointer;\n font-size: 12px;\n transition: all 0.2s ease;\n}\n\n.footer-button:hover {\n background-color: #f9fafb;\n}\n\n.today-button {\n color: #007ac2;\n border-color: #007ac2;\n}\n\n.today-button:hover {\n background-color: #ecfdf5;\n}\n\n.clear-button {\n color: #007ac2;\n border-color: #007ac2;\n}\n\n.clear-button:hover {\n background-color: #fef2f2;\n}\n\n.confirm-button {\n color: #007ac2;\n border-color: #007ac2;\n}\n\n.confirm-button:hover {\n background-color: #eff6ff;\n}\n\n "
|
|
2227
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2228
|
+
ref: containerRef,
|
|
2229
|
+
className: "datetime-picker ".concat(className),
|
|
2230
|
+
children: [jsxRuntimeExports.jsxs("div", {
|
|
2231
|
+
className: "datetime-picker-input-wrapper",
|
|
2232
|
+
children: [jsxRuntimeExports.jsx("input", {
|
|
2233
|
+
type: "text",
|
|
2234
|
+
value: inputValue,
|
|
2235
|
+
placeholder: placeholder || format,
|
|
2236
|
+
disabled: disabled,
|
|
2237
|
+
readOnly: true,
|
|
2238
|
+
onClick: () => !disabled && setIsOpen(true),
|
|
2239
|
+
className: "datetime-picker-input"
|
|
2240
|
+
}), jsxRuntimeExports.jsx("div", {
|
|
2241
|
+
className: "datetime-picker-icon",
|
|
2242
|
+
children: jsxRuntimeExports.jsx(CalendarDays, {
|
|
2243
|
+
size: "18"
|
|
2244
|
+
})
|
|
2245
|
+
})]
|
|
2246
|
+
}), isOpen && jsxRuntimeExports.jsx("div", {
|
|
2247
|
+
className: "datetime-picker-dropdown",
|
|
2248
|
+
children: jsxRuntimeExports.jsxs("div", {
|
|
2249
|
+
className: "datetime-picker-calendar",
|
|
2250
|
+
children: [jsxRuntimeExports.jsxs("div", {
|
|
2251
|
+
className: "calendar-header",
|
|
2252
|
+
children: [jsxRuntimeExports.jsx("button", {
|
|
2253
|
+
type: "button",
|
|
2254
|
+
onClick: goToPreviousYear,
|
|
2255
|
+
className: "nav-button",
|
|
2256
|
+
children: "\u27EA"
|
|
2257
|
+
}), jsxRuntimeExports.jsx("button", {
|
|
2258
|
+
type: "button",
|
|
2259
|
+
onClick: goToPreviousMonth,
|
|
2260
|
+
className: "nav-button",
|
|
2261
|
+
children: "\u27E8"
|
|
2262
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2263
|
+
className: "current-month-year",
|
|
2264
|
+
children: [t.months[currentMonth], " ", displayYear]
|
|
2265
|
+
}), jsxRuntimeExports.jsx("button", {
|
|
2266
|
+
type: "button",
|
|
2267
|
+
onClick: goToNextMonth,
|
|
2268
|
+
className: "nav-button",
|
|
2269
|
+
children: "\u27E9"
|
|
2270
|
+
}), jsxRuntimeExports.jsx("button", {
|
|
2271
|
+
type: "button",
|
|
2272
|
+
onClick: goToNextYear,
|
|
2273
|
+
className: "nav-button",
|
|
2274
|
+
children: "\u27EB"
|
|
2275
|
+
})]
|
|
2276
|
+
}), jsxRuntimeExports.jsx("div", {
|
|
2277
|
+
className: "weekdays",
|
|
2278
|
+
children: t.weekdaysShort.map((day, index) => jsxRuntimeExports.jsx("div", {
|
|
2279
|
+
className: "weekday",
|
|
2280
|
+
children: day
|
|
2281
|
+
}, index))
|
|
2282
|
+
}), jsxRuntimeExports.jsx("div", {
|
|
2283
|
+
className: "calendar-days",
|
|
2284
|
+
children: calendarDays.map((dateInfo, index) => {
|
|
2285
|
+
let actualDate;
|
|
2286
|
+
// Determine the correct date object for the day
|
|
2287
|
+
if (dateInfo.isCurrentMonth) {
|
|
2288
|
+
actualDate = new Date(currentYear, currentMonth, dateInfo.day);
|
|
2289
|
+
} else if (index < 7 && dateInfo.day > 20) {
|
|
2290
|
+
actualDate = new Date(currentYear, currentMonth - 1, dateInfo.day);
|
|
2291
|
+
} else {
|
|
2292
|
+
actualDate = new Date(currentYear, currentMonth + 1, dateInfo.day);
|
|
2293
|
+
}
|
|
2294
|
+
const isSelected = selectedDate && isSameDay(actualDate, selectedDate);
|
|
2295
|
+
const isToday = isSameDay(actualDate, today);
|
|
2296
|
+
const isDayDisabled = isDisabled(actualDate, disabledPast, disabledFuture);
|
|
2297
|
+
return jsxRuntimeExports.jsx("button", {
|
|
2298
|
+
type: "button",
|
|
2299
|
+
onClick: () => {
|
|
2300
|
+
if (dateInfo.isCurrentMonth) {
|
|
2301
|
+
handleDateSelect(dateInfo.day, currentYear, currentMonth);
|
|
2302
|
+
} else if (index < 7 && dateInfo.day > 20) {
|
|
2303
|
+
// Navigate to previous month and select date
|
|
2304
|
+
const prevMonth = currentMonth === 0 ? 11 : currentMonth - 1;
|
|
2305
|
+
const prevYear = currentMonth === 0 ? currentYear - 1 : currentYear;
|
|
2306
|
+
const newDate = new Date(prevYear, prevMonth, dateInfo.day);
|
|
2307
|
+
if (isDisabled(newDate, disabledPast, disabledFuture)) return;
|
|
2308
|
+
setCurrentMonth(prevMonth);
|
|
2309
|
+
setCurrentYear(prevYear);
|
|
2310
|
+
handleDateSelect(dateInfo.day, prevYear, prevMonth);
|
|
2311
|
+
} else {
|
|
2312
|
+
// Navigate to next month and select date
|
|
2313
|
+
const nextMonth = currentMonth === 11 ? 0 : currentMonth + 1;
|
|
2314
|
+
const nextYear = currentMonth === 11 ? currentYear + 1 : currentYear;
|
|
2315
|
+
const newDate = new Date(nextYear, nextMonth, dateInfo.day);
|
|
2316
|
+
if (isDisabled(newDate, disabledPast, disabledFuture)) return;
|
|
2317
|
+
setCurrentMonth(nextMonth);
|
|
2318
|
+
setCurrentYear(nextYear);
|
|
2319
|
+
handleDateSelect(dateInfo.day, nextYear, nextMonth);
|
|
2320
|
+
}
|
|
2321
|
+
},
|
|
2322
|
+
disabled: isDayDisabled,
|
|
2323
|
+
className: "\n calendar-day\n ".concat(dateInfo.isOtherMonth ? 'other-month' : '', "\n ").concat(isSelected ? 'selected' : '', "\n ").concat(isToday ? 'today' : '', "\n ").concat(isDayDisabled ? 'disabled' : '', "\n ").trim(),
|
|
2324
|
+
children: dateInfo.day
|
|
2325
|
+
}, index);
|
|
2326
|
+
})
|
|
2327
|
+
}), includeTime && jsxRuntimeExports.jsxs("div", {
|
|
2328
|
+
className: "time-picker",
|
|
2329
|
+
children: [jsxRuntimeExports.jsxs("div", {
|
|
2330
|
+
className: "time-picker-section",
|
|
2331
|
+
children: [jsxRuntimeExports.jsx("label", {
|
|
2332
|
+
children: t.hour
|
|
2333
|
+
}), jsxRuntimeExports.jsx("select", {
|
|
2334
|
+
value: timeHour,
|
|
2335
|
+
onChange: e => handleTimeChange('hour', parseInt(e.target.value)),
|
|
2336
|
+
className: "time-select",
|
|
2337
|
+
children: Array.from({
|
|
2338
|
+
length: 24
|
|
2339
|
+
}, (_, i) => jsxRuntimeExports.jsx("option", {
|
|
2340
|
+
value: i,
|
|
2341
|
+
children: String(i).padStart(2, '0')
|
|
2342
|
+
}, i))
|
|
2343
|
+
})]
|
|
2344
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2345
|
+
className: "time-picker-section",
|
|
2346
|
+
children: [jsxRuntimeExports.jsx("label", {
|
|
2347
|
+
children: t.minute
|
|
2348
|
+
}), jsxRuntimeExports.jsx("select", {
|
|
2349
|
+
value: timeMinute,
|
|
2350
|
+
onChange: e => handleTimeChange('minute', parseInt(e.target.value)),
|
|
2351
|
+
className: "time-select",
|
|
2352
|
+
children: Array.from({
|
|
2353
|
+
length: 60
|
|
2354
|
+
}, (_, i) => jsxRuntimeExports.jsx("option", {
|
|
2355
|
+
value: i,
|
|
2356
|
+
children: String(i).padStart(2, '0')
|
|
2357
|
+
}, i))
|
|
2358
|
+
})]
|
|
2359
|
+
})]
|
|
2360
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2361
|
+
className: "calendar-footer",
|
|
2362
|
+
children: [showToday && jsxRuntimeExports.jsx("button", {
|
|
2363
|
+
type: "button",
|
|
2364
|
+
onClick: handleToday,
|
|
2365
|
+
disabled: isDisabled(today, disabledPast, disabledFuture),
|
|
2366
|
+
className: "footer-button today-button ".concat(isDisabled(today, disabledPast, disabledFuture) ? 'disabled' : ''),
|
|
2367
|
+
children: t.today
|
|
2368
|
+
}), showClear && jsxRuntimeExports.jsx("button", {
|
|
2369
|
+
type: "button",
|
|
2370
|
+
onClick: handleClear,
|
|
2371
|
+
className: "footer-button clear-button",
|
|
2372
|
+
children: t.clear
|
|
2373
|
+
}), includeTime && jsxRuntimeExports.jsx("button", {
|
|
2374
|
+
type: "button",
|
|
2375
|
+
onClick: handleConfirm,
|
|
2376
|
+
className: "footer-button confirm-button",
|
|
2377
|
+
children: t.ok
|
|
2378
|
+
})]
|
|
2379
|
+
})]
|
|
2380
|
+
})
|
|
2381
|
+
})]
|
|
2382
|
+
})]
|
|
2383
|
+
});
|
|
2384
|
+
};
|
|
2385
|
+
|
|
1847
2386
|
// Ensure React is available before importing components
|
|
1848
2387
|
|
|
1849
2388
|
exports.React = React;
|
|
1850
2389
|
exports.default = React;
|
|
1851
2390
|
exports.Button = Button;
|
|
1852
2391
|
exports.Checkbox = Checkbox;
|
|
2392
|
+
exports.DatePicker = DatePicker;
|
|
1853
2393
|
exports.Input = Input;
|
|
1854
2394
|
exports.InputFile = InputFile;
|
|
1855
2395
|
exports.Radio = Radio;
|