ywana-core8 0.1.10 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ywana-core8",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
package/src/html/table.js CHANGED
@@ -165,11 +165,11 @@ const DataTableFiltersRow = ({ columns, onClear }) => {
165
165
 
166
166
  return (
167
167
  <tr className="filters-row">
168
- {columns.map(({ id, filterable, onFilter, options }) => {
168
+ {columns.map(({ id, filterable, onFilter, predictive=false, options }) => {
169
169
 
170
170
  const value = form[id] ? form[id] : ''
171
171
  const field = options ?
172
- <DropDown id={id} value={value} options={options} onChange={(id, value) => changeFilter(id, value, onFilter)} outlined />
172
+ <DropDown id={id} value={value} options={options} predictive={predictive} onChange={(id, value) => changeFilter(id, value, onFilter)} outlined />
173
173
  :
174
174
  <TextField id={id} value={value} onChange={(id, value) => changeFilter(id, value, onFilter)} outlined />
175
175
  return (
@@ -220,7 +220,6 @@ const DataTableCell = ({ index, row, column, cell, editable }) => {
220
220
  const render = (type) => {
221
221
  const { id, disabled = false, min, max, onChange, format, options, item, action, maxDecimals } = column
222
222
 
223
-
224
223
  if (id === "checked") {
225
224
  return row.checkDisabled ? null : <CheckBox id={id} value={cell} onChange={(id, value) => onChange(row.id, id, value)} />
226
225
  } else if (editable && onChange) {
@@ -92,6 +92,11 @@
92
92
  background-color: var(--secondary-color-lighter);
93
93
  }
94
94
 
95
+ .content-cell.drag-over {
96
+ background-color: var(--hover-color);
97
+ border: dashed 2px var(--accent-color);
98
+ }
99
+
95
100
  .row-header {
96
101
  position: sticky;
97
102
  left: 0px;
@@ -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 drop() {
45
- //TODO
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 className={`content-row ${lane.className}`} style={{ width: `${totalDaysWidth}rem` }}>
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
- onDrop={drop}
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", id);
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: "1", lane: "1", date: "2024-01-04", color: "yellow", title: "Event One" },
185
- { id: "1", lane: "1", date: "2024-01-05", color: "yellow", title: "Event One" },
186
- { id: "2", lane: "1", date: "2024-01-05", color: "red", title: "Event One" },
187
- { id: "3", lane: "1", date: "2024-01-05", color: "blue", title: "Event One" },
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
  }