@bigbinary/neeto-molecules 4.0.85 → 4.0.87

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": "@bigbinary/neeto-molecules",
3
- "version": "4.0.85",
3
+ "version": "4.0.87",
4
4
  "description": "A package of reusable molecular components for neeto products.",
5
5
  "repository": "git@github.com:bigbinary/neeto-molecules.git",
6
6
  "author": "Amaljith K <amaljith.k@bigbinary.com>",
@@ -65,6 +65,7 @@
65
65
  "@bigbinary/neeto-time-zones": "0.5.5",
66
66
  "@bigbinary/neetoui": "8.2.13",
67
67
  "@dnd-kit/core": "^6.2.0",
68
+ "@dnd-kit/modifiers": "^9.0.0",
68
69
  "@dnd-kit/sortable": "^10.0.0",
69
70
  "@eslint/compat": "^1.2.8",
70
71
  "@eslint/eslintrc": "^3.3.1",
@@ -229,6 +230,7 @@
229
230
  "@bigbinary/neeto-time-zones": "0.5.5",
230
231
  "@bigbinary/neetoui": "8.2.13",
231
232
  "@dnd-kit/core": "^6.2.0",
233
+ "@dnd-kit/modifiers": "^9.0.0",
232
234
  "@dnd-kit/sortable": "^10.0.0",
233
235
  "@fullcalendar/core": "^6.1.8",
234
236
  "@fullcalendar/daygrid": "^6.1.8",
