funda-ui 4.7.202 → 4.7.222
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/Date/index.js +20 -12
- package/README.md +205 -0
- package/Select/index.d.ts +20 -9
- package/Select/index.js +408 -345
- package/Table/index.js +69 -16
- package/Utils/time.d.ts +2 -0
- package/Utils/time.js +25 -20
- package/lib/cjs/Date/index.js +20 -12
- package/lib/cjs/Select/index.d.ts +20 -9
- package/lib/cjs/Select/index.js +408 -345
- package/lib/cjs/Table/index.js +69 -16
- package/lib/cjs/Utils/time.d.ts +2 -0
- package/lib/cjs/Utils/time.js +25 -20
- package/lib/esm/Date/index.tsx +24 -10
- package/lib/esm/Select/index.tsx +45 -18
- package/lib/esm/Table/Table.tsx +37 -2
- package/lib/esm/Table/TableCell.tsx +2 -2
- package/lib/esm/Table/utils/func.ts +2 -2
- package/lib/esm/Table/utils/hooks/useTableKeyPress.tsx +28 -6
- package/lib/esm/Utils/libs/time.ts +24 -22
- package/package.json +1 -1
|
@@ -22,7 +22,8 @@ const App = () => {
|
|
|
22
22
|
refNode,
|
|
23
23
|
focusableCellId,
|
|
24
24
|
setFocusableCellId,
|
|
25
|
-
onCellKeyPressed
|
|
25
|
+
onCellKeyPressed,
|
|
26
|
+
onCellPressEnter,
|
|
26
27
|
}, [rootRef]);
|
|
27
28
|
|
|
28
29
|
|
|
@@ -50,6 +51,7 @@ export interface UseTableKeyPressProps {
|
|
|
50
51
|
focusableCellId: string;
|
|
51
52
|
setFocusableCellId: (s: string) => void;
|
|
52
53
|
onCellKeyPressed: (classname: string, elem: HTMLTableCellElement, event: KeyboardEvent) => void;
|
|
54
|
+
onCellPressEnter: (classname: string, elem: HTMLTableCellElement, event: KeyboardEvent) => void;
|
|
53
55
|
onKeyDown?: (e: any) => void;
|
|
54
56
|
}
|
|
55
57
|
|
|
@@ -64,13 +66,24 @@ const useTableKeyPress = ({
|
|
|
64
66
|
focusableCellId,
|
|
65
67
|
setFocusableCellId,
|
|
66
68
|
onCellKeyPressed,
|
|
69
|
+
onCellPressEnter,
|
|
67
70
|
onKeyDown
|
|
68
71
|
}: UseTableKeyPressProps, deps: any[]) => {
|
|
69
72
|
|
|
70
73
|
const handleKeyPressed = useCallback( async (event: KeyboardEvent<HTMLTableCellElement>) => {
|
|
74
|
+
const key = event.code;
|
|
75
|
+
|
|
76
|
+
if ((key === 'Enter' || key === 'NumpadEnter') && !enabled) {
|
|
77
|
+
const currentCell = event.target as HTMLTableCellElement;
|
|
78
|
+
const row = Number(currentCell.getAttribute('data-table-row'));
|
|
79
|
+
const col = Number(currentCell.getAttribute('data-table-col'));
|
|
80
|
+
const nextCellSignal: string = cellMark(row, col);
|
|
81
|
+
onCellPressEnter?.(nextCellSignal, refNode.current.get(nextCellSignal), event);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
|
|
71
85
|
if (!Array.isArray(data) || rootDataInfo === null || spyElement === null || typeof enabled === 'undefined' || enabled === false) return;
|
|
72
86
|
|
|
73
|
-
const key = event.code;
|
|
74
87
|
const oldCellSignal = focusableCellId?.replace('cell-', '').split('-');
|
|
75
88
|
let _row = Number(oldCellSignal[0]);
|
|
76
89
|
let _col = Number(oldCellSignal[1]);
|
|
@@ -80,15 +93,19 @@ const useTableKeyPress = ({
|
|
|
80
93
|
|
|
81
94
|
switch (key) {
|
|
82
95
|
case 'ArrowLeft':
|
|
96
|
+
case 'Numpad4':
|
|
83
97
|
_col = _col - 1 < 0 ? 0 : _col - 1;
|
|
84
98
|
break;
|
|
85
99
|
case 'ArrowRight':
|
|
100
|
+
case 'Numpad6':
|
|
86
101
|
_col = _col + 1 > data.length - 1 ? data.length -1 : _col + 1;
|
|
87
102
|
break;
|
|
88
103
|
case 'ArrowUp':
|
|
104
|
+
case 'Numpad8':
|
|
89
105
|
_row = _row - 1 < 0 ? 0 : _row - 1;
|
|
90
106
|
break;
|
|
91
107
|
case 'ArrowDown':
|
|
108
|
+
case 'Numpad2':
|
|
92
109
|
_row = _row + 1 > rootDataInfo.totalRow - 1 ? rootDataInfo.totalRow - 1 : _row + 1;
|
|
93
110
|
break;
|
|
94
111
|
}
|
|
@@ -109,23 +126,28 @@ const useTableKeyPress = ({
|
|
|
109
126
|
|
|
110
127
|
};
|
|
111
128
|
|
|
112
|
-
if (key === 'ArrowLeft') {
|
|
129
|
+
if (key === 'ArrowLeft' || key === 'Numpad4') {
|
|
113
130
|
move('ArrowLeft');
|
|
114
131
|
}
|
|
115
132
|
|
|
116
|
-
if (key === 'ArrowRight') {
|
|
133
|
+
if (key === 'ArrowRight' || key === 'Numpad6') {
|
|
117
134
|
move('ArrowRight');
|
|
118
135
|
}
|
|
119
136
|
|
|
120
137
|
|
|
121
|
-
if (key === 'ArrowUp') {
|
|
138
|
+
if (key === 'ArrowUp' || key === 'Numpad8') {
|
|
122
139
|
move('ArrowUp');
|
|
123
140
|
}
|
|
124
141
|
|
|
125
|
-
if (key === 'ArrowDown') {
|
|
142
|
+
if (key === 'ArrowDown' || key === 'Numpad2') {
|
|
126
143
|
move('ArrowDown');
|
|
127
144
|
}
|
|
128
145
|
|
|
146
|
+
if (key === 'Enter' || key === 'NumpadEnter') {
|
|
147
|
+
const nextCellSignal: string = cellMark(_row, _col);
|
|
148
|
+
onCellPressEnter?.(nextCellSignal, refNode.current.get(nextCellSignal), event);
|
|
149
|
+
}
|
|
150
|
+
|
|
129
151
|
}, [focusableCellId]);
|
|
130
152
|
|
|
131
153
|
useEffect(() => {
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
console.log(getTimeslots("10:00", "14:00", 60, true)); //['10:00 - 11:00', '11:00 - 12:00', '12:00 - 13:00', '13:00 - 14:00']
|
|
11
11
|
console.log(getTimeslots("10:00", "14:00", 60)); // ['10:00', '11:00', '12:00', '13:00']
|
|
12
|
+
console.log(getTimeslots("08:00:00", "08:02:00", 0.4)); // ['08:00:00', '08:00:24', '08:00:48', '08:01:12', '08:01:36', '08:02:00']
|
|
13
|
+
|
|
12
14
|
*/
|
|
13
15
|
|
|
14
16
|
function getTimeslots(
|
|
@@ -17,49 +19,49 @@ function getTimeslots(
|
|
|
17
19
|
timeInterval: number,
|
|
18
20
|
formatRange: boolean = false
|
|
19
21
|
): string[] {
|
|
22
|
+
// Parse time string to seconds
|
|
20
23
|
const parseTime = (s: string): number => {
|
|
21
|
-
const c = s.split(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const convertHours = (mins: number): string => {
|
|
26
|
-
const hour = Math.floor(mins / 60);
|
|
27
|
-
mins = Math.trunc(mins % 60);
|
|
28
|
-
const converted = pad(hour, 2) + ':' + pad(mins, 2);
|
|
29
|
-
return converted;
|
|
24
|
+
const c = s.split(":").map(Number);
|
|
25
|
+
// Support HH:mm or HH:mm:ss
|
|
26
|
+
return c[0] * 3600 + c[1] * 60 + (c[2] || 0);
|
|
30
27
|
}
|
|
31
28
|
|
|
29
|
+
// Pad with zeros
|
|
32
30
|
const pad = (str: string | number, max: number): string => {
|
|
33
31
|
str = str.toString();
|
|
34
32
|
return str.length < max ? pad("0" + str, max) : str;
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
//
|
|
35
|
+
// Convert seconds to HH:mm:ss
|
|
36
|
+
const convertTime = (secs: number): string => {
|
|
37
|
+
const hour = Math.floor(secs / 3600);
|
|
38
|
+
const min = Math.floor((secs % 3600) / 60);
|
|
39
|
+
const sec = secs % 60;
|
|
40
|
+
return pad(hour, 2) + ":" + pad(min, 2) + ":" + pad(sec, 2);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Calculate time slots
|
|
38
44
|
const calculateTimeSlot = (_startTime: number, _endTime: number, _timeInterval: number): string[] => {
|
|
39
45
|
const timeSlots: string[] = [];
|
|
40
|
-
// Round start and end times to next 30 min interval
|
|
41
|
-
_startTime = Math.ceil(_startTime / 30) * 30;
|
|
42
|
-
_endTime = Math.ceil(_endTime / 30) * 30;
|
|
43
|
-
|
|
44
|
-
// Start and end of interval in the loop
|
|
45
46
|
let currentTime = _startTime;
|
|
46
|
-
while (currentTime
|
|
47
|
+
while (currentTime <= _endTime) {
|
|
47
48
|
if (formatRange) {
|
|
48
|
-
const t =
|
|
49
|
+
const t = convertTime(currentTime) + ' - ' + convertTime(Math.min(currentTime + _timeInterval, _endTime));
|
|
49
50
|
timeSlots.push(t);
|
|
50
51
|
} else {
|
|
51
|
-
timeSlots.push(
|
|
52
|
+
timeSlots.push(convertTime(currentTime));
|
|
52
53
|
}
|
|
53
54
|
currentTime += _timeInterval;
|
|
54
55
|
}
|
|
55
56
|
return timeSlots;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
const inputEndTime = parseTime(endTime);
|
|
59
59
|
const inputStartTime = parseTime(startTime);
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
const inputEndTime = parseTime(endTime);
|
|
61
|
+
// If timeInterval is not an integer, treat as minutes with decimals, convert to seconds
|
|
62
|
+
const isDecimal = !Number.isInteger(timeInterval);
|
|
63
|
+
const intervalInSeconds = isDecimal ? Math.round(timeInterval * 60) : timeInterval * 60;
|
|
64
|
+
return calculateTimeSlot(inputStartTime, inputEndTime, intervalInSeconds);
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "UIUX Lab",
|
|
3
3
|
"email": "uiuxlab@gmail.com",
|
|
4
4
|
"name": "funda-ui",
|
|
5
|
-
"version": "4.7.
|
|
5
|
+
"version": "4.7.222",
|
|
6
6
|
"description": "React components using pure Bootstrap 5+ which does not contain any external style and script libraries.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|