@sito/dashboard 0.0.29 → 0.0.30
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 +131 -17
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -35,12 +35,6 @@ const App = () => {
|
|
|
35
35
|
{ id: 2, name: "Jane Smith", age: 25 },
|
|
36
36
|
];
|
|
37
37
|
|
|
38
|
-
const parseRows = (row) => ({
|
|
39
|
-
id: row.id,
|
|
40
|
-
name: row.name,
|
|
41
|
-
age: row.age,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
38
|
const columns = [
|
|
45
39
|
{ key: "name", label: "Name" },
|
|
46
40
|
{ key: "age", label: "Age" },
|
|
@@ -91,17 +85,19 @@ export default App;
|
|
|
91
85
|
The Table component is a flexible and feature-rich table for displaying data.
|
|
92
86
|
|
|
93
87
|
#### Props
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
88
|
+
| Propiedad | Tipo | Valor por defecto | Descripción |
|
|
89
|
+
|-----------------------|--------------|-------------------------|---------------------------------------------------------------------|
|
|
90
|
+
| `title` | `string` | `""` | El título de la tabla. |
|
|
91
|
+
| `data` | `array` | — | Los datos a mostrar en la tabla. |
|
|
92
|
+
| `columns` | `array` | `[]` | Definiciones de columnas, incluyendo claves (`key`) y etiquetas. |
|
|
93
|
+
| `isLoading` | `boolean` | `false` | Indica si la tabla está en estado de carga. |
|
|
94
|
+
| `actions` | `Action[]` | — | Función para renderizar acciones por fila. |
|
|
95
|
+
| `className` | `string` | `""` | Clase personalizada para el contenedor de la tabla. |
|
|
96
|
+
| `contentClassName` | `string` | `""` | Clase personalizada para el contenido de la tabla. |
|
|
97
|
+
| `softDeleteProperty` | `string` | `"deleted"` | Propiedad usada para lógica de borrado suave. |
|
|
98
|
+
| `toolbar` | `ReactNode` | `<></>` | Componente personalizado para la barra de herramientas. |
|
|
99
|
+
| `onSort` | `function` | — | Callback que se llama cuando se cambia el orden de la tabla. |
|
|
100
|
+
|
|
105
101
|
|
|
106
102
|
### TranslationProvider
|
|
107
103
|
|
|
@@ -110,6 +106,124 @@ Provides translation support for your application.
|
|
|
110
106
|
#### Props
|
|
111
107
|
- `t` (function): A translation function that takes a key and returns the translated string.
|
|
112
108
|
|
|
109
|
+
### Examples
|
|
110
|
+
|
|
111
|
+
#### Columns definition
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
key: string;
|
|
115
|
+
label: string;
|
|
116
|
+
sortable?: boolean;
|
|
117
|
+
sortOptions: {
|
|
118
|
+
icons: {
|
|
119
|
+
className: string;
|
|
120
|
+
asc: string;
|
|
121
|
+
desc: string;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
className?: string;
|
|
125
|
+
display?: "visible" | "none";
|
|
126
|
+
pos?: number;
|
|
127
|
+
renderBody?: (value: any, row: any) => ReactNode;
|
|
128
|
+
renderHead?: () => void;
|
|
129
|
+
filterOptions?: ColumnFilterOptions;
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
ColumnFilterOptions
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
{
|
|
136
|
+
type: FilterTypes;
|
|
137
|
+
defaultValue: any;
|
|
138
|
+
label?: string;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
FilterTypes enum
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
text,
|
|
146
|
+
number,
|
|
147
|
+
select,
|
|
148
|
+
autocomplete,
|
|
149
|
+
date,
|
|
150
|
+
check,
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
import { Table } from "@sito/dashboard";
|
|
155
|
+
|
|
156
|
+
const columns = [
|
|
157
|
+
{
|
|
158
|
+
key: "tagIds",
|
|
159
|
+
label: t("_entities:news.tags.label"),
|
|
160
|
+
filterOptions: {
|
|
161
|
+
type: FilterTypes.autocomplete,
|
|
162
|
+
options: tagsList,
|
|
163
|
+
defaultValue: [],
|
|
164
|
+
},
|
|
165
|
+
sortable: false,
|
|
166
|
+
renderBody: (_, news) =>
|
|
167
|
+
(
|
|
168
|
+
<div className="flex flex-wrap gap-3">
|
|
169
|
+
{news.tags?.map(({ name, id }) => (
|
|
170
|
+
<Chip key={id} label={name} spanClassName="text-xs" />
|
|
171
|
+
))}
|
|
172
|
+
</div>
|
|
173
|
+
) ?? " - ",
|
|
174
|
+
},
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
<Table data={...} columns={columns} />
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### Actions definition
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
{
|
|
184
|
+
id: string;
|
|
185
|
+
onClick: (entity: object) => void;
|
|
186
|
+
icon: any;
|
|
187
|
+
tooltip: string;
|
|
188
|
+
hidden: (entity: object) => boolean;
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
import { Table } from "@sito/dashboard";
|
|
194
|
+
|
|
195
|
+
const addAction = {
|
|
196
|
+
id: "add",
|
|
197
|
+
hidden: false,
|
|
198
|
+
onClick: async () => {
|
|
199
|
+
// do some stuff here
|
|
200
|
+
},
|
|
201
|
+
icon: (
|
|
202
|
+
<FontAwesomeIcon
|
|
203
|
+
icon={isLoading ? faSpinner : faAdd}
|
|
204
|
+
className={`text-success ${isLoading ? "rotate" : ""}`}
|
|
205
|
+
/>
|
|
206
|
+
),
|
|
207
|
+
tooltip: t("_accessibility:buttons.add"),
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
<Table data={...} columns={...} actions={[addAction]} />
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
#### Your custom toolbar
|
|
214
|
+
|
|
215
|
+
```
|
|
216
|
+
import { Table } from "@sito/dashboard";
|
|
217
|
+
|
|
218
|
+
const Toolbar = () => {
|
|
219
|
+
return <div>
|
|
220
|
+
<h1>My custom toolbar</h1>
|
|
221
|
+
</div>
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
<Table data={...} columns={...} toolbar={<Toolbar />} />
|
|
225
|
+
```
|
|
226
|
+
|
|
113
227
|
## Development
|
|
114
228
|
|
|
115
229
|
Running Locally
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sito/dashboard",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.30",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "UI library with custom components for dashboards",
|
|
7
7
|
"main": "dist/dashboard.cjs",
|
|
@@ -37,6 +37,9 @@
|
|
|
37
37
|
],
|
|
38
38
|
"author": "sito8943",
|
|
39
39
|
"license": "ISC",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"react": "^18.3.1"
|
|
42
|
+
},
|
|
40
43
|
"devDependencies": {
|
|
41
44
|
"@types/node": "20.8.10",
|
|
42
45
|
"@types/react": "^18.3.3",
|
|
@@ -50,7 +53,6 @@
|
|
|
50
53
|
"eslint-plugin-react-refresh": "0.4.3",
|
|
51
54
|
"postcss": "^8.4.41",
|
|
52
55
|
"prettier": "^3.3.3",
|
|
53
|
-
"react": "^18.3.1",
|
|
54
56
|
"tailwindcss": "^3.4.10",
|
|
55
57
|
"typescript": "^5.5.4",
|
|
56
58
|
"vite": "^4.2.0",
|