From d991a1005830990670182f3e5cde2d2c635bec41 Mon Sep 17 00:00:00 2001 From: Liangdi Date: Thu, 5 Dec 2024 01:52:24 +1100 Subject: [PATCH] add responsive inputs to UI --- package-lock.json | 37 ++++++++++++++++ package.json | 1 + src/components/ui/input.tsx | 2 +- src/components/ui/popover.tsx | 29 ++++++++++++ src/components/ui/select.tsx | 9 ++-- src/components/ui/table.tsx | 11 +++-- src/routes/-components/columns.tsx | 71 ++++++++++++++++++++++++++++-- src/routes/index.lazy.tsx | 4 +- 8 files changed, 148 insertions(+), 16 deletions(-) create mode 100644 src/components/ui/popover.tsx diff --git a/package-lock.json b/package-lock.json index a511a11..f5dc074 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2", "@radix-ui/react-label": "^2.1.0", + "@radix-ui/react-popover": "^1.1.2", "@radix-ui/react-progress": "^1.1.0", "@radix-ui/react-scroll-area": "^1.2.1", "@radix-ui/react-select": "^2.1.2", @@ -1413,6 +1414,42 @@ } } }, + "node_modules/@radix-ui/react-popover": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.1.2.tgz", + "integrity": "sha512-u2HRUyWW+lOiA2g0Le0tMmT55FGOEWHwPFt1EPfbLly7uXQExFo5duNKqG2DzmFXIdqOeNd+TpE8baHWJCyP9w==", + "dependencies": { + "@radix-ui/primitive": "1.1.0", + "@radix-ui/react-compose-refs": "1.1.0", + "@radix-ui/react-context": "1.1.1", + "@radix-ui/react-dismissable-layer": "1.1.1", + "@radix-ui/react-focus-guards": "1.1.1", + "@radix-ui/react-focus-scope": "1.1.0", + "@radix-ui/react-id": "1.1.0", + "@radix-ui/react-popper": "1.2.0", + "@radix-ui/react-portal": "1.1.2", + "@radix-ui/react-presence": "1.1.1", + "@radix-ui/react-primitive": "2.0.0", + "@radix-ui/react-slot": "1.1.0", + "@radix-ui/react-use-controllable-state": "1.1.0", + "aria-hidden": "^1.1.1", + "react-remove-scroll": "2.6.0" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-popper": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.2.0.tgz", diff --git a/package.json b/package.json index 61bbcd1..03f84f6 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2", "@radix-ui/react-label": "^2.1.0", + "@radix-ui/react-popover": "^1.1.2", "@radix-ui/react-progress": "^1.1.0", "@radix-ui/react-scroll-area": "^1.2.1", "@radix-ui/react-select": "^2.1.2", diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx index 68551b9..e99481a 100644 --- a/src/components/ui/input.tsx +++ b/src/components/ui/input.tsx @@ -8,7 +8,7 @@ const Input = React.forwardRef>( , + React.ComponentPropsWithoutRef +>(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( + + + +)) +PopoverContent.displayName = PopoverPrimitive.Content.displayName + +export { Popover, PopoverTrigger, PopoverContent } diff --git a/src/components/ui/select.tsx b/src/components/ui/select.tsx index fe56d4d..cdd4b6f 100644 --- a/src/components/ui/select.tsx +++ b/src/components/ui/select.tsx @@ -17,7 +17,7 @@ const SelectTrigger = React.forwardRef< span]:line-clamp-1", + "flex h-8 md:h-10 w-full items-center justify-between rounded-md border border-input bg-background px-2 md:px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", className )} {...props} @@ -103,7 +103,7 @@ const SelectLabel = React.forwardRef< >(({ className, ...props }, ref) => ( )) @@ -116,17 +116,16 @@ const SelectItem = React.forwardRef< - + - {children} )) diff --git a/src/components/ui/table.tsx b/src/components/ui/table.tsx index aee7be6..abc84f5 100644 --- a/src/components/ui/table.tsx +++ b/src/components/ui/table.tsx @@ -9,7 +9,7 @@ const Table = React.forwardRef<
@@ -73,7 +73,7 @@ const TableHead = React.forwardRef<
[role=checkbox]]:translate-y-[2px]", className )} {...props} @@ -87,7 +87,10 @@ const TableCell = React.forwardRef< >(({ className, ...props }, ref) => ( [role=checkbox]]:translate-y-[2px]", + className + )} {...props} /> )) @@ -99,7 +102,7 @@ const TableCaption = React.forwardRef< >(({ className, ...props }, ref) => (
)) diff --git a/src/routes/-components/columns.tsx b/src/routes/-components/columns.tsx index da78930..4764ef9 100644 --- a/src/routes/-components/columns.tsx +++ b/src/routes/-components/columns.tsx @@ -1,4 +1,16 @@ import { ColumnDef } from "@tanstack/react-table" +import { Trash2 } from "lucide-react" +import { Input } from "@/components/ui/input" +import { Button } from "@/components/ui/button" +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectLabel, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" // This type is used to define the shape of our data. // You can use a Zod schema here if you want. @@ -15,18 +27,69 @@ export type Result = { export const columns: ColumnDef[] = [ { accessorKey: "unitCode", - header: "Unit Code", + header: () =>
Unit Code
, + cell: ({ row }) => { + return ( + + ) + }, }, { accessorKey: "creditPoints", - header: "Credit Points", + header: () =>
Credit Points
, + cell: ({ row }) => { + return + }, }, { accessorKey: "mark", - header: "Mark", + header: () =>
Mark
, + cell: ({ row }) => { + return + }, }, { accessorKey: "grade", - header: "Grade", + header: () =>
Grade
, + cell: ({ row }) => { + return ( + + ) + }, + }, + { + accessorKey: "delete", + header: "", + cell: () => { + return + }, }, ] diff --git a/src/routes/index.lazy.tsx b/src/routes/index.lazy.tsx index a624133..3404604 100644 --- a/src/routes/index.lazy.tsx +++ b/src/routes/index.lazy.tsx @@ -135,8 +135,8 @@ function Index() { const data = getData() return ( -
-
+
+
WAM (Weighted Average Mark)