@stratametriq/id-card-designer 1.1.0 → 1.2.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/README.md CHANGED
@@ -9,6 +9,7 @@ Whether you are building an **Educational ERP / Student Information System**, **
9
9
  ## 🌟 Features
10
10
 
11
11
  - **🎨 Turnkey All-In-One Dashboard (`<IdCardManager />`):** Drop in a complete, ready-to-use workspace containing department tabs, live vector stage, batch A4 print setup, and roster selection table.
12
+ - **🔍 Instant Roster Search & Status Filters:** Real-time search bar across names, ID numbers, departments, and phone numbers, plus quick status filter pill tabs (`All | Selected | Unselected`) with smart batch selection.
12
13
  - **✨ Interactive Visual Studio Canvas:** Drag-and-drop element positioning (`react-draggable`), real-time zoom controls (`80% - 200%`), grid snapping (`1mm / 5mm`), and Z-index layering.
13
14
  - **📏 Technical Precision Rulers & Grid Overlay:** Toggleable millimeter measurement rulers (`0mm - 86mm`) and radial matrix grid overlays for exact PVC card alignment.
14
15
  - **🔄 Undo & Redo History Control:** Full history stack tracking (`Ctrl+Z` / `Cmd+Z` to undo, `Ctrl+Y` / `Cmd+Shift+Z` to redo) alongside keyboard arrow key precision nudging (`1px` or `5px` with Shift).
@@ -37,6 +38,123 @@ import "@stratametriq/id-card-designer/dist/index.css";
37
38
 
38
39
  ---
39
40
 
41
+ ## 🚀 Sweet & Simple Guide: How to Use with Real Data & Features
42
+
43
+ Whether you want a **1-Minute Turnkey Dashboard** (`<IdCardManager />`) or want to build your own **Custom Portal** using individual modular features (`<IdCardPreview />`, `<IdCardDesignerModal />`, `generateIdCardsPdf`), connecting your real database or API data is effortless!
44
+
45
+ ### Option 1: Turnkey All-In-One Dashboard (`<IdCardManager />`)
46
+
47
+ By default, rendering `<IdCardManager />` without props opens our full interactive demo screen. To connect your **real API or database records**, simply pass them into the `sampleRecords` prop:
48
+
49
+ ```jsx
50
+ import React, { useState, useEffect } from 'react';
51
+ import { IdCardManager } from '@stratametriq/id-card-designer';
52
+ import '@stratametriq/id-card-designer/dist/index.css';
53
+
54
+ export default function SchoolPortal() {
55
+ const [dbRecords, setDbRecords] = useState({ student: [], staff: [] });
56
+
57
+ // 1. Fetch real students/employees from your backend (Node.js, Laravel, Supabase, etc.)
58
+ useEffect(() => {
59
+ fetch('https://api.yourschool.com/students')
60
+ .then(res => res.json())
61
+ .then(data => setDbRecords({ student: data }));
62
+ }, []);
63
+
64
+ // 2. Pass your live data right into <IdCardManager />!
65
+ return (
66
+ <IdCardManager
67
+ sampleRecords={dbRecords}
68
+
69
+ // Save customized card designs back to your database
70
+ onSaveCategoryTemplate={(category, templateSchema) => {
71
+ console.log(`Saving ${category} template to DB:`, templateSchema);
72
+ }}
73
+
74
+ // Listen when batch PDF export completes
75
+ onBatchExportComplete={(category, exportedRecords) => {
76
+ console.log(`Generated A4 PDF for ${exportedRecords.length} records!`);
77
+ }}
78
+ />
79
+ );
80
+ }
81
+ ```
82
+
83
+ ---
84
+
85
+ ### Option 2: Building Custom Screens (Using Modular Features)
86
+
87
+ If you don't want our full dashboard and instead want to embed specific ID card features directly into your own custom pages, tables, or profile screens, use our **standalone building blocks**:
88
+
89
+ #### A. Show a Live ID Card on a Student Profile Page (`<IdCardPreview />`)
90
+ ```jsx
91
+ import { IdCardPreview } from '@stratametriq/id-card-designer';
92
+
93
+ function StudentProfilePage({ realStudentData, savedTemplateJson }) {
94
+ return (
95
+ <div className="profile-card-widget">
96
+ <h3>Student ID Card</h3>
97
+
98
+ {/* Automatically binds realStudentData fields into the template */}
99
+ <IdCardPreview
100
+ templateSchema={savedTemplateJson}
101
+ data={realStudentData} // e.g. { studentName: 'Aarav Patel', admissionNo: 'ADM-101', profilePhoto: '...' }
102
+ orientation="vertical"
103
+ zoom={1.2}
104
+ />
105
+ </div>
106
+ );
107
+ }
108
+ ```
109
+
110
+ #### B. Trigger Batch A4 PDF Export from Your Own Custom Button (`generateIdCardsPdf`)
111
+ ```jsx
112
+ import { generateIdCardsPdf } from '@stratametriq/id-card-designer';
113
+
114
+ function CustomRosterTable({ selectedStudents, activeTemplate }) {
115
+ const handlePrint = async () => {
116
+ // Generate high-resolution A4 multi-page PDF directly from your data array
117
+ await generateIdCardsPdf({
118
+ records: selectedStudents,
119
+ templateSchema: activeTemplate,
120
+ orientation: 'vertical',
121
+ fileName: `Student_Cards_Batch_${new Date().toISOString().slice(0,10)}.pdf`,
122
+ pageOptions: { format: 'a4', showCropMarks: true }
123
+ });
124
+ };
125
+
126
+ return <button onClick={handlePrint}>Download A4 Print Sheet ({selectedStudents.length} Cards)</button>;
127
+ }
128
+ ```
129
+
130
+ #### C. Open the Drag-and-Drop Studio inside Your Own Modal (`<IdCardDesignerModal />`)
131
+ ```jsx
132
+ import { IdCardDesignerModal } from '@stratametriq/id-card-designer';
133
+
134
+ function DesignButton({ currentTemplate, onSaveToDatabase }) {
135
+ const [isOpen, setIsOpen] = useState(false);
136
+
137
+ return (
138
+ <>
139
+ <button onClick={() => setIsOpen(true)}>✨ Design Card Layout</button>
140
+
141
+ <IdCardDesignerModal
142
+ show={isOpen}
143
+ onHide={() => setIsOpen(false)}
144
+ initialTemplate={currentTemplate}
145
+ sampleData={[{ studentName: 'Sample Student', admissionNo: '101' }]}
146
+ onSaveTemplate={(newTemplate) => {
147
+ onSaveToDatabase(newTemplate);
148
+ setIsOpen(false);
149
+ }}
150
+ />
151
+ </>
152
+ );
153
+ }
154
+ ```
155
+
156
+ ---
157
+
40
158
  ## 🌐 Multi-Framework & Vanilla JS Support (`Vue`, `Angular`, `Svelte`, `Next.js` & `HTML`)