@@ -0,0 +1,168 @@
1
+ interface DndTableProps<RowData = any> {
2
+ /**
3
+ * The data for the rows of the table.
4
+ */
5
+ rowData: RowData[];
6
+ /**
7
+ * The data for the columns of the table.
8
+ */
9
+ columnData: any[];
10
+ /**
11
+ * The index of the column to display the overlay for.
12
+ */
13
+ overlayColumnIndex?: number;
14
+ /**
15
+ * A function that determines if a row is droppable based on checks on the data.
16
+ */
17
+ isRowDroppable?: (data: RowData) => boolean;
18
+ /**
19
+ * A function that is called when a row is dropped.
20
+ */
21
+ onDrop: (active: RowData, over: RowData) => void;
22
+ [key: string]: any;
23
+ }
24
+ interface UseDndTableProps<RowData = any> {
25
+ rowData: RowData[];
26
+ onUpdate: (active: RowData, over: RowData) => void;
27
+ }
28
+ declare const useDndTable: (props: UseDndTableProps<RowData>) => {
29
+ rowData: RowData[];
30
+ onDrop: (active: RowData, over: RowData) => void;
31
+ };
32
+ /**
33
+ *
34
+ * The DndTable component is a drag-and-drop enabled table that allows users to
35
+ *
36
+ * reorder rows by dragging and dropping them. It provides visual feedback during
37
+ *
38
+ * drag operations and supports custom overlay rendering.
39
+ *
40
+ * The main table component with drag-and-drop functionality built on top of the
41
+ *
42
+ * neetoui Table component.
43
+ *
44
+ * A custom hook that provides state management and error handling for
45
+ *
46
+ * drag-and-drop operations. It automatically handles optimistic updates and
47
+ *
48
+ * rollback on errors.
49
+ *
50
+ * @example
51
+ *
52
+ * import DndTable, { useDndTable } from "@bigbinary/neeto-molecules/DndTable";
53
+ *
54
+ * const MyComponent = () => {
55
+ * const [data, setData] = useState([
56
+ * { id: 1, name: "John Doe", email: "john.doe@example.com" },
57
+ * { id: 2, name: "Jane Doe", email: "jane.doe@example.com" },
58
+ * { id: 3, name: "Alice Smith", email: "alice.smith@example.com" },
59
+ * { id: 4, name: "Bob Johnson", email: "bob.johnson@example.com" },
60
+ * { id: 5, name: "Carol Williams", email: "carol.williams@example.com" },
61
+ * { id: 6, name: "David Brown", email: "david.brown@example.com" },
62
+ * { id: 7, name: "Emma Davis", email: "emma.davis@example.com" },
63
+ * { id: 8, name: "Frank Miller", email: "frank.miller@example.com" },
64
+ * { id: 9, name: "Grace Wilson", email: "grace.wilson@example.com" },
65
+ * { id: 10, name: "Henry Moore", email: "henry.moore@example.com" },
66
+ * { id: 11, name: "Ivy Taylor", email: "ivy.taylor@example.com" },
67
+ * { id: 12, name: "Jack Anderson", email: "jack.anderson@example.com" },
68
+ * { id: 13, name: "Kate Thomas", email: "kate.thomas@example.com" },
69
+ * { id: 14, name: "Liam Jackson", email: "liam.jackson@example.com" },
70
+ * { id: 15, name: "Maya White", email: "maya.white@example.com" },
71
+ * { id: 16, name: "Noah Harris", email: "noah.harris@example.com" },
72
+ * { id: 17, name: "Olivia Martin", email: "olivia.martin@example.com" },
73
+ * { id: 18, name: "Paul Thompson", email: "paul.thompson@example.com" },
74
+ * { id: 19, name: "Quinn Garcia", email: "quinn.garcia@example.com" },
75
+ * { id: 20, name: "Rachel Martinez", email: "rachel.martinez@example.com" },
76
+ * { id: 21, name: "Sam Robinson", email: "sam.robinson@example.com" },
77
+ * { id: 22, name: "Tina Clark", email: "tina.clark@example.com" },
78
+ * { id: 23, name: "Uma Rodriguez", email: "uma.rodriguez@example.com" },
79
+ * { id: 24, name: "Victor Lewis", email: "victor.lewis@example.com" },
80
+ * { id: 25, name: "Wendy Lee", email: "wendy.lee@example.com" },
81
+ * { id: 26, name: "Xavier Walker", email: "xavier.walker@example.com" },
82
+ * { id: 27, name: "Yara Hall", email: "yara.hall@example.com" },
83
+ * { id: 28, name: "Zoe Allen", email: "zoe.allen@example.com" },
84
+ * { id: 29, name: "Aaron Young", email: "aaron.young@example.com" },
85
+ * { id: 30, name: "Bella King", email: "bella.king@example.com" },
86
+ * ]);
87
+ *
88
+ * const { rowData, onDrop } = useDndTable({
89
+ * rowData: data,
90
+ * onUpdate: async (active, over) => {
91
+ * // Make API call to update order, the item is automatically removed from the local state by the hook.
92
+ * await updateRowOrder(active.id, over.id);
93
+ * },
94
+ * });
95
+ *
96
+ * const columnData = [
97
+ * { key: "name", dataIndex: "name", title: "Name" },
98
+ * { key: "email", dataIndex: "email", title: "Email" },
99
+ * ];
100
+ *
101
+ * return (
102
+ * <DndTable
103
+ * rowData={rowData}
104
+ * columnData={columnData}
105
+ * onDrop={onDrop}
106
+ * isRowDroppable={row => row.status !== "archived"}
107
+ * />
108
+ * );
109
+ * };
110
+ * @endexample
111
+ * You can customize the drag overlay by providing a render function in your
112
+ *
113
+ * column configuration:
114
+ *
115
+ * @example
116
+ *
117
+ * const columnData = [
118
+ * {
119
+ * key: "name",
120
+ * dataIndex: "name",
121
+ * title: "Name",
122
+ * render: (value, record) => (
123
+ * <div className="flex items-center">
124
+ * <Avatar name={record.name} />
125
+ * <span className="ml-2">{value}</span>
126
+ * </div>
127
+ * ),
128
+ * },
129
+ * { key: "email", dataIndex: "email", title: "Email" },
130
+ * ];
131
+ *
132
+ * <DndTable
133
+ * rowData={rowData}
134
+ * columnData={columnData}
135
+ * overlayColumnIndex={0} // Use the first column for overlay
136
+ * onDrop={onDrop}
137
+ * />;
138
+ * @endexample
139
+ * You can make certain rows non-droppable based on their data:
140
+ *
141
+ * @example
142
+ *
143
+ * <DndTable
144
+ * rowData={rowData}
145
+ * columnData={columnData}
146
+ * onDrop={onDrop}
147
+ * isRowDroppable={row => {
148
+ * // Only allow dropping if row is not locked
149
+ * return !row.isLocked;
150
+ * }}
151
+ * />
152
+ * @endexample
153
+ * The useDndTable hook automatically handles errors and shows toast
154
+ *
155
+ * notifications:
156
+ *
157
+ * @example
158
+ *
159
+ * const { rowData, onDrop } = useDndTable({
160
+ * rowData: data,
161
+ * onUpdate: (active, over) => api.updateOrder(active.id, over.id);
162
+ * // Note: Changes to local state are automatically rolled back by the hook on error.
163
+ * });
164
+ * @endexample
165
+ */
166
+ declare const DndTable: <RowData = any>(props: DndTableProps<RowData>) => JSX.Element | null;
167
+
168
+ export { DndTable as default, useDndTable };