shadcn-data-views 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 ADDED
@@ -0,0 +1,133 @@
1
+ # shadcn-data-views
2
+
3
+ A powerful, schema-driven data view component for React, built with modern aesthetics and flexibility in mind. Instantly spin up Grid, Kanban, Gallery, Calendar, and Form views for your data.
4
+
5
+ ## Description
6
+
7
+ `shadcn-data-views` allows developers to render complex data interfaces by simply defining a JSON schema and providing a data client. It abstracts away the complexity of building multiple view types (tables, boards, galleries) while providing a premium, polished UI out of the box.
8
+
9
+ ## Advantages
10
+
11
+ - **Schema-Driven**: Define your data structure once in JSON (fields, types, options) and the UI adapts automatically.
12
+ - **Multi-View Support**: Comes with 5 built-in views:
13
+ - **Grid**: classic spreadsheet-like table.
14
+ - **Kanban**: drag-and-drop board for status management.
15
+ - **Gallery**: card-based visual layout.
16
+ - **Calendar**: date-based schedule view.
17
+ - **Form**: auto-generated input forms.
18
+ - **Backend Agnostic**: You provide the `dbClient` implementation. It works with any data source: REST APIs, Supabase, Firebase, or even LocalStorage.
19
+ - **Beautiful Design**: Built with modern design principles (shadcn-like), featuring smooth transitions and a clean aesthetic.
20
+ - **Type-Safe**: Written in TypeScript with comprehensive type definitions.
21
+
22
+ ## Use Cases
23
+
24
+ - **Admin Dashboards**: Quickly build CRUD interfaces for internal tools.
25
+ - **Project Management Tools**: Implement task tracking with Kanban and List views in minutes.
26
+ - **SaaS Applications**: Add "Airtable-like" or "Notion-like" database features to your customer-facing app.
27
+ - **Rapid Prototyping**: Visualize data structures immediately without writing custom UI code for each entity.
28
+
29
+ ## Usage
30
+
31
+ ### Installation
32
+
33
+ ```bash
34
+ npm install shadcn-data-views
35
+ # or
36
+ pnpm add shadcn-data-views
37
+ ```
38
+
39
+ ### Setup
40
+
41
+ The package now injects its own styles automatically. You do NOT need to import a CSS file.
42
+
43
+ **Important**: This package uses `next-themes` for dark mode support. You **must** wrap your application (or the component) in a `ThemeProvider` to enable theme switching.
44
+
45
+ ```tsx
46
+ // Example in a Next.js app (providers.tsx)
47
+ import { ThemeProvider } from 'next-themes';
48
+
49
+ export function Providers({ children }) {
50
+ return (
51
+ <ThemeProvider attribute="class" defaultTheme="system" enableSystem>
52
+ {children}
53
+ </ThemeProvider>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ### Basic Example
59
+
60
+ To use the `DataViews` component, you likely need just three steps:
61
+ 1. Define the **Schema** (`TableSchema`).
62
+ 2. Implement the **Client** (`IDataViewsClient`).
63
+ 3. Render the **Component**.
64
+
65
+ ```tsx
66
+ import { DataViews, TableSchema, IDataViewsClient, IRecord } from 'shadcn-data-views';
67
+
68
+ // 1. Define Schema
69
+ const mySchema: TableSchema = {
70
+ id: 'tasks',
71
+ name: 'Tasks',
72
+ icon: '📋',
73
+ fields: [
74
+ { id: 'title', name: 'Title', type: 'text', isPrimary: true },
75
+ { id: 'status', name: 'Status', type: 'select', options: [{ id: 'todo', name: 'To Do' }, { id: 'done', name: 'Done' }] },
76
+ { id: 'dueDate', name: 'Due Date', type: 'date' },
77
+ ],
78
+ };
79
+
80
+ // 2. Implement Client (Connecting to your API)
81
+ class MyDbClient implements IDataViewsClient {
82
+ async getRecords(): Promise<IRecord[]> {
83
+ return await fetch('/api/tasks').then(res => res.json());
84
+ }
85
+
86
+ async createRecord(record: Partial<IRecord>): Promise<IRecord> {
87
+ return await fetch('/api/tasks', { method: 'POST', body: JSON.stringify(record) }).then(res => res.json());
88
+ }
89
+
90
+ async updateRecord(id: string, record: Partial<IRecord>): Promise<IRecord> {
91
+ return await fetch(`/api/tasks/${id}`, { method: 'PATCH', body: JSON.stringify(record) }).then(res => res.json());
92
+ }
93
+
94
+ async deleteRecord(id: string): Promise<void> {
95
+ await fetch(`/api/tasks/${id}`, { method: 'DELETE' });
96
+ }
97
+ }
98
+
99
+ const dbClient = new MyDbClient();
100
+
101
+ // 3. Render Component
102
+ export default function App() {
103
+ return (
104
+ <div style={{ height: '100vh', width: '100%' }}>
105
+ <DataViews
106
+ schema={mySchema}
107
+ dbClient={dbClient}
108
+ config={{ defaultView: 'grid' }}
109
+ />
110
+ </div>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ### Configuration
116
+
117
+ You can customize the component via the `config` prop:
118
+
119
+ ```tsx
120
+ <DataViews
121
+ schema={mySchema}
122
+ dbClient={dbClient}
123
+ config={{
124
+ defaultView: 'kanban'
125
+ }}
126
+ />
127
+ ```
128
+
129
+ ---
130
+
131
+ ## License
132
+
133
+ MIT