zabi-components 1.0.4 → 1.0.6

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
@@ -1,15 +1,18 @@
1
1
  # Zabi Components
2
2
 
3
- A modern SvelteKit component library with TypeScript and Tailwind CSS support.
3
+ A comprehensive Svelte component library built with TypeScript and Tailwind CSS, designed for easy integration across multiple Svelte projects.
4
4
 
5
5
  ## Features
6
6
 
7
- - 🎨 **Modern Design**: Built with Tailwind CSS for consistent, responsive styling
8
- - 🔧 **TypeScript**: Full TypeScript support with comprehensive type definitions
9
- - 📦 **Modular**: Import only what you need with tree-shaking support
10
- - ♿ **Accessible**: Built with accessibility best practices
11
- - 🚀 **Performance**: Optimized for production with minimal bundle size
12
- - 📱 **Responsive**: Mobile-first design approach
7
+ - 🎨 **Consistent Design System** - Standardized props, events, and styling across all components
8
+ - 🎯 **TypeScript First** - Full TypeScript support with comprehensive type definitions
9
+ - 🎨 **Tailwind CSS Integration** - Built with Tailwind CSS and CSS custom properties for easy theming
10
+ - ♿ **Accessibility First** - ARIA compliant components with keyboard navigation support
11
+ - 📱 **Responsive Design** - Mobile-first approach with responsive utilities
12
+ - 🎭 **Dark Mode Support** - Built-in dark mode support with CSS custom properties
13
+ - 🧩 **Slot Support** - Flexible slot system for custom content
14
+ - 📦 **Tree Shakeable** - Import only what you need
15
+ - ✅ **Production Ready** - Fully tested and optimized for production use
13
16
 
14
17
  ## Installation
15
18
 
@@ -17,130 +20,532 @@ A modern SvelteKit component library with TypeScript and Tailwind CSS support.
17
20
  npm install zabi-components
18
21
  ```
19
22
 
20
- ## Usage
23
+ ### Peer Dependencies
21
24
 
22
- ### Import All Components
25
+ Make sure you have the required peer dependencies installed:
23
26
 
24
- ```typescript
25
- import { Button, Card, Input, Modal } from 'zabi-components';
27
+ ```bash
28
+ npm install svelte@^4.0.0 || ^5.0.0
29
+ npm install @sveltejs/kit@^2.0.0 # Optional, for SvelteKit projects
26
30
  ```
27
31
 
28
- ### Import by Category
32
+ ## Import Methods
29
33
 
34
+ Zabi Components supports multiple import patterns:
35
+
36
+ ### Main Import (All Components)
30
37
  ```typescript
31
- // Atomic components
32
- import { Button, Input, Card } from 'zabi-components/atoms';
38
+ import { Button, Input, Card, Alert, Badge, Modal } from 'zabi-components';
39
+ ```
33
40
 
34
- // Molecular components
35
- import { Modal, Alert, Dropdown } from 'zabi-components/molecules';
41
+ ### Subpath Imports (Recommended for Tree Shaking)
42
+ ```typescript
43
+ // Import from specific categories
44
+ import { Button, Input, Badge } from 'zabi-components/atoms';
45
+ import { Alert, Modal, Dropdown } from 'zabi-components/molecules';
46
+ import { Navbar, ToastManager } from 'zabi-components/organisms';
36
47
 
37
- // Organism components
38
- import { ToastContainer } from 'zabi-components/organisms';
48
+ // Import types separately
49
+ import type { ButtonEvents, InputEvents } from 'zabi-components/types';
39
50
  ```
40
51
 
41
- ### Basic Example
52
+ ## Quick Start
42
53
 
