tango-ui-cw 0.0.1 → 0.1.0
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/index.css +1 -0
- package/dist/index.js +10 -10
- package/dist/index.mjs +1459 -359
- package/package.json +6 -3
- package/src/component/TDate/index.jsx +2 -2
- package/src/component/TDatePicker/index.jsx +15 -3
package/package.json
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "tango-ui-cw",
|
3
|
-
"version": "0.0
|
3
|
+
"version": "0.1.0",
|
4
4
|
"description": "A lightweight ui library with ClayW",
|
5
5
|
"main": "dist/index.js",
|
6
|
-
"module": "dist/index.mjs",
|
6
|
+
"module": "dist/index.mjs",
|
7
7
|
"author": "ClayW",
|
8
8
|
"license": "MIT",
|
9
9
|
"scripts": {
|
@@ -32,6 +32,9 @@
|
|
32
32
|
],
|
33
33
|
"exports": {
|
34
34
|
"import": "./dist/index.mjs",
|
35
|
-
"require": "./dist/index.js"
|
35
|
+
"require": "./dist/index.js"
|
36
|
+
},
|
37
|
+
"dependencies": {
|
38
|
+
"prop-types": "^15.8.1"
|
36
39
|
}
|
37
40
|
}
|
@@ -4,7 +4,7 @@ import "./TDate.css";
|
|
4
4
|
import { useTangoStyle } from "../CSSFab/useTangoStyle"; // 导入 useFastStyle 函数
|
5
5
|
|
6
6
|
export default function Date(props) {
|
7
|
-
const { type, single, sx = {}, style: userStyle = {}, en } = props;
|
7
|
+
const { type = "default", single = false, sx = {}, style: userStyle = {}, en = false } = props|| {};
|
8
8
|
|
9
9
|
// 用于接收 sx 属性设置的样式
|
10
10
|
const sxStyle = useTangoStyle(sx);
|
@@ -32,7 +32,7 @@ export default function Date(props) {
|
|
32
32
|
};
|
33
33
|
|
34
34
|
Date.defaultProps = {
|
35
|
-
type:
|
35
|
+
type: "default", // 默认无 type 的格式
|
36
36
|
single: false, // 默认显示 "星期"
|
37
37
|
sx: {},
|
38
38
|
style: {},
|
@@ -15,14 +15,27 @@ export default function DatePicker(props) {
|
|
15
15
|
|
16
16
|
const [value, setValue] = useState("");
|
17
17
|
|
18
|
+
// 格式化日期函数
|
19
|
+
const formatDate = (date) => {
|
20
|
+
const d = new Date(date);
|
21
|
+
const year = d.getFullYear();
|
22
|
+
const month = (d.getMonth() + 1).toString().padStart(2, "0");
|
23
|
+
const day = d.getDate().toString().padStart(2, "0");
|
24
|
+
const hours = d.getHours().toString().padStart(2, "0");
|
25
|
+
const minutes = d.getMinutes().toString().padStart(2, "0");
|
26
|
+
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
27
|
+
};
|
28
|
+
|
18
29
|
const handleChange = (e) => {
|
19
30
|
const val = e.target.value;
|
20
31
|
setValue(val);
|
21
|
-
|
32
|
+
|
33
|
+
// 如果选择了时间,格式化并调用 onChange
|
34
|
+
const formattedValue = time ? formatDate(val) : val;
|
35
|
+
if (onChange) onChange(formattedValue, val); // 格式化后传递给 onChange
|
22
36
|
};
|
23
37
|
|
24
38
|
const inputType = time ? "datetime-local" : "date";
|
25
|
-
|
26
39
|
const className = `date-picker ${disabled ? "date-picker-disabled" : ""} ${userClassName}`;
|
27
40
|
|
28
41
|
const sxStyle = useTangoStyle(sx);
|
@@ -57,4 +70,3 @@ DatePicker.defaultProps = {
|
|
57
70
|
onChange: () => {},
|
58
71
|
time: false,
|
59
72
|
};
|
60
|
-
|