react-base-data-table 0.0.0

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.
Files changed (54) hide show
  1. package/README.md +183 -0
  2. package/dist/index.cjs.js +77 -0
  3. package/dist/index.cjs.js.map +1 -0
  4. package/dist/index.es.js +10434 -0
  5. package/dist/index.es.js.map +1 -0
  6. package/dist/style.css +1 -0
  7. package/dist/types/App.d.ts +3 -0
  8. package/dist/types/DUMMY_ITEMS.d.ts +6 -0
  9. package/dist/types/components/BaseButton.d.ts +17 -0
  10. package/dist/types/components/BaseTable/BaseTable.d.ts +46 -0
  11. package/dist/types/components/BaseTable/BaseTableCell.d.ts +29 -0
  12. package/dist/types/components/BaseTable/BaseTableGroupRow.d.ts +13 -0
  13. package/dist/types/components/BaseTable/BaseTableHeader.d.ts +18 -0
  14. package/dist/types/components/BaseTable/BaseTableHeaders.d.ts +16 -0
  15. package/dist/types/components/BaseTable/BaseTableRow.d.ts +29 -0
  16. package/dist/types/components/BaseTable/BaseTableWithContext.d.ts +3 -0
  17. package/dist/types/components/BaseTable/CommentPopup.d.ts +15 -0
  18. package/dist/types/components/BaseTable/ContextMenu.d.ts +15 -0
  19. package/dist/types/components/BaseTable/CustomRenderItem.d.ts +8 -0
  20. package/dist/types/components/BaseTable/TableFilter.d.ts +16 -0
  21. package/dist/types/components/BaseTable/cellImplementation/ListCell.d.ts +10 -0
  22. package/dist/types/components/BaseTable/contexts/useCommentPopupContext.d.ts +12 -0
  23. package/dist/types/components/BaseTable/hooks/useCellPopup.d.ts +16 -0
  24. package/dist/types/components/BaseTable/hooks/useDragSelection.d.ts +13 -0
  25. package/dist/types/components/BaseTable/hooks/useRowDragDrop.d.ts +16 -0
  26. package/dist/types/components/BaseTable/hooks/useTableData.d.ts +19 -0
  27. package/dist/types/components/BaseTable/hooks/useTableFiltering.d.ts +13 -0
  28. package/dist/types/components/BaseTable/hooks/useTableGrouping.d.ts +28 -0
  29. package/dist/types/components/BaseTable/hooks/useTableInteractions.d.ts +35 -0
  30. package/dist/types/components/BaseTable/hooks/useTableSorting.d.ts +13 -0
  31. package/dist/types/components/BaseTable/hooks/useVirtualRows.d.ts +10 -0
  32. package/dist/types/components/BaseTable/models/ActiveTableFilter.d.ts +4 -0
  33. package/dist/types/components/BaseTable/models/BaseTableHeaders.d.ts +30 -0
  34. package/dist/types/components/BaseTable/models/CellCordinate.d.ts +4 -0
  35. package/dist/types/components/BaseTable/models/CommentData.d.ts +9 -0
  36. package/dist/types/components/BaseTable/models/ContextMenuAction.d.ts +12 -0
  37. package/dist/types/components/BaseTable/models/GroupInfo.d.ts +7 -0
  38. package/dist/types/components/BaseTable/models/HighlightCondition.d.ts +7 -0
  39. package/dist/types/components/BaseTable/models/ItemWithGroupInfo.d.ts +7 -0
  40. package/dist/types/components/BaseTable/models/TableConfiguration.d.ts +4 -0
  41. package/dist/types/components/BaseTable/models/TableItem.d.ts +4 -0
  42. package/dist/types/components/BaseTable/tableFunctions/CellSelection.d.ts +6 -0
  43. package/dist/types/components/BaseTable/tableFunctions/FilteringAndSorting.d.ts +7 -0
  44. package/dist/types/components/ColorPicker.d.ts +7 -0
  45. package/dist/types/enum/DateUnits.d.ts +8 -0
  46. package/dist/types/enum/FilterTypes.d.ts +4 -0
  47. package/dist/types/hooks/useClickOutside.d.ts +2 -0
  48. package/dist/types/index.d.ts +7 -0
  49. package/dist/types/main.d.ts +1 -0
  50. package/dist/types/utils/array.d.ts +5 -0
  51. package/dist/types/utils/enum.d.ts +3 -0
  52. package/dist/types/utils/sorting.d.ts +4 -0
  53. package/dist/vite.svg +1 -0
  54. package/package.json +74 -0
