@dust-tt/sparkle 0.2.561 → 0.2.562

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.
@@ -20,7 +20,11 @@ import {
20
20
  Input,
21
21
  ScrollableDataTable,
22
22
  } from "@sparkle/components/";
23
- import { createSelectionColumn, MenuItem } from "@sparkle/components/DataTable";
23
+ import {
24
+ createRadioSelectionColumn,
25
+ createSelectionColumn,
26
+ MenuItem,
27
+ } from "@sparkle/components/DataTable";
24
28
  import { FolderIcon } from "@sparkle/icons/app";
25
29
 
26
30
  const meta = {
@@ -649,3 +653,59 @@ export const DataTableWithRowSelectionExample = () => {
649
653
  </div>
650
654
  );
651
655
  };
656
+
657
+ export const DataTableWithRadioSelectionExample = () => {
658
+ const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
659
+ const [data] = useState<Data[]>(() => createData(0, 10));
660
+ const [filter, setFilter] = useState("");
661
+
662
+ const columnsWithRadioSelection: ColumnDef<Data>[] = useMemo(
663
+ () => [createRadioSelectionColumn<Data>(), ...columns],
664
+ []
665
+ );
666
+
667
+ // Get the selected row ID from rowSelection state
668
+ const selectedRowId = Object.keys(rowSelection).find(
669
+ (id) => rowSelection[id]
670
+ );
671
+
672
+ return (
673
+ <div className="s-flex s-w-full s-max-w-4xl s-flex-col s-gap-6">
674
+ <h3 className="s-text-lg s-font-medium">
675
+ DataTable with Radio Selection (Single Row)
676
+ </h3>
677
+
678
+ <div className="s-flex s-flex-col s-gap-4">
679
+ <Input
680
+ name="filter"
681
+ placeholder="Filter"
682
+ value={filter}
683
+ onChange={(e) => setFilter(e.target.value)}
684
+ />
685
+
686
+ <DataTable
687
+ data={data}
688
+ filter={filter}
689
+ filterColumn="name"
690
+ columns={columnsWithRadioSelection}
691
+ rowSelection={rowSelection}
692
+ setRowSelection={setRowSelection}
693
+ enableRowSelection={true}
694
+ enableMultiRowSelection={false}
695
+ getRowId={(row) => row.name}
696
+ />
697
+
698
+ <div className="s-rounded-md s-border s-bg-muted/50 s-p-2">
699
+ <h4 className="s-mb-2 s-font-medium">Radio Selection State:</h4>
700
+ <pre className="s-overflow-auto s-text-xs">
701
+ {JSON.stringify(rowSelection, null, 2)}
702
+ </pre>
703
+ <p className="s-mt-2 s-text-sm">
704
+ {selectedRowId ? `Selected: ${selectedRowId}` : "No row selected"}{" "}
705
+ (only one row can be selected at a time)
706
+ </p>
707
+ </div>
708
+ </div>
709
+ </div>
710
+ );
711
+ };