From 54fa2b9c06b4bfe3ce9158d0410b555d23f47452 Mon Sep 17 00:00:00 2001 From: Ed Castro Date: Wed, 2 Oct 2024 18:42:08 -0300 Subject: [PATCH] feat(ui): Add table component and updated in community validator --- .../src/app/components/delegated-list.tsx | 218 ++++++++++-------- packages/ui/src/components/index.ts | 10 + packages/ui/src/components/table.tsx | 120 ++++++++++ 3 files changed, 253 insertions(+), 95 deletions(-) create mode 100644 packages/ui/src/components/table.tsx diff --git a/apps/commune-validator/src/app/components/delegated-list.tsx b/apps/commune-validator/src/app/components/delegated-list.tsx index d7c0166..3c4d795 100644 --- a/apps/commune-validator/src/app/components/delegated-list.tsx +++ b/apps/commune-validator/src/app/components/delegated-list.tsx @@ -5,7 +5,15 @@ import { usePathname, useRouter } from "next/navigation"; import { ChevronUpIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { useCommune } from "@commune-ts/providers/use-commune"; -import { cn } from "@commune-ts/ui"; +import { + cn, + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@commune-ts/ui"; import { formatToken, smallAddress } from "@commune-ts/utils"; import { useDelegateModuleStore } from "~/stores/delegateModuleStore"; @@ -418,99 +426,115 @@ export function DelegatedList() { {isOpen && (
-
-
{activeTab === "modules" ? "Module" : "Subnet"}
-
Name
-
{activeTab === "modules" ? "Address" : "Founder"}
-
Percentage
-
- {activeTab === "modules" ? ( - delegatedModules.length ? ( - delegatedModules.map((module) => ( -
-
{module.title}
-
- {module.name} -
-
- {smallAddress(module.address)} -
-
- - handlePercentageChange( - module.id, - Number(e.target.value), - ) - } - className="mr-1 w-12 bg-[#898989]/10 p-1 text-white" - min="0" - max="100" - /> - % - -
-
- )) - ) : ( -
- No modules found. Select a module to allocate weight through - the modules page and they will appear here. -
- ) - ) : delegatedSubnets.length ? ( - delegatedSubnets.map((subnet) => ( -
-
{subnet.name}
-
- {subnet.name} -
-
- {smallAddress(subnet.founder)} -
-
- - handlePercentageChange( - subnet.id, - Number(e.target.value), - ) - } - className="mr-1 w-12 bg-[#898989]/10 p-1 text-white" - min="0" - max="100" - /> - % - -
-
- )) - ) : ( -
- No subnets found. Select a subnet to allocate weight through - the subnets page and they will appear here. -
- )} + + + + + {activeTab === "modules" ? "Module" : "Subnet"} + + Name + + {activeTab === "modules" ? "Address" : "Founder"} + + Percentage + + + + {activeTab === "modules" ? ( + delegatedModules.length ? ( + delegatedModules.map((module) => ( + + + {module.title} + + + {module.name} + + + {smallAddress(module.address)} + + +
+ + handlePercentageChange( + module.id, + Number(e.target.value), + ) + } + className="mr-1 w-12 bg-[#898989]/10 p-1 text-white" + min="0" + max="100" + /> + % + +
+
+
+ )) + ) : ( + + + No modules found. Select a module to allocate weight + through the modules page and they will appear here. + + + ) + ) : delegatedSubnets.length ? ( + delegatedSubnets.map((subnet) => ( + + + {subnet.name} + + + {subnet.name} + + + {smallAddress(subnet.founder)} + + +
+ + handlePercentageChange( + subnet.id, + Number(e.target.value), + ) + } + className="mr-1 w-12 bg-[#898989]/10 p-1 text-white" + min="0" + max="100" + /> + % + +
+
+
+ )) + ) : ( + + + No subnets found. Select a subnet to allocate weight + through the subnets page and they will appear here. + + + )} +
+
diff --git a/packages/ui/src/components/index.ts b/packages/ui/src/components/index.ts index 89d514e..f12ef24 100644 --- a/packages/ui/src/components/index.ts +++ b/packages/ui/src/components/index.ts @@ -124,3 +124,13 @@ export { SheetDescription, } from "./sheet"; export { Tabs, TabsList, TabsTrigger, TabsContent } from "./tabs"; +export { + Table, + TableHeader, + TableBody, + TableFooter, + TableHead, + TableRow, + TableCell, + TableCaption, +} from "./table"; diff --git a/packages/ui/src/components/table.tsx b/packages/ui/src/components/table.tsx new file mode 100644 index 0000000..d13e28a --- /dev/null +++ b/packages/ui/src/components/table.tsx @@ -0,0 +1,120 @@ +import * as React from "react"; + +import { cn } from "."; + +const Table = React.forwardRef< + HTMLTableElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+ + +)); +Table.displayName = "Table"; + +const TableHeader = React.forwardRef< + HTMLTableSectionElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( + +)); +TableHeader.displayName = "TableHeader"; + +const TableBody = React.forwardRef< + HTMLTableSectionElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( + +)); +TableBody.displayName = "TableBody"; + +const TableFooter = React.forwardRef< + HTMLTableSectionElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( + tr]:last:border-b-0", + className, + )} + {...props} + /> +)); +TableFooter.displayName = "TableFooter"; + +const TableRow = React.forwardRef< + HTMLTableRowElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( + +)); +TableRow.displayName = "TableRow"; + +const TableHead = React.forwardRef< + HTMLTableCellElement, + React.ThHTMLAttributes +>(({ className, ...props }, ref) => ( +
[role=checkbox]]:translate-y-[2px]", + className, + )} + {...props} + /> +)); +TableHead.displayName = "TableHead"; + +const TableCell = React.forwardRef< + HTMLTableCellElement, + React.TdHTMLAttributes +>(({ className, ...props }, ref) => ( + [role=checkbox]]:translate-y-[2px]", + className, + )} + {...props} + /> +)); +TableCell.displayName = "TableCell"; + +const TableCaption = React.forwardRef< + HTMLTableCaptionElement, + React.HTMLAttributes +>(({ className, ...props }, ref) => ( +
+)); +TableCaption.displayName = "TableCaption"; + +export { + Table, + TableHeader, + TableBody, + TableFooter, + TableHead, + TableRow, + TableCell, + TableCaption, +};