@dsbtek/component-library 1.0.0 → 1.0.1

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.
Files changed (2) hide show
  1. package/README.md +330 -7
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,17 +1,340 @@
1
- # SFT Advanced Components
1
+ # @dsbtek/component-library
2
2
 
3
- This package provides advanced React components built on top of shadcn/ui.
3
+ A collection of advanced React components built with shadcn/ui.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Installation](#installation)
8
+ - [Components](#components)
9
+ - [AdvancedCombobox](#advancedcombobox)
10
+ - [AdvancedDataTable](#advanceddatatable)
11
+ - [Styling](#styling)
12
+ - [Contributing](#contributing)
13
+ - [License](#license)
4
14
 
5
15
  ## Installation
6
16
 
17
+ 1. Install the package and its peer dependencies:
18
+
19
+ ```bash
20
+ # Install the component library
21
+ npm install @dsbtek/component-library
22
+
23
+ # Install peer dependencies
24
+ npm install @radix-ui/react-popover cmdk class-variance-authority clsx lucide-react tailwind-merge
25
+ ```
26
+
27
+ 2. Set up Tailwind CSS in your project:
28
+
7
29
  ```bash
8
- npm install @smartflowtech/component-library
30
+ # Install Tailwind CSS and its dependencies
31
+ npm install -D tailwindcss postcss autoprefixer tailwindcss-animate
32
+ ```
33
+
34
+ 3. Initialize Tailwind CSS if you haven't already:
35
+
36
+ ```bash
37
+ npx tailwindcss init -p
38
+ ```
39
+
40
+ 4. Update your `tailwind.config.js`:
41
+
42
+ ```javascript
43
+ /** @type {import('tailwindcss').Config} */
44
+ module.exports = {
45
+ darkMode: ['class'],
46
+ content: [
47
+ './src/**/*.{js,ts,jsx,tsx}',
48
+ './node_modules/@dsbtek/component-library/**/*.{js,ts,jsx,tsx}',
49
+ ],
50
+ theme: {
51
+ extend: {
52
+ colors: {
53
+ border: 'hsl(var(--border))',
54
+ input: 'hsl(var(--input))',
55
+ ring: 'hsl(var(--ring))',
56
+ background: 'hsl(var(--background))',
57
+ foreground: 'hsl(var(--foreground))',
58
+ primary: {
59
+ DEFAULT: 'hsl(var(--primary))',
60
+ foreground: 'hsl(var(--primary-foreground))',
61
+ },
62
+ secondary: {
63
+ DEFAULT: 'hsl(var(--secondary))',
64
+ foreground: 'hsl(var(--secondary-foreground))',
65
+ },
66
+ destructive: {
67
+ DEFAULT: 'hsl(var(--destructive))',
68
+ foreground: 'hsl(var(--destructive-foreground))',
69
+ },
70
+ muted: {
71
+ DEFAULT: 'hsl(var(--muted))',
72
+ foreground: 'hsl(var(--muted-foreground))',
73
+ },
74
+ accent: {
75
+ DEFAULT: 'hsl(var(--accent))',
76
+ foreground: 'hsl(var(--accent-foreground))',
77
+ },
78
+ popover: {
79
+ DEFAULT: 'hsl(var(--popover))',
80
+ foreground: 'hsl(var(--popover-foreground))',
81
+ },
82
+ card: {
83
+ DEFAULT: 'hsl(var(--card))',
84
+ foreground: 'hsl(var(--card-foreground))',
85
+ },
86
+ },
87
+ borderRadius: {
88
+ lg: `var(--radius)`,
89
+ md: `calc(var(--radius) - 2px)`,
90
+ sm: 'calc(var(--radius) - 4px)',
91
+ },
92
+ },
93
+ },
94
+ plugins: [require('tailwindcss-animate')],
95
+ };
9
96
  ```
10
97
 
11
- ## Usage
98
+ 5. Add the following CSS variables to your global CSS file:
12
99
 
13
- ```jsx
14
- import { AdvancedCombobox } from '@smartflowtech/component-library';
100
+ ```css
101
+ @tailwind base;
102
+ @tailwind components;
103
+ @tailwind utilities;
15
104
 
16
- // ... rest of the documentation
105
+ @layer base {
106
+ :root {
107
+ --background: 0 0% 100%;
108
+ --foreground: 222.2 84% 4.9%;
109
+ --card: 0 0% 100%;
110
+ --card-foreground: 222.2 84% 4.9%;
111
+ --popover: 0 0% 100%;
112
+ --popover-foreground: 222.2 84% 4.9%;
113
+ --primary: 222.2 47.4% 11.2%;
114
+ --primary-foreground: 210 40% 98%;
115
+ --secondary: 210 40% 96.1%;
116
+ --secondary-foreground: 222.2 47.4% 11.2%;
117
+ --muted: 210 40% 96.1%;
118
+ --muted-foreground: 215.4 16.3% 46.9%;
119
+ --accent: 210 40% 96.1%;
120
+ --accent-foreground: 222.2 47.4% 11.2%;
121
+ --destructive: 0 84.2% 60.2%;
122
+ --destructive-foreground: 210 40% 98%;
123
+ --border: 214.3 31.8% 91.4%;
124
+ --input: 214.3 31.8% 91.4%;
125
+ --ring: 222.2 84% 4.9%;
126
+ --radius: 0.5rem;
127
+ }
128
+ }
17
129
  ```
130
+
131
+ ## Components
132
+
133
+ ### AdvancedCombobox
134
+
135
+ A searchable dropdown component with single or multiple selection support.
136
+
137
+ #### Features
138
+
139
+ - Single or multiple item selection
140
+ - Search functionality with fuzzy matching
141
+ - Keyboard navigation support (↑↓ to navigate, Enter to select)
142
+ - Clear selection option
143
+ - Customizable styling
144
+ - Accessible by default (WAI-ARIA compliant)
145
+
146
+ #### Props
147
+
148
+ | Prop | Type | Default | Description |
149
+ | ----------- | ----------------------------------------- | -------- | ------------------------------------------ |
150
+ | items | `Array<{ value: string, label: string }>` | Required | Array of items to display in the dropdown |
151
+ | placeholder | `string` | Required | Placeholder text when no item is selected |
152
+ | onSelect | `(value: string) => void` | Required | Callback function when an item is selected |
153
+ | multiple | `boolean` | `false` | Enable multiple item selection |
154
+ | searchable | `boolean` | `true` | Enable search functionality |
155
+ | className | `string` | - | Additional CSS classes |
156
+
157
+ #### Keyboard Shortcuts
158
+
159
+ - `↑/↓`: Navigate through items
160
+ - `Enter`: Select highlighted item
161
+ - `Esc`: Close dropdown
162
+ - `Backspace`: Clear selection (when input is empty)
163
+ - `Type`: Search items (when searchable is true)
164
+
165
+ #### Example Usage
166
+
167
+ ```tsx
168
+ import { AdvancedCombobox } from '@dsbtek/component-library';
169
+
170
+ // Single Selection with Search
171
+ function SingleSelectExample() {
172
+ return (
173
+ <AdvancedCombobox
174
+ items={[
175
+ { value: '1', label: 'Option 1' },
176
+ { value: '2', label: 'Option 2' },
177
+ { value: '3', label: 'Option 3' },
178
+ ]}
179
+ placeholder="Select an option"
180
+ onSelect={(value) => console.log('Selected:', value)}
181
+ />
182
+ );
183
+ }
184
+
185
+ // Multiple Selection
186
+ function MultipleSelectExample() {
187
+ return (
188
+ <AdvancedCombobox
189
+ items={[
190
+ { value: 'react', label: 'React' },
191
+ { value: 'vue', label: 'Vue' },
192
+ { value: 'angular', label: 'Angular' },
193
+ ]}
194
+ placeholder="Select frameworks"
195
+ onSelect={(value) => console.log('Selected:', value)}
196
+ multiple={true}
197
+ />
198
+ );
199
+ }
200
+ ```
201
+
202
+ ### AdvancedDataTable
203
+
204
+ A feature-rich data table component with sorting, filtering, and pagination.
205
+
206
+ #### Features
207
+
208
+ - Column sorting (click column headers)
209
+ - Text filtering
210
+ - Pagination with customizable page sizes
211
+ - Row selection with checkboxes
212
+ - Responsive design
213
+ - Customizable styling
214
+ - Loading states
215
+ - Empty state handling
216
+
217
+ #### Props
218
+
219
+ | Prop | Type | Default | Description |
220
+ | ------------------- | ---------------------------------------------------- | ------------ | -------------------------------------------------- |
221
+ | columns | `Array<Column<T>>` | Required | Array of column definitions |
222
+ | fetchData | `(params: FetchParams) => Promise<FetchResponse<T>>` | Required | Function to fetch data with pagination and sorting |
223
+ | itemsPerPageOptions | `number[]` | `[10,20,50]` | Available options for items per page |
224
+ | className | `string` | - | Additional CSS classes |
225
+
226
+ #### Column Definition
227
+
228
+ | Property | Type | Default | Description |
229
+ | ---------- | ------------------------------------------- | -------- | ---------------------------------------- |
230
+ | accessor | `keyof T \| ((item: T) => React.ReactNode)` | Required | Key or function to access the cell value |
231
+ | header | `string` | Required | Column header text |
232
+ | sortable | `boolean` | `false` | Enable column sorting |
233
+ | filterable | `boolean` | `false` | Enable column filtering |
234
+ | cell | `(value: any, item: T) => React.ReactNode` | - | Custom cell renderer |
235
+
236
+ #### FetchParams Type
237
+
238
+ ```typescript
239
+ interface FetchParams {
240
+ page: number;
241
+ perPage: number;
242
+ sortBy?: string;
243
+ sortOrder?: 'asc' | 'desc';
244
+ filters?: Record<string, string>;
245
+ }
246
+ ```
247
+
248
+ #### FetchResponse Type
249
+
250
+ ```typescript
251
+ interface FetchResponse<T> {
252
+ data: T[];
253
+ meta: {
254
+ current_page: number;
255
+ last_page: number;
256
+ per_page: number;
257
+ total: number;
258
+ };
259
+ }
260
+ ```
261
+
262
+ #### Example Usage
263
+
264
+ ```tsx
265
+ import { AdvancedDataTable } from '@dsbtek/component-library';
266
+
267
+ function TableExample() {
268
+ const columns = [
269
+ {
270
+ accessor: 'name',
271
+ header: 'Name',
272
+ sortable: true,
273
+ filterable: true,
274
+ },
275
+ {
276
+ accessor: 'email',
277
+ header: 'Email',
278
+ sortable: true,
279
+ },
280
+ {
281
+ accessor: 'status',
282
+ header: 'Status',
283
+ cell: (value) => (
284
+ <span className={`status-${value.toLowerCase()}`}>{value}</span>
285
+ ),
286
+ },
287
+ ];
288
+
289
+ const fetchData = async (params) => {
290
+ const response = await fetch(
291
+ '/api/users?' +
292
+ new URLSearchParams({
293
+ page: params.page.toString(),
294
+ perPage: params.perPage.toString(),
295
+ sortBy: params.sortBy,
296
+ sortOrder: params.sortOrder,
297
+ ...params.filters,
298
+ }),
299
+ );
300
+ return response.json();
301
+ };
302
+
303
+ return (
304
+ <AdvancedDataTable
305
+ columns={columns}
306
+ fetchData={fetchData}
307
+ itemsPerPageOptions={[5, 10, 20, 50]}
308
+ />
309
+ );
310
+ }
311
+ ```
312
+
313
+ ## Styling
314
+
315
+ All components use Tailwind CSS for styling and can be customized using Tailwind classes. The components also respect the theme variables defined in your CSS.
316
+
317
+ ### Custom Styling Example
318
+
319
+ ```tsx
320
+ <AdvancedCombobox
321
+ className="w-[300px] rounded-lg"
322
+ items={items}
323
+ placeholder="Custom styled combobox"
324
+ onSelect={handleSelect}
325
+ />
326
+
327
+ <AdvancedDataTable
328
+ className="border rounded-lg shadow-sm"
329
+ columns={columns}
330
+ fetchData={fetchData}
331
+ />
332
+ ```
333
+
334
+ ## Contributing
335
+
336
+ [Add contribution guidelines here]
337
+
338
+ ## License
339
+
340
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsbtek/component-library",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",