From b09a06e875f0a897919a68756e9d5fba3a13cef0 Mon Sep 17 00:00:00 2001 From: Ajay Ghanwat Date: Mon, 27 Oct 2025 12:55:37 +0530 Subject: [PATCH] New Changes with Table Component --- src/components/Field.astro | 2 +- src/components/Table.astro | 410 ++++++++++++++++++++++++++++++ src/global.d.ts | 2 + src/index.ts | 4 +- src/layouts/ComponentLayout.astro | 3 + src/pages/table.astro | 399 +++++++++++++++++++++++++++++ src/types/table/types.ts | 20 ++ 7 files changed, 838 insertions(+), 2 deletions(-) create mode 100644 src/components/Table.astro create mode 100644 src/pages/table.astro create mode 100644 src/types/table/types.ts diff --git a/src/components/Field.astro b/src/components/Field.astro index 0b98920..dd8a099 100644 --- a/src/components/Field.astro +++ b/src/components/Field.astro @@ -90,7 +90,7 @@ const iconSize = const labelCls = "wr:block wr:text-sm wr:font-medium wr:mb-2 wr:dark:text-white"; const helpCls = "wr:mt-2 wr:text-sm wr:text-gray-500 wr:dark:text-neutral-500"; -const errCls = "wr:text-sm wr:text-red-600 wr:mt-2"; +const errCls = "wr:text-sm wr:text-red-600 wr:mt-2 wr:capitalize"; const groupCls = "wr:relative wr:flex wr:items-stretch"; const addonBase = "wr:px-4 wr:inline-flex wr:items-center wr:min-w-fit wr:rounded-md wr:border wr:border-border wr:bg-gray-200 wr:text-sm wr:text-gray-500 wr:dark:bg-card wr:dark:border-border wr:dark:text-neutral-400"; diff --git a/src/components/Table.astro b/src/components/Table.astro new file mode 100644 index 0000000..847719d --- /dev/null +++ b/src/components/Table.astro @@ -0,0 +1,410 @@ +--- +import type { TableProps } from "../types/table/types"; + +const { + columns = [], + data = [], + selectable = false, + search = false, + striped = false, + pageSize = 10, + fetchData, + columnsRendererKey, +} = Astro.props as TableProps; + +const id = `table-${Math.random().toString(36).slice(2, 9)}`; +--- + +
+ { + search && ( +
+ +
+ ) + } + + +
+ + + + { + selectable && ( + + ) + } + { + columns.map((col) => ( + + )) + } + + + + + +
+ + +
+ {col.label} + {col.sortable && ( + + )} +
+
+
+ + +
+ +
+ + +
+
+ Rows per page: + +
+ +
+
+
+ +
+
+
+
+
+ + diff --git a/src/global.d.ts b/src/global.d.ts index 240be73..3904fa8 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -6,6 +6,8 @@ declare global { schema: any; submit: any; upload: any; + fetchData: any; + columnsRenderer: any myModal_open: any; myModal_close: any; hls: typeof Hls, diff --git a/src/index.ts b/src/index.ts index 532bc79..cfe68d8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,5 +17,7 @@ export { default as Panel } from "./components/Panel.astro"; export { default as PasswordField } from "./components/PasswordField.astro"; export { default as ThemeSwitcher } from "./components/ThemeSwitcher.astro"; export { default as TimePicker } from "./components/TimePicker.astro"; +export { default as Table } from "./components/Table.astro"; export { default as Tooltip } from "./components/Tooltip.astro"; -export { cn } from "./utils/cn.js"; \ No newline at end of file +export { cn } from "./utils/cn.js"; +export type { Column, TableProps } from "./types/table/types.js"; \ No newline at end of file diff --git a/src/layouts/ComponentLayout.astro b/src/layouts/ComponentLayout.astro index 272fc21..3118d0a 100644 --- a/src/layouts/ComponentLayout.astro +++ b/src/layouts/ComponentLayout.astro @@ -83,6 +83,9 @@ import Base from "./Base.astro";
  • WebRTC Player
  • +
  • + Table +
  • diff --git a/src/pages/table.astro b/src/pages/table.astro new file mode 100644 index 0000000..0382bd9 --- /dev/null +++ b/src/pages/table.astro @@ -0,0 +1,399 @@ +--- +import ComponentLayout from "../layouts/ComponentLayout.astro"; +import Table from "../components/Table.astro"; + +export const columns = [ + { key: "id", label: "ID", sortable: true, searchable: true }, + { key: "name", label: "Name", searchable: true, sortable: true }, + { key: "email", label: "Email", searchable: true, sortable: true }, + { key: "role", label: "Role", sortable: true }, + { key: "status", label: "Status", sortable: true }, + { key: "created_at", label: "Created At", sortable: true }, + { key: "actions", label: "Actions" }, +]; + +const data = [ + { + id: 1, + name: "Ajay Ghanwat", + email: "ajay.gh@example.com", + role: "Admin", + status: "Active", + created_at: "2025-10-10 09:32", + avatar: "https://i.pravatar.cc/40?img=1", + }, + { + id: 2, + name: "Rahul Sharma", + email: "rahul.sharma@example.com", + role: "Member", + status: "Pending", + created_at: "2025-10-15 11:42", + avatar: "https://i.pravatar.cc/40?img=2", + }, + { + id: 3, + name: "Sophia Patel", + email: "sophia.patel@example.com", + role: "Manager", + status: "Active", + created_at: "2025-10-11 15:20", + avatar: "https://i.pravatar.cc/40?img=3", + }, + { + id: 4, + name: "Liam Brown", + email: "liam.brown@example.com", + role: "Member", + status: "Suspended", + created_at: "2025-10-12 08:45", + avatar: "https://i.pravatar.cc/40?img=4", + }, + { + id: 5, + name: "Olivia Smith", + email: "olivia.smith@example.com", + role: "Admin", + status: "Active", + created_at: "2025-10-09 18:12", + avatar: "https://i.pravatar.cc/40?img=5", + }, + { + id: 6, + name: "Noah Wilson", + email: "noah.wilson@example.com", + role: "Member", + status: "Pending", + created_at: "2025-10-13 10:18", + avatar: "https://i.pravatar.cc/40?img=6", + }, + { + id: 7, + name: "Emma Johnson", + email: "emma.johnson@example.com", + role: "Member", + status: "Active", + created_at: "2025-10-14 13:55", + avatar: "https://i.pravatar.cc/40?img=7", + }, + { + id: 8, + name: "William Lee", + email: "william.lee@example.com", + role: "Manager", + status: "Inactive", + created_at: "2025-10-12 17:44", + avatar: "https://i.pravatar.cc/40?img=8", + }, + { + id: 9, + name: "Isabella Taylor", + email: "isabella.taylor@example.com", + role: "Member", + status: "Active", + created_at: "2025-10-10 07:31", + avatar: "https://i.pravatar.cc/40?img=9", + }, + { + id: 10, + name: "Ethan Martinez", + email: "ethan.martinez@example.com", + role: "Admin", + status: "Suspended", + created_at: "2025-10-08 19:22", + avatar: "https://i.pravatar.cc/40?img=10", + }, + { + id: 11, + name: "Mia Thompson", + email: "mia.thompson@example.com", + role: "Member", + status: "Active", + created_at: "2025-10-09 09:45", + avatar: "https://i.pravatar.cc/40?img=11", + }, + { + id: 12, + name: "Alexander Davis", + email: "alex.davis@example.com", + role: "Manager", + status: "Pending", + created_at: "2025-10-15 14:10", + avatar: "https://i.pravatar.cc/40?img=12", + }, + { + id: 13, + name: "Charlotte Moore", + email: "charlotte.moore@example.com", + role: "Member", + status: "Active", + created_at: "2025-10-14 10:01", + avatar: "https://i.pravatar.cc/40?img=13", + }, + { + id: 14, + name: "Benjamin Anderson", + email: "benjamin.anderson@example.com", + role: "Member", + status: "Suspended", + created_at: "2025-10-08 11:32", + avatar: "https://i.pravatar.cc/40?img=14", + }, + { + id: 15, + name: "Amelia Harris", + email: "amelia.harris@example.com", + role: "Manager", + status: "Active", + created_at: "2025-10-13 08:50", + avatar: "https://i.pravatar.cc/40?img=15", + }, + { + id: 16, + name: "Lucas White", + email: "lucas.white@example.com", + role: "Member", + status: "Active", + created_at: "2025-10-10 17:10", + avatar: "https://i.pravatar.cc/40?img=16", + }, + { + id: 17, + name: "Harper Lewis", + email: "harper.lewis@example.com", + role: "Member", + status: "Pending", + created_at: "2025-10-14 09:00", + avatar: "https://i.pravatar.cc/40?img=17", + }, + { + id: 18, + name: "Evelyn Hall", + email: "evelyn.hall@example.com", + role: "Manager", + status: "Active", + created_at: "2025-10-11 16:42", + avatar: "https://i.pravatar.cc/40?img=18", + }, + { + id: 19, + name: "Henry Allen", + email: "henry.allen@example.com", + role: "Member", + status: "Inactive", + created_at: "2025-10-09 13:25", + avatar: "https://i.pravatar.cc/40?img=19", + }, + { + id: 20, + name: "Ava Scott", + email: "ava.scott@example.com", + role: "Admin", + status: "Active", + created_at: "2025-10-15 15:33", + avatar: "https://i.pravatar.cc/40?img=20", + }, + { + id: 21, + name: "Michael Young", + email: "michael.young@example.com", + role: "Member", + status: "Pending", + created_at: "2025-10-13 10:20", + avatar: "https://i.pravatar.cc/40?img=21", + }, + { + id: 22, + name: "Ella King", + email: "ella.king@example.com", + role: "Manager", + status: "Active", + created_at: "2025-10-14 08:45", + avatar: "https://i.pravatar.cc/40?img=22", + }, + { + id: 23, + name: "Daniel Clark", + email: "daniel.clark@example.com", + role: "Member", + status: "Active", + created_at: "2025-10-12 12:05", + avatar: "https://i.pravatar.cc/40?img=23", + }, + { + id: 24, + name: "Luna Wright", + email: "luna.wright@example.com", + role: "Member", + status: "Pending", + created_at: "2025-10-15 11:18", + avatar: "https://i.pravatar.cc/40?img=24", + }, + { + id: 25, + name: "Jack Turner", + email: "jack.turner@example.com", + role: "Admin", + status: "Active", + created_at: "2025-10-13 09:50", + avatar: "https://i.pravatar.cc/40?img=25", + }, +]; +--- + + +
    + + +
    + +
    + + + + diff --git a/src/types/table/types.ts b/src/types/table/types.ts new file mode 100644 index 0000000..eba83db --- /dev/null +++ b/src/types/table/types.ts @@ -0,0 +1,20 @@ +export interface Column { + key: keyof T | string; + label: string; + sortable?: boolean; + searchable?: boolean; + render?: (value: any, row: T) => string; + width?: string; + align?: "left" | "center" | "right"; +} + +export interface TableProps { + columns: Column[]; + data?: T[]; + fetchData?: string; + selectable?: boolean; + search?: boolean; + striped?: boolean; + pageSize?: number + columnsRendererKey?: string +} \ No newline at end of file