@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,78 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { DotsHorizontalIcon } from "@radix-ui/react-icons";
|
|
4
|
+
import { Row } from "@tanstack/react-table";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
DropdownMenu,
|
|
8
|
+
DropdownMenuContent,
|
|
9
|
+
DropdownMenuItem,
|
|
10
|
+
DropdownMenuRadioGroup,
|
|
11
|
+
DropdownMenuRadioItem,
|
|
12
|
+
DropdownMenuSeparator,
|
|
13
|
+
DropdownMenuShortcut,
|
|
14
|
+
DropdownMenuSub,
|
|
15
|
+
DropdownMenuSubContent,
|
|
16
|
+
DropdownMenuSubTrigger,
|
|
17
|
+
DropdownMenuTrigger,
|
|
18
|
+
} from "../../../../../components/ui/dropdown-menu";
|
|
19
|
+
import { Button } from "../../../../../components/ui/button";
|
|
20
|
+
import { taskSchema } from "./schema";
|
|
21
|
+
import { labels } from "./data";
|
|
22
|
+
|
|
23
|
+
interface DataTableRowActionsProps<TData> {
|
|
24
|
+
row: Row<TData>;
|
|
25
|
+
options: {
|
|
26
|
+
action: (row: Row<TData>) => void;
|
|
27
|
+
label: string;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function DataTableRowActions<TData>({
|
|
32
|
+
row,
|
|
33
|
+
options,
|
|
34
|
+
}: DataTableRowActionsProps<TData>) {
|
|
35
|
+
// const task = taskSchema.parse(row.original);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<DropdownMenu>
|
|
39
|
+
<DropdownMenuTrigger asChild>
|
|
40
|
+
<Button
|
|
41
|
+
variant="ghost"
|
|
42
|
+
className="flex h-8 w-8 p-0 data-[state=open]:bg-muted"
|
|
43
|
+
>
|
|
44
|
+
<DotsHorizontalIcon className="h-4 w-4" />
|
|
45
|
+
<span className="sr-only">Open menu</span>
|
|
46
|
+
</Button>
|
|
47
|
+
</DropdownMenuTrigger>
|
|
48
|
+
<DropdownMenuContent align="end" className="w-[160px]">
|
|
49
|
+
{options.map(({ action, label }, index) => (
|
|
50
|
+
<DropdownMenuItem key={index} onClick={() => action(row)}>
|
|
51
|
+
{label}
|
|
52
|
+
</DropdownMenuItem>
|
|
53
|
+
))}
|
|
54
|
+
{/* <DropdownMenuItem>Edit</DropdownMenuItem>
|
|
55
|
+
<DropdownMenuItem>Make a copy</DropdownMenuItem>
|
|
56
|
+
<DropdownMenuItem>Favorite</DropdownMenuItem>
|
|
57
|
+
<DropdownMenuSeparator />
|
|
58
|
+
<DropdownMenuSub>
|
|
59
|
+
<DropdownMenuSubTrigger>Labels</DropdownMenuSubTrigger>
|
|
60
|
+
<DropdownMenuSubContent>
|
|
61
|
+
<DropdownMenuRadioGroup value={task.label}>
|
|
62
|
+
{labels.map((label) => (
|
|
63
|
+
<DropdownMenuRadioItem key={label.value} value={label.value}>
|
|
64
|
+
{label.label}
|
|
65
|
+
</DropdownMenuRadioItem>
|
|
66
|
+
))}
|
|
67
|
+
</DropdownMenuRadioGroup>
|
|
68
|
+
</DropdownMenuSubContent>
|
|
69
|
+
</DropdownMenuSub>
|
|
70
|
+
<DropdownMenuSeparator />
|
|
71
|
+
<DropdownMenuItem>
|
|
72
|
+
Delete
|
|
73
|
+
<DropdownMenuShortcut>⌘⌫</DropdownMenuShortcut>
|
|
74
|
+
</DropdownMenuItem> */}
|
|
75
|
+
</DropdownMenuContent>
|
|
76
|
+
</DropdownMenu>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Cross2Icon } from "@radix-ui/react-icons";
|
|
4
|
+
import { Table } from "@tanstack/react-table";
|
|
5
|
+
|
|
6
|
+
import { priorities, statuses } from "./data";
|
|
7
|
+
import { DataTableFacetedFilter } from "./data-table-faceted-filter";
|
|
8
|
+
import { Input } from "../../../../../components/ui/input";
|
|
9
|
+
import { Button } from "../../../../../components/ui/button";
|
|
10
|
+
import { DataTableViewOptions } from "./data-table-view-options";
|
|
11
|
+
|
|
12
|
+
interface DataTableToolbarProps<TData> {
|
|
13
|
+
table: Table<TData>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function DataTableToolbar<TData>({
|
|
17
|
+
table,
|
|
18
|
+
}: DataTableToolbarProps<TData>) {
|
|
19
|
+
const isFiltered = table.getState().columnFilters.length > 0;
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="flex items-center justify-between">
|
|
23
|
+
<div className="flex flex-1 items-center space-x-2">
|
|
24
|
+
<Input
|
|
25
|
+
placeholder="Filter tasks..."
|
|
26
|
+
value={(table.getColumn("title")?.getFilterValue() as string) ?? ""}
|
|
27
|
+
onChange={(event) =>
|
|
28
|
+
table.getColumn("title")?.setFilterValue(event.target.value)
|
|
29
|
+
}
|
|
30
|
+
className="h-8 w-[150px] lg:w-[250px]"
|
|
31
|
+
/>
|
|
32
|
+
{table.getColumn("status") && (
|
|
33
|
+
<DataTableFacetedFilter
|
|
34
|
+
column={table.getColumn("status")}
|
|
35
|
+
title="Status"
|
|
36
|
+
options={statuses}
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
39
|
+
{table.getColumn("priority") && (
|
|
40
|
+
<DataTableFacetedFilter
|
|
41
|
+
column={table.getColumn("priority")}
|
|
42
|
+
title="Priority"
|
|
43
|
+
options={priorities}
|
|
44
|
+
/>
|
|
45
|
+
)}
|
|
46
|
+
{isFiltered && (
|
|
47
|
+
<Button
|
|
48
|
+
variant="ghost"
|
|
49
|
+
onClick={() => table.resetColumnFilters()}
|
|
50
|
+
className="h-8 px-2 lg:px-3"
|
|
51
|
+
>
|
|
52
|
+
Reset
|
|
53
|
+
<Cross2Icon className="ml-2 h-4 w-4" />
|
|
54
|
+
</Button>
|
|
55
|
+
)}
|
|
56
|
+
</div>
|
|
57
|
+
<DataTableViewOptions table={table} />
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { DropdownMenuTrigger } from "@radix-ui/react-dropdown-menu";
|
|
4
|
+
import { MixerHorizontalIcon } from "@radix-ui/react-icons";
|
|
5
|
+
import { Table } from "@tanstack/react-table";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuCheckboxItem,
|
|
10
|
+
DropdownMenuContent,
|
|
11
|
+
DropdownMenuLabel,
|
|
12
|
+
DropdownMenuSeparator,
|
|
13
|
+
} from "../../../../../components/ui/dropdown-menu";
|
|
14
|
+
import { Button } from "../../../../../components/ui/button";
|
|
15
|
+
|
|
16
|
+
interface DataTableViewOptionsProps<TData> {
|
|
17
|
+
table: Table<TData>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function DataTableViewOptions<TData>({
|
|
21
|
+
table,
|
|
22
|
+
}: DataTableViewOptionsProps<TData>) {
|
|
23
|
+
return (
|
|
24
|
+
<DropdownMenu>
|
|
25
|
+
<DropdownMenuTrigger asChild>
|
|
26
|
+
<Button
|
|
27
|
+
variant="outline"
|
|
28
|
+
size="sm"
|
|
29
|
+
className="ml-auto hidden h-8 lg:flex"
|
|
30
|
+
>
|
|
31
|
+
<MixerHorizontalIcon className="mr-2 h-4 w-4" />
|
|
32
|
+
View
|
|
33
|
+
</Button>
|
|
34
|
+
</DropdownMenuTrigger>
|
|
35
|
+
<DropdownMenuContent align="end" className="w-[150px]">
|
|
36
|
+
<DropdownMenuLabel>Toggle columns</DropdownMenuLabel>
|
|
37
|
+
<DropdownMenuSeparator />
|
|
38
|
+
{table
|
|
39
|
+
.getAllColumns()
|
|
40
|
+
.filter(
|
|
41
|
+
(column) =>
|
|
42
|
+
typeof column.accessorFn !== "undefined" && column.getCanHide()
|
|
43
|
+
)
|
|
44
|
+
.map((column) => {
|
|
45
|
+
return (
|
|
46
|
+
<DropdownMenuCheckboxItem
|
|
47
|
+
key={column.id}
|
|
48
|
+
className="capitalize"
|
|
49
|
+
checked={column.getIsVisible()}
|
|
50
|
+
onCheckedChange={(value) => column.toggleVisibility(!!value)}
|
|
51
|
+
>
|
|
52
|
+
{column.id}
|
|
53
|
+
</DropdownMenuCheckboxItem>
|
|
54
|
+
);
|
|
55
|
+
})}
|
|
56
|
+
</DropdownMenuContent>
|
|
57
|
+
</DropdownMenu>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useEffect, useState } from "react";
|
|
4
|
+
import {
|
|
5
|
+
ColumnDef,
|
|
6
|
+
ColumnFiltersState,
|
|
7
|
+
SortingState,
|
|
8
|
+
TableState,
|
|
9
|
+
VisibilityState,
|
|
10
|
+
flexRender,
|
|
11
|
+
getCoreRowModel,
|
|
12
|
+
getFacetedRowModel,
|
|
13
|
+
getFacetedUniqueValues,
|
|
14
|
+
getFilteredRowModel,
|
|
15
|
+
getPaginationRowModel,
|
|
16
|
+
getSortedRowModel,
|
|
17
|
+
useReactTable,
|
|
18
|
+
} from "@tanstack/react-table";
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
Table,
|
|
22
|
+
TableBody,
|
|
23
|
+
TableCell,
|
|
24
|
+
TableHead,
|
|
25
|
+
TableHeader,
|
|
26
|
+
TableRow,
|
|
27
|
+
} from "../../../../../components/ui/table";
|
|
28
|
+
|
|
29
|
+
import { DataTablePagination } from "./data-table-pagination";
|
|
30
|
+
import { DataTableToolbar } from "./data-table-toolbar";
|
|
31
|
+
|
|
32
|
+
interface DataTableProps<TData, TValue> {
|
|
33
|
+
columns: ColumnDef<TData, TValue>[];
|
|
34
|
+
data: TData[];
|
|
35
|
+
callback?: (data: TableState) => void;
|
|
36
|
+
renderToolbar?: (table: any) => React.ReactNode;
|
|
37
|
+
renderPagination?: (table: any) => React.ReactNode;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function DataTable<TData, TValue>({
|
|
41
|
+
columns,
|
|
42
|
+
data,
|
|
43
|
+
callback = () => {},
|
|
44
|
+
renderToolbar = () => null,
|
|
45
|
+
renderPagination = () => null,
|
|
46
|
+
}: DataTableProps<TData, TValue>) {
|
|
47
|
+
const [rowSelection, setRowSelection] = useState({});
|
|
48
|
+
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
|
49
|
+
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
|
|
50
|
+
const [sorting, setSorting] = useState<SortingState>([]);
|
|
51
|
+
|
|
52
|
+
const table = useReactTable({
|
|
53
|
+
data,
|
|
54
|
+
columns,
|
|
55
|
+
state: {
|
|
56
|
+
sorting,
|
|
57
|
+
columnVisibility,
|
|
58
|
+
rowSelection,
|
|
59
|
+
columnFilters,
|
|
60
|
+
},
|
|
61
|
+
enableRowSelection: true,
|
|
62
|
+
onRowSelectionChange: setRowSelection,
|
|
63
|
+
onSortingChange: setSorting,
|
|
64
|
+
onColumnFiltersChange: setColumnFilters,
|
|
65
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
66
|
+
getCoreRowModel: getCoreRowModel(),
|
|
67
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
68
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
69
|
+
getSortedRowModel: getSortedRowModel(),
|
|
70
|
+
getFacetedRowModel: getFacetedRowModel(),
|
|
71
|
+
getFacetedUniqueValues: getFacetedUniqueValues(),
|
|
72
|
+
manualPagination: true,
|
|
73
|
+
manualSorting: true,
|
|
74
|
+
manualFiltering: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const {
|
|
78
|
+
pagination,
|
|
79
|
+
sorting: tableSorting,
|
|
80
|
+
columnFilters: tableFilters,
|
|
81
|
+
} = table.getState();
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
callback(table.getState());
|
|
85
|
+
}, [pagination, tableSorting, tableFilters]);
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div className="space-y-4">
|
|
89
|
+
{/* <DataTableToolbar table={table} /> */}
|
|
90
|
+
{renderToolbar(table)}
|
|
91
|
+
<div className="rounded-md border">
|
|
92
|
+
<Table>
|
|
93
|
+
<TableHeader>
|
|
94
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
95
|
+
<TableRow key={headerGroup.id}>
|
|
96
|
+
{headerGroup.headers.map((header) => {
|
|
97
|
+
return (
|
|
98
|
+
<TableHead key={header.id} colSpan={header.colSpan}>
|
|
99
|
+
{header.isPlaceholder
|
|
100
|
+
? null
|
|
101
|
+
: flexRender(
|
|
102
|
+
header.column.columnDef.header,
|
|
103
|
+
header.getContext()
|
|
104
|
+
)}
|
|
105
|
+
</TableHead>
|
|
106
|
+
);
|
|
107
|
+
})}
|
|
108
|
+
</TableRow>
|
|
109
|
+
))}
|
|
110
|
+
</TableHeader>
|
|
111
|
+
<TableBody>
|
|
112
|
+
{table.getRowModel().rows?.length ? (
|
|
113
|
+
table.getRowModel().rows.map((row) => (
|
|
114
|
+
<TableRow
|
|
115
|
+
key={row.id}
|
|
116
|
+
data-state={row.getIsSelected() && "selected"}
|
|
117
|
+
>
|
|
118
|
+
{row.getVisibleCells().map((cell) => (
|
|
119
|
+
<TableCell key={cell.id}>
|
|
120
|
+
{flexRender(
|
|
121
|
+
cell.column.columnDef.cell,
|
|
122
|
+
cell.getContext()
|
|
123
|
+
)}
|
|
124
|
+
</TableCell>
|
|
125
|
+
))}
|
|
126
|
+
</TableRow>
|
|
127
|
+
))
|
|
128
|
+
) : (
|
|
129
|
+
<TableRow>
|
|
130
|
+
<TableCell
|
|
131
|
+
colSpan={columns.length}
|
|
132
|
+
className="h-24 text-center"
|
|
133
|
+
>
|
|
134
|
+
Sem resultados.
|
|
135
|
+
</TableCell>
|
|
136
|
+
</TableRow>
|
|
137
|
+
)}
|
|
138
|
+
</TableBody>
|
|
139
|
+
</Table>
|
|
140
|
+
</div>
|
|
141
|
+
{renderPagination(table)}
|
|
142
|
+
{/* <DataTablePagination table={table} /> */}
|
|
143
|
+
</div>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrowDownIcon,
|
|
3
|
+
ArrowRightIcon,
|
|
4
|
+
ArrowUpIcon,
|
|
5
|
+
CheckCircledIcon,
|
|
6
|
+
CircleIcon,
|
|
7
|
+
CrossCircledIcon,
|
|
8
|
+
QuestionMarkCircledIcon,
|
|
9
|
+
StopwatchIcon,
|
|
10
|
+
} from "@radix-ui/react-icons";
|
|
11
|
+
|
|
12
|
+
export const labels = [
|
|
13
|
+
{
|
|
14
|
+
value: "bug",
|
|
15
|
+
label: "Bug",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
value: "feature",
|
|
19
|
+
label: "Feature",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
value: "documentation",
|
|
23
|
+
label: "Documentation",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export const statuses = [
|
|
28
|
+
{
|
|
29
|
+
value: "backlog",
|
|
30
|
+
label: "Backlog",
|
|
31
|
+
icon: QuestionMarkCircledIcon,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
value: "todo",
|
|
35
|
+
label: "Todo",
|
|
36
|
+
icon: CircleIcon,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
value: "in progress",
|
|
40
|
+
label: "In Progress",
|
|
41
|
+
icon: StopwatchIcon,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
value: "done",
|
|
45
|
+
label: "Done",
|
|
46
|
+
icon: CheckCircledIcon,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
value: "canceled",
|
|
50
|
+
label: "Canceled",
|
|
51
|
+
icon: CrossCircledIcon,
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
export const priorities = [
|
|
56
|
+
{
|
|
57
|
+
label: "Low",
|
|
58
|
+
value: "low",
|
|
59
|
+
icon: ArrowDownIcon,
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: "Medium",
|
|
63
|
+
value: "medium",
|
|
64
|
+
icon: ArrowRightIcon,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
label: "High",
|
|
68
|
+
value: "high",
|
|
69
|
+
icon: ArrowUpIcon,
|
|
70
|
+
},
|
|
71
|
+
];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DataTable } from "./data-table";
|
|
3
|
+
export { DataTableColumnHeader } from "./data-table-column-header";
|
|
4
|
+
export { DataTableRowActions } from "./data-table-row-actions";
|
|
5
|
+
export { DataTablePagination } from "./data-table-pagination";
|
|
6
|
+
export { DataTableToolbar } from "./data-table-toolbar";
|
|
7
|
+
|
|
8
|
+
import { ColumnDef, TableState } from "@tanstack/react-table";
|
|
9
|
+
|
|
10
|
+
export type CustomTableProps<TData, TValue> = {
|
|
11
|
+
data: TData[];
|
|
12
|
+
columns: ColumnDef<TData, TValue>[];
|
|
13
|
+
callback?: (data: TableState) => void;
|
|
14
|
+
renderToolbar?: (table: any) => React.ReactNode;
|
|
15
|
+
renderPagination?: (table: any) => React.ReactNode;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function CustomTable<TData, TValue>({
|
|
19
|
+
data,
|
|
20
|
+
columns,
|
|
21
|
+
callback = () => {},
|
|
22
|
+
renderPagination = () => null,
|
|
23
|
+
renderToolbar = () => null,
|
|
24
|
+
}: CustomTableProps<TData, TValue>) {
|
|
25
|
+
return (
|
|
26
|
+
<DataTable
|
|
27
|
+
columns={columns}
|
|
28
|
+
data={data}
|
|
29
|
+
callback={callback}
|
|
30
|
+
renderPagination={renderPagination}
|
|
31
|
+
renderToolbar={renderToolbar}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/nextjs";
|
|
2
|
+
import { Table } from "./Table";
|
|
3
|
+
import { ColumnDef } from "@tanstack/react-table";
|
|
4
|
+
|
|
5
|
+
const meta: Meta<typeof Table> = {
|
|
6
|
+
title: "DataDisplay/Table",
|
|
7
|
+
component: Table,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "centered",
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof Table<User>>;
|
|
15
|
+
|
|
16
|
+
type User = {
|
|
17
|
+
id: number;
|
|
18
|
+
name: string;
|
|
19
|
+
email: string;
|
|
20
|
+
role: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const mockData: User[] = [
|
|
24
|
+
{
|
|
25
|
+
id: 1,
|
|
26
|
+
name: "John Doe",
|
|
27
|
+
email: "john@example.com",
|
|
28
|
+
role: "Admin",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 2,
|
|
32
|
+
name: "Jane Smith",
|
|
33
|
+
email: "jane@example.com",
|
|
34
|
+
role: "User",
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 3,
|
|
38
|
+
name: "Bob Johnson",
|
|
39
|
+
email: "bob@example.com",
|
|
40
|
+
role: "Editor",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 4,
|
|
44
|
+
name: "Alice Brown",
|
|
45
|
+
email: "alice@example.com",
|
|
46
|
+
role: "User",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 5,
|
|
50
|
+
name: "Charlie Wilson",
|
|
51
|
+
email: "charlie@example.com",
|
|
52
|
+
role: "Editor",
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 6,
|
|
56
|
+
name: "Diana Miller",
|
|
57
|
+
email: "diana@example.com",
|
|
58
|
+
role: "User",
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const columns: ColumnDef<User>[] = [
|
|
63
|
+
{
|
|
64
|
+
accessorKey: "id",
|
|
65
|
+
header: "ID",
|
|
66
|
+
enableSorting: true,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
accessorKey: "name",
|
|
70
|
+
header: "Name",
|
|
71
|
+
enableSorting: true,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
accessorKey: "email",
|
|
75
|
+
header: "Email",
|
|
76
|
+
enableSorting: true,
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
accessorKey: "role",
|
|
80
|
+
header: "Role",
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
|
|
84
|
+
export const Default: Story = {
|
|
85
|
+
args: {
|
|
86
|
+
data: mockData,
|
|
87
|
+
columns: columns,
|
|
88
|
+
pagination: {
|
|
89
|
+
pageIndex: 0,
|
|
90
|
+
pageSize: 5,
|
|
91
|
+
},
|
|
92
|
+
onPaginationChange: (pagination) => {
|
|
93
|
+
console.log("Page changed:", {
|
|
94
|
+
pageIndex: pagination.pageIndex,
|
|
95
|
+
pageSize: pagination.pageSize,
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const SmallPageSize: Story = {
|
|
102
|
+
args: {
|
|
103
|
+
data: mockData,
|
|
104
|
+
columns: columns,
|
|
105
|
+
pagination: {
|
|
106
|
+
pageIndex: 0,
|
|
107
|
+
pageSize: 3,
|
|
108
|
+
},
|
|
109
|
+
onPaginationChange: (pagination) => {
|
|
110
|
+
console.log("Page changed:", {
|
|
111
|
+
pageIndex: pagination.pageIndex,
|
|
112
|
+
pageSize: pagination.pageSize,
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export const StartingFromPage2: Story = {
|
|
119
|
+
args: {
|
|
120
|
+
data: mockData,
|
|
121
|
+
columns: columns,
|
|
122
|
+
pagination: {
|
|
123
|
+
pageIndex: 1, // Starts from second page
|
|
124
|
+
pageSize: 3,
|
|
125
|
+
},
|
|
126
|
+
onPaginationChange: (pagination) => {
|
|
127
|
+
console.log("Page changed:", {
|
|
128
|
+
pageIndex: pagination.pageIndex,
|
|
129
|
+
pageSize: pagination.pageSize,
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const EmptyTable: Story = {
|
|
136
|
+
args: {
|
|
137
|
+
data: [],
|
|
138
|
+
columns: columns,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
export const SingleRow: Story = {
|
|
143
|
+
args: {
|
|
144
|
+
data: [mockData[0]],
|
|
145
|
+
columns: columns,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Column<T> {
|
|
2
|
+
header: string;
|
|
3
|
+
accessorKey: keyof T;
|
|
4
|
+
cell?: (row: T) => React.ReactNode;
|
|
5
|
+
sortable?: boolean;
|
|
6
|
+
filterable?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TableProps<T> {
|
|
10
|
+
data: T[];
|
|
11
|
+
columns: Column<T>[];
|
|
12
|
+
className?: string;
|
|
13
|
+
filters?: React.ReactNode;
|
|
14
|
+
onSort?: (field: keyof T, direction: "asc" | "desc") => void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/nextjs";
|
|
2
|
+
|
|
3
|
+
import { Tabs } from "./Tabs";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "DataDisplay/Tabs",
|
|
7
|
+
component: Tabs,
|
|
8
|
+
parameters: {
|
|
9
|
+
layout: "centered",
|
|
10
|
+
},
|
|
11
|
+
tags: ["autodocs"],
|
|
12
|
+
} satisfies Meta<typeof Tabs>;
|
|
13
|
+
|
|
14
|
+
export default meta;
|
|
15
|
+
type Story = StoryObj<typeof meta>;
|
|
16
|
+
|
|
17
|
+
export const Default: Story = {
|
|
18
|
+
args: {
|
|
19
|
+
data: [
|
|
20
|
+
{
|
|
21
|
+
label: "Tab 1",
|
|
22
|
+
value: "tab1",
|
|
23
|
+
content: <div>Tab 1 content</div>,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
label: "Tab 2",
|
|
27
|
+
value: "tab2",
|
|
28
|
+
content: <div>Tab 2 content</div>,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
defaultValue: "tab1",
|
|
32
|
+
onSelectTab: (value) => console.log(value),
|
|
33
|
+
},
|
|
34
|
+
};
|