mantine-gantt 0.6.0 → 0.6.1

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.
@@ -15,6 +15,7 @@ var utils = require('./utils.cjs');
15
15
  var Gantt_module = require('./Gantt.module.css.cjs');
16
16
 
17
17
  const DRAG_BUFFER_DAYS = 30;
18
+ const MIN_TIMELINE_WIDTH = 240;
18
19
  const EMPTY_CRITICAL = /* @__PURE__ */ new Set();
19
20
  const FLEX_COLUMN_WIDTH = 200;
20
21
  const FLEX_COLUMN_MIN_WIDTH = 100;
@@ -71,6 +72,9 @@ const Gantt = core.factory((_props, ref) => {
71
72
  columnWidth = 40,
72
73
  rowHeight = 44,
73
74
  taskListWidth,
75
+ taskListCollapsed,
76
+ defaultTaskListCollapsed,
77
+ onTaskListCollapsedChange,
74
78
  showTitle,
75
79
  showTodayMarker,
76
80
  autoSchedule,
@@ -165,10 +169,20 @@ const Gantt = core.factory((_props, ref) => {
165
169
  const [announcement, setAnnouncement] = React.useState("");
166
170
  const [viewport, setViewport] = React.useState({ width: 0, height: 0 });
167
171
  const [scrollTop, setScrollTop] = React.useState(0);
172
+ const [narrow, setNarrow] = React.useState(false);
173
+ const [collapsedChoice, setCollapsedChoice] = hooks.useUncontrolled({
174
+ value: taskListCollapsed,
175
+ defaultValue: defaultTaskListCollapsed,
176
+ onChange: onTaskListCollapsedChange
177
+ });
178
+ const listCollapsed = collapsedChoice ?? narrow;
179
+ const listWidth = resolveTaskListWidth(taskListWidth, columns);
168
180
  const timelineBodyRef = React.useRef(null);
169
181
  const taskListBodyRef = React.useRef(null);
170
182
  const timelineHeaderRef = React.useRef(null);
171
183
  const timelineContentRef = React.useRef(null);
184
+ const rootRef = React.useRef(null);
185
+ const mergedRootRef = hooks.useMergedRef(ref, rootRef);
172
186
  const drag = useGanttDrag.useGanttDrag({
173
187
  tasks,
174
188
  commitTasks: setTasks,
@@ -245,20 +259,30 @@ const Gantt = core.factory((_props, ref) => {
245
259
  }, []);
246
260
  React.useEffect(() => {
247
261
  const node = timelineBodyRef.current;
248
- if (!node) {
262
+ const root = rootRef.current;
263
+ if (!node || !root) {
249
264
  return void 0;
250
265
  }
251
266
  setViewport({ width: node.clientWidth, height: node.clientHeight });
267
+ const measureRoot = (width) => setNarrow(width > 0 && width < listWidth + MIN_TIMELINE_WIDTH);
268
+ measureRoot(root.clientWidth);
252
269
  if (typeof ResizeObserver === "undefined") {
253
270
  return void 0;
254
271
  }
255
272
  const observer = new ResizeObserver((entries) => {
256
- const { width, height } = entries[0].contentRect;
257
- setViewport({ width, height });
273
+ for (const entry of entries) {
274
+ const { width, height } = entry.contentRect;
275
+ if (entry.target === root) {
276
+ measureRoot(width);
277
+ } else {
278
+ setViewport({ width, height });
279
+ }
280
+ }
258
281
  });
259
282
  observer.observe(node);
283
+ observer.observe(root);
260
284
  return () => observer.disconnect();
261
- }, []);
285
+ }, [listWidth]);
262
286
  const zoomAnchorRef = React.useRef(0);
263
287
  const zoomRef = React.useRef({ width: baseColumnWidth, onChange: onColumnWidthChange });
264
288
  zoomRef.current = { width: baseColumnWidth, onChange: onColumnWidthChange };
@@ -418,7 +442,7 @@ const Gantt = core.factory((_props, ref) => {
418
442
  const today = dayjs();
419
443
  const todayPosition = utils.dateToPixel(today, bounds.start, effectiveColumnWidth);
420
444
  const showTodayLine = showTodayMarker && today.isAfter(bounds.start) && today.isBefore(displayEnd);
421
- return /* @__PURE__ */ React.createElement(core.Box, { ref, ...getStyles("root"), ...others }, /* @__PURE__ */ React.createElement(
445
+ return /* @__PURE__ */ React.createElement(core.Box, { ref: mergedRootRef, ...getStyles("root"), ...others }, /* @__PURE__ */ React.createElement(
422
446
  TaskList.TaskList,
423
447
  {
424
448
  rows: visibleRows,
@@ -431,7 +455,9 @@ const Gantt = core.factory((_props, ref) => {
431
455
  onToggleExpand: toggleExpand,
432
456
  offsetTop: firstRow * rowHeight,
433
457
  contentHeight: rows.length * rowHeight,
434
- selectedTaskId
458
+ selectedTaskId,
459
+ collapsed: listCollapsed,
460
+ onToggleCollapsed: () => setCollapsedChoice(!listCollapsed)
435
461
  }
436
462
  ), /* @__PURE__ */ React.createElement("div", { ...getStyles("timeline") }, /* @__PURE__ */ React.createElement("div", { ...getStyles("timelineHeader"), ref: timelineHeaderRef }, /* @__PURE__ */ React.createElement(
437
463
  TimelineHeader.TimelineHeader,