ywana-core8 0.1.11 → 0.1.12
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.cjs +56 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.css +5 -0
- package/dist/index.css.map +1 -1
- package/dist/index.modern.js +56 -25
- package/dist/index.modern.js.map +1 -1
- package/dist/index.umd.js +56 -25
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/incubator/planner.css +5 -0
- package/src/incubator/planner.js +36 -20
package/package.json
CHANGED
package/src/incubator/planner.js
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
import React, { useEffect, useState } from 'react'
|
2
2
|
import "./planner.css"
|
3
3
|
|
4
|
-
export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, rowHeaderWidth = 10, rowHeaderTitle, EventRenderer, onSelectCell, hideEmptyRows=false}) => {
|
4
|
+
export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, rowHeaderWidth = 10, rowHeaderTitle, EventRenderer, onSelectCell, onCellDrop, hideEmptyRows=false}) => {
|
5
5
|
|
6
6
|
const [days, setDays] = useState([]);
|
7
7
|
const lastDay = new Date(to);
|
8
8
|
const today = new Date();
|
9
|
+
const [dragOverCell, setDragOverCell] = useState(null);
|
9
10
|
|
10
11
|
useEffect(() => {
|
11
12
|
const day = new Date(from);
|
@@ -41,10 +42,24 @@ export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, ro
|
|
41
42
|
if (onSelectCell) onSelectCell(cell)
|
42
43
|
}
|
43
44
|
|
44
|
-
function
|
45
|
-
|
45
|
+
function onDragOver(event) {
|
46
|
+
event.preventDefault();
|
47
|
+
setDragOverCell(event.target.id);
|
46
48
|
}
|
47
49
|
|
50
|
+
function onDragLeave(event) {
|
51
|
+
event.preventDefault();
|
52
|
+
setDragOverCell(null);
|
53
|
+
}
|
54
|
+
|
55
|
+
function drop(event, { lane, date }) {
|
56
|
+
event.preventDefault();
|
57
|
+
const data = event.dataTransfer.getData("text");
|
58
|
+
if (onCellDrop) onCellDrop({ data, lane, date });
|
59
|
+
setDragOverCell(null);
|
60
|
+
}
|
61
|
+
|
62
|
+
|
48
63
|
const uniqueMonths = Array.from(
|
49
64
|
new Set(days.map(({ month }) => month))
|
50
65
|
);
|
@@ -119,7 +134,9 @@ export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, ro
|
|
119
134
|
}
|
120
135
|
|
121
136
|
return (
|
122
|
-
<div
|
137
|
+
<div
|
138
|
+
key={`content-row-${index}`}
|
139
|
+
className={`content-row ${lane.className}`} style={{ width: `${totalDaysWidth}rem` }}>
|
123
140
|
<div className="row-header" style={{ minWidth: `${rowHeaderWidth}rem`, maxWidth: `${rowHeaderWidth}rem` }} >
|
124
141
|
{lane.title}
|
125
142
|
</div>
|
@@ -132,12 +149,15 @@ export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, ro
|
|
132
149
|
eventDate.getFullYear() === dayDate.getFullYear();
|
133
150
|
});
|
134
151
|
const weekendClass = isWeekend ? 'weekend' : '';
|
152
|
+
const dragOverStyle = dragOverCell === `cell${index}_${year}-${month}-${day}` ? 'drag-over' : '';
|
135
153
|
return (
|
136
154
|
<div
|
155
|
+
id={`cell${index}_${year}-${month}-${day}`}
|
137
156
|
key={`content${index}_${year}-${month}-${day}`}
|
138
|
-
className={`content-cell ${weekendClass}`} style={{ minWidth: dayWidth, maxWidth: dayWidth }}
|
157
|
+
className={`content-cell ${weekendClass} ${dragOverStyle}`} style={{ minWidth: dayWidth, maxWidth: dayWidth }}
|
139
158
|
onClick={() => selectCell({ lane: lane.id, date: dayDate })}
|
140
|
-
|
159
|
+
onDragOver={onDragOver} onDragLeave={onDragLeave}
|
160
|
+
onDrop={(event) => drop(event, { lane: lane.id, date: dayDate })}
|
141
161
|
>
|
142
162
|
{dayEvents.map((event, index) => <EventRenderer key={`${event.id}-${index}`} event={event} />)}
|
143
163
|
</div>
|
@@ -155,7 +175,7 @@ const EventCard = (props) => {
|
|
155
175
|
const { id, title, color } = event
|
156
176
|
|
157
177
|
function drag(ev) {
|
158
|
-
ev.dataTransfer.setData("text",
|
178
|
+
ev.dataTransfer.setData("text", title);
|
159
179
|
}
|
160
180
|
|
161
181
|
let style = { backgroundColor: event.color, color: "white" }
|
@@ -181,23 +201,19 @@ const CalendarTest = (props) => {
|
|
181
201
|
|
182
202
|
const events = [
|
183
203
|
{ id: "1", lane: "1", date: "2024-01-04", color: "yellow", title: "Event One" },
|
184
|
-
{ id: "
|
185
|
-
{ id: "
|
186
|
-
{ id: "
|
187
|
-
{ id: "
|
188
|
-
{ id: "4", lane: "1", date: "2024-01-05", color: "red", title: "Event One" },
|
189
|
-
{ id: "5", lane: "2", date: "2024-01-04", color: "yellow", title: "Event One" },
|
190
|
-
{ id: "6", lane: "2", date: "2024-01-05", color: "red", title: "Event One" },
|
191
|
-
{ id: "7", lane: "2", date: "2024-01-06", color: "blue", title: "Event One" },
|
192
|
-
{ id: "8", lane: "2", date: "2024-01-07", color: "red", title: "Event One" },
|
193
|
-
{ id: "9", lane: "3", date: "2024-01-04", color: "yellow", title: "Event One" },
|
194
|
-
{ id: "10", lane: "3", date: "2024-01-05", color: "red", title: "Event One" },
|
195
|
-
{ id: "11", lane: "3", date: "2024-01-06", color: "blue", title: "Event One" },
|
204
|
+
{ id: "2", lane: "1", date: "2024-01-05", color: "green", title: "Event Two" },
|
205
|
+
{ id: "3", lane: "2", date: "2024-01-06", color: "blue", title: "Event Three" },
|
206
|
+
{ id: "4", lane: "2", date: "2024-01-07", color: "red", title: "Event Four" },
|
207
|
+
{ id: "5", lane: "3", date: "2024-01-08", color: "purple", title: "Event Five" },
|
196
208
|
]
|
197
209
|
|
210
|
+
function onDrop({ data, lane, date }) {
|
211
|
+
console.log(`Dropped ${data} on lane ${lane} date ${date}`);
|
212
|
+
}
|
213
|
+
|
198
214
|
return (
|
199
215
|
<>
|
200
|
-
<Planner2 from="2024-01-01" to="2024-02-01" lanes={lanes} events={events} EventRenderer={EventCard} hideEmptyRows />
|
216
|
+
<Planner2 from="2024-01-01" to="2024-02-01" lanes={lanes} events={events} EventRenderer={EventCard} hideEmptyRows onCellDrop={onDrop} />
|
201
217
|
</>
|
202
218
|
)
|
203
219
|
}
|