angel-table 0.1.1 → 0.1.2
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/README.md +334 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,3 +1,337 @@
|
|
|
1
|
+
# Angel Table
|
|
2
|
+
|
|
3
|
+
A flexible and customizable React Table component with built-in sorting, pagination, search, column visibility, row selection, and responsive card layout.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Responsive Layout** – Automatically adapts between table and card views.
|
|
8
|
+
- **Card View** – Display data as cards on smaller screens.
|
|
9
|
+
- **Sorting** – Sort columns in ascending and descending order.
|
|
10
|
+
- **Pagination** – Built-in pagination controls.
|
|
11
|
+
- **Search** – Search and filter table data.
|
|
12
|
+
- **Row Selection** – Select individual rows or multiple rows.
|
|
13
|
+
- **Column Visibility** – Show or hide columns dynamically.
|
|
14
|
+
- **Custom Rendering** – Customize cell content using render functions.
|
|
15
|
+
- **Remote Data** – Fetch data from an API using a URL.
|
|
16
|
+
- **Custom Styling** – Customize the appearance using CSS.
|
|
17
|
+
- **TypeScript Support** – Built-in TypeScript declarations.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Install the package using npm:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install angel-table
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or using yarn:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add angel-table
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or using pnpm:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pnpm add angel-table
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Basic Usage
|
|
40
|
+
|
|
41
|
+
Import the `Table` component:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { Table } from 'angel-table';
|
|
45
|
+
|
|
46
|
+
function App() {
|
|
47
|
+
return (
|
|
48
|
+
<Table
|
|
49
|
+
columns={[
|
|
50
|
+
{
|
|
51
|
+
title: 'Name',
|
|
52
|
+
field: 'name',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
title: 'Email',
|
|
56
|
+
field: 'email',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
title: 'Age',
|
|
60
|
+
field: 'age',
|
|
61
|
+
},
|
|
62
|
+
]}
|
|
63
|
+
rows={[
|
|
64
|
+
{
|
|
65
|
+
id: 1,
|
|
66
|
+
name: 'John Doe',
|
|
67
|
+
email: 'john@example.com',
|
|
68
|
+
age: 25,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 2,
|
|
72
|
+
name: 'Jane Smith',
|
|
73
|
+
email: 'jane@example.com',
|
|
74
|
+
age: 28,
|
|
75
|
+
},
|
|
76
|
+
]}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export default App;
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## API Integration
|
|
85
|
+
|
|
86
|
+
Angel Table supports loading data from an API through `setup.url`.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
import { Table } from 'angel-table';
|
|
90
|
+
|
|
91
|
+
function App() {
|
|
92
|
+
return (
|
|
93
|
+
<Table
|
|
94
|
+
setup={{
|
|
95
|
+
keyObject: '_id',
|
|
96
|
+
url: 'https://fakestoreapi.noksha.dev/api/products',
|
|
97
|
+
}}
|
|
98
|
+
columns={[
|
|
99
|
+
{
|
|
100
|
+
title: 'Product',
|
|
101
|
+
field: 'title',
|
|
102
|
+
sort: true,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
title: 'Category',
|
|
106
|
+
field: 'category',
|
|
107
|
+
sort: true,
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
title: 'Price',
|
|
111
|
+
field: 'price',
|
|
112
|
+
sort: true,
|
|
113
|
+
},
|
|
114
|
+
]}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export default App;
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Advanced Usage
|
|
123
|
+
|
|
124
|
+
The following example demonstrates custom columns, responsive card view, column visibility, sorting, and custom cell rendering.
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { Table } from 'angel-table';
|
|
128
|
+
import './App.css';
|
|
129
|
+
|
|
130
|
+
function App() {
|
|
131
|
+
return (
|
|
132
|
+
<Table
|
|
133
|
+
className='e'
|
|
134
|
+
setup={{
|
|
135
|
+
viewDefault: 'card',
|
|
136
|
+
keyObject: '_id',
|
|
137
|
+
showColumns: true,
|
|
138
|
+
url: 'https://fakestoreapi.noksha.dev/api/products',
|
|
139
|
+
}}
|
|
140
|
+
columns={[
|
|
141
|
+
{
|
|
142
|
+
title: 'No.',
|
|
143
|
+
field: 'index_field',
|
|
144
|
+
width: '70px',
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
title: 'Image',
|
|
148
|
+
field: 'image',
|
|
149
|
+
width: '100px',
|
|
150
|
+
render: (row) => (
|
|
151
|
+
<img
|
|
152
|
+
src={row.image}
|
|
153
|
+
loading='lazy'
|
|
154
|
+
alt={row.title}
|
|
155
|
+
style={{
|
|
156
|
+
width: '50px',
|
|
157
|
+
height: '50px',
|
|
158
|
+
objectFit: 'cover',
|
|
159
|
+
borderRadius: '6px',
|
|
160
|
+
}}
|
|
161
|
+
/>
|
|
162
|
+
),
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
title: 'Product',
|
|
166
|
+
field: 'title',
|
|
167
|
+
width: '200px',
|
|
168
|
+
sort: true,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
title: 'Category',
|
|
172
|
+
field: 'category',
|
|
173
|
+
sort: true,
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
title: 'Type',
|
|
177
|
+
field: 'type',
|
|
178
|
+
sort: true,
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
title: 'Brand',
|
|
182
|
+
field: 'brand',
|
|
183
|
+
sort: true,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
title: 'Old Price',
|
|
187
|
+
field: 'oldPrice',
|
|
188
|
+
sort: true,
|
|
189
|
+
render: (row) => `$${row.oldPrice}`,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
title: 'Price',
|
|
193
|
+
field: 'price',
|
|
194
|
+
sort: true,
|
|
195
|
+
render: (row) => `$${row.price}`,
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
title: 'Discounted Price',
|
|
199
|
+
field: 'discountedPrice',
|
|
200
|
+
sort: true,
|
|
201
|
+
render: (row) => `$${row.discountedPrice}`,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
title: 'Stock',
|
|
205
|
+
field: 'stock',
|
|
206
|
+
sort: true,
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
title: 'Size',
|
|
210
|
+
field: 'size',
|
|
211
|
+
render: (row) => row.size?.join(', '),
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
title: 'New',
|
|
215
|
+
field: 'isNew',
|
|
216
|
+
render: (row) => (row.isNew ? 'Yes' : 'No'),
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
title: 'Description',
|
|
220
|
+
field: 'description',
|
|
221
|
+
show: false,
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
title: 'Actions',
|
|
225
|
+
field: 'action_field',
|
|
226
|
+
width: '120px',
|
|
227
|
+
},
|
|
228
|
+
]}
|
|
229
|
+
/>
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export default App;
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Column Configuration
|
|
237
|
+
|
|
238
|
+
Each column supports the following properties:
|
|
239
|
+
|
|
240
|
+
| Property | Type | Description |
|
|
241
|
+
| ----------- | ---------- | --------------------------- |
|
|
242
|
+
| `title` | `string` | Column heading |
|
|
243
|
+
| `field` | `string` | Data field or special field |
|
|
244
|
+
| `width` | `string` | Column width |
|
|
245
|
+
| `className` | `string` | Custom CSS class |
|
|
246
|
+
| `sort` | `boolean` | Enable sorting |
|
|
247
|
+
| `sortLabel` | `object` | Custom sorting labels |
|
|
248
|
+
| `show` | `boolean` | Control column visibility |
|
|
249
|
+
| `render` | `function` | Custom cell rendering |
|
|
250
|
+
|
|
251
|
+
### Special Fields
|
|
252
|
+
|
|
253
|
+
Angel Table provides special fields for common table functionality:
|
|
254
|
+
|
|
255
|
+
| Field | Description |
|
|
256
|
+
| -------------- | ---------------------- |
|
|
257
|
+
| `index_field` | Display row index |
|
|
258
|
+
| `check_field` | Row selection checkbox |
|
|
259
|
+
| `action_field` | Action column |
|
|
260
|
+
|
|
261
|
+
### Custom Rendering
|
|
262
|
+
|
|
263
|
+
Use `render` to customize how cell values are displayed.
|
|
264
|
+
|
|
265
|
+
```tsx
|
|
266
|
+
{
|
|
267
|
+
title: 'Status',
|
|
268
|
+
field: 'status',
|
|
269
|
+
render: (row) => (
|
|
270
|
+
<span className={`status status-${row.status}`}>
|
|
271
|
+
{row.status}
|
|
272
|
+
</span>
|
|
273
|
+
),
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Table Configuration
|
|
278
|
+
|
|
279
|
+
The `setup` property controls the table's behavior.
|
|
280
|
+
|
|
281
|
+
| Property | Type | Description |
|
|
282
|
+
| ------------- | --------- | ---------------------------------------- |
|
|
283
|
+
| `keyObject` | `string` | Unique identifier for each row |
|
|
284
|
+
| `url` | `string` | API endpoint for remote data |
|
|
285
|
+
| `viewDefault` | `string` | Default display mode (`table` or `card`) |
|
|
286
|
+
| `showColumns` | `boolean` | Enable column visibility controls |
|
|
287
|
+
|
|
288
|
+
Example:
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
<Table
|
|
292
|
+
setup={{
|
|
293
|
+
keyObject: 'id',
|
|
294
|
+
viewDefault: 'table',
|
|
295
|
+
showColumns: true,
|
|
296
|
+
url: 'https://example.com/api/data',
|
|
297
|
+
}}
|
|
298
|
+
columns={columns}
|
|
299
|
+
/>
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## Import Styles
|
|
303
|
+
|
|
304
|
+
Angel Table requires its stylesheet to be imported separately.
|
|
305
|
+
|
|
306
|
+
```tsx
|
|
307
|
+
import { Table } from 'angel-table';
|
|
308
|
+
import 'angel-table/style.css';
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Make sure to import the stylesheet once in your application entry point or main component.
|
|
312
|
+
|
|
313
|
+
Without importing the stylesheet, the table may not display correctly.
|
|
314
|
+
|
|
315
|
+
For dark mode, the component supports theme styling through:
|
|
316
|
+
|
|
317
|
+
```tsx
|
|
318
|
+
<Table columns={columns} setup={{ mode: 'dark' }} />
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
You can also override the CSS variables to customize colors, borders, backgrounds, and other visual properties.
|
|
322
|
+
|
|
323
|
+
## TypeScript
|
|
324
|
+
|
|
325
|
+
Angel Table includes TypeScript type declarations, allowing you to get autocomplete and type checking when configuring columns and table data.
|
|
326
|
+
|
|
327
|
+
```tsx
|
|
328
|
+
import { Table } from 'angel-table';
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## License
|
|
332
|
+
|
|
333
|
+
Mit
|
|
334
|
+
|
|
1
335
|
# React + TypeScript + Vite
|
|
2
336
|
|
|
3
337
|
This template provides a minimal setup to get React working in Vite with HMR and some Oxlint rules.
|