@phsa.tec/design-system-react 0.1.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/.eslintrc.json +7 -0
- package/.storybook/main.ts +16 -0
- package/.storybook/preview.ts +15 -0
- package/README.md +36 -0
- package/components.json +21 -0
- package/jest.config.ts +25 -0
- package/next.config.ts +7 -0
- package/package.json +88 -0
- package/postcss.config.mjs +8 -0
- package/public/file.svg +1 -0
- package/public/globe.svg +1 -0
- package/public/next.svg +1 -0
- package/public/vercel.svg +1 -0
- package/public/window.svg +1 -0
- package/src/app/columns.tsx +178 -0
- 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 +94 -0
- package/src/app/layout.tsx +35 -0
- package/src/app/page.tsx +7 -0
- package/src/components/actions/AlertDialog/AlertDialog.tsx +45 -0
- package/src/components/actions/AlertDialog/alert-dialog.stories.tsx +21 -0
- package/src/components/actions/AlertDialog/index.ts +1 -0
- package/src/components/actions/Button/Button.stories.ts +38 -0
- package/src/components/actions/Button/Button.tsx +23 -0
- package/src/components/actions/Button/index.ts +1 -0
- package/src/components/actions/Collapsible/index.ts +1 -0
- package/src/components/actions/Dialog/Dialog.stories.tsx +70 -0
- package/src/components/actions/Dialog/Dialog.tsx +87 -0
- package/src/components/actions/Dialog/components/DialogWithActions/index.tsx +40 -0
- package/src/components/actions/Dialog/index.ts +1 -0
- package/src/components/actions/Steps/Steps.stories.tsx +25 -0
- package/src/components/actions/Steps/Steps.tsx +51 -0
- package/src/components/actions/Steps/index.ts +1 -0
- package/src/components/actions/index.ts +5 -0
- package/src/components/dataDisplay/Avatar/Avatar.stories.tsx +22 -0
- package/src/components/dataDisplay/Avatar/Avatar.tsx +21 -0
- package/src/components/dataDisplay/Avatar/index.ts +2 -0
- package/src/components/dataDisplay/Badge/Badge.stories.tsx +36 -0
- package/src/components/dataDisplay/Badge/index.ts +1 -0
- package/src/components/dataDisplay/Card/Card.stories.tsx +24 -0
- package/src/components/dataDisplay/Card/Card.tsx +34 -0
- package/src/components/dataDisplay/Card/index.ts +1 -0
- package/src/components/dataDisplay/DataPairList/DataPairList.tsx +56 -0
- package/src/components/dataDisplay/DataPairList/data-pair-list.stories.tsx +87 -0
- package/src/components/dataDisplay/DataPairList/index.ts +2 -0
- package/src/components/dataDisplay/DataPairList/types.ts +10 -0
- package/src/components/dataDisplay/DropDownMenu/index.ts +1 -0
- package/src/components/dataDisplay/ErrorMessage/ErrorMessage.tsx +6 -0
- package/src/components/dataDisplay/ErrorMessage/index.ts +1 -0
- package/src/components/dataDisplay/Icon/Icon.stories.tsx +21 -0
- package/src/components/dataDisplay/Icon/Icon.tsx +47 -0
- package/src/components/dataDisplay/Icon/index.ts +1 -0
- package/src/components/dataDisplay/Icon/types.ts +6 -0
- package/src/components/dataDisplay/Label/Label.stories.tsx +21 -0
- package/src/components/dataDisplay/Label/Label.tsx +10 -0
- package/src/components/dataDisplay/Label/index.ts +1 -0
- package/src/components/dataDisplay/Table/Table.tsx +173 -0
- package/src/components/dataDisplay/Table/columns.tsx +223 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-column-header.tsx +72 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-pagination.tsx +91 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-toolbar.tsx +17 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table-view-options.tsx +58 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/data-table.stories.tsx +118 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/index.tsx +136 -0
- package/src/components/dataDisplay/Table/components/DynamicTable/types.ts +43 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-column-header.tsx +71 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-faceted-filter.tsx +147 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-pagination.tsx +97 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-row-actions.tsx +78 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-toolbar.tsx +60 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table-view-options.tsx +59 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data-table.tsx +145 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/data.ts +71 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/index.tsx +34 -0
- package/src/components/dataDisplay/Table/custom/CustomTable/schema.ts +11 -0
- package/src/components/dataDisplay/Table/index.ts +2 -0
- package/src/components/dataDisplay/Table/table.stories.tsx +147 -0
- package/src/components/dataDisplay/Table/types.ts +15 -0
- package/src/components/dataDisplay/Tabs/Tabs.stories.tsx +34 -0
- package/src/components/dataDisplay/Tabs/Tabs.tsx +53 -0
- package/src/components/dataDisplay/Tabs/index.ts +1 -0
- package/src/components/dataDisplay/Text/Text.stories.tsx +66 -0
- package/src/components/dataDisplay/Text/Text.tsx +56 -0
- package/src/components/dataDisplay/Text/index.ts +1 -0
- package/src/components/dataDisplay/index.ts +8 -0
- package/src/components/dataInput/Input/components/Input/Input.stories.tsx +99 -0
- package/src/components/dataInput/Input/components/Input/InputBase.tsx +50 -0
- package/src/components/dataInput/Input/components/Input/__tests__/Input.test.tsx +100 -0
- package/src/components/dataInput/Input/components/Input/index.tsx +257 -0
- package/src/components/dataInput/Input/components/InputBase/__tests__/InputBase.test.tsx +120 -0
- package/src/components/dataInput/Input/components/InputBase/index.tsx +89 -0
- package/src/components/dataInput/Input/components/MaskInput/__tests__/mask-input.test.tsx +67 -0
- package/src/components/dataInput/Input/components/MaskInput/index.ts +1 -0
- package/src/components/dataInput/Input/components/MaskInput/mask-input.stories.tsx +59 -0
- package/src/components/dataInput/Input/components/MaskInput/mask-input.tsx +43 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleInput.tsx +36 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleInputBase.tsx +100 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleMaskInput.tsx +35 -0
- package/src/components/dataInput/Input/components/MultipleInput/MultipleNumberInput.tsx +35 -0
- package/src/components/dataInput/Input/components/MultipleInput/index.ts +2 -0
- package/src/components/dataInput/Input/components/MultipleInput/multiple-input.stories.tsx +71 -0
- package/src/components/dataInput/Input/components/NumberInput/__tests__/number-input.test.tsx +95 -0
- package/src/components/dataInput/Input/components/NumberInput/index.ts +1 -0
- package/src/components/dataInput/Input/components/NumberInput/number-input.stories.tsx +76 -0
- package/src/components/dataInput/Input/components/NumberInput/number-input.tsx +68 -0
- package/src/components/dataInput/Input/index.ts +4 -0
- package/src/components/dataInput/Select/MultiSelect/MultiSelect.stories.tsx +119 -0
- package/src/components/dataInput/Select/MultiSelect/MultiSelectBase.tsx +135 -0
- package/src/components/dataInput/Select/MultiSelect/index.tsx +75 -0
- package/src/components/dataInput/Select/Select.stories.tsx +61 -0
- package/src/components/dataInput/Select/Select.tsx +73 -0
- package/src/components/dataInput/Select/SelectBase.tsx +58 -0
- package/src/components/dataInput/Select/index.ts +2 -0
- package/src/components/dataInput/Switch/Switch.stories.tsx +75 -0
- package/src/components/dataInput/Switch/Switch.tsx +52 -0
- package/src/components/dataInput/Switch/index.ts +1 -0
- package/src/components/dataInput/checkbox/Checkbox.tsx +57 -0
- package/src/components/dataInput/checkbox/Checkbox_old.tsx +58 -0
- package/src/components/dataInput/checkbox/Checkout.stories.tsx +62 -0
- package/src/components/dataInput/checkbox/index.ts +1 -0
- package/src/components/dataInput/form/Form.tsx +47 -0
- package/src/components/dataInput/form/index.ts +3 -0
- package/src/components/dataInput/index.ts +5 -0
- package/src/components/feedback/Spinner/index.ts +1 -0
- package/src/components/feedback/Toast/Toast.stories.tsx +45 -0
- package/src/components/feedback/Toast/index.ts +2 -0
- package/src/components/feedback/index.ts +2 -0
- package/src/components/index.ts +6 -0
- package/src/components/layout/Crud/components/Table/index.tsx +183 -0
- package/src/components/layout/Crud/components/Table/types.ts +15 -0
- package/src/components/layout/Crud/crud.stories.tsx +317 -0
- package/src/components/layout/Crud/hook/useCrudLayout/index.tsx +94 -0
- package/src/components/layout/Crud/hook/useRequest/index.tsx +156 -0
- package/src/components/layout/Crud/index.tsx +295 -0
- package/src/components/layout/Crud/store/CrudLayoutStore.ts +75 -0
- package/src/components/layout/Crud/types.ts +14 -0
- package/src/components/layout/Drawer/CustomDrawer/index.tsx +33 -0
- package/src/components/layout/Drawer/Drawer.stories.tsx +80 -0
- package/src/components/layout/Drawer/index.ts +2 -0
- package/src/components/layout/PageLayout/PageLayout.stories.tsx +42 -0
- package/src/components/layout/PageLayout/index.tsx +28 -0
- package/src/components/layout/Separator/index.ts +1 -0
- package/src/components/layout/Sheet/Sheet.stories.tsx +28 -0
- package/src/components/layout/Sheet/Sheet.tsx +22 -0
- package/src/components/layout/Sheet/index.ts +1 -0
- package/src/components/layout/Sidebar/Sidebar.stories.tsx +116 -0
- package/src/components/layout/Sidebar/Sidebar.tsx +50 -0
- package/src/components/layout/Sidebar/components/app-sidebar.tsx +203 -0
- package/src/components/layout/Sidebar/components/footer-sidebar.tsx +17 -0
- package/src/components/layout/Sidebar/components/header-sidebar.tsx +90 -0
- package/src/components/layout/Sidebar/components/menus.tsx +55 -0
- package/src/components/layout/Sidebar/components/nav-projects.tsx +88 -0
- package/src/components/layout/Sidebar/components/nav-user.tsx +114 -0
- package/src/components/layout/Sidebar/components/team-switcher.tsx +85 -0
- package/src/components/layout/Sidebar/index.ts +2 -0
- package/src/components/layout/Sidebar/provider/index.tsx +51 -0
- package/src/components/layout/Tabs/Tabs.tsx +51 -0
- package/src/components/layout/Tabs/index.ts +1 -0
- package/src/components/layout/Tabs/tabs.stories.tsx +57 -0
- package/src/components/layout/index.ts +6 -0
- package/src/components/navigation/Breadcrumbs/Breadcrumbs.tsx +66 -0
- package/src/components/navigation/Breadcrumbs/index.ts +2 -0
- package/src/components/navigation/index.ts +1 -0
- package/src/components/ui/alert-dialog.tsx +141 -0
- package/src/components/ui/alert.tsx +59 -0
- package/src/components/ui/avatar.tsx +50 -0
- package/src/components/ui/badge.tsx +40 -0
- package/src/components/ui/breadcrumb.tsx +115 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/card.tsx +83 -0
- package/src/components/ui/checkbox.tsx +34 -0
- package/src/components/ui/collapsible.tsx +11 -0
- package/src/components/ui/command.tsx +153 -0
- package/src/components/ui/dialog.tsx +124 -0
- package/src/components/ui/drawer.tsx +117 -0
- package/src/components/ui/dropdown-menu.tsx +201 -0
- package/src/components/ui/form.tsx +179 -0
- package/src/components/ui/input.tsx +24 -0
- package/src/components/ui/label.tsx +30 -0
- package/src/components/ui/popover.tsx +33 -0
- package/src/components/ui/select.tsx +161 -0
- package/src/components/ui/separator.tsx +31 -0
- package/src/components/ui/sheet.tsx +140 -0
- package/src/components/ui/sidebar.tsx +763 -0
- package/src/components/ui/skeleton.tsx +15 -0
- package/src/components/ui/sonner.tsx +31 -0
- package/src/components/ui/spinner.tsx +54 -0
- package/src/components/ui/switch.tsx +33 -0
- package/src/components/ui/table.tsx +120 -0
- package/src/components/ui/tabs.tsx +55 -0
- package/src/components/ui/toast.tsx +130 -0
- package/src/components/ui/toaster.tsx +35 -0
- package/src/components/ui/tooltip.tsx +32 -0
- package/src/hooks/use-mobile.tsx +19 -0
- package/src/hooks/use-toast.ts +191 -0
- package/src/index.ts +1 -0
- package/src/lib/utils.ts +6 -0
- package/tailwind.config.ts +83 -0
- package/tsconfig.json +27 -0
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
+
}
|