41
159
 
42
160
  While the visual UI components (`<IdCardManager />` and `<IdCardDesignerModal />`) are built with React hooks and drag-and-drop vector canvas state (`react-draggable`), **this npm package can be used across any frontend framework or vanilla JavaScript project**:
@@ -129,7 +247,7 @@ When users open `<IdCardManager />`, they interact with a unified, professional
129
247
  | **Step 1** | **Select Department / Organization Category** | A clean 4-card header grid showing your configured organization categories (e.g., *Student IDs*, *Faculty & Admin*, *Corporate HR*, *Hospital Portal*). Each card displays the number of bound data fields (`{fieldDefinitions.length} fields`) and template layouts (`{templateCount} template`). Clicking any card instantly switches the active category, isolating state, templates, and roster tables cleanly. |
130
248
  | **Step 2** | **Live Stage Preview & Studio Launcher** | A high-resolution vector canvas preview displaying the currently selected person's ID card in real-time. Includes:<br>• **Interactive Zoom Controls (`80% - 150%`)** alongside instant reset buttons.<br>• **Toggleable Grid & Measurement Rulers (`0-80mm`)** for visual precision inspection.<br>• **Launch Studio Canvas Button:** Opens our popup drag-and-drop design studio modal where operators can add new text fields, upload background textures, bind database keys, and drag elements around with snap-to-grid accuracy. |
131
249
  | **Step 3** | **Batch A4 Print Engine (`⚡ Live Sheet Matrix`)** | A commercial print-engine sidebar that calculates and exports production-ready multi-page grid sheets:<br>• **⚡ Live Sheet Matrix Calculation Box:** Dynamically computes physical sheet mathematics in real-time right before your eyes! When you toggle **Paper Sheet Size (`A4` vs `US Letter`)**, **Orientation (`Portrait` vs `Landscape` Sheet)**, or **Card Cut Size (`86×54mm Standard ID-1`, `90×50mm Business Card`, `100×70mm Event Badge`)**, the matrix immediately recalculates the exact column × row capacity (`e.g., 3 Cols × 3 Rows = 9 cards/page`) and total job pages required.<br>• **Hardware Cut Guides Checkboxes:** Toggle corner crosshair cut marks (`0.35mm stroke`), card perimeter cut outline guides, and technical registration headers (`PRECISION CUT SHEET — JOB SPECIFICATIONS`) for print shop operators. |
