@wwog/react 1.2.5 → 1.2.7
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 +410 -410
- package/dist/index.d.mts +95 -65
- package/dist/index.js +1 -1
- package/package.json +12 -6
- package/src/components/ProcessControl/Switch.tsx +2 -2
- package/src/components/ProcessControl/index.ts +4 -4
- package/src/components/Struct/index.ts +2 -2
- package/src/components/Sundry/Styles.test.tsx +128 -0
- package/src/components/Sundry/Styles.tsx +131 -0
- package/src/components/Sundry/index.ts +4 -4
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useControlled.ts +22 -27
- package/src/index.ts +9 -5
- package/src/utils/cx.test.ts +33 -0
- package/src/utils/cx.ts +25 -0
- package/src/utils/reactUtils.ts +22 -0
- package/src/utils/sundry.test.ts +130 -0
- package/src/utils/sundry.ts +130 -0
- package/src/components/Sundry/ClassName.tsx +0 -86
- package/src/utils/index.ts +0 -185
package/src/utils/index.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
/**
|
|
3
|
-
* @description 性能优化,替代 React.Children.forEach, 回调可以返回 false 来中断循环
|
|
4
|
-
* @description_en Replace React.Children.forEach, the callback can return false to interrupt the loop
|
|
5
|
-
*/
|
|
6
|
-
export function childrenLoop(
|
|
7
|
-
children: React.ReactNode | undefined,
|
|
8
|
-
callback: (child: React.ReactNode, index: number) => boolean | void
|
|
9
|
-
): void {
|
|
10
|
-
if (children === undefined) return;
|
|
11
|
-
let index = 0;
|
|
12
|
-
if (Array.isArray(children)) {
|
|
13
|
-
for (const child of children) {
|
|
14
|
-
const shouldContinue = callback(child, index++);
|
|
15
|
-
if (shouldContinue === false) {
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
} else {
|
|
20
|
-
callback(children, index);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param schema
|
|
26
|
-
* @example
|
|
27
|
-
* YY | 18 | Two-digit year
|
|
28
|
-
* YYYY | 2018 | Four-digit year
|
|
29
|
-
* M | 1-12 | The month, beginning at 1
|
|
30
|
-
* MM | 01-12 | The month, 2-digits
|
|
31
|
-
* MMM | Jan-Dec | The abbreviated month name
|
|
32
|
-
* MMMM | January-December | The full month name
|
|
33
|
-
* D | 1-31 | The day of the month
|
|
34
|
-
* DD | 01-31 | The day of the month, 2-digits
|
|
35
|
-
* d | 0-6 | The day of the week, with Sunday as 0
|
|
36
|
-
* dd | Su-Sa | The min name of the day of the week
|
|
37
|
-
* ddd | Sun-Sat | The short name of the day of the week
|
|
38
|
-
* dddd | Sunday-Saturday | The name of the day of the week
|
|
39
|
-
* H | 0-23 | The hour
|
|
40
|
-
* HH | 00-23 | The hour, 2-digits
|
|
41
|
-
* h | 1-12 | The hour, 12-hour clock
|
|
42
|
-
* hh | 01-12 | The hour, 12-hour clock, 2-digits
|
|
43
|
-
* m | 0-59 | The minute
|
|
44
|
-
* mm | 00-59 | The minute, 2-digits
|
|
45
|
-
* s | 0-59 | The second
|
|
46
|
-
* ss | 00-59 | The second, 2-digits
|
|
47
|
-
* SSS | 000-999 | The millisecond, 3-digits
|
|
48
|
-
* Z | +05:00 | The offset from UTC, ±HH:mm
|
|
49
|
-
* ZZ | +0500 | The offset from UTC, ±HHmm
|
|
50
|
-
* A | AM | PM
|
|
51
|
-
* a | am | pm
|
|
52
|
-
*/
|
|
53
|
-
export function formatDate(schema: string, date?: Date): string {
|
|
54
|
-
const d = date || new Date();
|
|
55
|
-
const year = d.getFullYear();
|
|
56
|
-
const month = d.getMonth() + 1;
|
|
57
|
-
const day = d.getDate();
|
|
58
|
-
const hour = d.getHours();
|
|
59
|
-
const minute = d.getMinutes();
|
|
60
|
-
const second = d.getSeconds();
|
|
61
|
-
const millisecond = d.getMilliseconds();
|
|
62
|
-
const week = d.getDay();
|
|
63
|
-
const weekName = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
64
|
-
const weekFullName = [
|
|
65
|
-
"Sunday",
|
|
66
|
-
"Monday",
|
|
67
|
-
"Tuesday",
|
|
68
|
-
"Wednesday",
|
|
69
|
-
"Thursday",
|
|
70
|
-
"Friday",
|
|
71
|
-
"Saturday",
|
|
72
|
-
];
|
|
73
|
-
const monthName = [
|
|
74
|
-
"Jan",
|
|
75
|
-
"Feb",
|
|
76
|
-
"Mar",
|
|
77
|
-
"Apr",
|
|
78
|
-
"May",
|
|
79
|
-
"Jun",
|
|
80
|
-
"Jul",
|
|
81
|
-
"Aug",
|
|
82
|
-
"Sep",
|
|
83
|
-
"Oct",
|
|
84
|
-
"Nov",
|
|
85
|
-
"Dec",
|
|
86
|
-
];
|
|
87
|
-
const monthFullName = [
|
|
88
|
-
"January",
|
|
89
|
-
"February",
|
|
90
|
-
"March",
|
|
91
|
-
"April",
|
|
92
|
-
"May",
|
|
93
|
-
"June",
|
|
94
|
-
"July",
|
|
95
|
-
"August",
|
|
96
|
-
"September",
|
|
97
|
-
"October",
|
|
98
|
-
"November",
|
|
99
|
-
"December",
|
|
100
|
-
];
|
|
101
|
-
const weekIndex = week === 0 ? 6 : week - 1;
|
|
102
|
-
const weekFull = weekFullName[weekIndex]!;
|
|
103
|
-
const weekShort = weekName[weekIndex]!;
|
|
104
|
-
const monthIndex = month - 1;
|
|
105
|
-
const monthFull = monthFullName[monthIndex]!;
|
|
106
|
-
const monthShort = monthName[monthIndex]!;
|
|
107
|
-
const map: Record<string, string> = {
|
|
108
|
-
YY: year.toString().slice(2),
|
|
109
|
-
YYYY: year.toString(),
|
|
110
|
-
M: month.toString(),
|
|
111
|
-
MM: month.toString().padStart(2, "0"),
|
|
112
|
-
MMM: monthShort,
|
|
113
|
-
MMMM: monthFull,
|
|
114
|
-
D: day.toString(),
|
|
115
|
-
DD: day.toString().padStart(2, "0"),
|
|
116
|
-
d: week.toString(),
|
|
117
|
-
dd: weekShort,
|
|
118
|
-
ddd: weekShort,
|
|
119
|
-
dddd: weekFull,
|
|
120
|
-
H: hour.toString(),
|
|
121
|
-
HH: hour.toString().padStart(2, "0"),
|
|
122
|
-
h: (hour % 12).toString(),
|
|
123
|
-
hh: (hour % 12).toString().padStart(2, "0"),
|
|
124
|
-
m: minute.toString(),
|
|
125
|
-
mm: minute.toString().padStart(2, "0"),
|
|
126
|
-
s: second.toString(),
|
|
127
|
-
ss: second.toString().padStart(2, "0"),
|
|
128
|
-
SSS: millisecond.toString().padStart(3, "0"),
|
|
129
|
-
Z: "+08:00",
|
|
130
|
-
ZZ: "+0800",
|
|
131
|
-
A: hour < 12 ? "AM" : "PM",
|
|
132
|
-
a: hour < 12 ? "am" : "pm",
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
return schema.replace(
|
|
136
|
-
/YYYY|YY|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|m{1,2}|s{1,2}|SSS|Z{1,2}|A|a/g,
|
|
137
|
-
(match) => {
|
|
138
|
-
return map[match]!;
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export class Counter {
|
|
144
|
-
count = 0;
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* @description 获取下一个计数值,不考虑越界。
|
|
148
|
-
* @description_en Get the next count value, without considering overflow.
|
|
149
|
-
*/
|
|
150
|
-
next() {
|
|
151
|
-
return this.count++;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export type CxInput =
|
|
156
|
-
| string
|
|
157
|
-
| string[]
|
|
158
|
-
| Record<string, boolean>
|
|
159
|
-
| undefined
|
|
160
|
-
| null
|
|
161
|
-
| false;
|
|
162
|
-
|
|
163
|
-
export function cx(...args: CxInput[]): string {
|
|
164
|
-
const classes = new Set<string>();
|
|
165
|
-
|
|
166
|
-
for (const arg of args) {
|
|
167
|
-
if (!arg) {
|
|
168
|
-
continue;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (typeof arg === "string") {
|
|
172
|
-
classes.add(arg);
|
|
173
|
-
} else if (Array.isArray(arg)) {
|
|
174
|
-
arg.forEach((item) => classes.add(item));
|
|
175
|
-
} else if (typeof arg === "object") {
|
|
176
|
-
for (const [key, value] of Object.entries(arg)) {
|
|
177
|
-
if (value) {
|
|
178
|
-
classes.add(key);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return Array.from(classes).join(" ");
|
|
185
|
-
}
|