@kkkarsss/ui 1.1.5 → 1.1.6
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/ui/information/calendar-like/calendar-hour-slot.d.ts +1 -1
- package/dist/ui/information/calendar-like/calendar-hour-slot.js +21 -1
- package/dist/ui/information/calendar-like/calendar-item-wrapper.js +7 -7
- package/dist/ui/information/calendar-like/calendar-like.js +2 -2
- package/dist/ui/information/calendar-like/types.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FC, type DragEvent, ReactNode } from 'react';
|
|
2
2
|
export type TCalendarHourSlotProps = {
|
|
3
3
|
hour: number;
|
|
4
|
-
onDrop?: (e: DragEvent<HTMLDivElement>, hour: number) => void;
|
|
4
|
+
onDrop?: (e: DragEvent<HTMLDivElement>, hour: number, minutes: number) => void;
|
|
5
5
|
onCreateTask?: (hour: number, minutes: number, estimatedTime: number) => void;
|
|
6
6
|
children?: ReactNode;
|
|
7
7
|
};
|
|
@@ -3,8 +3,25 @@ import { useState } from 'react';
|
|
|
3
3
|
import { Typo } from '../text/typo';
|
|
4
4
|
export const CalendarHourSlot = ({ hour, onDrop, onCreateTask, children }) => {
|
|
5
5
|
const [selection, setSelection] = useState(null);
|
|
6
|
+
const [dragOverMinutes, setDragOverMinutes] = useState(null);
|
|
6
7
|
const handleDragOver = (e) => {
|
|
7
8
|
e.preventDefault();
|
|
9
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
10
|
+
const offsetY = e.clientY - rect.top;
|
|
11
|
+
const minutes = Math.floor(offsetY / 20) * 15;
|
|
12
|
+
if (minutes !== dragOverMinutes) {
|
|
13
|
+
setDragOverMinutes(minutes);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const handleDragLeave = () => {
|
|
17
|
+
setDragOverMinutes(null);
|
|
18
|
+
};
|
|
19
|
+
const handleInternalDrop = (e) => {
|
|
20
|
+
setDragOverMinutes(null);
|
|
21
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
22
|
+
const offsetY = e.clientY - rect.top;
|
|
23
|
+
const minutes = Math.floor(offsetY / 20) * 15;
|
|
24
|
+
onDrop?.(e, hour, minutes);
|
|
8
25
|
};
|
|
9
26
|
const handleMouseDown = (e) => {
|
|
10
27
|
if (e.button !== 0 || !onCreateTask)
|
|
@@ -37,7 +54,10 @@ export const CalendarHourSlot = ({ hour, onDrop, onCreateTask, children }) => {
|
|
|
37
54
|
document.addEventListener('mousemove', onMouseMove);
|
|
38
55
|
document.addEventListener('mouseup', onMouseUp);
|
|
39
56
|
};
|
|
40
|
-
return (_jsxs("div", { onDragOver: handleDragOver,
|
|
57
|
+
return (_jsxs("div", { onDragOver: handleDragOver, onDragLeave: handleDragLeave, onDrop: handleInternalDrop, onMouseDown: handleMouseDown, className: "relative h-20 border-b border-secondary-foreground group hover:z-10 has-[.calendar-item:hover]:z-30 has-[.calendar-item:active]:z-30", children: [_jsx("div", { className: "absolute -left-12 top-0 -translate-y-1/2 w-10 text-right", children: _jsxs(Typo, { size: "xs", color: "secondary", children: [String(hour).padStart(2, '0'), ":00"] }) }), _jsxs("div", { className: "pl-4 py-1 relative h-full", children: [children, dragOverMinutes !== null && (_jsx("div", { className: "absolute left-4 right-1 bg-accent/10 border border-dashed border-accent/50 rounded-sm z-[40] pointer-events-none", style: {
|
|
58
|
+
top: `${(dragOverMinutes / 60) * 80}px`,
|
|
59
|
+
height: '20px',
|
|
60
|
+
} })), selection && (_jsx("div", { className: "absolute left-4 right-1 bg-accent/30 border border-accent rounded-sm z-[40] pointer-events-none", style: {
|
|
41
61
|
top: `${(selection.startMinutes / 60) * 80}px`,
|
|
42
62
|
height: `${(selection.currentEstimatedTime / 60) * 80}px`,
|
|
43
63
|
}, children: _jsxs("div", { className: "p-1", children: [_jsx(Typo, { size: "xs", weight: "500", children: "\u041D\u043E\u0432\u0430\u044F \u0437\u0430\u0434\u0430\u0447\u0430" }), _jsxs(Typo, { size: "xs", color: "secondary", children: [selection.currentEstimatedTime, " \u043C\u0438\u043D"] })] }) }))] })] }));
|
|
@@ -38,15 +38,15 @@ export const CalendarItemWrapper = ({ task, position, onDragStart, onResize, ren
|
|
|
38
38
|
const displayHeight = previewEstimatedTime ? `${(previewEstimatedTime / 60) * 80}px` : position.height;
|
|
39
39
|
return (_jsx("div", { draggable: !!onDragStart, onDragStart: (e) => {
|
|
40
40
|
onDragStart?.(e, task.id);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}, 0);
|
|
41
|
+
const el = e.currentTarget;
|
|
42
|
+
if (el) {
|
|
43
|
+
el.style.opacity = '0.4';
|
|
44
|
+
}
|
|
46
45
|
}, onDragEnd: (e) => {
|
|
47
46
|
const el = e.currentTarget;
|
|
48
|
-
if (el)
|
|
49
|
-
el.style.
|
|
47
|
+
if (el) {
|
|
48
|
+
el.style.opacity = '';
|
|
49
|
+
}
|
|
50
50
|
}, style: {
|
|
51
51
|
height: displayHeight,
|
|
52
52
|
width: position.width,
|
|
@@ -13,10 +13,10 @@ export const CalendarLike = ({ tasks, hours = DEFAULT_HOURS, renderTask, onTaskD
|
|
|
13
13
|
const handleDragStart = (e, taskId) => {
|
|
14
14
|
e.dataTransfer.setData('taskId', taskId);
|
|
15
15
|
};
|
|
16
|
-
const handleDrop = (e, hour) => {
|
|
16
|
+
const handleDrop = (e, hour, minutes) => {
|
|
17
17
|
const taskId = e.dataTransfer.getData('taskId');
|
|
18
18
|
if (taskId && onTaskDrop) {
|
|
19
|
-
onTaskDrop(taskId, hour);
|
|
19
|
+
onTaskDrop(taskId, hour, minutes);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
return (_jsx("div", { className: "relative border-l border-secondary/20 ml-12 select-none", children: hours.map((hour) => {
|
|
@@ -17,7 +17,7 @@ export type TCalendarLikeProps = {
|
|
|
17
17
|
tasks: TCalendarTask[];
|
|
18
18
|
hours?: number[];
|
|
19
19
|
renderTask: (task: TCalendarTask) => ReactNode;
|
|
20
|
-
onTaskDrop?: (taskId: string, hour: number) => void;
|
|
20
|
+
onTaskDrop?: (taskId: string, hour: number, minutes: number) => void;
|
|
21
21
|
onTaskResize?: (taskId: string, newEstimatedTime: number) => void;
|
|
22
22
|
onTaskClick?: (taskId: string) => void;
|
|
23
23
|
onCreateTask?: (hour: number, minutes: number, estimatedTime: number) => void;
|