package/README.md ADDED
@@ -0,0 +1,183 @@
1
+ # @redevilkz/react-base-table
2
+
3
+ A simple and customizable React table component with support for sorting, filtering, and custom rendering.
4
+
5
+ ## Installation
6
+
7
+ Install the package via npm or yarn:
8
+
9
+ ```bash
10
+ npm install @redevilkz/react-base-table
11
+ ```
12
+
13
+ or
14
+
15
+ ```bash
16
+ yarn add @redevilkz/react-base-table
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ To use the table component, you need to import both the `BaseTable` component and its CSS file:
22
+
23
+ ```javascript
24
+ import { BaseTable } from "@redevilkz/react-base-table";
25
+ import "@redevilkz/react-base-table/style.css";
26
+ ```
27
+
28
+ ### Basic Example
29
+
30
+ Here's how to render a simple table:
31
+
32
+ ```javascript
33
+ const headers = [
34
+ { id: "name", text: "Name", type: "string", sortable: true },
35
+ { id: "age", text: "Age", type: "number", sortable: true },
36
+ ];
37
+
38
+ const items = [
39
+ { name: "John Doe", age: "30" },
40
+ { name: "Jane Smith", age: "25" },
41
+ ];
42
+
43
+ <BaseTable headers={headers} items={items}></BaseTable>;
44
+ ```
45
+
46
+ ## Props
47
+
48
+ The `BaseTable` component accepts the following props:
49
+
50
+ ### `BaseTableProps`
51
+
52
+ | Prop | Type | Default | Description |
53
+ | -------------------- | ---------------------------------------------------------------- | ------- | ---------------------------------------------------- |
54
+ | `height` | `string` | `auto` | Sets the height of the table. |
55
+ | `headers` | `BaseTableHeader[]` | - | Defines the headers of the table. |
56
+ | `items` | `TableItem[]` | - | Defines the data items to display in the table. |
57
+ | `marginTop` | `string` | `0` | Sets the top margin for the table. |
58
+ | `noBorder` | `boolean` | `false` | Removes the border around the table if `true`. |
59
+ | `pinColumns` | `boolean` | `false` | Pins the columns for horizontal scrolling if `true`. |
60
+ | `alignCenterInLine` | `boolean` | `false` | Aligns content centrally within rows if `true`. |
61
+ | `currentSortId` | `string` | - | Sets the ID of the column currently being sorted. |
62
+ | `highlightCondition` | `{ propertyId: string, value: unknown, style: CSSProperties }[]` | - | Defines conditions for highlighting rows. |
63
+ | `onResetSort` | `() => void` | - | Callback triggered to reset sorting. |
64
+ | `onRowDoubleClick` | `(item: TableItem) => void` | - | Callback triggered when a row is double-clicked. |
65
+ | `onSortByColumn` | `(columnId: string) => void` | - | Callback triggered when sorting by a column. |
66
+
67
+ ## Header Definition
68
+
69
+ ### `BaseTableHeader`
70
+
71
+ | Property | Type | Description |
72
+ | -------------- | ----------------------------------------------------------------- | ----------------------------------------------- |
73
+ | `id` | `string` | Unique identifier for the column. |
74
+ | `text` | `string` | The display text for the column header. |
75
+ | `type` | `'string', 'list', 'number'` | The type of data in the column. |
76
+ | `customHeader` | `(header: BaseTableHeader) => ReactNode` | Custom rendering function for the header. |
77
+ | `customRender` | `(item: TableItem, header: BaseTableHeader) => ReactNode` | Custom rendering function for the cell content. |
78
+ | `sortable` | `boolean` | Enables sorting for the column if `true`. |
79
+ | `customSort` | `(a: TableItem, b: TableItem, ascendingOrder: boolean) => number` | Custom sorting function for the column. |
80
+ | `hasFilter` | `boolean` | Enables filtering for the column if `true`. |
81
+
82
+ ## Data Items
83
+
84
+ ### `TableItem`
85
+
86
+ A `TableItem` is an object where each key corresponds to a column ID defined in the `headers`.
87
+
88
+ Example:
89
+
90
+ ```javascript
91
+ const item = {
92
+ name: "John Doe",
93
+ age: "30",
94
+ };
95
+ ```
96
+
97
+ ## Advanced Usage
98
+
99
+ ### Highlighting Rows
100
+
101
+ You can highlight rows based on specific conditions using the `highlightCondition` prop:
102
+
103
+ ```javascript
104
+ const highlightCondition = [
105
+ {
106
+ propertyId: "age",
107
+ value: "30",
108
+ style: { backgroundColor: "yellow" },
109
+ },
110
+ ];
111
+
112
+ <BaseTable
113
+ headers={headers}
114
+ items={items}
115
+ highlightCondition={highlightCondition}
116
+ ></BaseTable>;
117
+ ```
118
+
119
+ ### Custom Rendering
120
+
121
+ You can use the `customRender` function in `BaseTableHeader` to customize how a cell is displayed:
122
+
123
+ ```javascript
124
+ const headers = [
125
+ {
126
+ id: "name",
127
+ text: "Name",
128
+ customRender: (item) => <strong>{item.name}</strong>,
129
+ },
130
+ ];
131
+ ```
132
+
133
+ ### Sorting Callback
134
+
135
+ Handle sorting logic with the `onSortByColumn` callback:
136
+
137
+ ```javascript
138
+ const handleSort = (columnId) => {
139
+ console.log(`Sorting by column: ${columnId}`);
140
+ };
141
+
142
+ <BaseTable
143
+ headers={headers}
144
+ items={items}
145
+ onSortByColumn={handleSort}
146
+ ></BaseTable>;
147
+ ```
148
+
149
+ ## How to test the package in dev
150
+
151
+ Yalc emulates npm publish. I prefer it to npm link because it causes less issues.
152
+
153
+ ```bash
154
+ npm i yalc -g
155
+ ```
156
+
157
+ In your package:
158
+
159
+ ```bash
160
+ yalc publish
161
+ ```
162
+
163
+ In the project that wants to consume the package:
164
+
165
+ ```bash
166
+ yalc add @redevilkz/react-base-table
167
+ ```
168
+
169
+ In your package, after a rebuild:
170
+
171
+ ```bash
172
+ yalc push
173
+ ```
174
+
175
+ When you change something in your library
176
+
177
+ ```bash
178
+ npm run buildForNPM && yalc push --sig
179
+ ```
180
+
181
+ ## License
182
+
183
+ This project is licensed under the [MIT License](LICENSE).