@kareemelbalshe/any-table 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -414,28 +414,108 @@ export default function EnterpriseOrdersDashboard() {
414
414
 
415
415
  Define clean actions per row without mixing UI code with data rendering:
416
416
 
417
- ### 1. Action Buttons
417
+ ### 1. Action Buttons with Icons & Labels
418
+
419
+ AnyTable supports rich action buttons and handles **ANY icon format** automatically:
420
+ - **React Components directly** (e.g. `icon: FiEye` from `react-icons` or Lucide, without needing `< >`)
421
+ - **JSX Elements** (e.g. `icon: <FiEye size={16} className="text-blue-500" />`)
422
+ - **Dynamic Functions** (e.g. `icon: (row) => row.isLocked ? FiUnlock : FiLock`)
423
+ - **Emoji / Text strings** (e.g. `icon: "⭐"` or `"✏️"`)
424
+ - **Image URLs & SVGs** (e.g. `icon: "/icons/edit.svg"` or `"https://..."`)
418
425
 
419
426
  ```tsx
427
+ import { FiEye, FiEdit2, FiTrash2, FiLock, FiUnlock } from "react-icons/fi";
428
+
420
429
  <AnyTable<User>
421
430
  data={users}
431
+ actionsTitle="Operations" // Custom column header (default: "Actions")
432
+ actionsWidth={280} // Custom column width in px
422
433
  actions={[
434
+ // 1. Direct Component from react-icons (Cleanest syntax: no JSX tags needed!)
423
435
  {
424
436
  id: "view",
425
- label: "View Profile",
437
+ label: "View",
438
+ icon: FiEye, // Passes component reference directly
426
439
  variant: "primary",
427
440
  onClick: (row) => navigate(`/users/${row.id}`),
428
441
  },
442
+
443
+ // 2. JSX Element with custom props
429
444
  {
430
445
  id: "edit",
431
- label: "Edit",
446
+ icon: <FiEdit2 size={15} className="text-blue-400" />,
447
+ tooltip: "Edit User Information",
432
448
  variant: "neutral",
433
449
  onClick: (row) => openEditModal(row),
434
450
  },
451
+
452
+ // 3. Dynamic Icon & Variant based on row data
453
+ {
454
+ id: "toggle-lock",
455
+ icon: (row) => (row.isLocked ? FiUnlock : FiLock),
456
+ label: (row) => (row.isLocked ? "Unlock" : "Lock"),
457
+ variant: (row) => (row.isLocked ? "warning" : "neutral"),
458
+ onClick: async (row, context) => {
459
+ await api.toggleLock(row.id);
460
+ context.refresh();
461
+ },
462
+ },
463
+
464
+ // 4. Emoji or Text String
465
+ {
466
+ id: "star",
467
+ icon: "⭐",
468
+ tooltip: "Bookmark",
469
+ onClick: (row) => toggleBookmark(row),
470
+ },
471
+
472
+ // 5. Image URL or custom SVG path
473
+ {
474
+ id: "badge",
475
+ icon: "/icons/verified.svg",
476
+ tooltip: "Verified Badge",
477
+ onClick: (row) => openBadge(row),
478
+ },
479
+
480
+ // 4. Destructive Action with Icon & Confirmation
481
+ {
482
+ id: "delete",
483
+ icon: <FiTrash2 />,
484
+ label: "Delete",
485
+ variant: "danger",
486
+ confirmation: {
487
+ title: "Delete Account",
488
+ message: (row) => `Are you sure you want to delete ${row.name}?`,
489
+ confirmText: "Yes, Delete",
490
+ cancelText: "Cancel",
491
+ },
492
+ onClick: async (row, context) => {
493
+ await api.deleteUser(row.id);
494
+ context.refresh();
495
+ },
496
+ },
435
497
  ]}
436
498
  />
437
499
  ```
438
500
 
501
+ #### Action Configuration Reference (`TableAction<TData>`)
502
+
503
+ | Property | Type | Default | Description |
504
+ | :--- | :--- | :--- | :--- |
505
+ | `id` | `string` | **Required** | Unique identifier for this action. |
506
+ | `icon` | `ReactNode \| ((row: TData) => ReactNode)` | `undefined` | Custom icon element (SVG, `react-icons`, emoji) or dynamic generator function. |
507
+ | `label` | `string \| ((row: TData) => string)` | `undefined` | Action text label. Optional (can be omitted for icon-only buttons). |
508
+ | `variant` | `ActionVariant \| ((row) => ActionVariant)` | `'neutral'` | Theme color: `'primary' \| 'secondary' \| 'success' \| 'warning' \| 'danger' \| 'info' \| 'neutral' \| 'ghost'`. |
509
+ | `tooltip` | `string \| ((row: TData) => string)` | `undefined` | Helpful hover tooltip (recommended for icon-only buttons). |
510
+ | `onClick` | `(row, context) => void \| Promise<void>` | `undefined` | Click callback receiving current row and table controller context. |
511
+ | `disabled` | `boolean \| ((row: TData) => boolean)` | `false` | Conditionally disable the button for specific rows. |
512
+ | `show` / `hide`| `boolean \| ((row: TData) => boolean)` | `undefined` | Conditionally show or hide the action per row. |
513
+ | `loading` | `boolean \| ((row: TData) => boolean)` | `false` | Displays an inline spinner while async operations execute. |
514
+ | `confirmation`| `ActionConfirmation<TData>` | `undefined` | Built-in confirmation modal config before triggering `onClick`. |
515
+ | `className` | `string \| ((row: TData) => string)` | `""` | Additional Tailwind / custom CSS classes. |
516
+ | `color` | `string` | `undefined` | Custom background color override (hex / rgb). |
517
+
518
+
439
519
  ### 2. Instant PATCH / PUT Toggle Switch
440
520
 
441
521
  Perfect for toggling active status, ban status, or feature flags directly with auto-refresh:
@@ -639,23 +719,308 @@ AnyTable includes built-in resilience for real-world network conditions:
639
719
 
640
720
  ---
641
721
 
642
- ## 🎨 Theming & Dark Mode
722
+ ## 🎨 Theming & Styling Architecture (Global & Per-Page)
723
+
724
+ AnyTable is designed from the ground up for maximum visual flexibility. You can define a **unified global theme once** for all tables in your application, or customize tables individually on specific pages.
725
+
726
+ ---
727
+
728
+ ### 🎭 Built-in Visual Presets (1-Line Designer Themes)
729
+
730
+ AnyTable comes pre-packaged with **8 handcrafted design presets**. You can switch the entire aesthetic of any table with a single prop:
731
+
732
+ ```tsx
733
+ <AnyTable preset="midnight" data={cryptoTransactions} />
734
+ <AnyTable preset="emerald" data={financialInvoices} />
735
+ <AnyTable preset="ocean" data={shipmentLogistics} />
736
+ <AnyTable preset="luxury" data={vipCustomers} />
737
+ <AnyTable preset="crimson" data={criticalAlerts} />
738
+ <AnyTable preset="minimal" data={cleanArticles} />
739
+ <AnyTable preset="corporate" data={enterpriseData} />
740
+ ```
741
+
742
+ | Preset | Visual Identity | Primary Accent | Vibe / Recommended For |
743
+ | :--- | :--- | :--- | :--- |
744
+ | **`default`** | Modern Electric Blue + Balanced Slate | `#2667EC` | General SaaS, Admin Dashboards, Standard Products |
745
+ | **`midnight`** | Deep Cyber Void + Luminous Neon Indigo | `#6366F1` | Developer Tools, Cyber Security, Web3, Crypto Dashboards |
746
+ | **`emerald`** | Crisp Forest + Vibrant Mint Green | `#10B981` | Fintech, Banking, Healthcare, Accounting, Analytics |
747
+ | **`ocean`** | Deep Marine Navy + Radiant Cyan / Teal | `#0EA5E9` | Logistics, Supply Chain, Travel, Cloud Monitoring |
748
+ | **`luxury`** | Champagne Gold + Obsidian & Bronze | `#D97706` | VIP Tiers, High-End Fashion, Real Estate, Concierge |
749
+ | **`crimson`** | Bold Scarlet Rose + High Contrast | `#F43F5E` | Security Incidents, Critical Errors, Alert Monitors |
750
+ | **`minimal`** | Monochromatic Borderless Airy High-Contrast | Monochromatic | Notion-style docs, Clean portfolios, Minimalist blogs |
751
+ | **`corporate`** | Structured Enterprise Navy + Classic Borders | `#1E40AF` | ERP Systems, Traditional Corporate Systems, Audits |
752
+
753
+ ---
754
+
755
+ ### 🛠️ Deep Granular Customization (Control Every Pixel Literally)
756
+
757
+ Don't want presets? AnyTable allows you to manually dictate the exact color, border, padding, and class for **literally every single element**:
758
+
759
+ ```tsx
760
+ <AnyTable<Order>
761
+ data={orders}
762
+ bordered={false} // Toggle table wrapper borders
763
+ compact={false} // Density control ('compact' | 'normal' | 'spacious')
764
+
765
+ // 1. Custom CSS on the <thead> element
766
+ headerClassName="bg-gradient-to-r from-purple-900 to-indigo-900 text-purple-200 uppercase tracking-widest text-[11px]"
767
+
768
+ // 2. Dynamic Row Styling based on row data
769
+ rowClassName={(row, index) =>
770
+ row.status === "Cancelled"
771
+ ? "bg-red-500/10 hover:bg-red-500/20 text-red-400 font-semibold"
772
+ : row.tier === "VIP"
773
+ ? "bg-amber-500/10 hover:bg-amber-500/20"
774
+ : ""
775
+ }
776
+
777
+ // 3. Complete Deep Theme Token Overrides
778
+ theme={{
779
+ borderRadius: "0px", // Sharp brutalist square borders, or "1.5rem" for pill curves
780
+ fontFamily: "'Fira Code', monospace", // Custom font
781
+ density: "normal",
782
+ colors: {
783
+ primary: "#9333EA", // Active pagination, search rings, default button
784
+ primaryHover: "#7E22CE",
785
+ border: "#3B0764", // Border color everywhere
786
+ theadBg: "#1E1B4B", // Custom header background
787
+ theadText: "#E0E7FF", // Custom header text color
788
+ rowHover: "rgba(147, 51, 234, 0.08)", // Row hover background
789
+ rowSelected: "rgba(147, 51, 234, 0.16)",
790
+ card: "#0F0B1E", // Card background
791
+ },
792
+ classes: {
793
+ tableWrapper: "border-2 border-purple-800/50 shadow-2xl shadow-purple-900/30",
794
+ searchInput: "bg-purple-950/40 border border-purple-700 text-purple-100 placeholder:text-purple-400 focus:ring-purple-500",
795
+ paginationButtonActive: "bg-purple-600 text-white font-black shadow-lg shadow-purple-600/50",
796
+ },
797
+ }}
798
+ />
799
+ ```
800
+
801
+ ---
802
+
803
+ ### 🌐 Part 1: How to Set a Unified Global Style for ALL Tables
804
+
805
+ There are **3 recommended ways** to define a global style across your entire application:
806
+
807
+ #### Method A: Global Provider (`AnyTableThemeProvider`) — *Recommended*
808
+
809
+ Wrap your root layout or application entry point with `<AnyTableThemeProvider>`. Every `<AnyTable />` across all pages will automatically inherit these brand colors, Tailwind classes, and layout rules:
810
+
811
+ **In Next.js (`app/layout.tsx` or `pages/_app.tsx`):**
812
+ ```tsx
813
+ import "@kareemelbalshe/any-table/style.css";
814
+ import { AnyTableThemeProvider } from "@kareemelbalshe/any-table";
815
+
816
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
817
+ return (
818
+ <html lang="en">
819
+ <body>
820
+ <AnyTableThemeProvider
821
+ theme={{
822
+ colors: {
823
+ primary: "#2667EC", // Your brand primary color
824
+ primaryHover: "#1E54C6",
825
+ card: "#0f172a", // Dark card background
826
+ border: "#1e293b", // Subtle borders
827
+ },
828
+ borderRadius: "1rem", // Rounded table corners
829
+ density: "normal", // 'compact' | 'normal' | 'comfortable'
830
+ classes: {
831
+ // Custom Tailwind classes applied to all tables in the app
832
+ tableWrapper: "rounded-2xl border border-slate-800 shadow-xl shadow-blue-500/5",
833
+ thead: "bg-slate-900/90 backdrop-blur-md text-slate-300 font-bold uppercase text-xs",
834
+ searchInput: "rounded-xl border border-slate-700 bg-slate-900 text-white focus:ring-primary",
835
+ paginationButtonActive: "bg-primary text-white shadow-md shadow-primary/30",
836
+ },
837
+ }}
838
+ >
839
+ {children}
840
+ </AnyTableThemeProvider>
841
+ </body>
842
+ </html>
843
+ );
844
+ }
845
+ ```
846
+
847
+ **In Vite / CRA (`src/main.tsx` or `src/App.tsx`):**
848
+ ```tsx
849
+ import React from "react";
850
+ import ReactDOM from "react-dom/client";
851
+ import { AnyTableThemeProvider } from "@kareemelbalshe/any-table";
852
+ import "@kareemelbalshe/any-table/style.css";
853
+ import App from "./App";
854
+
855
+ ReactDOM.createRoot(document.getElementById("root")!).render(
856
+ <React.StrictMode>
857
+ <AnyTableThemeProvider
858
+ theme={{
859
+ colors: { primary: "#7c3aed" }, // Violet brand theme
860
+ borderRadius: "0.75rem",
861
+ }}
862
+ >
863
+ <App />
864
+ </AnyTableThemeProvider>
865
+ </React.StrictMode>
866
+ );
867
+ ```
868
+
869
+ ---
870
+
871
+ #### Method B: Global CSS Variables (`globals.css` / `index.css`)
872
+
873
+ AnyTable exposes native CSS variables that can be overridden directly in your global stylesheet:
874
+
875
+ ```css
876
+ /* In your globals.css or index.css */
877
+ :root {
878
+ --any-table-primary: #2667EC; /* Main brand accent */
879
+ --any-table-primary-hover: #1E54C6;
880
+ --any-table-primary-soft: #397FF6;
881
+ --any-table-secondary: #39E965; /* Secondary accent */
882
+ --any-table-success: #10B981;
883
+ --any-table-warning: #F59E0B;
884
+ --any-table-danger: #EF4444;
885
+ --any-table-font: "Inter", system-ui, sans-serif; /* Global table font */
886
+ }
887
+ ```
643
888
 
644
- AnyTable is built with CSS variables and seamlessly adapts to light & dark modes. You can customize colors via the `theme` prop:
889
+ ---
890
+
891
+ #### Method C: Corporate Preset Component (`components/AppTable.tsx`)
892
+
893
+ A proven enterprise pattern is to create a reusable wrapper component that pre-configures common settings (like standard actions title, bordered, striped, etc.):
645
894
 
646
895
  ```tsx
896
+ // components/AppTable.tsx
897
+ import { AnyTable, AnyTableProps } from "@kareemelbalshe/any-table";
898
+
899
+ export function AppTable<TData = any>(props: AnyTableProps<TData>) {
900
+ return (
901
+ <AnyTable<TData>
902
+ bordered
903
+ hoverable
904
+ striped={false}
905
+ actionsTitle="Operations"
906
+ actionsWidth={220}
907
+ className="shadow-sm transition-all"
908
+ {...props} // Allows per-page overrides whenever needed
909
+ />
910
+ );
911
+ }
912
+
913
+ // Then in ANY page, just use:
914
+ // <AppTable data={orders} />
915
+ ```
916
+
917
+ ---
918
+
919
+ ### 📄 Part 2: Per-Page & Per-Table Customization (All Real-World Cases)
920
+
921
+ When using AnyTable on specific pages, you can customize the appearance to match the exact context:
922
+
923
+ #### Case 1: Pure Zero-Config (Inherits Global Theme Automatically)
924
+ ```tsx
925
+ // Consumes the root AnyTableThemeProvider automatically with zero extra code
926
+ <AnyTable data={users} />
927
+ ```
928
+
929
+ #### Case 2: Local Color Override on a Specific Page
930
+ ```tsx
931
+ // Overrides the primary color to Emerald for a Financials page without affecting other pages
647
932
  <AnyTable
933
+ data={invoices}
648
934
  theme={{
649
935
  colors: {
650
- primary: "#2667EC", // Wasel Electric Blue
651
- background: "#0f172a", // Custom Dark Background
652
- text: "#f8fafc", // Custom Light Text
653
- borderRadius: "0.75rem", // Border Radius
936
+ primary: "#10B981", // Emerald accent for finance
654
937
  },
655
938
  }}
656
939
  />
657
940
  ```
658
941
 
942
+ #### Case 3: Dense Data Dashboard (`compact` mode)
943
+ ```tsx
944
+ // Tight padding for high-density enterprise data tables
945
+ <AnyTable
946
+ data={logs}
947
+ compact={true} // Reduces padding on cells and headers
948
+ stickyHeader={true} // Keeps the header visible while scrolling
949
+ />
950
+ ```
951
+
952
+ #### Case 4: Visual Presets (Zebra Striped, Borderless, or Shadowed)
953
+ ```tsx
954
+ <AnyTable
955
+ data={products}
956
+ bordered={false} // Clean borderless look
957
+ striped={true} // Alternating zebra row backgrounds
958
+ hoverable={true} // Subtle highlight on hovered row
959
+ className="shadow-2xl rounded-3xl"
960
+ tableClassName="text-xs"
961
+ />
962
+ ```
963
+
964
+ #### Case 5: Per-Column & Per-Cell Styling
965
+ ```tsx
966
+ <AnyTable
967
+ data={transactions}
968
+ columns={[
969
+ { key: "id", title: "Ref #", width: 100 },
970
+ // Custom cell text color, alignment, and font
971
+ {
972
+ key: "amount",
973
+ title: "Amount",
974
+ align: "right",
975
+ className: "font-mono font-black text-emerald-500",
976
+ headerClassName: "text-right",
977
+ },
978
+ // Custom JSX rendering inside a cell
979
+ {
980
+ key: "riskScore",
981
+ title: "Risk Level",
982
+ render: (val) => (
983
+ <span className={val > 70 ? "text-rose-500 font-bold" : "text-gray-400"}>
984
+ {val}%
985
+ </span>
986
+ ),
987
+ },
988
+ ]}
989
+ />
990
+ ```
991
+
992
+ #### Case 6: Dark Mode & Light Mode
993
+ AnyTable automatically synchronizes with Tailwind's `dark` class on the `<html>` or `<body>` element (seamlessly compatible with `next-themes`). You can also force a specific mode on any table:
994
+ ```tsx
995
+ <AnyTable
996
+ data={users}
997
+ theme={{ mode: "dark" }} // Forces dark theme regardless of system setting
998
+ />
999
+ ```
1000
+
1001
+ #### Case 7: Custom Action Buttons Styling
1002
+ ```tsx
1003
+ <AnyTable
1004
+ data={users}
1005
+ actions={[
1006
+ {
1007
+ id: "vip-btn",
1008
+ label: "VIP Upgrade",
1009
+ icon: "⭐",
1010
+ color: "#8B5CF6", // Custom purple hex background
1011
+ className: "hover:scale-105 shadow-md shadow-purple-500/30",
1012
+ onClick: (row) => upgradeUser(row),
1013
+ },
1014
+ {
1015
+ id: "delete",
1016
+ icon: "🗑️",
1017
+ variant: "danger", // Built-in danger theme
1018
+ onClick: (row) => deleteUser(row),
1019
+ },
1020
+ ]}
1021
+ />
1022
+ ```
1023
+
659
1024
  ---
660
1025
 
661
1026
  ## 🌐 Integration Guides (Next.js & Vite)
@@ -833,29 +1198,99 @@ import axios from "axios";
833
1198
 
834
1199
  ---
835
1200
 
836
- ### 💡 الحالة 5: مفاتيح الـ PATCH الفورية وأزرار العمليات (Actions & Switches)
837
- تعديل حالة السجل مباشرة بمفتاح Toggle دون مغادرة الجدول مع التحديث الفوري:
1201
+ ### 💡 الحالة 5: أزرار العمليات المتقدمة، الأيقونات، ومفاتيح التبديل (Action Buttons, Icons & Switches)
1202
+ تتعامل AnyTable مع **أي شكل من أشكال الأيقونات تلقائياً وبكل مرونة**:
1203
+ - **مكوّن `react-icons` أو Lucide مباشرة بدون أوسمة** (مثل: `icon: FiEye` مباشرة دون الحاجة لكتابة `< >`).
1204
+ - **عنصر JSX كامل** مع تمرير الحجم واللون (مثل: `<FiEdit3 size={16} className="text-blue-500" />`).
1205
+ - **دالة ديناميكية** ترجع مكوّن أو JSX حسب بيانات السطر `(row) => row.isLocked ? FiUnlock : FiLock`.
1206
+ - **نص أو إيموجي** (مثل: `icon: "⭐"` أو `"🗑️"`).
1207
+ - **مسار صورة أو SVG** (مثل: `icon: "/icons/avatar.svg"` أو رابط خارجي).
1208
+
838
1209
  ```tsx
839
- actions={[
840
- // 1. مفتاح تبديل يرسل طلب PATCH للباك إند ويحدث الجدول فوراً
841
- {
842
- id: "active-switch",
843
- type: "switch",
844
- label: "تفعيل",
845
- checked: (row) => row.isActive,
846
- onChange: async (row, nextState, context) => {
847
- await axios.patch(`/api/users/${row.id}`, { isActive: nextState });
848
- context.refresh(); // يعيد جلب البيانات بسلاسة
1210
+ import { FiEye, FiEdit3, FiTrash2, FiLock, FiUnlock } from "react-icons/fi";
1211
+
1212
+ <AnyTable
1213
+ data={users}
1214
+ actionsTitle="الإجراءات" // عنوان عمود العمليات (افتراضياً: "Actions")
1215
+ actionsWidth={280} // عرض عمود العمليات بالبكسل للتحكم في المساحة
1216
+ actions={[
1217
+ // 1. مكوّن من react-icons مباشرة (أنظف طريقة: بدون أقواس JSX)
1218
+ {
1219
+ id: "view",
1220
+ label: "عرض",
1221
+ icon: FiEye, // تمرير المكوّن مباشرة
1222
+ variant: "primary",
1223
+ onClick: (row) => router.push(`/users/${row.id}`),
849
1224
  },
850
- },
851
- // 2. زر عرض التفاصيل
852
- {
853
- id: "view",
854
- label: "عرض",
855
- variant: "primary",
856
- onClick: (row) => router.push(`/users/${row.id}`),
857
- },
858
- ]}
1225
+
1226
+ // 2. عنصر JSX مع خصائص الحجم واللون وتلميح Tooltip
1227
+ {
1228
+ id: "edit",
1229
+ icon: <FiEdit3 size={15} className="text-blue-400" />,
1230
+ tooltip: "تعديل بيانات المستخدم",
1231
+ variant: "neutral",
1232
+ onClick: (row) => openEditModal(row),
1233
+ },
1234
+
1235
+ // 3. أيقونة ونص ديناميكي يتغير حسب بيانات السطر (Dynamic Component)
1236
+ {
1237
+ id: "toggle-lock",
1238
+ icon: (row) => (row.isLocked ? FiUnlock : FiLock),
1239
+ label: (row) => (row.isLocked ? "إلغاء القفل" : "قفل الحساب"),
1240
+ variant: (row) => (row.isLocked ? "warning" : "neutral"),
1241
+ onClick: async (row, context) => {
1242
+ await axios.patch(`/api/users/${row.id}/toggle-lock`);
1243
+ context.refresh(); // إعادة جلب البيانات فوراً
1244
+ },
1245
+ },
1246
+
1247
+ // 4. إيموجي لطيف كأيقونة
1248
+ {
1249
+ id: "star-btn",
1250
+ icon: "⭐",
1251
+ tooltip: "تمييز بنجمة",
1252
+ onClick: (row) => toggleStar(row),
1253
+ },
1254
+
1255
+ // 5. مسار صورة أو SVG مخصص
1256
+ {
1257
+ id: "verified-badge",
1258
+ icon: "/icons/verified.svg",
1259
+ tooltip: "حساب موثق",
1260
+ onClick: (row) => showBadgeModal(row),
1261
+ },
1262
+
1263
+ // 4. مفتاح تبديل PATCH فوري (Instant Switch)
1264
+ {
1265
+ id: "active-switch",
1266
+ type: "switch",
1267
+ label: "تفعيل",
1268
+ checked: (row) => row.isActive,
1269
+ onChange: async (row, nextState, context) => {
1270
+ await axios.patch(`/api/users/${row.id}`, { isActive: nextState });
1271
+ context.refresh();
1272
+ },
1273
+ },
1274
+
1275
+ // 5. زر حذف بأيقونة ونافذة تأكيد مدمجة (Confirmation Modal)
1276
+ {
1277
+ id: "delete-btn",
1278
+ label: "حذف",
1279
+ icon: <FiTrash2 />,
1280
+ variant: "danger",
1281
+ confirmation: {
1282
+ title: "تأكيد حذف الحساب",
1283
+ message: (row) => `هل أنت متأكد من رغبتك في حذف "${row.name}" نهائياً؟`,
1284
+ confirmText: "نعم، احذف",
1285
+ cancelText: "إلغاء",
1286
+ },
1287
+ onClick: async (row, context) => {
1288
+ await axios.delete(`/api/users/${row.id}`);
1289
+ context.refresh();
1290
+ },
1291
+ },
1292
+ ]}
1293
+ />
859
1294
  ```
860
1295
 
861
1296
  ---
@@ -954,18 +1389,301 @@ export default function SelectionPage() {
954
1389
 
955
1390
  ---
956
1391
 
957
- ### 💡 الحالة 10: تخصيص الألوان والثيم والوضع الليلي (Theming & Dark Mode)
1392
+ ### 💡 الحالة 10: الستايلات الجاهزة المعينة (Presets) والتخصيص اليدوي الكامل لكل تفصيلة في الجدول حرفياً (Theming & Granular Customization)
1393
+
1394
+ توفر لك مكتبة **AnyTable** نظام تصميم مزدوج:
1395
+ 1. **شوية استايلات جاهزة معينة (Built-in Presets)** يختار منها المطور بكلمة واحدة (`preset="midnight"`).
1396
+ 2. **تخصيص يدوي كامل لكل حاجة حرفياً** من أول البوردرات وتدوير الحواف وألوان الأزرار وترويسة الجدول وألوان الصفوف الديناميكية.
1397
+
1398
+ ---
1399
+
1400
+ #### 🎭 1. الستايلات الجاهزة المعينة (Built-in Presets):
1401
+ يمكنك تغيير شكل وهوية الجدول بالكامل بتمرير خاصية `preset`:
1402
+
1403
+ ```tsx
1404
+ <AnyTable preset="midnight" data={cryptoData} />
1405
+ <AnyTable preset="emerald" data={finances} />
1406
+ <AnyTable preset="ocean" data={shipments} />
1407
+ <AnyTable preset="luxury" data={vipUsers} />
1408
+ <AnyTable preset="crimson" data={incidents} />
1409
+ <AnyTable preset="minimal" data={documents} />
1410
+ <AnyTable preset="corporate" data={auditLogs} />
1411
+ ```
1412
+
1413
+ | البريسيت | الطابع الجمالي | اللون الأساسي | الاستخدام المثالي |
1414
+ | :--- | :--- | :--- | :--- |
1415
+ | **`default`** | الأزرق الكهربائي العصري + رمادي متزن | `#2667EC` | لوحات التحكم العامة، وتطبيقات SaaS المعتادة |
1416
+ | **`midnight`** | الوضع الليلي العميق + توهج نيون إنديجو | `#6366F1` | أدوات المطورين، الأمن السيبراني، ومنصات الكريبتو |
1417
+ | **`emerald`** | الأخضر الزمردي والنعناعي المنعش | `#10B981` | التكنولوجيا المالية، الفواتير، الصحة، والتحليلات |
1418
+ | **`ocean`** | الأزرق البحري العميق + سماوي متألق | `#0EA5E9` | الخدمات اللوجستية، الشحن، السفر، ومراقبة السيرفرات |
1419
+ | **`luxury`** | الذهبي والكهرمان الفاخر + أسود زجاجي | `#D97706` | فئات الـ VIP، السلع الفاخرة، والعقارات |
1420
+ | **`crimson`** | القرمزي والوردي الصارخ | `#F43F5E` | جداول الحوادث الطارئة، السجلات الخطيرة، والتنبيهات |
1421
+ | **`minimal`** | بسيط بدون حواف وبتباين عالٍ وأنيق | أحادي اللون | المقالات، واجهات Notion، والمواقع الشخصية |
1422
+ | **`corporate`** | كحلي شركات رصين بحواف كلاسيكية منظمة | `#1E40AF` | أنظمة الـ ERP، البنوك التقليدية، والمؤسسات الرسمية |
1423
+
1424
+ ---
1425
+
1426
+ #### 🛠️ 2. التخصيص اليدوي الشامل لكل تفصيلة حرفياً (Granular Customization):
1427
+ إذا أردت وضع قيمة كل شيء بنفسك، من أول البوردر إلى ألوان الأزرار والصفوف:
1428
+
1429
+ ```tsx
1430
+ <AnyTable<Order>
1431
+ data={orders}
1432
+ bordered={true} // إظهار أو إخفاء حواف الجدول بالكامل
1433
+ compact={false} // كثافة التباعد ('compact' | 'normal' | 'spacious')
1434
+
1435
+ // 1. تخصيص ترويسة الجدول <thead> بكلاسات تيلويند خاصة
1436
+ headerClassName="bg-gradient-to-r from-purple-900 to-indigo-900 text-purple-200 font-black text-xs uppercase"
1437
+
1438
+ // 2. تلوين كل سطر ديناميكياً بحسب حالته
1439
+ rowClassName={(row, index) =>
1440
+ row.status === "Cancelled"
1441
+ ? "bg-red-500/10 hover:bg-red-500/20 text-red-500 font-bold"
1442
+ : row.isVip
1443
+ ? "bg-amber-500/10 hover:bg-amber-500/20 text-amber-600"
1444
+ : ""
1445
+ }
1446
+
1447
+ // 3. التحكم الكامل في قيم الستايل والألوان والحواف
1448
+ theme={{
1449
+ borderRadius: "0px", // زوايا حادة تماماً (Brutalist)، أو "1.5rem" لزوايا فائقة الاستدارة
1450
+ fontFamily: "'Cairo', sans-serif", // خط مخصص للجداول
1451
+ colors: {
1452
+ primary: "#8B5CF6", // لون أزرار الترقيم، وعناصر البحث النشطة
1453
+ primaryHover: "#7C3AED", // لون الـ Hover للأزرار
1454
+ border: "#4C1D95", // لون حواف الجدول والخلايا
1455
+ theadBg: "#1E1B4B", // خلفية الترويسة
1456
+ theadText: "#E0E7FF", // لون خط الترويسة
1457
+ rowHover: "rgba(139, 92, 246, 0.08)", // لون مرور الماوس على السطر
1458
+ rowSelected: "rgba(139, 92, 246, 0.16)", // لون السطر المحدد بـ Checkbox
1459
+ card: "#0F0A1E", // خلفية كارت الجدول
1460
+ },
1461
+ classes: {
1462
+ tableWrapper: "border-2 border-purple-800 shadow-2xl shadow-purple-900/30",
1463
+ searchInput: "bg-purple-950/40 border border-purple-700 text-white placeholder:text-purple-400",
1464
+ paginationButtonActive: "bg-purple-600 text-white font-black shadow-lg shadow-purple-600/50",
1465
+ },
1466
+ }}
1467
+ />
1468
+ ```
1469
+
1470
+ ---
1471
+
1472
+ #### 🌟 3. أين وكيف تضع الاستايل الموحد لكافة الجداول في المشروع؟
1473
+
1474
+ لديك **3 طرق قياسية واحترافية** لتطبيق استايل موحد للمشروع كاملاً:
1475
+
1476
+ ##### الطريقة 1: استخدام المزوّد العام `AnyTableThemeProvider` في جذر المشروع (الأفضل والأنظف)
1477
+ قم بإحاطة تطبيقك بمكوّن `<AnyTableThemeProvider>` مرة واحدة في ملف الـ Layout الرئيسي:
1478
+
1479
+ **في Next.js (داخل ملف `app/layout.tsx` أو `pages/_app.tsx`):**
1480
+ ```tsx
1481
+ import "@kareemelbalshe/any-table/style.css";
1482
+ import { AnyTableThemeProvider } from "@kareemelbalshe/any-table";
1483
+
1484
+ export default function RootLayout({ children }: { children: React.ReactNode }) {
1485
+ return (
1486
+ <html lang="ar" dir="rtl">
1487
+ <body>
1488
+ <AnyTableThemeProvider
1489
+ theme={{
1490
+ colors: {
1491
+ primary: "#2667EC", // اللون الأساسي لأزرار البحث والترقيم والعمليات
1492
+ primaryHover: "#1E54C6",
1493
+ card: "#0f172a", // لون خلفية كارت الجدول
1494
+ border: "#1e293b", // لون الحواف الخفيفة
1495
+ },
1496
+ borderRadius: "1rem", // تدوير حواف الجداول
1497
+ density: "normal", // كثافة التباعد: 'compact' | 'normal' | 'comfortable'
1498
+ classes: {
1499
+ // كلاسات Tailwind تطبق تلقائياً على كل الجداول في كل صفحات الموقع
1500
+ tableWrapper: "rounded-2xl border border-slate-800 shadow-xl",
1501
+ thead: "bg-slate-900/90 backdrop-blur-md text-slate-300 font-bold uppercase text-xs",
1502
+ searchInput: "rounded-xl border border-slate-700 bg-slate-900 text-white focus:ring-primary",
1503
+ paginationButtonActive: "bg-primary text-white shadow-md shadow-primary/30",
1504
+ },
1505
+ }}
1506
+ >
1507
+ {children}
1508
+ </AnyTableThemeProvider>
1509
+ </body>
1510
+ </html>
1511
+ );
1512
+ }
1513
+ ```
1514
+
1515
+ **في تطبيقات Vite / React (داخل `src/main.tsx` أو `src/App.tsx`):**
1516
+ ```tsx
1517
+ import React from "react";
1518
+ import ReactDOM from "react-dom/client";
1519
+ import { AnyTableThemeProvider } from "@kareemelbalshe/any-table";
1520
+ import "@kareemelbalshe/any-table/style.css";
1521
+ import App from "./App";
1522
+
1523
+ ReactDOM.createRoot(document.getElementById("root")!).render(
1524
+ <React.StrictMode>
1525
+ <AnyTableThemeProvider
1526
+ theme={{
1527
+ colors: { primary: "#7c3aed" }, // لون الهوية البنفسجي للمشروع
1528
+ borderRadius: "0.75rem",
1529
+ }}
1530
+ >
1531
+ <App />
1532
+ </AnyTableThemeProvider>
1533
+ </React.StrictMode>
1534
+ );
1535
+ ```
1536
+ > **النتيجة السحرية:** الآن في أي صفحة تستدعي فيها `<AnyTable data={...} />`، ستجد الجدول يظهر فوراً بألوان مشروعك وهوية موقعك بدون كتابة أي إعدادات تصميم في الصفحة!
1537
+
1538
+ ---
1539
+
1540
+ ##### الطريقة 2: عبر متغيرات الـ CSS العامة (داخل `globals.css` أو `index.css`)
1541
+ إذا كنت تفضل التحكم في الألوان عبر CSS مباشرة:
1542
+ ```css
1543
+ /* في ملف globals.css أو index.css الرئيسي */
1544
+ :root {
1545
+ --any-table-primary: #2667EC; /* لون الأزرار والعناصر الفعالة */
1546
+ --any-table-primary-hover: #1E54C6;
1547
+ --any-table-primary-soft: #397FF6;
1548
+ --any-table-secondary: #39E965; /* لون ثانوي */
1549
+ --any-table-success: #10B981;
1550
+ --any-table-warning: #F59E0B;
1551
+ --any-table-danger: #EF4444;
1552
+ --any-table-font: "Alexandria", system-ui, sans-serif; /* خط الجداول الموحد */
1553
+ }
1554
+ ```
1555
+
1556
+ ---
1557
+
1558
+ ##### الطريقة 3: إنشاء مكوّن وسيط موحد للمشروع (`components/AppTable.tsx`)
1559
+ وهو أسلوب الشركات الكبرى (Enterprise Best Practice) لإنشاء مكوّن مسبق الإعدادات:
1560
+ ```tsx
1561
+ // components/AppTable.tsx
1562
+ import { AnyTable, AnyTableProps } from "@kareemelbalshe/any-table";
1563
+
1564
+ export function AppTable<TData = any>(props: AnyTableProps<TData>) {
1565
+ return (
1566
+ <AnyTable<TData>
1567
+ bordered={true}
1568
+ hoverable={true}
1569
+ striped={false}
1570
+ actionsTitle="الإجراءات" // عنوان عمود العمليات الموحد
1571
+ actionsWidth={220}
1572
+ className="shadow-sm transition-all"
1573
+ {...props} // يسمح لأي صفحة بتجاوز أي خاصية عند الحاجة
1574
+ />
1575
+ );
1576
+ }
1577
+
1578
+ // ثم في أي صفحة داخل مشروعك:
1579
+ // <AppTable data={orders} />
1580
+ ```
1581
+
1582
+ ---
1583
+
1584
+ #### 📄 ثانياً: جميع حالات الاستخدام الممكنة عند استخدام الجدول في الصفحات (All Page Use Cases)
1585
+
1586
+ إليك كل الحالات العملية التي قد تحتاجها أثناء بناء صفحاتك:
1587
+
1588
+ ##### الحالة 1: الاستخدام التلقائي المباشر (Zero-Config)
1589
+ يرث الستايل الموحد من الـ Provider بدون أي كود إضافي:
1590
+ ```tsx
1591
+ <AnyTable data={users} />
1592
+ ```
1593
+
1594
+ ##### الحالة 2: تغيير لون جدول مالي أو تحذيري في صفحة محددة (Local Theme Override)
1595
+ إذا أردت جعل جدول في صفحة الحسابات والماليات باللون الأخضر (Emerald) دون التأثير على باقي جداول الموقع:
958
1596
  ```tsx
959
1597
  <AnyTable
1598
+ data={invoices}
960
1599
  theme={{
961
1600
  colors: {
962
- primary: "#2667EC", // اللون الأساسي
963
- borderRadius: "0.75rem", // انحناء الحواف
1601
+ primary: "#10B981", // تغيير اللون لهذا الجدول فقط
964
1602
  },
965
1603
  }}
966
1604
  />
967
1605
  ```
968
1606
 
1607
+ ##### الحالة 3: شاشات العمليات والبيانات الكثيفة (High-Density Dashboard)
1608
+ لجعل المسافات الداخلية أصغر وتثبيت الهيدر أثناء التمرير العمودي:
1609
+ ```tsx
1610
+ <AnyTable
1611
+ data={auditLogs}
1612
+ compact={true} // يقلل الـ padding للأسطر والخلايا لعرض كمية بيانات أكبر
1613
+ stickyHeader={true} // يثبت ترويسة الجدول أثناء النزول بالماوس
1614
+ />
1615
+ ```
1616
+
1617
+ ##### الحالة 4: التبديل بين الأنماط المظهرية الجاهزة (Visual Presets)
1618
+ ```tsx
1619
+ <AnyTable
1620
+ data={products}
1621
+ bordered={false} // إخفاء الحواف الخارجية لمظهر ناعم وبسيط
1622
+ striped={true} // تفعيل الصفوف المقلمة المتبادلة (Zebra Stripes)
1623
+ hoverable={true} // إضاءة وتمييز السطر عند الوقوف عليه بالماوس
1624
+ className="shadow-2xl rounded-3xl" // كلاسات إضافية للكارت الخارجي
1625
+ tableClassName="text-xs" // تصغير حجم خط الجدول
1626
+ />
1627
+ ```
1628
+
1629
+ ##### الحالة 5: تنسيق عمود أو خلية معينة بمظهر مخصص (Per-Column & Per-Cell)
1630
+ ```tsx
1631
+ <AnyTable
1632
+ data={orders}
1633
+ columns={[
1634
+ { key: "id", title: "رقم الطلب", width: 100 },
1635
+ // تخصيص الخط والمحاذاة ولون النص لعمود المبلغ
1636
+ {
1637
+ key: "totalAmount",
1638
+ title: "الإجمالي",
1639
+ align: "right",
1640
+ className: "font-mono font-bold text-emerald-500",
1641
+ headerClassName: "text-right",
1642
+ },
1643
+ // تخصيص خلية بالكامل عبر JSX
1644
+ {
1645
+ key: "status",
1646
+ title: "حالة الدفع",
1647
+ render: (val) => (
1648
+ <span className={val === "Paid" ? "bg-emerald-500/20 text-emerald-500 px-2 py-1 rounded-full text-xs font-bold" : "bg-rose-500/20 text-rose-500 px-2 py-1 rounded-full text-xs font-bold"}>
1649
+ {val}
1650
+ </span>
1651
+ ),
1652
+ },
1653
+ ]}
1654
+ />
1655
+ ```
1656
+
1657
+ ##### الحالة 6: التحكم في الوضع الليلي والنهاري (Dark / Light Mode)
1658
+ الجدول يتوافق تلقائياً مع كلاس `dark` في Tailwind أو مكتبات مثل `next-themes`. كما يمكنك إجبار جدول معين على وضع محدد:
1659
+ ```tsx
1660
+ // إجبار هذا الجدول على وضع الـ Dark Mode دائماً
1661
+ <AnyTable data={users} theme={{ mode: "dark" }} />
1662
+ ```
1663
+
1664
+ ##### الحالة 7: تخصيص أزرار العمليات (Action Buttons Styling)
1665
+ ```tsx
1666
+ <AnyTable
1667
+ data={users}
1668
+ actions={[
1669
+ {
1670
+ id: "vip-btn",
1671
+ label: "ترقية VIP",
1672
+ icon: "⭐",
1673
+ color: "#8B5CF6", // لون مخصص عبر Hex
1674
+ className: "hover:scale-105 shadow-md shadow-purple-500/30",
1675
+ onClick: (row) => upgradeUser(row),
1676
+ },
1677
+ {
1678
+ id: "delete",
1679
+ icon: "🗑️",
1680
+ variant: "danger", // ستايل الخطر الجاهز
1681
+ onClick: (row) => deleteUser(row),
1682
+ },
1683
+ ]}
1684
+ />
1685
+ ```
1686
+
969
1687
  ---
970
1688
 
971
1689
  ### 💡 الحالة 11: التوافق الكامل مع Next.js (App Router)