132
- | **Step 4** | **Live Roster Directory Table** | Displays a dynamic, paginated table of all people in that department. Columns automatically reflect your category's database fields (`studentName`, `admissionNo`, `classSec`, etc.). Check or uncheck individual records to include them in the Batch A4 Print Engine, or click any row to preview their rendered card live in Step 2! |
250
+ | **Step 4** | **Live Roster Directory Table & Instant Search** | Displays an interactive data table of all records in that department equipped with:<br>• **🔍 Instant Search Input:** Type any name, admission/employee number, department, or phone number to instantly filter records right before your eyes.<br>• **🏷️ Quick Status Filter Pills (`All \| Selected \| Unselected`):** Isolate checked vs unchecked records instantly before batch printing.<br>• **⚡ Smart Batch Selection:** Clicking **Select Shown / Unselect Shown** smartly checks or unchecks *only the records matching your current search or filter* without disrupting unrelated records outside your filter! Clicking any row previews their rendered card live on stage in Step 2. |
133
251
 
134
252
  ---
135
253
 
@@ -347,6 +465,156 @@ const CATEGORY_CONFIGS = {
347
465
 
348
466
  ---
349
467
 
468
+ ## 🏗️ Recommended Consumer App Architecture (`my-consumer-app/`)
469
+
470
+ When integrating `@stratametriq/id-card-designer` into an enterprise or institutional web application (e.g., School Management System, Hospital Portal, or Corporate HR Suite), we recommend structuring your project with clean separation of concerns:
471
+
472
+ ```text
473
+ my-consumer-app/
474
+ ├── src/
475
+ │ ├── config/
476
+ │ │ └── idCardFields.js # 1. Centralized field definitions & mappings across categories
477
+ │ │
478
+ │ ├── services/
479
+ │ │ └── idCardApi.js # 2. API helper methods to load/save JSON templates & records from backend
480
+ │ │
481
+ │ ├── components/
482
+ │ │ └── id-cards/
483
+ │ │ ├── CardTemplateStudio.jsx # 3. Admin component wrapping <IdCardDesignerModal />
484
+ │ │ ├── CardPreviewBadge.jsx # 4. Reusable UI component wrapping <IdCardPreview />
485
+ │ │ └── BatchPrintActions.jsx # 5. Component managing high-DPI PDF generation & progress (`generateIdCardsPdf`)
486
+ │ │
487
+ │ ├── pages/
488
+ │ │ ├── AdminSettingsPage.jsx # Uses <CardTemplateStudio /> for administrators to design ID cards
489
+ │ │ └── StaffDirectoryPage.jsx # Uses <CardPreviewBadge /> and <BatchPrintActions /> for staff/student rosters
490
+ │ └── main.jsx # Imports global "@stratametriq/id-card-designer/dist/index.css"
491
+ ```
492
+
493
+ ### 🗂️ Explanation of Key Architectural Components
494
+
495
+ 1. **`src/config/idCardFields.js` (Centralized Configuration)**
496
+ Maintains all available data fields for each department. By isolating fields in config, adding new custom fields (`bloodGroup`, `busRoute`, `rfidTag`) never requires modifying UI components:
497
+ ```javascript
498
+ export const ID_CARD_FIELDS = {
499
+ student: [
500
+ { key: "studentName", label: "Student Full Name" },
501
+ { key: "admissionNo", label: "Admission Number" },
502
+ { key: "bloodGroup", label: "Blood Group" }
503
+ ],
504
+ staff: [
505
+ { key: "staffName", label: "Staff Member Name" },
506
+ { key: "designation", label: "Job Title / Role" }
507
+ ]
508
+ };
509
+ ```
510
+
511
+ 2. **`src/services/idCardApi.js` (API & Storage Layer)**
512
+ Handles communicating with your backend server or local storage to persist the JSON template schemas (`templateSchema`) saved by administrators:
513
+ ```javascript
514
+ export async function fetchCategoryTemplate(categoryKey) {
515
+ const res = await fetch(`/api/id-cards/templates/${categoryKey}`);
516
+ return res.json();
517
+ }
518
+
519
+ export async function saveCategoryTemplate(categoryKey, schema) {
520
+ return fetch(`/api/id-cards/templates/${categoryKey}`, {
521
+ method: "POST",
522
+ headers: { "Content-Type": "application/json" },
523
+ body: JSON.stringify(schema)
524
+ });
525
+ }
526
+ ```
527
+
528
+ 3. **`src/components/id-cards/CardTemplateStudio.jsx` (Admin Studio Wrapper)**
529
+ Wraps `<IdCardDesignerModal />` with your application's custom saving logic and category switcher:
530
+ ```jsx
531
+ import React, { useState } from "react";
532
+ import { IdCardDesignerModal } from "@stratametriq/id-card-designer";
533
+ import { ID_CARD_FIELDS } from "../../config/idCardFields";
534
+ import { saveCategoryTemplate } from "../../services/idCardApi";
535
+
536
+ export function CardTemplateStudio({ categoryKey = "student", initialSchema }) {
537
+ const [showModal, setShowModal] = useState(false);
538
+
539
+ return (
540
+ <div>
541
+ <button onClick={() => setShowModal(true)}>Open ID Card Designer</button>
542
+ <IdCardDesignerModal
543
+ show={showModal}
544
+ onHide={() => setShowModal(false)}
545
+ initialTemplate={initialSchema}
546
+ fieldDefinitions={ID_CARD_FIELDS[categoryKey]}
547
+ onSaveTemplate={async (schema) => {
548
+ await saveCategoryTemplate(categoryKey, schema);
549
+ setShowModal(false);
550
+ }}
551
+ />
552
+ </div>
553
+ );
554
+ }
555
+ ```
556
+
557
+ 4. **`src/components/id-cards/CardPreviewBadge.jsx` (Reusable Live Badge)**
558
+ Wraps `<IdCardPreview />` to render clean vector ID cards in directory listings, profile popups, or student tables:
559
+ ```jsx
560
+ import React from "react";
561
+ import { IdCardPreview } from "@stratametriq/id-card-designer";
562
+
563
+ export function CardPreviewBadge({ recordData, templateSchema }) {
564
+ return (
565
+ <div className="card-preview-wrapper shadow-md rounded-lg overflow-hidden">
566
+ <IdCardPreview
567
+ templateSchema={templateSchema}
568
+ data={recordData}
569
+ zoom={1}
570
+ />
571
+ </div>
572
+ );
573
+ }
574
+ ```
575
+
576
+ 5. **`src/components/id-cards/BatchPrintActions.jsx` (Batch Print Utility Button)**
577
+ Manages batch exporting checked staff or student records into multi-page A4 or Letter sheets:
578
+ ```jsx
579
+ import React, { useState } from "react";
580
+ import { generateIdCardsPdf } from "@stratametriq/id-card-designer";
581
+
582
+ export function BatchPrintActions({ selectedRecords, templateSchema }) {
583
+ const [exporting, setExporting] = useState(false);
584
+
585
+ const handleExport = async () => {
586
+ setExporting(true);
587
+ await generateIdCardsPdf({
588
+ records: selectedRecords,
589
+ templateSchema: templateSchema,
590
+ orientation: templateSchema?.orientation || "vertical",
591
+ fileName: "Batch_ID_Cards_Job.pdf",
592
+ pageOptions: { format: "a4", showCropMarks: true, showCutOutline: true }
593
+ });
594
+ setExporting(false);
595
+ };
596
+
597
+ return (
598
+ <button onClick={handleExport} disabled={exporting || selectedRecords.length === 0}>
599
+ {exporting ? "Generating PDF Sheets..." : `Batch Print (${selectedRecords.length} Cards)`}
600
+ </button>
601
+ );
602
+ }
603
+ ```
604
+
605
+ 6. **`src/main.jsx` (Global Stylesheet Import)**
606
+ Always import the universal stylesheet right at the root entry point of your application:
607
+ ```javascript
608
+ import React from 'react';
609
+ import ReactDOM from 'react-dom/client';
610
+ import App from './App.jsx';
611
+ import "@stratametriq/id-card-designer/dist/index.css";
612
+
613
+ ReactDOM.createRoot(document.getElementById('root')).render(<App />);
614
+ ```
615
+
616
+ ---
617
+
350
618
  ## 📜 License
351
619
 
352
620
  MIT © Stratametriq