@ttoss/components 1.30.5 → 1.31.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.
- package/README.md +232 -40
- package/dist/components/Table.d.ts +14 -0
- package/dist/esm/components/Table.js +55 -0
- package/dist/esm/index.js +2271 -3
- package/dist/index.d.ts +36 -1
- package/package.json +14 -8
- package/src/components/Drawer.tsx +27 -0
- package/src/components/Menu.tsx +107 -0
- package/src/components/Search.tsx +2 -2
- package/src/components/Table.tsx +36 -0
- package/src/index.ts +2 -0
package/README.md
CHANGED
|
@@ -20,6 +20,46 @@ pnpm add @ttoss/components @ttoss/ui @emotion/react @ttoss/react-hooks
|
|
|
20
20
|
|
|
21
21
|
You can check all the components of the library `@ttoss/ui` on the [Storybook](https://storybook.ttoss.dev/?path=/story/components).
|
|
22
22
|
|
|
23
|
+
### Markdown
|
|
24
|
+
|
|
25
|
+
Markdown uses [react-markdown](https://remarkjs.github.io/react-markdown/) under the hood, so the props are the same. You can update the elements as you want. Ex:
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
const MARKDOWN_CONTENT = `
|
|
29
|
+
# Heading 1
|
|
30
|
+
## Heading 2
|
|
31
|
+
### Heading 3
|
|
32
|
+
#### Heading 4
|
|
33
|
+
##### Heading 5
|
|
34
|
+
|
|
35
|
+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odit quasi dolorum aperiam fugiat earum expedita non eligendi similique id minus explicabo, eum facere nihil aspernatur libero! Sapiente aliquid tenetur dolor.
|
|
36
|
+
|
|
37
|
+
- Item 1
|
|
38
|
+
- Item 2
|
|
39
|
+
- Item 3
|
|
40
|
+
|
|
41
|
+

|
|
42
|
+
|
|
43
|
+
[Google](https://google.com)
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
const Component = () => {
|
|
47
|
+
return (
|
|
48
|
+
<Markdown
|
|
49
|
+
components={{
|
|
50
|
+
a: ({ children, ...props }) => (
|
|
51
|
+
<Link {...props} quiet>
|
|
52
|
+
{children}
|
|
53
|
+
</Link>
|
|
54
|
+
),
|
|
55
|
+
}}
|
|
56
|
+
>
|
|
57
|
+
{MARKDOWN_CONTENT}
|
|
58
|
+
</Markdown>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
```
|
|
62
|
+
|
|
23
63
|
### Modal
|
|
24
64
|
|
|
25
65
|
Modal uses [react-modal](https://reactcommunity.org/react-modal/) under the hood, so the props are the same. The only difference is that the styles are theme-aware. You can [style the modal](https://reactcommunity.org/react-modal/styles/) using theme tokens, except that [array as value](https://theme-ui.com/sx-prop#responsive-values) don't work.
|
|
@@ -82,46 +122,6 @@ const Component = () => {
|
|
|
82
122
|
};
|
|
83
123
|
```
|
|
84
124
|
|
|
85
|
-
### Markdown
|
|
86
|
-
|
|
87
|
-
Markdown uses [react-markdown](https://remarkjs.github.io/react-markdown/) under the hood, so the props are the same. You can update the elements as you want. Ex:
|
|
88
|
-
|
|
89
|
-
```tsx
|
|
90
|
-
const MARKDOWN_CONTENT = `
|
|
91
|
-
# Heading 1
|
|
92
|
-
## Heading 2
|
|
93
|
-
### Heading 3
|
|
94
|
-
#### Heading 4
|
|
95
|
-
##### Heading 5
|
|
96
|
-
|
|
97
|
-
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Odit quasi dolorum aperiam fugiat earum expedita non eligendi similique id minus explicabo, eum facere nihil aspernatur libero! Sapiente aliquid tenetur dolor.
|
|
98
|
-
|
|
99
|
-
- Item 1
|
|
100
|
-
- Item 2
|
|
101
|
-
- Item 3
|
|
102
|
-
|
|
103
|
-

|
|
104
|
-
|
|
105
|
-
[Google](https://google.com)
|
|
106
|
-
`;
|
|
107
|
-
|
|
108
|
-
const Component = () => {
|
|
109
|
-
return (
|
|
110
|
-
<Markdown
|
|
111
|
-
components={{
|
|
112
|
-
a: ({ children, ...props }) => (
|
|
113
|
-
<Link {...props} quiet>
|
|
114
|
-
{children}
|
|
115
|
-
</Link>
|
|
116
|
-
),
|
|
117
|
-
}}
|
|
118
|
-
>
|
|
119
|
-
{MARKDOWN_CONTENT}
|
|
120
|
-
</Markdown>
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
```
|
|
124
|
-
|
|
125
125
|
### Search
|
|
126
126
|
|
|
127
127
|
`Search` is a component that integrates an input field with debouncing functionality, making it ideal for search bars where you want to limit the rate of search queries based on user input.
|
|
@@ -155,3 +155,195 @@ const SearchComponent = () => {
|
|
|
155
155
|
```
|
|
156
156
|
|
|
157
157
|
In this example, the `Search` component receives the current search text and a handler function to update this text. The `loading` prop can be used to display a loading indicator, and the `debounce` prop controls the debounce delay.
|
|
158
|
+
|
|
159
|
+
### Table
|
|
160
|
+
|
|
161
|
+
The `Table` component is a flexible and customizable table that supports sorting, filtering, and pagination. It is designed to be easy to use and integrate with your data sources. It exports all [TanStack Table](https://tanstack.com/table/latest) hooks and methods.
|
|
162
|
+
|
|
163
|
+
#### Basic Usage
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import * as React from 'react';
|
|
167
|
+
import {
|
|
168
|
+
Table,
|
|
169
|
+
TableBody,
|
|
170
|
+
TableCell,
|
|
171
|
+
TableFooter,
|
|
172
|
+
TableHead,
|
|
173
|
+
TableHeader,
|
|
174
|
+
TableRow,
|
|
175
|
+
createColumnHelper,
|
|
176
|
+
flexRender,
|
|
177
|
+
getCoreRowModel,
|
|
178
|
+
useReactTable,
|
|
179
|
+
} from '@ttoss/components/table';
|
|
180
|
+
|
|
181
|
+
type Person = {
|
|
182
|
+
firstName: string;
|
|
183
|
+
lastName: string;
|
|
184
|
+
age: number;
|
|
185
|
+
visits: number;
|
|
186
|
+
status: string;
|
|
187
|
+
progress: number;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const defaultData: Person[] = [
|
|
191
|
+
{
|
|
192
|
+
firstName: 'tanner',
|
|
193
|
+
lastName: 'linsley',
|
|
194
|
+
age: 24,
|
|
195
|
+
visits: 100,
|
|
196
|
+
status: 'In Relationship',
|
|
197
|
+
progress: 50,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
firstName: 'tandy',
|
|
201
|
+
lastName: 'miller',
|
|
202
|
+
age: 40,
|
|
203
|
+
visits: 40,
|
|
204
|
+
status: 'Single',
|
|
205
|
+
progress: 80,
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
firstName: 'joe',
|
|
209
|
+
lastName: 'dirte',
|
|
210
|
+
age: 45,
|
|
211
|
+
visits: 20,
|
|
212
|
+
status: 'Complicated',
|
|
213
|
+
progress: 10,
|
|
214
|
+
},
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
const columnHelper = createColumnHelper<Person>();
|
|
218
|
+
|
|
219
|
+
const columns = [
|
|
220
|
+
columnHelper.accessor('firstName', {
|
|
221
|
+
cell: (info) => {
|
|
222
|
+
return info.getValue();
|
|
223
|
+
},
|
|
224
|
+
footer: (info) => {
|
|
225
|
+
return info.column.id;
|
|
226
|
+
},
|
|
227
|
+
}),
|
|
228
|
+
columnHelper.accessor(
|
|
229
|
+
(row) => {
|
|
230
|
+
return row.lastName;
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
id: 'lastName',
|
|
234
|
+
cell: (info) => {
|
|
235
|
+
return <i>{info.getValue()}</i>;
|
|
236
|
+
},
|
|
237
|
+
header: () => {
|
|
238
|
+
return <span>Last Name</span>;
|
|
239
|
+
},
|
|
240
|
+
footer: (info) => {
|
|
241
|
+
return info.column.id;
|
|
242
|
+
},
|
|
243
|
+
}
|
|
244
|
+
),
|
|
245
|
+
columnHelper.accessor('age', {
|
|
246
|
+
header: () => {
|
|
247
|
+
return 'Age';
|
|
248
|
+
},
|
|
249
|
+
cell: (info) => {
|
|
250
|
+
return info.renderValue();
|
|
251
|
+
},
|
|
252
|
+
footer: (info) => {
|
|
253
|
+
return info.column.id;
|
|
254
|
+
},
|
|
255
|
+
}),
|
|
256
|
+
columnHelper.accessor('visits', {
|
|
257
|
+
header: () => {
|
|
258
|
+
return <span>Visits</span>;
|
|
259
|
+
},
|
|
260
|
+
footer: (info) => {
|
|
261
|
+
return info.column.id;
|
|
262
|
+
},
|
|
263
|
+
}),
|
|
264
|
+
columnHelper.accessor('status', {
|
|
265
|
+
header: 'Status',
|
|
266
|
+
footer: (info) => {
|
|
267
|
+
return info.column.id;
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
columnHelper.accessor('progress', {
|
|
271
|
+
header: 'Profile Progress',
|
|
272
|
+
footer: (info) => {
|
|
273
|
+
return info.column.id;
|
|
274
|
+
},
|
|
275
|
+
}),
|
|
276
|
+
];
|
|
277
|
+
|
|
278
|
+
const RenderTable = () => {
|
|
279
|
+
const [data] = React.useState(() => {
|
|
280
|
+
return [...defaultData];
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const table = useReactTable({
|
|
284
|
+
data,
|
|
285
|
+
columns,
|
|
286
|
+
getCoreRowModel: getCoreRowModel(),
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
return (
|
|
290
|
+
<Table>
|
|
291
|
+
<TableHead>
|
|
292
|
+
{table.getHeaderGroups().map((headerGroup) => {
|
|
293
|
+
return (
|
|
294
|
+
<TableRow key={headerGroup.id}>
|
|
295
|
+
{headerGroup.headers.map((header) => {
|
|
296
|
+
return (
|
|
297
|
+
<TableHeader key={header.id}>
|
|
298
|
+
{header.isPlaceholder
|
|
299
|
+
? null
|
|
300
|
+
: flexRender(
|
|
301
|
+
header.column.columnDef.header,
|
|
302
|
+
header.getContext()
|
|
303
|
+
)}
|
|
304
|
+
</TableHeader>
|
|
305
|
+
);
|
|
306
|
+
})}
|
|
307
|
+
</TableRow>
|
|
308
|
+
);
|
|
309
|
+
})}
|
|
310
|
+
</TableHead>
|
|
311
|
+
<TableBody>
|
|
312
|
+
{table.getRowModel().rows.map((row) => {
|
|
313
|
+
return (
|
|
314
|
+
<TableRow key={row.id}>
|
|
315
|
+
{row.getVisibleCells().map((cell) => {
|
|
316
|
+
return (
|
|
317
|
+
<TableCell key={cell.id}>
|
|
318
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
319
|
+
</TableCell>
|
|
320
|
+
);
|
|
321
|
+
})}
|
|
322
|
+
</TableRow>
|
|
323
|
+
);
|
|
324
|
+
})}
|
|
325
|
+
</TableBody>
|
|
326
|
+
<TableFooter>
|
|
327
|
+
{table.getFooterGroups().map((footerGroup) => {
|
|
328
|
+
return (
|
|
329
|
+
<TableRow key={footerGroup.id}>
|
|
330
|
+
{footerGroup.headers.map((header) => {
|
|
331
|
+
return (
|
|
332
|
+
<TableHeader key={header.id}>
|
|
333
|
+
{header.isPlaceholder
|
|
334
|
+
? null
|
|
335
|
+
: flexRender(
|
|
336
|
+
header.column.columnDef.footer,
|
|
337
|
+
header.getContext()
|
|
338
|
+
)}
|
|
339
|
+
</TableHeader>
|
|
340
|
+
);
|
|
341
|
+
})}
|
|
342
|
+
</TableRow>
|
|
343
|
+
);
|
|
344
|
+
})}
|
|
345
|
+
</TableFooter>
|
|
346
|
+
</Table>
|
|
347
|
+
);
|
|
348
|
+
};
|
|
349
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { BoxProps } from '@ttoss/ui';
|
|
3
|
+
export * from '@tanstack/react-table';
|
|
4
|
+
|
|
5
|
+
declare const Table: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
6
|
+
declare const TableHead: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
7
|
+
declare const TableBody: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
8
|
+
declare const TableRow: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
9
|
+
declare const TableCell: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
10
|
+
declare const TableHeader: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
11
|
+
declare const TableCaption: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
12
|
+
declare const TableFooter: (props: BoxProps) => react_jsx_runtime.JSX.Element;
|
|
13
|
+
|
|
14
|
+
export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
+
|
|
3
|
+
// src/components/Table.tsx
|
|
4
|
+
import { Box } from "@ttoss/ui";
|
|
5
|
+
export * from "@tanstack/react-table";
|
|
6
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
|
+
var Table = props => {
|
|
8
|
+
return /* @__PURE__ */jsx(Box, {
|
|
9
|
+
as: "table",
|
|
10
|
+
...props
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var TableHead = props => {
|
|
14
|
+
return /* @__PURE__ */jsx(Box, {
|
|
15
|
+
as: "thead",
|
|
16
|
+
...props
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var TableBody = props => {
|
|
20
|
+
return /* @__PURE__ */jsx(Box, {
|
|
21
|
+
as: "tbody",
|
|
22
|
+
...props
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var TableRow = props => {
|
|
26
|
+
return /* @__PURE__ */jsx(Box, {
|
|
27
|
+
as: "tr",
|
|
28
|
+
...props
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var TableCell = props => {
|
|
32
|
+
return /* @__PURE__ */jsx(Box, {
|
|
33
|
+
as: "td",
|
|
34
|
+
...props
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var TableHeader = props => {
|
|
38
|
+
return /* @__PURE__ */jsx(Box, {
|
|
39
|
+
as: "th",
|
|
40
|
+
...props
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var TableCaption = props => {
|
|
44
|
+
return /* @__PURE__ */jsx(Box, {
|
|
45
|
+
as: "caption",
|
|
46
|
+
...props
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
var TableFooter = props => {
|
|
50
|
+
return /* @__PURE__ */jsx(Box, {
|
|
51
|
+
as: "tfoot",
|
|
52
|
+
...props
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow };
|