@ttoss/components 1.30.6 → 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 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
+ ![Alt Text](https://fastly.picsum.photos/id/436/200/300.jpg?hmac=OuJRsPTZRaNZhIyVFbzDkMYMyORVpV86q5M8igEfM3Y "Alt Text")
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
- ![Alt Text](https://fastly.picsum.photos/id/436/200/300.jpg?hmac=OuJRsPTZRaNZhIyVFbzDkMYMyORVpV86q5M8igEfM3Y "Alt Text")
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 };
package/dist/esm/index.js CHANGED
@@ -249,10 +249,10 @@ var Search = ({
249
249
  const debouncedValue = useDebounce(text, 500);
250
250
  React4.useEffect(() => {
251
251
  onChange(debouncedValue);
252
- }, [debouncedValue]);
252
+ }, [debouncedValue, onChange]);
253
253
  return /* @__PURE__ */jsx6(Input, {
254
254
  leadingIcon: loading ? "loading" : "search",
255
- value: text,
255
+ defaultValue: text,
256
256
  onChange: e => {
257
257
  return setText(e.target.value);
258
258
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/components",
3
- "version": "1.30.6",
3
+ "version": "1.31.0",
4
4
  "description": "React components for ttoss ecosystem.",
5
5
  "author": "ttoss",
6
6
  "contributors": [
@@ -16,6 +16,10 @@
16
16
  ".": {
17
17
  "types": "./dist/index.d.ts",
18
18
  "import": "./dist/esm/index.js"
19
+ },
20
+ "./table": {
21
+ "types": "./dist/components/Table.d.ts",
22
+ "import": "./dist/esm/components/Table.js"
19
23
  }
20
24
  },
21
25
  "files": [
@@ -25,6 +29,7 @@
25
29
  "sideEffects": false,
26
30
  "dependencies": {
27
31
  "@emotion/css": "^11.11.2",
32
+ "@tanstack/react-table": "^8.15.3",
28
33
  "@theme-ui/css": "^0.16.2",
29
34
  "@types/react-modal": "^3.16.3",
30
35
  "react-accessible-accordion": "^5.0.0",
@@ -45,10 +50,10 @@
45
50
  "@types/react": "^18.2.58",
46
51
  "jest": "^29.7.0",
47
52
  "tsup": "^8.0.2",
53
+ "@ttoss/react-hooks": "^1.25.3",
48
54
  "@ttoss/config": "^1.31.5",
49
55
  "@ttoss/react-icons": "^0.3.1",
50
56
  "@ttoss/test-utils": "^2.1.1",
51
- "@ttoss/react-hooks": "^1.25.3",
52
57
  "@ttoss/ui": "^4.1.4"
53
58
  },
54
59
  "keywords": [
@@ -21,12 +21,12 @@ export const Search = ({
21
21
 
22
22
  React.useEffect(() => {
23
23
  onChange(debouncedValue);
24
- }, [debouncedValue]);
24
+ }, [debouncedValue, onChange]);
25
25
 
26
26
  return (
27
27
  <Input
28
28
  leadingIcon={loading ? 'loading' : 'search'}
29
- value={text}
29
+ defaultValue={text}
30
30
  onChange={(e) => {
31
31
  return setText(e.target.value);
32
32
  }}
@@ -0,0 +1,36 @@
1
+ import { Box, BoxProps } from '@ttoss/ui';
2
+
3
+ // eslint-disable-next-line react-refresh/only-export-components
4
+ export * from '@tanstack/react-table';
5
+
6
+ export const Table = (props: BoxProps) => {
7
+ return <Box as="table" {...props} />;
8
+ };
9
+
10
+ export const TableHead = (props: BoxProps) => {
11
+ return <Box as="thead" {...props} />;
12
+ };
13
+
14
+ export const TableBody = (props: BoxProps) => {
15
+ return <Box as="tbody" {...props} />;
16
+ };
17
+
18
+ export const TableRow = (props: BoxProps) => {
19
+ return <Box as="tr" {...props} />;
20
+ };
21
+
22
+ export const TableCell = (props: BoxProps) => {
23
+ return <Box as="td" {...props} />;
24
+ };
25
+
26
+ export const TableHeader = (props: BoxProps) => {
27
+ return <Box as="th" {...props} />;
28
+ };
29
+
30
+ export const TableCaption = (props: BoxProps) => {
31
+ return <Box as="caption" {...props} />;
32
+ };
33
+
34
+ export const TableFooter = (props: BoxProps) => {
35
+ return <Box as="tfoot" {...props} />;
36
+ };