@phsa.tec/design-system-react 0.1.5 → 0.1.8
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 +390 -209
- package/dist/index.d.mts +485 -0
- package/dist/index.d.ts +485 -0
- package/dist/index.js +4259 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4186 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +46 -6
- package/.eslintrc.json +0 -7
- package/.github/workflows/deploy-storybook.yml +0 -75
- package/.storybook/main.ts +0 -16
- package/.storybook/preview.ts +0 -15
- package/components.json +0 -21
- package/jest.config.ts +0 -25
- package/next.config.ts +0 -7
- package/postcss.config.mjs +0 -8
- package/public/file.svg +0 -1
- package/public/globe.svg +0 -1
- package/public/next.svg +0 -1
- package/public/vercel.svg +0 -1
- package/public/window.svg +0 -1
- package/src/app/columns.tsx +0 -178
- package/src/app/favicon.ico +0 -0
- package/src/app/fonts/GeistMonoVF.woff +0 -0
- package/src/app/fonts/GeistVF.woff +0 -0
- package/src/app/globals.css +0 -94
- package/src/app/layout.tsx +0 -35
- package/src/app/page.tsx +0 -7
- package/src/components/actions/AlertDialog/AlertDialog.tsx +0 -45
- package/src/components/actions/AlertDialog/alert-dialog.stories.tsx +0 -21
- package/src/components/actions/AlertDialog/index.ts +0 -1
- package/src/components/actions/Button/Button.stories.ts +0 -38
- package/src/components/actions/Button/Button.tsx +0 -23
- package/src/components/actions/Button/index.ts +0 -1
- package/src/components/actions/Collapsible/index.ts +0 -1
- package/src/components/actions/Dialog/Dialog.stories.tsx +0 -70
- package/src/components/actions/Dialog/Dialog.tsx +0 -87
- package/src/components/actions/Dialog/components/DialogWithActions/index.tsx +0 -40
- package/src/components/actions/Dialog/index.ts +0 -1
- package/src/components/actions/Steps/Steps.stories.tsx +0 -25
- package/src/components/actions/Steps/Steps.tsx +0 -51
- package/src/components/actions/Steps/index.ts +0 -1
- package/src/components/actions/index.ts +0 -5
- package/src/components/dataDisplay/Avatar/Avatar.stories.tsx +0 -22
- package/src/components/dataDisplay/Avatar/Avatar.tsx +0 -21
- package/src/components/dataDisplay/Avatar/index.ts +0 -2
- package/src/components/dataDisplay/Badge/Badge.stories.tsx +0 -36
- package/src/components/dataDisplay/Badge/index.ts +0 -1
- package/src/components/dataDisplay/Card/Card.stories.tsx +0 -24
- package/src/components/dataDisplay/Card/Card.tsx +0 -34
- package/src/components/dataDisplay/Card/index.ts +0 -1
- package/src/components/dataDisplay/DataPairList/DataPairList.tsx +0 -56
- package/src/components/dataDisplay/DataPairList/data-pair-list.stories.tsx +0 -87
- package/src/components/dataDisplay/DataPairList/index.ts +0 -2
- package/src/components/dataDisplay/DataPairList/types.ts +0 -10
- package/src/components/dataDisplay/DropDownMenu/index.ts +0 -1
- package/src/components/dataDisplay/ErrorMessage/ErrorMessage.tsx +0 -6
- package/src/components/dataDisplay/ErrorMessage/index.ts +0 -1
- package/src/components/dataDisplay/Icon/Icon.stories.tsx +0 -21
- package/src/components/dataDisplay/Icon/Icon.tsx +0 -47
- package/src/components/dataDisplay/Icon/index.ts +0 -1
- package/src/components/dataDisplay/Icon/types.ts +0 -6
- package/src/components/dataDisplay/Label/Label.stories.tsx +0 -21
- package/src/components/dataDisplay/Label/Label.tsx +0 -10
- package/src/components/dataDisplay/Label/index.ts +0 -1
- package/src/components/dataDisplay/Table/Table.tsx +0 -173
- package/src/components/dataDisplay/Table/columns.tsx +0 -223
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-column-header.tsx +0 -72
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-pagination.tsx +0 -91
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-toolbar.tsx +0 -17
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-view-options.tsx +0 -58
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table.stories.tsx +0 -118
- package/src/components/dataDisplay/Table/components/DynamicTable/index.tsx +0 -136
- package/src/components/dataDisplay/Table/components/DynamicTable/types.ts +0 -43
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-column-header.tsx +0 -71
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-faceted-filter.tsx +0 -147
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-pagination.tsx +0 -97
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-row-actions.tsx +0 -78
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-toolbar.tsx +0 -60
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-view-options.tsx +0 -59
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table.tsx +0 -145
- package/src/components/dataDisplay/Table/custom/CustomTable/data.ts +0 -71
- package/src/components/dataDisplay/Table/custom/CustomTable/index.tsx +0 -34
- package/src/components/dataDisplay/Table/custom/CustomTable/schema.ts +0 -11
- package/src/components/dataDisplay/Table/index.ts +0 -2
- package/src/components/dataDisplay/Table/table.stories.tsx +0 -147
- package/src/components/dataDisplay/Table/types.ts +0 -15
- package/src/components/dataDisplay/Tabs/Tabs.stories.tsx +0 -34
- package/src/components/dataDisplay/Tabs/Tabs.tsx +0 -53
- package/src/components/dataDisplay/Tabs/index.ts +0 -1
- package/src/components/dataDisplay/Text/Text.stories.tsx +0 -66
- package/src/components/dataDisplay/Text/Text.tsx +0 -56
- package/src/components/dataDisplay/Text/index.ts +0 -1
- package/src/components/dataDisplay/index.ts +0 -8
- package/src/components/dataInput/Input/components/Input/Input.stories.tsx +0 -99
- package/src/components/dataInput/Input/components/Input/InputBase.tsx +0 -50
- package/src/components/dataInput/Input/components/Input/__tests__/input.test.tsx +0 -38
- package/src/components/dataInput/Input/components/Input/index.tsx +0 -48
- package/src/components/dataInput/Input/components/Input/types.ts +0 -15
- package/src/components/dataInput/Input/components/InputBase/index.tsx +0 -31
- package/src/components/dataInput/Input/components/MaskInput/__tests__/mask-input.test.tsx +0 -77
- package/src/components/dataInput/Input/components/MaskInput/index.ts +0 -1
- package/src/components/dataInput/Input/components/MaskInput/mask-input.stories.tsx +0 -85
- package/src/components/dataInput/Input/components/MaskInput/mask-input.tsx +0 -73
- package/src/components/dataInput/Input/components/MultipleInput/MultipleInput.tsx +0 -105
- package/src/components/dataInput/Input/components/MultipleInput/MultipleInputBase.tsx +0 -100
- package/src/components/dataInput/Input/components/MultipleInput/MultipleMaskInput.tsx +0 -35
- package/src/components/dataInput/Input/components/MultipleInput/MultipleNumberInput.tsx +0 -35
- package/src/components/dataInput/Input/components/MultipleInput/__tests__/multiple-input.test.tsx +0 -152
- package/src/components/dataInput/Input/components/MultipleInput/index.ts +0 -2
- package/src/components/dataInput/Input/components/MultipleInput/multiple-input.stories.tsx +0 -96
- package/src/components/dataInput/Input/components/NumberInput/index.ts +0 -1
- package/src/components/dataInput/Input/components/NumberInput/number-input.stories.tsx +0 -76
- package/src/components/dataInput/Input/components/NumberInput/number-input.tsx +0 -68
- package/src/components/dataInput/Input/index.ts +0 -4
- package/src/components/dataInput/Select/MultiSelect/MultiSelect.stories.tsx +0 -119
- package/src/components/dataInput/Select/MultiSelect/MultiSelectBase.tsx +0 -135
- package/src/components/dataInput/Select/MultiSelect/index.tsx +0 -75
- package/src/components/dataInput/Select/Select.stories.tsx +0 -61
- package/src/components/dataInput/Select/Select.tsx +0 -73
- package/src/components/dataInput/Select/SelectBase.tsx +0 -58
- package/src/components/dataInput/Select/index.ts +0 -2
- package/src/components/dataInput/Switch/Switch.stories.tsx +0 -75
- package/src/components/dataInput/Switch/Switch.tsx +0 -52
- package/src/components/dataInput/Switch/index.ts +0 -1
- package/src/components/dataInput/checkbox/Checkbox.tsx +0 -57
- package/src/components/dataInput/checkbox/Checkbox_old.tsx +0 -58
- package/src/components/dataInput/checkbox/Checkout.stories.tsx +0 -62
- package/src/components/dataInput/checkbox/index.ts +0 -1
- package/src/components/dataInput/form/Form.tsx +0 -47
- package/src/components/dataInput/form/index.ts +0 -3
- package/src/components/dataInput/index.ts +0 -5
- package/src/components/feedback/ErrorLabel/index.tsx +0 -24
- package/src/components/feedback/Spinner/index.ts +0 -1
- package/src/components/feedback/Toast/Toast.stories.tsx +0 -45
- package/src/components/feedback/Toast/index.ts +0 -2
- package/src/components/feedback/index.ts +0 -2
- package/src/components/index.ts +0 -6
- package/src/components/layout/Crud/components/Table/index.tsx +0 -183
- package/src/components/layout/Crud/components/Table/types.ts +0 -15
- package/src/components/layout/Crud/crud.stories.tsx +0 -317
- package/src/components/layout/Crud/hook/useCrudLayout/index.tsx +0 -94
- package/src/components/layout/Crud/hook/useRequest/index.tsx +0 -156
- package/src/components/layout/Crud/index.tsx +0 -295
- package/src/components/layout/Crud/store/CrudLayoutStore.ts +0 -75
- package/src/components/layout/Crud/types.ts +0 -14
- package/src/components/layout/Drawer/CustomDrawer/index.tsx +0 -33
- package/src/components/layout/Drawer/Drawer.stories.tsx +0 -80
- package/src/components/layout/Drawer/index.ts +0 -2
- package/src/components/layout/PageLayout/PageLayout.stories.tsx +0 -42
- package/src/components/layout/PageLayout/index.tsx +0 -28
- package/src/components/layout/Separator/index.ts +0 -1
- package/src/components/layout/Sheet/Sheet.stories.tsx +0 -28
- package/src/components/layout/Sheet/Sheet.tsx +0 -22
- package/src/components/layout/Sheet/index.ts +0 -1
- package/src/components/layout/Sidebar/Sidebar.stories.tsx +0 -116
- package/src/components/layout/Sidebar/Sidebar.tsx +0 -50
- package/src/components/layout/Sidebar/components/app-sidebar.tsx +0 -203
- package/src/components/layout/Sidebar/components/footer-sidebar.tsx +0 -17
- package/src/components/layout/Sidebar/components/header-sidebar.tsx +0 -90
- package/src/components/layout/Sidebar/components/menus.tsx +0 -55
- package/src/components/layout/Sidebar/components/nav-projects.tsx +0 -88
- package/src/components/layout/Sidebar/components/nav-user.tsx +0 -114
- package/src/components/layout/Sidebar/components/team-switcher.tsx +0 -85
- package/src/components/layout/Sidebar/index.ts +0 -2
- package/src/components/layout/Sidebar/provider/index.tsx +0 -51
- package/src/components/layout/Tabs/Tabs.tsx +0 -51
- package/src/components/layout/Tabs/index.ts +0 -1
- package/src/components/layout/Tabs/tabs.stories.tsx +0 -57
- package/src/components/layout/index.ts +0 -6
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.tsx +0 -66
- package/src/components/navigation/Breadcrumbs/index.ts +0 -2
- package/src/components/navigation/index.ts +0 -1
- package/src/components/ui/alert-dialog.tsx +0 -141
- package/src/components/ui/alert.tsx +0 -59
- package/src/components/ui/avatar.tsx +0 -50
- package/src/components/ui/badge.tsx +0 -40
- package/src/components/ui/breadcrumb.tsx +0 -115
- package/src/components/ui/button.tsx +0 -57
- package/src/components/ui/card.tsx +0 -83
- package/src/components/ui/checkbox.tsx +0 -34
- package/src/components/ui/collapsible.tsx +0 -11
- package/src/components/ui/command.tsx +0 -153
- package/src/components/ui/dialog.tsx +0 -124
- package/src/components/ui/drawer.tsx +0 -117
- package/src/components/ui/dropdown-menu.tsx +0 -201
- package/src/components/ui/form.tsx +0 -179
- package/src/components/ui/input.tsx +0 -24
- package/src/components/ui/label.tsx +0 -30
- package/src/components/ui/popover.tsx +0 -33
- package/src/components/ui/select.tsx +0 -161
- package/src/components/ui/separator.tsx +0 -31
- package/src/components/ui/sheet.tsx +0 -140
- package/src/components/ui/sidebar.tsx +0 -763
- package/src/components/ui/skeleton.tsx +0 -15
- package/src/components/ui/sonner.tsx +0 -31
- package/src/components/ui/spinner.tsx +0 -54
- package/src/components/ui/switch.tsx +0 -33
- package/src/components/ui/table.tsx +0 -120
- package/src/components/ui/tabs.tsx +0 -55
- package/src/components/ui/toast.tsx +0 -130
- package/src/components/ui/toaster.tsx +0 -35
- package/src/components/ui/tooltip.tsx +0 -32
- package/src/hooks/use-conditional-controller.tsx +0 -35
- package/src/hooks/use-mask.tsx +0 -116
- package/src/hooks/use-mobile.tsx +0 -19
- package/src/hooks/use-toast.ts +0 -191
- package/src/index.ts +0 -1
- package/src/introduction.mdx +0 -132
- package/src/lib/utils.ts +0 -6
- package/tailwind.config.ts +0 -83
- package/tsconfig.json +0 -27
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Table as TableUI,
|
|
3
|
-
TableBody,
|
|
4
|
-
TableHead,
|
|
5
|
-
TableHeader,
|
|
6
|
-
TableRow,
|
|
7
|
-
TableCell,
|
|
8
|
-
} from "@/components/ui/table";
|
|
9
|
-
import {
|
|
10
|
-
flexRender,
|
|
11
|
-
getCoreRowModel,
|
|
12
|
-
useReactTable,
|
|
13
|
-
} from "@tanstack/react-table";
|
|
14
|
-
import { TableProps } from "./types";
|
|
15
|
-
import { Button } from "@/components/ui/button";
|
|
16
|
-
import {
|
|
17
|
-
Select,
|
|
18
|
-
SelectContent,
|
|
19
|
-
SelectItem,
|
|
20
|
-
SelectTrigger,
|
|
21
|
-
SelectValue,
|
|
22
|
-
} from "@/components/ui/select";
|
|
23
|
-
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
24
|
-
|
|
25
|
-
export function Table<TData>({
|
|
26
|
-
data,
|
|
27
|
-
columns,
|
|
28
|
-
isLoading,
|
|
29
|
-
pagination,
|
|
30
|
-
}: TableProps<TData>) {
|
|
31
|
-
// Configuração da tabela
|
|
32
|
-
const table = useReactTable({
|
|
33
|
-
data,
|
|
34
|
-
columns,
|
|
35
|
-
getCoreRowModel: getCoreRowModel(),
|
|
36
|
-
manualPagination: true,
|
|
37
|
-
pageCount: pagination ? Math.ceil(pagination.total / pagination.limit) : 1,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (isLoading && data.length === 0) {
|
|
41
|
-
return (
|
|
42
|
-
<div className="rounded-md border">
|
|
43
|
-
<TableUI>
|
|
44
|
-
<TableHeader>
|
|
45
|
-
{table.getHeaderGroups().map((headerGroup) => (
|
|
46
|
-
<TableRow key={headerGroup.id}>
|
|
47
|
-
{headerGroup.headers.map((header) => (
|
|
48
|
-
<TableHead key={header.id}>
|
|
49
|
-
{flexRender(
|
|
50
|
-
header.column.columnDef.header,
|
|
51
|
-
header.getContext()
|
|
52
|
-
)}
|
|
53
|
-
</TableHead>
|
|
54
|
-
))}
|
|
55
|
-
</TableRow>
|
|
56
|
-
))}
|
|
57
|
-
</TableHeader>
|
|
58
|
-
<TableBody>
|
|
59
|
-
<TableRow>
|
|
60
|
-
<TableCell colSpan={columns.length} className="text-center">
|
|
61
|
-
Carregando...
|
|
62
|
-
</TableCell>
|
|
63
|
-
</TableRow>
|
|
64
|
-
</TableBody>
|
|
65
|
-
</TableUI>
|
|
66
|
-
</div>
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (data.length === 0) {
|
|
71
|
-
return (
|
|
72
|
-
<div className="rounded-md border">
|
|
73
|
-
<TableUI>
|
|
74
|
-
<TableHeader>
|
|
75
|
-
{table.getHeaderGroups().map((headerGroup) => (
|
|
76
|
-
<TableRow key={headerGroup.id}>
|
|
77
|
-
{headerGroup.headers.map((header) => (
|
|
78
|
-
<TableHead key={header.id}>
|
|
79
|
-
{flexRender(
|
|
80
|
-
header.column.columnDef.header,
|
|
81
|
-
header.getContext()
|
|
82
|
-
)}
|
|
83
|
-
</TableHead>
|
|
84
|
-
))}
|
|
85
|
-
</TableRow>
|
|
86
|
-
))}
|
|
87
|
-
</TableHeader>
|
|
88
|
-
<TableBody>
|
|
89
|
-
<TableRow>
|
|
90
|
-
<TableCell colSpan={columns.length} className="text-center">
|
|
91
|
-
Nenhuma configuração encontrada
|
|
92
|
-
</TableCell>
|
|
93
|
-
</TableRow>
|
|
94
|
-
</TableBody>
|
|
95
|
-
</TableUI>
|
|
96
|
-
</div>
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return (
|
|
101
|
-
<div className="space-y-4">
|
|
102
|
-
<div className="rounded-md border">
|
|
103
|
-
<TableUI>
|
|
104
|
-
<TableHeader>
|
|
105
|
-
{table.getHeaderGroups().map((headerGroup) => (
|
|
106
|
-
<TableRow key={headerGroup.id}>
|
|
107
|
-
{headerGroup.headers.map((header) => (
|
|
108
|
-
<TableHead key={header.id}>
|
|
109
|
-
{flexRender(
|
|
110
|
-
header.column.columnDef.header,
|
|
111
|
-
header.getContext()
|
|
112
|
-
)}
|
|
113
|
-
</TableHead>
|
|
114
|
-
))}
|
|
115
|
-
</TableRow>
|
|
116
|
-
))}
|
|
117
|
-
</TableHeader>
|
|
118
|
-
<TableBody>
|
|
119
|
-
{table.getRowModel().rows.map((row) => (
|
|
120
|
-
<TableRow key={row.id}>
|
|
121
|
-
{row.getVisibleCells().map((cell) => (
|
|
122
|
-
<TableCell key={cell.id}>
|
|
123
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
124
|
-
</TableCell>
|
|
125
|
-
))}
|
|
126
|
-
</TableRow>
|
|
127
|
-
))}
|
|
128
|
-
</TableBody>
|
|
129
|
-
</TableUI>
|
|
130
|
-
</div>
|
|
131
|
-
|
|
132
|
-
{pagination && (
|
|
133
|
-
<div className="flex items-center justify-between px-2">
|
|
134
|
-
<div className="flex items-center space-x-2">
|
|
135
|
-
<p className="text-sm font-medium">Linhas por página</p>
|
|
136
|
-
<Select
|
|
137
|
-
value={pagination.limit.toString()}
|
|
138
|
-
onValueChange={(value) => pagination.onLimitChange(Number(value))}
|
|
139
|
-
>
|
|
140
|
-
<SelectTrigger className="h-8 w-[70px]">
|
|
141
|
-
<SelectValue />
|
|
142
|
-
</SelectTrigger>
|
|
143
|
-
<SelectContent side="top">
|
|
144
|
-
<SelectItem value="10">10</SelectItem>
|
|
145
|
-
<SelectItem value="20">20</SelectItem>
|
|
146
|
-
<SelectItem value="50">50</SelectItem>
|
|
147
|
-
<SelectItem value="100">100</SelectItem>
|
|
148
|
-
</SelectContent>
|
|
149
|
-
</Select>
|
|
150
|
-
</div>
|
|
151
|
-
|
|
152
|
-
<div className="flex items-center space-x-6 lg:space-x-8">
|
|
153
|
-
<div className="flex w-[100px] items-center justify-center text-sm font-medium">
|
|
154
|
-
Página {pagination.page} de{" "}
|
|
155
|
-
{Math.ceil(pagination.total / pagination.limit)}
|
|
156
|
-
</div>
|
|
157
|
-
<div className="flex items-center space-x-2">
|
|
158
|
-
<Button
|
|
159
|
-
variant="outline"
|
|
160
|
-
className="h-8 w-8 p-0"
|
|
161
|
-
onClick={() => pagination.onPageChange(pagination.page - 1)}
|
|
162
|
-
disabled={pagination.page <= 1}
|
|
163
|
-
>
|
|
164
|
-
<ChevronLeft className="h-4 w-4" />
|
|
165
|
-
</Button>
|
|
166
|
-
<Button
|
|
167
|
-
variant="outline"
|
|
168
|
-
className="h-8 w-8 p-0"
|
|
169
|
-
onClick={() => pagination.onPageChange(pagination.page + 1)}
|
|
170
|
-
disabled={
|
|
171
|
-
pagination.page >=
|
|
172
|
-
Math.ceil(pagination.total / pagination.limit)
|
|
173
|
-
}
|
|
174
|
-
>
|
|
175
|
-
<ChevronRight className="h-4 w-4" />
|
|
176
|
-
</Button>
|
|
177
|
-
</div>
|
|
178
|
-
</div>
|
|
179
|
-
</div>
|
|
180
|
-
)}
|
|
181
|
-
</div>
|
|
182
|
-
);
|
|
183
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ColumnDef } from "@tanstack/react-table";
|
|
2
|
-
|
|
3
|
-
export interface TableProps<TData> {
|
|
4
|
-
data: TData[];
|
|
5
|
-
columns: ColumnDef<TData>[];
|
|
6
|
-
isLoading: boolean;
|
|
7
|
-
pagination: {
|
|
8
|
-
page: number;
|
|
9
|
-
limit: number;
|
|
10
|
-
total: number;
|
|
11
|
-
onPageChange: (page: number) => void;
|
|
12
|
-
onLimitChange: (limit: number) => void;
|
|
13
|
-
pageOptions: number[];
|
|
14
|
-
};
|
|
15
|
-
}
|
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from "@storybook/nextjs";
|
|
2
|
-
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
-
import { CrudLayout } from "./index";
|
|
4
|
-
import { useForm } from "react-hook-form";
|
|
5
|
-
import { Input } from "@/components/dataInput/Input/components/Input";
|
|
6
|
-
import { Button } from "@/components/ui/button";
|
|
7
|
-
import { ColumnDef } from "@tanstack/react-table";
|
|
8
|
-
import { Edit, Trash2 } from "lucide-react";
|
|
9
|
-
import { useCrudLayoutActions } from "./store/CrudLayoutStore";
|
|
10
|
-
import { useCrudLayout } from "./hook/useCrudLayout";
|
|
11
|
-
|
|
12
|
-
// Tipos de exemplo para as stories
|
|
13
|
-
interface ExampleData {
|
|
14
|
-
_id: string;
|
|
15
|
-
name: string;
|
|
16
|
-
email: string;
|
|
17
|
-
status: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface CreateData {
|
|
21
|
-
name: string;
|
|
22
|
-
email: string;
|
|
23
|
-
status: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface UpdateData extends CreateData {
|
|
27
|
-
_id: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Função para gerar dados aleatórios
|
|
31
|
-
const generateMockData = (count: number): ExampleData[] => {
|
|
32
|
-
const firstNames = [
|
|
33
|
-
"João",
|
|
34
|
-
"Maria",
|
|
35
|
-
"Pedro",
|
|
36
|
-
"Ana",
|
|
37
|
-
"Carlos",
|
|
38
|
-
"Lucia",
|
|
39
|
-
"Roberto",
|
|
40
|
-
"Fernanda",
|
|
41
|
-
"Ricardo",
|
|
42
|
-
"Juliana",
|
|
43
|
-
"Marcos",
|
|
44
|
-
"Patricia",
|
|
45
|
-
"Antonio",
|
|
46
|
-
"Carla",
|
|
47
|
-
"José",
|
|
48
|
-
"Sandra",
|
|
49
|
-
"Paulo",
|
|
50
|
-
"Beatriz",
|
|
51
|
-
"Francisco",
|
|
52
|
-
"Mariana",
|
|
53
|
-
"Luiz",
|
|
54
|
-
"Gabriela",
|
|
55
|
-
"Miguel",
|
|
56
|
-
"Larissa",
|
|
57
|
-
"Rafael",
|
|
58
|
-
"Camila",
|
|
59
|
-
"Daniel",
|
|
60
|
-
"Renata",
|
|
61
|
-
"Felipe",
|
|
62
|
-
"Vanessa",
|
|
63
|
-
"Bruno",
|
|
64
|
-
"Priscila",
|
|
65
|
-
"Thiago",
|
|
66
|
-
"Amanda",
|
|
67
|
-
"Leonardo",
|
|
68
|
-
"Bianca",
|
|
69
|
-
"Gustavo",
|
|
70
|
-
"Natalia",
|
|
71
|
-
"Rodrigo",
|
|
72
|
-
"Tatiana",
|
|
73
|
-
"Eduardo",
|
|
74
|
-
"Viviane",
|
|
75
|
-
"Vinicius",
|
|
76
|
-
"Claudia",
|
|
77
|
-
"Matheus",
|
|
78
|
-
"Sabrina",
|
|
79
|
-
"Lucas",
|
|
80
|
-
"Adriana",
|
|
81
|
-
"Diego",
|
|
82
|
-
"Monica",
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
const lastNames = [
|
|
86
|
-
"Silva",
|
|
87
|
-
"Santos",
|
|
88
|
-
"Oliveira",
|
|
89
|
-
"Costa",
|
|
90
|
-
"Ferreira",
|
|
91
|
-
"Pereira",
|
|
92
|
-
"Lima",
|
|
93
|
-
"Alves",
|
|
94
|
-
"Souza",
|
|
95
|
-
"Rodrigues",
|
|
96
|
-
"Martins",
|
|
97
|
-
"Carvalho",
|
|
98
|
-
"Barbosa",
|
|
99
|
-
"Gomes",
|
|
100
|
-
"Nascimento",
|
|
101
|
-
"Ribeiro",
|
|
102
|
-
"Araujo",
|
|
103
|
-
"Dias",
|
|
104
|
-
"Fernandes",
|
|
105
|
-
"Morais",
|
|
106
|
-
"Cardoso",
|
|
107
|
-
"Campos",
|
|
108
|
-
"Rocha",
|
|
109
|
-
"Monteiro",
|
|
110
|
-
"Mendes",
|
|
111
|
-
"Freitas",
|
|
112
|
-
"Pinto",
|
|
113
|
-
"Cavalcanti",
|
|
114
|
-
"Vieira",
|
|
115
|
-
"Teixeira",
|
|
116
|
-
"Moreira",
|
|
117
|
-
"Correia",
|
|
118
|
-
"Castro",
|
|
119
|
-
"Andrade",
|
|
120
|
-
"Nunes",
|
|
121
|
-
"Ramos",
|
|
122
|
-
"Lopes",
|
|
123
|
-
"Machado",
|
|
124
|
-
"Reis",
|
|
125
|
-
"Moura",
|
|
126
|
-
"Cunha",
|
|
127
|
-
"Pires",
|
|
128
|
-
"Farias",
|
|
129
|
-
"Melo",
|
|
130
|
-
"Azevedo",
|
|
131
|
-
"Borges",
|
|
132
|
-
"Paiva",
|
|
133
|
-
"Coelho",
|
|
134
|
-
"Guimaraes",
|
|
135
|
-
"Nogueira",
|
|
136
|
-
];
|
|
137
|
-
|
|
138
|
-
const domains = [
|
|
139
|
-
"example.com",
|
|
140
|
-
"test.com",
|
|
141
|
-
"demo.com",
|
|
142
|
-
"sample.org",
|
|
143
|
-
"mock.net",
|
|
144
|
-
];
|
|
145
|
-
const statuses = ["Ativo", "Inativo", "Pendente", "Suspenso"];
|
|
146
|
-
|
|
147
|
-
const data: ExampleData[] = [];
|
|
148
|
-
|
|
149
|
-
for (let i = 1; i <= count; i++) {
|
|
150
|
-
const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
|
|
151
|
-
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
|
|
152
|
-
const domain = domains[Math.floor(Math.random() * domains.length)];
|
|
153
|
-
const status = statuses[Math.floor(Math.random() * statuses.length)];
|
|
154
|
-
|
|
155
|
-
const email = `${firstName.toLowerCase()}.${lastName.toLowerCase()}@${domain}`;
|
|
156
|
-
|
|
157
|
-
data.push({
|
|
158
|
-
_id: i.toString(),
|
|
159
|
-
name: `${firstName} ${lastName}`,
|
|
160
|
-
email: email,
|
|
161
|
-
status: status,
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return data;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
// Dados de exemplo gerados automaticamente
|
|
169
|
-
const mockData: ExampleData[] = generateMockData(100);
|
|
170
|
-
|
|
171
|
-
// Componente de formulário de exemplo
|
|
172
|
-
const ExampleForm = () => {
|
|
173
|
-
return (
|
|
174
|
-
<div className="space-y-4">
|
|
175
|
-
<Input name="name" label="Nome" placeholder="Digite o nome" required />
|
|
176
|
-
<Input name="email" label="Email" placeholder="Digite o email" required />
|
|
177
|
-
<Input
|
|
178
|
-
name="status"
|
|
179
|
-
label="Status"
|
|
180
|
-
placeholder="Digite o status"
|
|
181
|
-
required
|
|
182
|
-
/>
|
|
183
|
-
</div>
|
|
184
|
-
);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// Create a QueryClient instance for Storybook
|
|
188
|
-
const queryClient = new QueryClient({
|
|
189
|
-
defaultOptions: {
|
|
190
|
-
queries: {
|
|
191
|
-
retry: false, // Disable retries in Storybook
|
|
192
|
-
refetchOnWindowFocus: false, // Disable refetch on window focus
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
// Componente wrapper para usar o store
|
|
198
|
-
const CrudWrapper = (args: any) => {
|
|
199
|
-
const form = useForm<CreateData | UpdateData>();
|
|
200
|
-
useCrudLayout({
|
|
201
|
-
create: {
|
|
202
|
-
titleModal: "Criar Usuário",
|
|
203
|
-
submitButtonText: "Criar",
|
|
204
|
-
descriptionModal: "Crie um novo usuário",
|
|
205
|
-
},
|
|
206
|
-
update: {
|
|
207
|
-
titleModal: "Atualizar Usuário",
|
|
208
|
-
submitButtonText: "Atualizar",
|
|
209
|
-
descriptionModal: "Atualize os dados do usuário",
|
|
210
|
-
},
|
|
211
|
-
delete: {
|
|
212
|
-
titleModal: "Deletar Usuário",
|
|
213
|
-
submitButtonText: "Deletar",
|
|
214
|
-
descriptionModal: "Tem certeza que deseja deletar o usuário?",
|
|
215
|
-
},
|
|
216
|
-
createButtonText: "Novo usuário",
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// Colunas da tabela
|
|
220
|
-
const columns: ColumnDef<ExampleData>[] = [
|
|
221
|
-
{
|
|
222
|
-
accessorKey: "name",
|
|
223
|
-
header: "Nome",
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
accessorKey: "email",
|
|
227
|
-
header: "Email",
|
|
228
|
-
},
|
|
229
|
-
{
|
|
230
|
-
accessorKey: "status",
|
|
231
|
-
header: "Status",
|
|
232
|
-
},
|
|
233
|
-
];
|
|
234
|
-
|
|
235
|
-
// Funções de exemplo
|
|
236
|
-
const createRequest = async (data: CreateData) => {
|
|
237
|
-
console.log("Creating:", data);
|
|
238
|
-
// Simula delay de requisição
|
|
239
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
240
|
-
return Promise.resolve();
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
const updateRequest = async (data: UpdateData) => {
|
|
244
|
-
console.log("Updating:", data);
|
|
245
|
-
// Simula delay de requisição
|
|
246
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
247
|
-
return Promise.resolve();
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
const deleteRequest = async (id: string) => {
|
|
251
|
-
console.log("Deleting:", id);
|
|
252
|
-
// Simula delay de requisição
|
|
253
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
254
|
-
return Promise.resolve();
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
const listRequest = async (page?: number, limit?: number) => {
|
|
258
|
-
// Simula delay de carregamento
|
|
259
|
-
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
260
|
-
|
|
261
|
-
// Implementar paginação nos dados mock
|
|
262
|
-
const startIndex = ((page || 1) - 1) * (limit || 10);
|
|
263
|
-
const endIndex = startIndex + (limit || 10);
|
|
264
|
-
const paginatedData = mockData.slice(startIndex, endIndex);
|
|
265
|
-
|
|
266
|
-
return Promise.resolve({
|
|
267
|
-
data: paginatedData,
|
|
268
|
-
total: mockData.length,
|
|
269
|
-
});
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
return (
|
|
273
|
-
<QueryClientProvider client={queryClient}>
|
|
274
|
-
<CrudLayout
|
|
275
|
-
{...args}
|
|
276
|
-
columns={columns}
|
|
277
|
-
form={form}
|
|
278
|
-
formComponent={<ExampleForm />}
|
|
279
|
-
createRequest={createRequest}
|
|
280
|
-
updateRequest={updateRequest}
|
|
281
|
-
deleteRequest={deleteRequest}
|
|
282
|
-
listRequest={listRequest}
|
|
283
|
-
actions={["update", "delete"]}
|
|
284
|
-
title="Gerenciar Usuários"
|
|
285
|
-
description="Gerencie os usuários do sistema"
|
|
286
|
-
/>
|
|
287
|
-
</QueryClientProvider>
|
|
288
|
-
);
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
const meta: Meta<typeof CrudLayout> = {
|
|
292
|
-
title: "Layout/Crud",
|
|
293
|
-
component: CrudLayout,
|
|
294
|
-
tags: ["autodocs"],
|
|
295
|
-
parameters: {
|
|
296
|
-
layout: "fullscreen",
|
|
297
|
-
},
|
|
298
|
-
decorators: [
|
|
299
|
-
(Story) => (
|
|
300
|
-
<QueryClientProvider client={queryClient}>
|
|
301
|
-
<div className="p-4">
|
|
302
|
-
<Story />
|
|
303
|
-
</div>
|
|
304
|
-
</QueryClientProvider>
|
|
305
|
-
),
|
|
306
|
-
],
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
export default meta;
|
|
310
|
-
type Story = StoryObj<typeof CrudLayout>;
|
|
311
|
-
|
|
312
|
-
export const Default: Story = {
|
|
313
|
-
render: (args) => <CrudWrapper {...args} />,
|
|
314
|
-
args: {
|
|
315
|
-
title: "Gerenciar Usuários",
|
|
316
|
-
},
|
|
317
|
-
};
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo } from "react";
|
|
2
|
-
import {
|
|
3
|
-
useCreateButtonText,
|
|
4
|
-
useCrudLayoutActions,
|
|
5
|
-
useDeleteId,
|
|
6
|
-
useEditId,
|
|
7
|
-
useDescriptionModal,
|
|
8
|
-
useIsEditMode,
|
|
9
|
-
useSubmitButtonText,
|
|
10
|
-
useTitleModal,
|
|
11
|
-
useOpenEditModal,
|
|
12
|
-
} from "../../store/CrudLayoutStore";
|
|
13
|
-
|
|
14
|
-
type CommonProps = {
|
|
15
|
-
titleModal: string;
|
|
16
|
-
descriptionModal?: string;
|
|
17
|
-
submitButtonText: string;
|
|
18
|
-
sendingButtonText?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
type UseCrudLayoutProps = {
|
|
22
|
-
create?: CommonProps;
|
|
23
|
-
update?: CommonProps;
|
|
24
|
-
delete?: CommonProps;
|
|
25
|
-
createButtonText: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export function useCrudLayout(props: UseCrudLayoutProps) {
|
|
29
|
-
const deleteId = useDeleteId();
|
|
30
|
-
const editId = useEditId();
|
|
31
|
-
const titleModal = useTitleModal();
|
|
32
|
-
const descriptionModal = useDescriptionModal();
|
|
33
|
-
const submitButtonText = useSubmitButtonText();
|
|
34
|
-
const createButtonText = useCreateButtonText();
|
|
35
|
-
const isEditMode = useIsEditMode();
|
|
36
|
-
const openEditModal = useOpenEditModal();
|
|
37
|
-
const {
|
|
38
|
-
setTitleModal,
|
|
39
|
-
setDescriptionModal,
|
|
40
|
-
setSubmitButtonText,
|
|
41
|
-
setCreateButtonText,
|
|
42
|
-
setIsEditMode,
|
|
43
|
-
setDeleteId,
|
|
44
|
-
setEditId,
|
|
45
|
-
setOpenEditModal,
|
|
46
|
-
setSendingButtonText,
|
|
47
|
-
} = useCrudLayoutActions();
|
|
48
|
-
|
|
49
|
-
const key = useMemo(() => {
|
|
50
|
-
if (editId) return "update";
|
|
51
|
-
if (deleteId) return "delete";
|
|
52
|
-
return "create";
|
|
53
|
-
}, [editId, deleteId]);
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
const data = props[key] as CommonProps;
|
|
57
|
-
|
|
58
|
-
if (data) {
|
|
59
|
-
setTitleModal(data.titleModal);
|
|
60
|
-
setDescriptionModal(data.descriptionModal || "");
|
|
61
|
-
setSubmitButtonText(data.submitButtonText);
|
|
62
|
-
setCreateButtonText(props.createButtonText);
|
|
63
|
-
setSendingButtonText(data.sendingButtonText);
|
|
64
|
-
}
|
|
65
|
-
}, [
|
|
66
|
-
props,
|
|
67
|
-
key,
|
|
68
|
-
setTitleModal,
|
|
69
|
-
setDescriptionModal,
|
|
70
|
-
setSubmitButtonText,
|
|
71
|
-
setCreateButtonText,
|
|
72
|
-
setSendingButtonText,
|
|
73
|
-
deleteId,
|
|
74
|
-
]);
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
setTitleModal,
|
|
78
|
-
setDescriptionModal,
|
|
79
|
-
setSubmitButtonText,
|
|
80
|
-
setCreateButtonText,
|
|
81
|
-
setIsEditMode,
|
|
82
|
-
setDeleteId,
|
|
83
|
-
setEditId,
|
|
84
|
-
setOpenEditModal,
|
|
85
|
-
titleModal,
|
|
86
|
-
descriptionModal,
|
|
87
|
-
submitButtonText,
|
|
88
|
-
createButtonText,
|
|
89
|
-
isEditMode,
|
|
90
|
-
deleteId,
|
|
91
|
-
editId,
|
|
92
|
-
openEditModal,
|
|
93
|
-
};
|
|
94
|
-
}
|