43
54
  ```svelte
44
55
  <script lang="ts">
45
- import { Button, Card, Input } from 'zabi-components';
56
+ import { Button, Input, Card, Alert } from 'zabi-components';
46
57
 
47
58
  let name = '';
48
- let showCard = false;
59
+ let showAlert = false;
60
+
61
+ function handleSubmit(event: CustomEvent) {
62
+ console.log('Form submitted!', event.detail.value);
63
+ showAlert = true;
64
+ }
65
+
66
+ function handleInput(event: CustomEvent) {
67
+ console.log('Input changed:', event.detail.value);
68
+ }
69
+
70
+ function handleClose() {
71
+ showAlert = false;
72
+ }
49
73
  </script>
50
74
 
51
- <Input bind:value={name} placeholder="Enter your name" />
52
- <Button on:click={() => showCard = !showCard}>
53
- Toggle Card
75
+ <Card>
76
+ <div slot="header">
77
+ <h2>User Form</h2>
78
+ </div>
79
+
80
+ <Input
81
+ bind:value={name}
82
+ label="Name"
83
+ placeholder="Enter your name"
84
+ on:input={handleInput}
85
+ />
86
+
87
+ <Button on:click={handleSubmit}>
88
+ Submit
89
+ </Button>
90
+
91
+ <div slot="footer">
92
+ {#if showAlert}
93
+ <Alert variant="success" closable on:close={handleClose}>
94
+ Form submitted successfully!
95
+ </Alert>
96
+ {/if}
97
+ </div>
98
+ </Card>
99
+ ```
100
+
101
+ ## Component API
102
+
103
+ ### Button Component
104
+
105
+ ```svelte
106
+ <Button
107
+ variant="primary" | "secondary" | "danger" | "success" | "warning" | "info"
108
+ size="sm" | "md" | "lg"
109
+ disabled={boolean}
110
+ loading={boolean}
111
+ type="button" | "submit" | "reset"
112
+ className={string}
113
+ on:click={(e) => console.log(e.detail.value, e.detail.event)}
114
+ >
115
+ Button Content
54
116
  </Button>
117
+ ```
118
+
119
+ **Props:**
120
+ - `variant`: Button style variant (default: "primary")
121
+ - `size`: Button size (default: "md")
122
+ - `disabled`: Disable the button (default: false)
123
+ - `loading`: Show loading state (default: false)
124
+ - `type`: HTML button type (default: "button")
125
+ - `className`: Additional CSS classes
126
+
127
+ **Events:**
128
+ - `click`: Fired when button is clicked - `{ detail: { value: true, event: MouseEvent } }`
129
+
130
+ ### Input Component
131
+
132
+ ```svelte
133
+ <Input
134
+ bind:value={string}
135
+ type={string}
136
+ label={string}
137
+ placeholder={string}
138
+ required={boolean}
139
+ disabled={boolean}
140
+ size="sm" | "md" | "lg"
141
+ variant="default" | "error" | "success"
142
+ error={string}
143
+ success={string}
144
+ helpText={string}
145
+ className={string}
146
+ id={string}
147
+ on:input={(e) => console.log(e.detail.value, e.detail.event)}
148
+ on:change={(e) => console.log(e.detail.value, e.detail.event)}
149
+ />
150
+ ```
151
+
152
+ **Props:**
153
+ - `value`: Input value (bindable)
154
+ - `type`: Input type (default: "text")
155
+ - `label`: Input label
156
+ - `placeholder`: Input placeholder
157
+ - `required`: Mark as required (default: false)
158
+ - `disabled`: Disable the input (default: false)
159
+ - `size`: Input size (default: "md")
160
+ - `variant`: Input variant (default: "default")
161
+ - `error`: Error message
162
+ - `success`: Success message
163
+ - `helpText`: Helper text
164
+ - `className`: Additional CSS classes
165
+ - `id`: Input ID
166
+
167
+ **Events:**
168
+ - `input`: Fired on input - `{ detail: { value: string, event: InputEvent } }`
169
+ - `change`: Fired on change - `{ detail: { value: string, event: Event } }`
170
+
171
+ ### Card Component
172
+
173
+ ```svelte
174
+ <Card
175
+ variant="default" | "elevated" | "outlined"
176
+ density="comfortable" | "compact"
177
+ disabled={boolean}
178
+ loading={boolean}
179
+ className={string}
180
+ on:click={(e) => console.log(e.detail.value, e.detail.event)}
181
+ >
182
+ <div slot="header">Header Content</div>
183
+ Main Content
184
+ <div slot="footer">Footer Content</div>
185
+ </Card>
186
+ ```
187
+
188
+ **Props:**
189
+ - `variant`: Card style variant (default: "default")
190
+ - `density`: Card density (default: "comfortable")
191
+ - `disabled`: Disable interactions (default: false)
192
+ - `loading`: Show loading state (default: false)
193
+ - `className`: Additional CSS classes
194
+
195
+ **Slots:**
196
+ - `header`: Card header content
197
+ - `default`: Main card content
198
+ - `footer`: Card footer content
199
+
200
+ **Events:**
201
+ - `click`: Fired when card is clicked - `{ detail: { value: true, event: MouseEvent } }`
202
+
203
+ ### Alert Component
204
+
205
+ ```svelte
206
+ <Alert
207
+ variant="info" | "success" | "warning" | "error"
208
+ title={string}
209
+ message={string}
210
+ closable={boolean}
211
+ className={string}
212
+ on:close={(e) => console.log(e.detail.value, e.detail.event)}
213
+ >
214
+ Custom Alert Content
215
+ </Alert>
216
+ ```
55
217
 
