thailife-react 0.0.20 → 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/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 +1 -0
- package/package.json +4 -3
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default from 'react';
|
|
2
|
+
import React__default, { forwardRef, createElement, useState, useRef, useEffect } from 'react';
|
|
3
3
|
export { default as React, default } from 'react';
|
|
4
4
|
|
|
5
5
|
function _defineProperty(e, r, t) {
|
|
@@ -1511,7 +1511,7 @@ const cssClasses = {
|
|
|
1511
1511
|
shadowXl: "shadow-xl"
|
|
1512
1512
|
};
|
|
1513
1513
|
|
|
1514
|
-
const _excluded$
|
|
1514
|
+
const _excluded$8 = ["className", "color", "variant", "size", "fullWidth", "loading", "disabled", "children"];
|
|
1515
1515
|
const Button = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
1516
1516
|
let {
|
|
1517
1517
|
className,
|
|
@@ -1523,7 +1523,7 @@ const Button = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1523
1523
|
disabled,
|
|
1524
1524
|
children
|
|
1525
1525
|
} = _ref,
|
|
1526
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1526
|
+
props = _objectWithoutProperties(_ref, _excluded$8);
|
|
1527
1527
|
const baseClass = cssClasses.button;
|
|
1528
1528
|
const variantClass = variant === "contained" ? cssClasses.buttonContained : variant === "outlined" ? cssClasses.buttonOutlined : cssClasses.buttonLink;
|
|
1529
1529
|
const sizeClass = size === "sm" ? cssClasses.buttonSmall : size === "md" ? cssClasses.buttonMedium : cssClasses.buttonLarge;
|
|
@@ -1540,7 +1540,7 @@ const Button = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1540
1540
|
});
|
|
1541
1541
|
Button.displayName = "Button";
|
|
1542
1542
|
|
|
1543
|
-
const _excluded$
|
|
1543
|
+
const _excluded$7 = ["className", "type", "label", "error", "helperText", "size", "fullWidth", "id"];
|
|
1544
1544
|
const Input = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
1545
1545
|
let {
|
|
1546
1546
|
className,
|
|
@@ -1552,7 +1552,7 @@ const Input = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1552
1552
|
fullWidth = false,
|
|
1553
1553
|
id
|
|
1554
1554
|
} = _ref,
|
|
1555
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1555
|
+
props = _objectWithoutProperties(_ref, _excluded$7);
|
|
1556
1556
|
const inputId = id || "input-".concat(Math.random().toString(36).substr(2, 9));
|
|
1557
1557
|
const containerClass = fullWidth ? cssClasses.inputContainerFullWidth : cssClasses.inputContainer;
|
|
1558
1558
|
const inputClass = error ? "".concat(cssClasses.input, " ").concat(cssClasses.inputError) : cssClasses.input;
|
|
@@ -1577,7 +1577,7 @@ const Input = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1577
1577
|
});
|
|
1578
1578
|
Input.displayName = "Input";
|
|
1579
1579
|
|
|
1580
|
-
const _excluded$
|
|
1580
|
+
const _excluded$6 = ["className", "label", "error", "helperText", "size", "fullWidth", "rows", "id"];
|
|
1581
1581
|
const Textarea = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
1582
1582
|
let {
|
|
1583
1583
|
className,
|
|
@@ -1589,7 +1589,7 @@ const Textarea = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1589
1589
|
rows = 3,
|
|
1590
1590
|
id
|
|
1591
1591
|
} = _ref,
|
|
1592
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1592
|
+
props = _objectWithoutProperties(_ref, _excluded$6);
|
|
1593
1593
|
const textareaId = id || "textarea-".concat(Math.random().toString(36).substr(2, 9));
|
|
1594
1594
|
const containerClass = fullWidth ? cssClasses.textareaContainerFullWidth : cssClasses.textareaContainer;
|
|
1595
1595
|
const textareaClass = error ? "".concat(cssClasses.textarea, " ").concat(cssClasses.textareaError) : cssClasses.textarea;
|
|
@@ -1614,7 +1614,7 @@ const Textarea = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1614
1614
|
});
|
|
1615
1615
|
Textarea.displayName = "Textarea";
|
|
1616
1616
|
|
|
1617
|
-
const _excluded$
|
|
1617
|
+
const _excluded$5 = ["className", "label", "error", "helperText", "size", "fullWidth", "multiple", "accept", "buttonText", "id"];
|
|
1618
1618
|
const InputFile = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
1619
1619
|
let {
|
|
1620
1620
|
className,
|
|
@@ -1628,7 +1628,7 @@ const InputFile = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1628
1628
|
buttonText = "Choose File",
|
|
1629
1629
|
id
|
|
1630
1630
|
} = _ref,
|
|
1631
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1631
|
+
props = _objectWithoutProperties(_ref, _excluded$5);
|
|
1632
1632
|
const inputId = id || "input-file-".concat(Math.random().toString(36).substr(2, 9));
|
|
1633
1633
|
const containerClass = fullWidth ? cssClasses.inputFileContainerFullWidth : cssClasses.inputFileContainer;
|
|
1634
1634
|
const uploadAreaClass = error ? "".concat(cssClasses.inputFileUploadArea, " ").concat(cssClasses.inputFileUploadAreaError) : cssClasses.inputFileUploadArea;
|
|
@@ -1667,7 +1667,7 @@ const InputFile = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1667
1667
|
});
|
|
1668
1668
|
InputFile.displayName = "InputFile";
|
|
1669
1669
|
|
|
1670
|
-
const _excluded$
|
|
1670
|
+
const _excluded$4 = ["className", "label", "error", "helperText", "size", "fullWidth", "indeterminate", "id"];
|
|
1671
1671
|
const Checkbox = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
1672
1672
|
let {
|
|
1673
1673
|
className,
|
|
@@ -1679,7 +1679,7 @@ const Checkbox = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1679
1679
|
indeterminate = false,
|
|
1680
1680
|
id
|
|
1681
1681
|
} = _ref,
|
|
1682
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1682
|
+
props = _objectWithoutProperties(_ref, _excluded$4);
|
|
1683
1683
|
const checkboxId = id || "checkbox-".concat(Math.random().toString(36).substr(2, 9));
|
|
1684
1684
|
React__default.useEffect(() => {
|
|
1685
1685
|
if (ref && typeof ref === "object" && ref.current) {
|
|
@@ -1714,7 +1714,7 @@ const Checkbox = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1714
1714
|
});
|
|
1715
1715
|
Checkbox.displayName = "Checkbox";
|
|
1716
1716
|
|
|
1717
|
-
const _excluded$
|
|
1717
|
+
const _excluded$3 = ["className", "label", "error", "helperText", "size", "fullWidth", "id"];
|
|
1718
1718
|
const Radio = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
1719
1719
|
let {
|
|
1720
1720
|
className,
|
|
@@ -1725,7 +1725,7 @@ const Radio = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1725
1725
|
fullWidth = false,
|
|
1726
1726
|
id
|
|
1727
1727
|
} = _ref,
|
|
1728
|
-
props = _objectWithoutProperties(_ref, _excluded$
|
|
1728
|
+
props = _objectWithoutProperties(_ref, _excluded$3);
|
|
1729
1729
|
const radioId = id || "radio-".concat(Math.random().toString(36).substr(2, 9));
|
|
1730
1730
|
const containerClass = fullWidth ? cssClasses.radioContainerFullWidth : cssClasses.radioContainer;
|
|
1731
1731
|
const radioClass = error ? "".concat(cssClasses.radio, " ").concat(cssClasses.radioError) : cssClasses.radio;
|
|
@@ -1755,7 +1755,7 @@ const Radio = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1755
1755
|
});
|
|
1756
1756
|
Radio.displayName = "Radio";
|
|
1757
1757
|
|
|
1758
|
-
const _excluded = ["className", "label", "error", "helperText", "size", "fullWidth", "options", "placeholder", "id"];
|
|
1758
|
+
const _excluded$2 = ["className", "label", "error", "helperText", "size", "fullWidth", "options", "placeholder", "id"];
|
|
1759
1759
|
const Select = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
1760
1760
|
let {
|
|
1761
1761
|
className,
|
|
@@ -1768,7 +1768,7 @@ const Select = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1768
1768
|
placeholder,
|
|
1769
1769
|
id
|
|
1770
1770
|
} = _ref,
|
|
1771
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
1771
|
+
props = _objectWithoutProperties(_ref, _excluded$2);
|
|
1772
1772
|
const selectId = id || "select-".concat(Math.random().toString(36).substr(2, 9));
|
|
1773
1773
|
const containerClass = fullWidth ? cssClasses.selectContainerFullWidth : cssClasses.selectContainer;
|
|
1774
1774
|
const selectClass = error ? "".concat(cssClasses.select, " ").concat(cssClasses.selectError) : cssClasses.select;
|
|
@@ -1823,7 +1823,546 @@ const Select = /*#__PURE__*/React__default.forwardRef((_ref, ref) => {
|
|
|
1823
1823
|
});
|
|
1824
1824
|
Select.displayName = "Select";
|
|
1825
1825
|
|
|
1826
|
+
/**
|
|
1827
|
+
* @license lucide-react v0.542.0 - ISC
|
|
1828
|
+
*
|
|
1829
|
+
* This source code is licensed under the ISC license.
|
|
1830
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
1831
|
+
*/
|
|
1832
|
+
|
|
1833
|
+
const toKebabCase = string => string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1834
|
+
const toCamelCase = string => string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => p2 ? p2.toUpperCase() : p1.toLowerCase());
|
|
1835
|
+
const toPascalCase = string => {
|
|
1836
|
+
const camelCase = toCamelCase(string);
|
|
1837
|
+
return camelCase.charAt(0).toUpperCase() + camelCase.slice(1);
|
|
1838
|
+
};
|
|
1839
|
+
const mergeClasses = function () {
|
|
1840
|
+
for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1841
|
+
classes[_key] = arguments[_key];
|
|
1842
|
+
}
|
|
1843
|
+
return classes.filter((className, index, array) => {
|
|
1844
|
+
return Boolean(className) && className.trim() !== "" && array.indexOf(className) === index;
|
|
1845
|
+
}).join(" ").trim();
|
|
1846
|
+
};
|
|
1847
|
+
const hasA11yProp = props => {
|
|
1848
|
+
for (const prop in props) {
|
|
1849
|
+
if (prop.startsWith("aria-") || prop === "role" || prop === "title") {
|
|
1850
|
+
return true;
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
|
|
1855
|
+
/**
|
|
1856
|
+
* @license lucide-react v0.542.0 - ISC
|
|
1857
|
+
*
|
|
1858
|
+
* This source code is licensed under the ISC license.
|
|
1859
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
1860
|
+
*/
|
|
1861
|
+
|
|
1862
|
+
var defaultAttributes = {
|
|
1863
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1864
|
+
width: 24,
|
|
1865
|
+
height: 24,
|
|
1866
|
+
viewBox: "0 0 24 24",
|
|
1867
|
+
fill: "none",
|
|
1868
|
+
stroke: "currentColor",
|
|
1869
|
+
strokeWidth: 2,
|
|
1870
|
+
strokeLinecap: "round",
|
|
1871
|
+
strokeLinejoin: "round"
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
const _excluded$1 = ["color", "size", "strokeWidth", "absoluteStrokeWidth", "className", "children", "iconNode"];
|
|
1875
|
+
const Icon = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
1876
|
+
let {
|
|
1877
|
+
color = "currentColor",
|
|
1878
|
+
size = 24,
|
|
1879
|
+
strokeWidth = 2,
|
|
1880
|
+
absoluteStrokeWidth,
|
|
1881
|
+
className = "",
|
|
1882
|
+
children,
|
|
1883
|
+
iconNode
|
|
1884
|
+
} = _ref,
|
|
1885
|
+
rest = _objectWithoutProperties(_ref, _excluded$1);
|
|
1886
|
+
return /*#__PURE__*/createElement("svg", _objectSpread2(_objectSpread2(_objectSpread2({
|
|
1887
|
+
ref
|
|
1888
|
+
}, defaultAttributes), {}, {
|
|
1889
|
+
width: size,
|
|
1890
|
+
height: size,
|
|
1891
|
+
stroke: color,
|
|
1892
|
+
strokeWidth: absoluteStrokeWidth ? Number(strokeWidth) * 24 / Number(size) : strokeWidth,
|
|
1893
|
+
className: mergeClasses("lucide", className)
|
|
1894
|
+
}, !children && !hasA11yProp(rest) && {
|
|
1895
|
+
"aria-hidden": "true"
|
|
1896
|
+
}), rest), [...iconNode.map(_ref2 => {
|
|
1897
|
+
let [tag, attrs] = _ref2;
|
|
1898
|
+
return /*#__PURE__*/createElement(tag, attrs);
|
|
1899
|
+
}), ...(Array.isArray(children) ? children : [children])]);
|
|
1900
|
+
});
|
|
1901
|
+
|
|
1902
|
+
const _excluded = ["className"];
|
|
1903
|
+
const createLucideIcon = (iconName, iconNode) => {
|
|
1904
|
+
const Component = /*#__PURE__*/forwardRef((_ref, ref) => {
|
|
1905
|
+
let {
|
|
1906
|
+
className
|
|
1907
|
+
} = _ref,
|
|
1908
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
1909
|
+
return /*#__PURE__*/createElement(Icon, _objectSpread2({
|
|
1910
|
+
ref,
|
|
1911
|
+
iconNode,
|
|
1912
|
+
className: mergeClasses("lucide-".concat(toKebabCase(toPascalCase(iconName))), "lucide-".concat(iconName), className)
|
|
1913
|
+
}, props));
|
|
1914
|
+
});
|
|
1915
|
+
Component.displayName = toPascalCase(iconName);
|
|
1916
|
+
return Component;
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1919
|
+
/**
|
|
1920
|
+
* @license lucide-react v0.542.0 - ISC
|
|
1921
|
+
*
|
|
1922
|
+
* This source code is licensed under the ISC license.
|
|
1923
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
1924
|
+
*/
|
|
1925
|
+
|
|
1926
|
+
const __iconNode = [["path", {
|
|
1927
|
+
d: "M8 2v4",
|
|
1928
|
+
key: "1cmpym"
|
|
1929
|
+
}], ["path", {
|
|
1930
|
+
d: "M16 2v4",
|
|
1931
|
+
key: "4m81vk"
|
|
1932
|
+
}], ["rect", {
|
|
1933
|
+
width: "18",
|
|
1934
|
+
height: "18",
|
|
1935
|
+
x: "3",
|
|
1936
|
+
y: "4",
|
|
1937
|
+
rx: "2",
|
|
1938
|
+
key: "1hopcy"
|
|
1939
|
+
}], ["path", {
|
|
1940
|
+
d: "M3 10h18",
|
|
1941
|
+
key: "8toen8"
|
|
1942
|
+
}], ["path", {
|
|
1943
|
+
d: "M8 14h.01",
|
|
1944
|
+
key: "6423bh"
|
|
1945
|
+
}], ["path", {
|
|
1946
|
+
d: "M12 14h.01",
|
|
1947
|
+
key: "1etili"
|
|
1948
|
+
}], ["path", {
|
|
1949
|
+
d: "M16 14h.01",
|
|
1950
|
+
key: "1gbofw"
|
|
1951
|
+
}], ["path", {
|
|
1952
|
+
d: "M8 18h.01",
|
|
1953
|
+
key: "lrp35t"
|
|
1954
|
+
}], ["path", {
|
|
1955
|
+
d: "M12 18h.01",
|
|
1956
|
+
key: "mhygvu"
|
|
1957
|
+
}], ["path", {
|
|
1958
|
+
d: "M16 18h.01",
|
|
1959
|
+
key: "kzsmim"
|
|
1960
|
+
}]];
|
|
1961
|
+
const CalendarDays = createLucideIcon("calendar-days", __iconNode);
|
|
1962
|
+
|
|
1963
|
+
// Translations
|
|
1964
|
+
const translations = {
|
|
1965
|
+
th: {
|
|
1966
|
+
months: ['มกราคม', 'กุมภาพันธ์', 'มีนาคม', 'เมษายน', 'พฤษภาคม', 'มิถุนายน', 'กรกฎาคม', 'สิงหาคม', 'กันยายน', 'ตุลาคม', 'พฤศจิกายน', 'ธันวาคม'],
|
|
1967
|
+
weekdaysShort: ['อา', 'จ', 'อ', 'พ', 'พฤ', 'ศ', 'ส'],
|
|
1968
|
+
today: 'วันนี้',
|
|
1969
|
+
clear: 'ล้าง',
|
|
1970
|
+
ok: 'ตกลง',
|
|
1971
|
+
hour: 'ชั่วโมง',
|
|
1972
|
+
minute: 'นาที'
|
|
1973
|
+
},
|
|
1974
|
+
en: {
|
|
1975
|
+
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
|
1976
|
+
weekdaysShort: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
|
|
1977
|
+
today: 'Today',
|
|
1978
|
+
clear: 'Clear',
|
|
1979
|
+
ok: 'OK',
|
|
1980
|
+
hour: 'Hour',
|
|
1981
|
+
minute: 'Minute'
|
|
1982
|
+
}
|
|
1983
|
+
};
|
|
1984
|
+
// Utility functions
|
|
1985
|
+
const convertYear = (year, fromType, toType) => {
|
|
1986
|
+
return year + 543;
|
|
1987
|
+
};
|
|
1988
|
+
const formatDate = (date, format, yearType) => {
|
|
1989
|
+
if (!date || isNaN(date.getTime())) return '';
|
|
1990
|
+
const day = String(date.getDate()).padStart(2, '0');
|
|
1991
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
|
1992
|
+
const year = yearType === 'be' ? convertYear(date.getFullYear()) : date.getFullYear();
|
|
1993
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
|
1994
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
|
1995
|
+
let formatted = format.replace('DD', day).replace('MM', month).replace('YYYY', year.toString()).replace('HH', hours).replace('mm', minutes);
|
|
1996
|
+
return formatted;
|
|
1997
|
+
};
|
|
1998
|
+
const isSameDay = (date1, date2) => {
|
|
1999
|
+
return date1.getDate() === date2.getDate() && date1.getMonth() === date2.getMonth() && date1.getFullYear() === date2.getFullYear();
|
|
2000
|
+
};
|
|
2001
|
+
// New utility function to check for disabled dates
|
|
2002
|
+
const isDisabled = (date, disabledPast, disabledFuture) => {
|
|
2003
|
+
const today = new Date();
|
|
2004
|
+
const dateOnly = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
2005
|
+
const todayOnly = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
2006
|
+
if (disabledPast && dateOnly < todayOnly) {
|
|
2007
|
+
return true;
|
|
2008
|
+
}
|
|
2009
|
+
if (disabledFuture && dateOnly > todayOnly) {
|
|
2010
|
+
return true;
|
|
2011
|
+
}
|
|
2012
|
+
return false;
|
|
2013
|
+
};
|
|
2014
|
+
const DatePicker = _ref => {
|
|
2015
|
+
let {
|
|
2016
|
+
format = 'DD/MM/YYYY',
|
|
2017
|
+
language = 'en',
|
|
2018
|
+
yearType = 'ad',
|
|
2019
|
+
value = null,
|
|
2020
|
+
onChange,
|
|
2021
|
+
placeholder = '',
|
|
2022
|
+
disabled = false,
|
|
2023
|
+
className = '',
|
|
2024
|
+
showClear = true,
|
|
2025
|
+
showToday = true,
|
|
2026
|
+
disabledPast = false,
|
|
2027
|
+
// Default to false
|
|
2028
|
+
disabledFuture = false // Default to false
|
|
2029
|
+
} = _ref;
|
|
2030
|
+
// State
|
|
2031
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
2032
|
+
const [selectedDate, setSelectedDate] = useState(null);
|
|
2033
|
+
const [currentMonth, setCurrentMonth] = useState(new Date().getMonth());
|
|
2034
|
+
const [currentYear, setCurrentYear] = useState(new Date().getFullYear());
|
|
2035
|
+
const [inputValue, setInputValue] = useState('');
|
|
2036
|
+
const [timeHour, setTimeHour] = useState(0);
|
|
2037
|
+
const [timeMinute, setTimeMinute] = useState(0);
|
|
2038
|
+
// Refs
|
|
2039
|
+
const containerRef = useRef(null);
|
|
2040
|
+
// Constants
|
|
2041
|
+
const includeTime = format.includes('HH:mm');
|
|
2042
|
+
const t = translations[language];
|
|
2043
|
+
// Initialize from value prop
|
|
2044
|
+
useEffect(() => {
|
|
2045
|
+
if (value) {
|
|
2046
|
+
const date = new Date(value);
|
|
2047
|
+
if (!isNaN(date.getTime())) {
|
|
2048
|
+
setSelectedDate(date);
|
|
2049
|
+
setCurrentMonth(date.getMonth());
|
|
2050
|
+
setCurrentYear(date.getFullYear());
|
|
2051
|
+
setTimeHour(date.getHours());
|
|
2052
|
+
setTimeMinute(date.getMinutes());
|
|
2053
|
+
setInputValue(formatDate(date, format, yearType));
|
|
2054
|
+
}
|
|
2055
|
+
} else {
|
|
2056
|
+
setSelectedDate(null);
|
|
2057
|
+
setInputValue('');
|
|
2058
|
+
}
|
|
2059
|
+
}, [value, format, yearType]);
|
|
2060
|
+
// Handle date selection
|
|
2061
|
+
const handleDateSelect = (day, year, month) => {
|
|
2062
|
+
const newDate = new Date(year, month, day, timeHour, timeMinute);
|
|
2063
|
+
// Check if the selected date is disabled before proceeding
|
|
2064
|
+
if (isDisabled(newDate, disabledPast, disabledFuture)) {
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
setSelectedDate(newDate);
|
|
2068
|
+
setInputValue(formatDate(newDate, format, yearType));
|
|
2069
|
+
onChange === null || onChange === void 0 || onChange(newDate);
|
|
2070
|
+
if (!includeTime) {
|
|
2071
|
+
setIsOpen(false);
|
|
2072
|
+
}
|
|
2073
|
+
};
|
|
2074
|
+
// Handle time change
|
|
2075
|
+
const handleTimeChange = (type, newValue) => {
|
|
2076
|
+
if (type === 'hour') {
|
|
2077
|
+
setTimeHour(newValue);
|
|
2078
|
+
} else {
|
|
2079
|
+
setTimeMinute(newValue);
|
|
2080
|
+
}
|
|
2081
|
+
if (selectedDate) {
|
|
2082
|
+
const newDate = new Date(selectedDate);
|
|
2083
|
+
if (type === 'hour') {
|
|
2084
|
+
newDate.setHours(newValue);
|
|
2085
|
+
} else {
|
|
2086
|
+
newDate.setMinutes(newValue);
|
|
2087
|
+
}
|
|
2088
|
+
setSelectedDate(newDate);
|
|
2089
|
+
setInputValue(formatDate(newDate, format, yearType));
|
|
2090
|
+
onChange === null || onChange === void 0 || onChange(newDate);
|
|
2091
|
+
}
|
|
2092
|
+
};
|
|
2093
|
+
// Handle today button
|
|
2094
|
+
const handleToday = () => {
|
|
2095
|
+
const today = new Date();
|
|
2096
|
+
if (isDisabled(today, disabledPast, disabledFuture)) {
|
|
2097
|
+
return;
|
|
2098
|
+
}
|
|
2099
|
+
setSelectedDate(today);
|
|
2100
|
+
setCurrentMonth(today.getMonth());
|
|
2101
|
+
setCurrentYear(today.getFullYear());
|
|
2102
|
+
setTimeHour(today.getHours());
|
|
2103
|
+
setTimeMinute(today.getMinutes());
|
|
2104
|
+
setInputValue(formatDate(today, format, yearType));
|
|
2105
|
+
onChange === null || onChange === void 0 || onChange(today);
|
|
2106
|
+
if (!includeTime) {
|
|
2107
|
+
setIsOpen(false);
|
|
2108
|
+
}
|
|
2109
|
+
};
|
|
2110
|
+
// Handle clear button
|
|
2111
|
+
const handleClear = () => {
|
|
2112
|
+
setSelectedDate(null);
|
|
2113
|
+
setInputValue('');
|
|
2114
|
+
onChange === null || onChange === void 0 || onChange(null);
|
|
2115
|
+
setIsOpen(false);
|
|
2116
|
+
};
|
|
2117
|
+
// Handle confirm (for time picker)
|
|
2118
|
+
const handleConfirm = () => {
|
|
2119
|
+
setIsOpen(false);
|
|
2120
|
+
};
|
|
2121
|
+
// Navigation handlers
|
|
2122
|
+
const goToPreviousMonth = () => {
|
|
2123
|
+
if (currentMonth === 0) {
|
|
2124
|
+
setCurrentMonth(11);
|
|
2125
|
+
setCurrentYear(currentYear - 1);
|
|
2126
|
+
} else {
|
|
2127
|
+
setCurrentMonth(currentMonth - 1);
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
const goToNextMonth = () => {
|
|
2131
|
+
if (currentMonth === 11) {
|
|
2132
|
+
setCurrentMonth(0);
|
|
2133
|
+
setCurrentYear(currentYear + 1);
|
|
2134
|
+
} else {
|
|
2135
|
+
setCurrentMonth(currentMonth + 1);
|
|
2136
|
+
}
|
|
2137
|
+
};
|
|
2138
|
+
const goToPreviousYear = () => {
|
|
2139
|
+
setCurrentYear(currentYear - 1);
|
|
2140
|
+
};
|
|
2141
|
+
const goToNextYear = () => {
|
|
2142
|
+
setCurrentYear(currentYear + 1);
|
|
2143
|
+
};
|
|
2144
|
+
// Generate calendar days
|
|
2145
|
+
const generateCalendarDays = () => {
|
|
2146
|
+
const firstDayOfMonth = new Date(currentYear, currentMonth, 1);
|
|
2147
|
+
const lastDayOfMonth = new Date(currentYear, currentMonth + 1, 0);
|
|
2148
|
+
const firstDayOfWeek = firstDayOfMonth.getDay();
|
|
2149
|
+
const daysInMonth = lastDayOfMonth.getDate();
|
|
2150
|
+
const days = [];
|
|
2151
|
+
// Previous month days
|
|
2152
|
+
const prevMonth = new Date(currentYear, currentMonth - 1, 0);
|
|
2153
|
+
const daysFromPrevMonth = firstDayOfWeek;
|
|
2154
|
+
for (let i = daysFromPrevMonth - 1; i >= 0; i--) {
|
|
2155
|
+
days.push({
|
|
2156
|
+
day: prevMonth.getDate() - i,
|
|
2157
|
+
isCurrentMonth: false,
|
|
2158
|
+
isOtherMonth: true,
|
|
2159
|
+
month: currentMonth - 1,
|
|
2160
|
+
year: currentYear
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
// Current month days
|
|
2164
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
2165
|
+
days.push({
|
|
2166
|
+
day,
|
|
2167
|
+
isCurrentMonth: true,
|
|
2168
|
+
isOtherMonth: false,
|
|
2169
|
+
month: currentMonth,
|
|
2170
|
+
year: currentYear
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
// Next month days
|
|
2174
|
+
const remainingDays = 42 - days.length;
|
|
2175
|
+
for (let day = 1; day <= remainingDays; day++) {
|
|
2176
|
+
days.push({
|
|
2177
|
+
day,
|
|
2178
|
+
isCurrentMonth: false,
|
|
2179
|
+
isOtherMonth: true,
|
|
2180
|
+
month: currentMonth + 1,
|
|
2181
|
+
year: currentYear
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
return days;
|
|
2185
|
+
};
|
|
2186
|
+
// Click outside handler
|
|
2187
|
+
useEffect(() => {
|
|
2188
|
+
const handleClickOutside = event => {
|
|
2189
|
+
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
2190
|
+
setIsOpen(false);
|
|
2191
|
+
}
|
|
2192
|
+
};
|
|
2193
|
+
if (isOpen) {
|
|
2194
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
2195
|
+
}
|
|
2196
|
+
return () => {
|
|
2197
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
2198
|
+
};
|
|
2199
|
+
}, [isOpen]);
|
|
2200
|
+
const calendarDays = generateCalendarDays();
|
|
2201
|
+
const today = new Date();
|
|
2202
|
+
const displayYear = yearType === 'be' ? convertYear(currentYear) : currentYear;
|
|
2203
|
+
return jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, {
|
|
2204
|
+
children: [jsxRuntimeExports.jsx("style", {
|
|
2205
|
+
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 "
|
|
2206
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2207
|
+
ref: containerRef,
|
|
2208
|
+
className: "datetime-picker ".concat(className),
|
|
2209
|
+
children: [jsxRuntimeExports.jsxs("div", {
|
|
2210
|
+
className: "datetime-picker-input-wrapper",
|
|
2211
|
+
children: [jsxRuntimeExports.jsx("input", {
|
|
2212
|
+
type: "text",
|
|
2213
|
+
value: inputValue,
|
|
2214
|
+
placeholder: placeholder || format,
|
|
2215
|
+
disabled: disabled,
|
|
2216
|
+
readOnly: true,
|
|
2217
|
+
onClick: () => !disabled && setIsOpen(true),
|
|
2218
|
+
className: "datetime-picker-input"
|
|
2219
|
+
}), jsxRuntimeExports.jsx("div", {
|
|
2220
|
+
className: "datetime-picker-icon",
|
|
2221
|
+
children: jsxRuntimeExports.jsx(CalendarDays, {
|
|
2222
|
+
size: "18"
|
|
2223
|
+
})
|
|
2224
|
+
})]
|
|
2225
|
+
}), isOpen && jsxRuntimeExports.jsx("div", {
|
|
2226
|
+
className: "datetime-picker-dropdown",
|
|
2227
|
+
children: jsxRuntimeExports.jsxs("div", {
|
|
2228
|
+
className: "datetime-picker-calendar",
|
|
2229
|
+
children: [jsxRuntimeExports.jsxs("div", {
|
|
2230
|
+
className: "calendar-header",
|
|
2231
|
+
children: [jsxRuntimeExports.jsx("button", {
|
|
2232
|
+
type: "button",
|
|
2233
|
+
onClick: goToPreviousYear,
|
|
2234
|
+
className: "nav-button",
|
|
2235
|
+
children: "\u27EA"
|
|
2236
|
+
}), jsxRuntimeExports.jsx("button", {
|
|
2237
|
+
type: "button",
|
|
2238
|
+
onClick: goToPreviousMonth,
|
|
2239
|
+
className: "nav-button",
|
|
2240
|
+
children: "\u27E8"
|
|
2241
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2242
|
+
className: "current-month-year",
|
|
2243
|
+
children: [t.months[currentMonth], " ", displayYear]
|
|
2244
|
+
}), jsxRuntimeExports.jsx("button", {
|
|
2245
|
+
type: "button",
|
|
2246
|
+
onClick: goToNextMonth,
|
|
2247
|
+
className: "nav-button",
|
|
2248
|
+
children: "\u27E9"
|
|
2249
|
+
}), jsxRuntimeExports.jsx("button", {
|
|
2250
|
+
type: "button",
|
|
2251
|
+
onClick: goToNextYear,
|
|
2252
|
+
className: "nav-button",
|
|
2253
|
+
children: "\u27EB"
|
|
2254
|
+
})]
|
|
2255
|
+
}), jsxRuntimeExports.jsx("div", {
|
|
2256
|
+
className: "weekdays",
|
|
2257
|
+
children: t.weekdaysShort.map((day, index) => jsxRuntimeExports.jsx("div", {
|
|
2258
|
+
className: "weekday",
|
|
2259
|
+
children: day
|
|
2260
|
+
}, index))
|
|
2261
|
+
}), jsxRuntimeExports.jsx("div", {
|
|
2262
|
+
className: "calendar-days",
|
|
2263
|
+
children: calendarDays.map((dateInfo, index) => {
|
|
2264
|
+
let actualDate;
|
|
2265
|
+
// Determine the correct date object for the day
|
|
2266
|
+
if (dateInfo.isCurrentMonth) {
|
|
2267
|
+
actualDate = new Date(currentYear, currentMonth, dateInfo.day);
|
|
2268
|
+
} else if (index < 7 && dateInfo.day > 20) {
|
|
2269
|
+
actualDate = new Date(currentYear, currentMonth - 1, dateInfo.day);
|
|
2270
|
+
} else {
|
|
2271
|
+
actualDate = new Date(currentYear, currentMonth + 1, dateInfo.day);
|
|
2272
|
+
}
|
|
2273
|
+
const isSelected = selectedDate && isSameDay(actualDate, selectedDate);
|
|
2274
|
+
const isToday = isSameDay(actualDate, today);
|
|
2275
|
+
const isDayDisabled = isDisabled(actualDate, disabledPast, disabledFuture);
|
|
2276
|
+
return jsxRuntimeExports.jsx("button", {
|
|
2277
|
+
type: "button",
|
|
2278
|
+
onClick: () => {
|
|
2279
|
+
if (dateInfo.isCurrentMonth) {
|
|
2280
|
+
handleDateSelect(dateInfo.day, currentYear, currentMonth);
|
|
2281
|
+
} else if (index < 7 && dateInfo.day > 20) {
|
|
2282
|
+
// Navigate to previous month and select date
|
|
2283
|
+
const prevMonth = currentMonth === 0 ? 11 : currentMonth - 1;
|
|
2284
|
+
const prevYear = currentMonth === 0 ? currentYear - 1 : currentYear;
|
|
2285
|
+
const newDate = new Date(prevYear, prevMonth, dateInfo.day);
|
|
2286
|
+
if (isDisabled(newDate, disabledPast, disabledFuture)) return;
|
|
2287
|
+
setCurrentMonth(prevMonth);
|
|
2288
|
+
setCurrentYear(prevYear);
|
|
2289
|
+
handleDateSelect(dateInfo.day, prevYear, prevMonth);
|
|
2290
|
+
} else {
|
|
2291
|
+
// Navigate to next month and select date
|
|
2292
|
+
const nextMonth = currentMonth === 11 ? 0 : currentMonth + 1;
|
|
2293
|
+
const nextYear = currentMonth === 11 ? currentYear + 1 : currentYear;
|
|
2294
|
+
const newDate = new Date(nextYear, nextMonth, dateInfo.day);
|
|
2295
|
+
if (isDisabled(newDate, disabledPast, disabledFuture)) return;
|
|
2296
|
+
setCurrentMonth(nextMonth);
|
|
2297
|
+
setCurrentYear(nextYear);
|
|
2298
|
+
handleDateSelect(dateInfo.day, nextYear, nextMonth);
|
|
2299
|
+
}
|
|
2300
|
+
},
|
|
2301
|
+
disabled: isDayDisabled,
|
|
2302
|
+
className: "\n calendar-day\n ".concat(dateInfo.isOtherMonth ? 'other-month' : '', "\n ").concat(isSelected ? 'selected' : '', "\n ").concat(isToday ? 'today' : '', "\n ").concat(isDayDisabled ? 'disabled' : '', "\n ").trim(),
|
|
2303
|
+
children: dateInfo.day
|
|
2304
|
+
}, index);
|
|
2305
|
+
})
|
|
2306
|
+
}), includeTime && jsxRuntimeExports.jsxs("div", {
|
|
2307
|
+
className: "time-picker",
|
|
2308
|
+
children: [jsxRuntimeExports.jsxs("div", {
|
|
2309
|
+
className: "time-picker-section",
|
|
2310
|
+
children: [jsxRuntimeExports.jsx("label", {
|
|
2311
|
+
children: t.hour
|
|
2312
|
+
}), jsxRuntimeExports.jsx("select", {
|
|
2313
|
+
value: timeHour,
|
|
2314
|
+
onChange: e => handleTimeChange('hour', parseInt(e.target.value)),
|
|
2315
|
+
className: "time-select",
|
|
2316
|
+
children: Array.from({
|
|
2317
|
+
length: 24
|
|
2318
|
+
}, (_, i) => jsxRuntimeExports.jsx("option", {
|
|
2319
|
+
value: i,
|
|
2320
|
+
children: String(i).padStart(2, '0')
|
|
2321
|
+
}, i))
|
|
2322
|
+
})]
|
|
2323
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2324
|
+
className: "time-picker-section",
|
|
2325
|
+
children: [jsxRuntimeExports.jsx("label", {
|
|
2326
|
+
children: t.minute
|
|
2327
|
+
}), jsxRuntimeExports.jsx("select", {
|
|
2328
|
+
value: timeMinute,
|
|
2329
|
+
onChange: e => handleTimeChange('minute', parseInt(e.target.value)),
|
|
2330
|
+
className: "time-select",
|
|
2331
|
+
children: Array.from({
|
|
2332
|
+
length: 60
|
|
2333
|
+
}, (_, i) => jsxRuntimeExports.jsx("option", {
|
|
2334
|
+
value: i,
|
|
2335
|
+
children: String(i).padStart(2, '0')
|
|
2336
|
+
}, i))
|
|
2337
|
+
})]
|
|
2338
|
+
})]
|
|
2339
|
+
}), jsxRuntimeExports.jsxs("div", {
|
|
2340
|
+
className: "calendar-footer",
|
|
2341
|
+
children: [showToday && jsxRuntimeExports.jsx("button", {
|
|
2342
|
+
type: "button",
|
|
2343
|
+
onClick: handleToday,
|
|
2344
|
+
disabled: isDisabled(today, disabledPast, disabledFuture),
|
|
2345
|
+
className: "footer-button today-button ".concat(isDisabled(today, disabledPast, disabledFuture) ? 'disabled' : ''),
|
|
2346
|
+
children: t.today
|
|
2347
|
+
}), showClear && jsxRuntimeExports.jsx("button", {
|
|
2348
|
+
type: "button",
|
|
2349
|
+
onClick: handleClear,
|
|
2350
|
+
className: "footer-button clear-button",
|
|
2351
|
+
children: t.clear
|
|
2352
|
+
}), includeTime && jsxRuntimeExports.jsx("button", {
|
|
2353
|
+
type: "button",
|
|
2354
|
+
onClick: handleConfirm,
|
|
2355
|
+
className: "footer-button confirm-button",
|
|
2356
|
+
children: t.ok
|
|
2357
|
+
})]
|
|
2358
|
+
})]
|
|
2359
|
+
})
|
|
2360
|
+
})]
|
|
2361
|
+
})]
|
|
2362
|
+
});
|
|
2363
|
+
};
|
|
2364
|
+
|
|
1826
2365
|
// Ensure React is available before importing components
|
|
1827
2366
|
|
|
1828
|
-
export { Button, Checkbox, Input, InputFile, Radio, Select, Textarea, cssClasses };
|
|
2367
|
+
export { Button, Checkbox, DatePicker, Input, InputFile, Radio, Select, Textarea, cssClasses };
|
|
1829
2368
|
//# sourceMappingURL=index.esm.js.map
|