@dust-tt/sparkle 0.2.629 → 0.2.630

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.
@@ -236,9 +236,13 @@ export function DataTable<TData extends TBaseData>({
236
236
  <DataTable.Head
237
237
  column={header.column}
238
238
  key={header.id}
239
- onClick={header.column.getToggleSortingHandler()}
239
+ onClick={
240
+ header.column.getCanSort()
241
+ ? header.column.getToggleSortingHandler()
242
+ : undefined
243
+ }
240
244
  className={cn(
241
- header.column.getCanSort() ? "s-cursor-pointer" : ""
245
+ header.column.getCanSort() && "s-cursor-pointer"
242
246
  )}
243
247
  >
244
248
  <div className="s-flex s-items-center s-space-x-1 s-whitespace-nowrap">
@@ -251,9 +255,7 @@ export function DataTable<TData extends TBaseData>({
251
255
  visual={
252
256
  header.column.getIsSorted() === "asc"
253
257
  ? ArrowUpIcon
254
- : header.column.getIsSorted() === "desc"
255
- ? ArrowDownIcon
256
- : ArrowDownIcon
258
+ : ArrowDownIcon
257
259
  }
258
260
  size="xs"
259
261
  className={cn(
@@ -351,6 +353,8 @@ export function ScrollableDataTable<TData extends TBaseData>({
351
353
  columnsBreakpoints = {},
352
354
  maxHeight,
353
355
  onLoadMore,
356
+ sorting,
357
+ setSorting,
354
358
  isLoading = false,
355
359
  rowSelection,
356
360
  setRowSelection,
@@ -363,6 +367,8 @@ export function ScrollableDataTable<TData extends TBaseData>({
363
367
  const loadMoreRef = useRef<HTMLDivElement>(null);
364
368
  const [tableWidth, setTableWidth] = useState(0);
365
369
 
370
+ const isSorting = !!setSorting;
371
+
366
372
  // Monitor table width changes
367
373
  useEffect(() => {
368
374
  if (!tableContainerRef.current) {
@@ -382,6 +388,15 @@ export function ScrollableDataTable<TData extends TBaseData>({
382
388
  };
383
389
  }, []);
384
390
 
391
+ const onSortingChange =
392
+ sorting && setSorting
393
+ ? (updater: Updater<SortingState>) => {
394
+ const newValue =
395
+ typeof updater === "function" ? updater(sorting) : updater;
396
+ setSorting(newValue);
397
+ }
398
+ : undefined;
399
+
385
400
  const onRowSelectionChange =
386
401
  rowSelection && setRowSelection
387
402
  ? (updater: Updater<RowSelectionState>) => {
@@ -402,7 +417,15 @@ export function ScrollableDataTable<TData extends TBaseData>({
402
417
  }),
403
418
  state: {
404
419
  ...(enableRowSelection && { rowSelection }),
420
+ ...(isSorting && {
421
+ sorting,
422
+ }),
405
423
  },
424
+ manualSorting: isSorting,
425
+ ...(isSorting && {
426
+ onSortingChange: onSortingChange,
427
+ }),
428
+ enableSortingRemoval: true,
406
429
  enableRowSelection,
407
430
  enableMultiRowSelection,
408
431
  getRowId,
@@ -520,19 +543,45 @@ export function ScrollableDataTable<TData extends TBaseData>({
520
543
  <DataTable.Head
521
544
  column={header.column}
522
545
  key={header.id}
523
- className="s-max-w-0"
546
+ onClick={
547
+ isSorting && header.column.getCanSort()
548
+ ? header.column.getToggleSortingHandler()
549
+ : undefined
550
+ }
551
+ className={cn(
552
+ "s-max-w-0",
553
+ header.column.getCanSort() &&
554
+ isSorting &&
555
+ "s-cursor-pointer"
556
+ )}
524
557
  style={{
525
558
  width: columnSizing[header.id],
526
559
  minWidth: columnSizing[header.id],
527
560
  }}
528
561
  >
529
- <div className="s-flex s-w-full s-items-center s-space-x-1">
562
+ <div className="s-flex s-w-full s-items-center s-space-x-1 s-whitespace-nowrap">
530
563
  <span className="s-truncate">
531
564
  {flexRender(
532
565
  header.column.columnDef.header,
533
566
  header.getContext()
534
567
  )}
535
568
  </span>
569
+ {isSorting && header.column.getCanSort() && (
570
+ <Icon
571
+ visual={
572
+ header.column.getIsSorted() === "asc"
573
+ ? ArrowUpIcon
574
+ : ArrowDownIcon
575
+ }
576
+ size="xs"
577
+ className={cn(
578
+ "s-ml-1",
579
+ header.column.getIsSorted()
580
+ ? "s-opacity-100"
581
+ : "s-opacity-0"
582
+ )}
583
+ />
584
+ )}
536
585
  </div>
537
586
  </DataTable.Head>
538
587
  );
@@ -68,15 +68,15 @@ export function Tree({
68
68
  className
69
69
  )}
70
70
  >
71
- {modifiedChildren}
71
+ <div>{modifiedChildren}</div>
72
+ {isLoading && (
73
+ // add the spinner below modifiedChildren to keep the layout
74
+ // thus preventing re-render in case of pagination
75
+ <div className={cn("s-flex s-justify-center s-py-2")}>
76
+ <Spinner size="xs" />
77
+ </div>
78
+ )}
72
79
  </div>
73
- {isLoading && (
74
- // add the spinner below modifiedChildren to keep the layout
75
- // thus preventing re-render in case of pagination
76
- <div className={cn("s-py-2 s-pl-4", className)}>
77
- <Spinner size="xs" variant="dark" />
78
- </div>
79
- )}
80
80
  </>
81
81
  );
82
82
  }
@@ -587,6 +587,24 @@ export const TreeExample = () => {
587
587
  />
588
588
  </Tree>
589
589
  </Tree.Item>
590
+
591
+ <Tree.Item
592
+ label="Item 8 (loading, with existing nodes)"
593
+ visual={FolderIcon}
594
+ >
595
+ <Tree isLoading>
596
+ <Tree.Item
597
+ type="leaf"
598
+ label="Item 1"
599
+ checkbox={{
600
+ checked: checked["Item 1"],
601
+ onCheckedChange: () => {
602
+ check("Item 1");
603
+ },
604
+ }}
605
+ />
606
+ </Tree>
607
+ </Tree.Item>
590
608
  </Tree>
591
609
  </div>
592
610
  </div>