56
- {#if showCard}
57
- <Card>
58
- <h2>Hello, {name}!</h2>
59
- </Card>
60
- {/if}
61
- ```
62
-
63
- ## Component Categories
64
-
65
- ### Atoms
66
- Basic building blocks of your UI:
67
- - `Badge` - Status indicators and labels
68
- - `Button` - Interactive buttons with variants
69
- - `Card` - Content containers
70
- - `Checkbox` - Form checkboxes
71
- - `ColorPicker` - Color selection input
72
- - `Heading` - Typography headings
73
- - `Input` - Text input fields
74
- - `OptimizedImage` - Performance-optimized images
75
- - `Select` - Dropdown selections
76
- - `Skeleton` - Loading placeholders
77
- - `Textarea` - Multi-line text input
78
- - `TextAlignment` - Text alignment controls
79
- - `Toggle` - Switch controls
80
-
81
- ### Molecules
82
- Simple combinations of atoms:
83
- - `Alert` - Notification messages
84
- - `Modal` - Overlay dialogs
85
- - `FileUpload` - File upload interface
86
- - `DynamicForm` - Dynamic form builder
87
- - `Dropdown` - Dropdown menus
88
- - `SlideUp` - Slide-up animations
89
-
90
- ### Organisms
91
- Complex components with state management:
92
- - `ToastContainer` - Notification management system
218
+ **Props:**
219
+ - `variant`: Alert type (default: "info")
220
+ - `title`: Alert title
221
+ - `message`: Alert message
222
+ - `closable`: Show close button (default: false)
223
+ - `className`: Additional CSS classes
224
+
225
+ **Slots:**
226
+ - `default`: Custom alert content (overrides message prop)
227
+
228
+ **Events:**
229
+ - `close`: Fired when alert is closed - `{ detail: { value: true, event: Event } }`
230
+
231
+ ## Theming
232
+
233
+ Zabi Components uses CSS custom properties for easy theming. You can customize the appearance by overriding these variables:
234
+
235
+ ```css
236
+ :root {
237
+ /* Primary Colors */
238
+ --zabi-primary: theme('colors.blue.600');
239
+ --zabi-primary-hover: theme('colors.blue.700');
240
+ --zabi-primary-active: theme('colors.blue.800');
241
+
242
+ /* Secondary Colors */
243
+ --zabi-secondary: theme('colors.gray.600');
244
+ --zabi-secondary-hover: theme('colors.gray.700');
245
+
246
+ /* Success Colors */
247
+ --zabi-success: theme('colors.green.600');
248
+ --zabi-success-hover: theme('colors.green.700');
249
+
250
+ /* Warning Colors */
251
+ --zabi-warning: theme('colors.yellow.600');
252
+ --zabi-warning-hover: theme('colors.yellow.700');
253
+
254
+ /* Error Colors */
255
+ --zabi-error: theme('colors.red.600');
256
+ --zabi-error-hover: theme('colors.red.700');
257
+
258
+ /* Info Colors */
259
+ --zabi-info: theme('colors.blue.600');
260
+ --zabi-info-hover: theme('colors.blue.700');
261
+
262
+ /* Surface Colors */
263
+ --zabi-surface: theme('colors.white');
264
+ --zabi-surface-hover: theme('colors.gray.50');
265
+
266
+ /* Border Colors */
267
+ --zabi-border: theme('colors.gray.300');
268
+ --zabi-border-hover: theme('colors.gray.400');
269
+ --zabi-border-focus: theme('colors.blue.500');
270
+
271
+ /* Text Colors */
272
+ --zabi-text: theme('colors.gray.900');
273
+ --zabi-text-muted: theme('colors.gray.600');
274
+ --zabi-text-placeholder: theme('colors.gray.400');
275
+ --zabi-text-inverse: theme('colors.white');
276
+ }
277
+ ```
278
+
279
+ ### Dark Mode
280
+
281
+ Dark mode is automatically supported through CSS custom properties:
282
+
283
+ ```css
284
+ .dark {
285
+ --zabi-surface: theme('colors.gray.900');
286
+ --zabi-surface-hover: theme('colors.gray.800');
287
+ --zabi-text: theme('colors.gray.100');
288
+ --zabi-text-muted: theme('colors.gray.400');
289
+ --zabi-border: theme('colors.gray.700');
290
+ }
291
+ ```
292
+
293
+ ## Event Structure
294
+
295
+ All components follow a consistent event structure:
296
+
297
+ ```typescript
298
+ interface BaseEventDetail<T = any> {
299
+ value: T;
300
+ event?: Event;
301
+ }
302
+ ```
303
+
304
+ **Examples:**
305
+ - Button click: `{ detail: { value: true, event: MouseEvent } }`
306
+ - Input change: `{ detail: { value: string, event: Event } }`
307
+ - Checkbox change: `{ detail: { value: boolean, event: Event } }`
93
308
 
94
309
  ## TypeScript Support
95
310
 
96
- The library includes comprehensive TypeScript definitions:
311
+ Full TypeScript definitions are included with proper event typing:
97
312
 
98
313
  ```typescript
99
- import type { FieldConfig } from 'zabi-components';
100
-
101
- const formConfig: FieldConfig[] = [
102
- {
103
- key: 'email',
104
- type: 'email',
105
- label: 'Email Address',
106
- required: true
107
- }
108
- ];
314
+ import type { ButtonEvents, InputEvents, CardEvents, AlertEvents } from 'zabi-components';
315
+
316
+ // Event handlers with proper typing
317
+ function handleButtonClick(event: CustomEvent<{ value: boolean; event?: MouseEvent }>) {
318
+ console.log('Button clicked:', event.detail.value);
319
+ }
320
+
321
+ function handleInputChange(event: CustomEvent<{ value: string; event?: InputEvent }>) {
322
+ console.log('Input changed:', event.detail.value);
323
+ }
109
324
  ```
110
325
 
111
- ## Styling
326
+ ### Event Types
112
327
 
113
- Components are styled with Tailwind CSS. Make sure to include Tailwind in your project:
328
+ All components use standardized event types:
114
329
 
115
- ```bash
116
- npm install -D tailwindcss
330
+ ```typescript
331
+ // Base event structure
332
+ interface BaseEventDetail<T = any> {
333
+ value: T;
334
+ event?: Event;
335
+ }
336
+
337
+ // Specific event types
338
+ interface ClickEventDetail extends BaseEventDetail<boolean> {
339
+ event?: MouseEvent | KeyboardEvent;
340
+ }
341
+
342
+ interface InputEventDetail extends BaseEventDetail<string> {
343
+ event?: InputEvent;
344
+ }
345
+
346
+ interface ChangeEventDetail extends BaseEventDetail<string> {
347
+ event?: Event;
348
+ }
117
349
  ```
118
350
 
119
- ## Development
351
+ ### Component Event Interfaces
120
352
 
121
- ```bash
122
- # Install dependencies
123
- npm install
353
+ ```typescript
354
+ interface ButtonEvents {
355
+ click: ClickEventDetail;
356
+ }
357
+
358
+ interface InputEvents {
359
+ input: InputEventDetail;
360
+ change: ChangeEventDetail;
361
+ focus: { event: FocusEvent };
362
+ blur: { event: FocusEvent };
363
+ keydown: { event: KeyboardEvent };
364
+ keyup: { event: KeyboardEvent };
365
+ clear: { event: Event };
366
+ }
367
+ ```
124
368
 
125
- # Start development server
126
- npm run dev
369
+ ## Advanced Usage
127
370
 
128
- # Build library
129
- npm run build:lib
371
+ ### Custom Styling
130
372
 
131
- # Run Storybook
132
- npm run storybook
373
+ ```svelte
374
+ <Button
375
+ variant="primary"
376
+ size="lg"
377
+ className="w-full shadow-lg hover:shadow-xl"
378
+ on:click={(e) => console.log('Clicked!', e.detail.value)}
379
+ >
380
+ Custom Button
381
+ </Button>
133
382
  ```
134
383
 
135
- ## Publishing
384
+ ### Form Integration
136
385
 
137
- To publish your component library:
386
+ ```svelte
387
+ <script lang="ts">
388
+ import { Button, Input, Card, Alert } from 'zabi-components';
389
+
390
+ interface FormData {
391
+ name: string;
392
+ email: string;
393
+ message: string;
394
+ }
395
+
396
+ interface FormErrors {
397
+ name?: string;
398
+ email?: string;
399
+ message?: string;
400
+ }
401
+
402
+ let formData: FormData = {
403
+ name: '',
404
+ email: '',
405
+ message: ''
406
+ };
407
+
408
+ let errors: FormErrors = {};
409
+ let showSuccess = false;
410
+
411
+ function validateForm(): boolean {
412
+ errors = {};
413
+ if (!formData.name) errors.name = 'Name is required';
414
+ if (!formData.email) errors.email = 'Email is required';
415
+ return Object.keys(errors).length === 0;
416
+ }
417
+
418
+ function handleSubmit(event: CustomEvent) {
419
+ if (validateForm()) {
420
+ showSuccess = true;
421
+ // Submit form
422
+ console.log('Form submitted:', formData);
423
+ }
424
+ }
425
+ </script>
138
426
 
139
- 1. **Update version** in `package.json`
140
- 2. **Build the library**: `npm run build:lib`
141
- 3. **Test locally**: `npm pack` to create a tarball
142
- 4. **Publish**: `npm publish`
427
+ <Card>
428
+ <div slot="header">
429
+ <h2>Contact Form</h2>
430
+ </div>
431
+
432
+ <form on:submit|preventDefault={handleSubmit}>
433
+ <Input
434
+ bind:value={formData.name}
435
+ label="Name"
436
+ placeholder="Enter your name"
437
+ required
438
+ error={errors.name}
439
+ />
440
+
441
+ <Input
442
+ bind:value={formData.email}
443
+ type="email"
444
+ label="Email"
445
+ placeholder="Enter your email"
446
+ required
447
+ error={errors.email}
448
+ />
449
+
450
+ <Input
451
+ bind:value={formData.message}
452
+ label="Message"
453
+ placeholder="Enter your message"
454
+ helpText="Tell us what you think"
455
+ />
456
+
457
+ <Button type="submit" variant="primary">
458
+ Send Message
459
+ </Button>
460
+ </form>
461
+
462
+ <div slot="footer">
463
+ <Alert variant="success" closable bind:show={showSuccess}>
464
+ Message sent successfully!
465
+ </Alert>
466
+ </div>
467
+ </Card>
468
+ ```
469
+
470
+ ## Contributing
471
+
472
+ 1. Fork the repository
473
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
474
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
475
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
476
+ 5. Open a Pull Request
143
477
 
144
478
  ## License
145
479
 
146
- MIT
480
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
481
+
482
+ ## Changelog
483
+
484
+ ### v1.0.5 (Latest)
485
+
486
+ #### 🐛 Bug Fixes
487
+ - **Fixed Package Exports**: Resolved "Package subpath './atoms' is not defined" errors
488
+ - **Fixed Runtime Errors**: Eliminated null reference errors that caused application crashes
489
+ - **Fixed TypeScript Types**: Properly typed event handlers and component props
490
+ - **Fixed Slot Definitions**: Ensured slots work correctly with proper typing
491
+ - **Fixed Main Export**: Ensured zabi-components main import works correctly
492
+
493
+ #### ✨ Improvements
494
+ - Enhanced TypeScript support with comprehensive event type definitions
495
+ - Improved build configuration for better tree shaking
496
+ - Added proper type generation for all component categories
497
+ - Standardized event structure across all components
498
+
499
+ #### 📦 Package Structure
500
+ - Added support for subpath imports (`zabi-components/atoms`, `zabi-components/molecules`, etc.)
501
+ - Improved type definitions with proper event interfaces
502
+ - Enhanced build output with proper ES module exports
503
+
504
+ ## Troubleshooting
505
+
506
+ ### Common Issues
507
+
508
+ #### Import Errors
509
+ If you encounter import errors like "Package subpath './atoms' is not defined", make sure you're using the latest version:
510
+
511
+ ```bash
512
+ npm install zabi-components@latest
513
+ ```
514
+
515
+ #### TypeScript Event Handler Errors
516
+ If you see TypeScript errors with event handlers, make sure to use proper typing:
517
+
518
+ ```typescript
519
+ // ✅ Correct
520
+ function handleClick(event: CustomEvent) {
521
+ console.log(event.detail.value);
522
+ }
523
+
524
+ // ❌ Incorrect - missing event parameter
525
+ function handleClick() {
526
+ console.log('clicked');
527
+ }
528
+ ```
529
+
530
+ #### Runtime Errors
531
+ If you encounter runtime errors, ensure you have the correct peer dependencies:
532
+
533
+ ```bash
534
+ npm install svelte@^5.0.0 @sveltejs/kit@^2.0.0
535
+ ```
536
+
537
+ ### Migration from Previous Versions
538
+
539
+ If you're upgrading from a previous version, note these changes:
540
+
541
+ 1. **Event Structure**: All events now follow the standardized `{ detail: { value, event? } }` structure
542
+ 2. **Import Paths**: Subpath imports are now fully supported (`zabi-components/atoms`, etc.)
543
+ 3. **TypeScript**: Enhanced type definitions with proper event typing
544
+
545
+ ## Support
546
+
547
+ For support, please open an issue on GitHub or contact the maintainers.
548
+
549
+ ---
550
+
551
+ Built with ❤️ using Svelte, TypeScript, and Tailwind CSS.