@smilodon/vue 1.0.8 → 1.1.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 +832 -23
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,18 +2,38 @@
2
2
 
3
3
  Production-ready, accessible select component for Vue 3 applications.
4
4
 
5
+ ## 📖 Documentation
6
+
7
+ **For comprehensive documentation covering all features, styling options, and advanced patterns:**
8
+
9
+ 👉 **[Complete Vue Guide](./COMPLETE-GUIDE.md)** 👈
10
+
11
+ The complete guide includes:
12
+ - ✅ All 60+ CSS variables for complete customization
13
+ - ✅ Vue 3-specific patterns (Composition API, v-model, computed)
14
+ - ✅ Complete API reference with TypeScript types
15
+ - ✅ Pinia store integration examples
16
+ - ✅ Custom renderers with h() function and VNodes
17
+ - ✅ Theme examples and styling techniques
18
+ - ✅ Advanced patterns (dependent selects, async onMounted)
19
+ - ✅ Troubleshooting and accessibility information
20
+
21
+ ---
22
+
5
23
  ## Features
6
24
 
7
- - âœĻ **Single & Multi-Select** - Flexible selection modes
8
- - 🔍 **Searchable** - Built-in search with client or server-side filtering
9
- - â™ŋ **Fully Accessible** - WCAG 2.1 AAA compliant with complete keyboard navigation
10
- - 🚀 **Virtual Scrolling** - Handle thousands of items efficiently
11
- - ∞ **Infinite Scroll** - Load more items on demand
12
- - ðŸ“Ķ **Grouped Options** - Organize items with group headers
13
- - ðŸŽĻ **Themeable** - Multiple built-in themes or custom styles
14
- - 💊 **TypeScript** - Full type safety and intellisense
15
- - ðŸŠķ **Lightweight** - Only 2.0KB gzipped
16
- - ðŸŽŊ **Vue 3 Composition API** - Modern Vue patterns with v-model support
25
+ - ✅ **Vue 3 Native** - Built for Vue 3 with Composition API and `<script setup>` support
26
+ - ✅ **v-model Support** - Two-way binding that feels natural in Vue
27
+ - ✅ **Fully Typed** - Complete TypeScript support with detailed type definitions
28
+ - ✅ **Single & Multi-select** - One prop to switch modes
29
+ - ✅ **Searchable** - Built-in filtering with customizable behavior
30
+ - ✅ **Infinite Scroll** - Handle massive datasets efficiently
31
+ - ✅ **Virtual Scrolling** - Render only visible items for performance
32
+ - ✅ **Grouped Options** - Organize items into categories
33
+ - ✅ **Accessible** - WCAG 2.1 AAA compliant, full keyboard navigation
34
+ - ✅ **Flexible Input** - Accepts SelectItem objects, string arrays, or number arrays
35
+ - ✅ **Customizable** - Custom renderers, styles, and behaviors
36
+ - ✅ **Tiny Bundle** - Optimized for production
17
37
 
18
38
  ## Installation
19
39
 
@@ -21,15 +41,29 @@ Production-ready, accessible select component for Vue 3 applications.
21
41
  npm install @smilodon/vue @smilodon/core
22
42
  ```
23
43
 
44
+ or
45
+
46
+ ```bash
47
+ yarn add @smilodon/vue @smilodon/core
48
+ ```
49
+
50
+ or
51
+
52
+ ```bash
53
+ pnpm add @smilodon/vue @smilodon/core
54
+ ```
55
+
24
56
  ## Quick Start
25
57
 
26
58
  ```vue
27
- <script setup>
59
+ <script setup lang="ts">
28
60
  import { ref } from 'vue';
29
61
  import { Select } from '@smilodon/vue';
62
+ import type { SelectItem } from '@smilodon/core';
30
63
 
31
- const selectedValue = ref('');
32
- const items = [
64
+ const selectedValue = ref<string | number>('');
65
+
66
+ const items: SelectItem[] = [
33
67
  { value: 'apple', label: 'Apple' },
34
68
  { value: 'banana', label: 'Banana' },
35
69
  { value: 'cherry', label: 'Cherry' },
@@ -51,12 +85,14 @@ const items = [
51
85
  ### Basic Single Select
52
86
 
53
87
  ```vue
54
- <script setup>
88
+ <script setup lang="ts">
55
89
  import { ref } from 'vue';
56
90
  import { Select } from '@smilodon/vue';
91
+ import type { SelectItem } from '@smilodon/core';
57
92
 
58
- const value = ref('');
59
- const items = [
93
+ const selectedValue = ref<string | number>('');
94
+
95
+ const items: SelectItem[] = [
60
96
  { value: '1', label: 'Option 1' },
61
97
  { value: '2', label: 'Option 2' },
62
98
  { value: '3', label: 'Option 3' },
@@ -64,17 +100,181 @@ const items = [
64
100
  </script>
65
101
 
66
102
  <template>
67
- <div>
68
- <Select
69
- :items="items"
70
- v-model="value"
71
- placeholder="Choose an option..."
72
- />
73
- <p>Selected: {{ value }}</p>
103
+ <Select
104
+ :items="items"
105
+ v-model="selectedValue"
106
+ placeholder="Choose an option"
107
+ />
108
+
109
+ <div v-if="selectedValue">
110
+ Selected: {{ selectedValue }}
111
+ </div>
112
+ </template>
113
+ ```
114
+
115
+ ### String Array Input (Auto-converted)
116
+
117
+ The Select component accepts string arrays and automatically converts them to the SelectItem format:
118
+
119
+ ```vue
120
+ <script setup lang="ts">
121
+ import { ref } from 'vue';
122
+ import { Select } from '@smilodon/vue';
123
+
124
+ const selectedFruits = ref<Array<string | number>>([]);
125
+
126
+ const fruits = ['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry', 'Fig', 'Grape', 'Honeydew'];
127
+ </script>
128
+
129
+ <template>
130
+ <Select
131
+ :items="fruits"
132
+ v-model="selectedFruits"
133
+ placeholder="Select fruits..."
134
+ searchable
135
+ multiple
136
+ />
137
+
138
+ <div v-if="selectedFruits.length">
139
+ Selected: {{ selectedFruits.join(', ') }}
140
+ </div>
141
+ </template>
142
+ ```
143
+
144
+ **Note:** String arrays are automatically converted to `SelectItem` objects where both `value` and `label` equal the string:
145
+ - `"Apple"` becomes `{ value: "Apple", label: "Apple" }`
146
+
147
+ ### Number Array Input (Auto-converted)
148
+
149
+ ```vue
150
+ <script setup lang="ts">
151
+ import { ref } from 'vue';
152
+ import { Select } from '@smilodon/vue';
153
+
154
+ const selectedNumber = ref<string | number>(0);
155
+
156
+ const fibonacciNumbers = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
157
+ </script>
158
+
159
+ <template>
160
+ <Select
161
+ :items="fibonacciNumbers"
162
+ v-model="selectedNumber"
163
+ placeholder="Select a Fibonacci number"
164
+ />
165
+
166
+ <div v-if="selectedNumber">
167
+ Selected: {{ selectedNumber }}
74
168
  </div>
75
169
  </template>
76
170
  ```
77
171
 
172
+ **Note:** Number arrays are automatically converted to `SelectItem` objects:
173
+ - `42` becomes `{ value: 42, label: "42" }`
174
+
175
+ ## Complete Examples
176
+
177
+ ## Complete Examples
178
+
179
+ ### Multi-Select with Groups
180
+
181
+ ```vue
182
+ <script setup lang="ts">
183
+ import { ref } from 'vue';
184
+ import { Select } from '@smilodon/vue';
185
+ import type { SelectItem } from '@smilodon/core';
186
+
187
+ const selectedValues = ref<Array<string | number>>([]);
188
+
189
+ const groupedItems: SelectItem[] = [
190
+ { value: 'apple', label: 'Apple', group: 'Fruits' },
191
+ { value: 'banana', label: 'Banana', group: 'Fruits' },
192
+ { value: 'carrot', label: 'Carrot', group: 'Vegetables' },
193
+ { value: 'broccoli', label: 'Broccoli', group: 'Vegetables' },
194
+ ];
195
+ </script>
196
+
197
+ <template>
198
+ <Select
199
+ :items="groupedItems"
200
+ v-model="selectedValues"
201
+ placeholder="Select items..."
202
+ searchable
203
+ multiple
204
+ />
205
+
206
+ <div v-if="selectedValues.length">
207
+ Selected ({{ selectedValues.length }}): {{ selectedValues.join(', ') }}
208
+ </div>
209
+ </template>
210
+ ```
211
+
212
+ ### Searchable Multi-Select (50 items)
213
+
214
+ ```vue
215
+ <script setup lang="ts">
216
+ import { ref } from 'vue';
217
+ import { Select } from '@smilodon/vue';
218
+ import type { SelectItem } from '@smilodon/core';
219
+
220
+ const selectedValues = ref<Array<string | number>>([]);
221
+
222
+ // Generate 50 items
223
+ const items: SelectItem[] = Array.from({ length: 50 }, (_, i) => ({
224
+ value: `item-${i + 1}`,
225
+ label: `Item ${i + 1}`,
226
+ }));
227
+ </script>
228
+
229
+ <template>
230
+ <Select
231
+ :items="items"
232
+ v-model="selectedValues"
233
+ placeholder="Search and select..."
234
+ searchable
235
+ multiple
236
+ />
237
+
238
+ <div v-if="selectedValues.length">
239
+ Selected: {{ selectedValues.length }} items
240
+ </div>
241
+ </template>
242
+ ```
243
+
244
+ ### Large Dataset with Virtual Scrolling (1000 items)
245
+
246
+ ```vue
247
+ <script setup lang="ts">
248
+ import { ref } from 'vue';
249
+ import { Select } from '@smilodon/vue';
250
+ import type { SelectItem } from '@smilodon/core';
251
+
252
+ const selectedValue = ref<string | number>('');
253
+
254
+ // Generate 1000 items
255
+ const largeDataset: SelectItem[] = Array.from({ length: 1000 }, (_, i) => ({
256
+ value: `item-${i + 1}`,
257
+ label: `Item ${i + 1} - Large Dataset`,
258
+ }));
259
+ </script>
260
+
261
+ <template>
262
+ <Select
263
+ :items="largeDataset"
264
+ v-model="selectedValue"
265
+ placeholder="Select from 1000 items..."
266
+ searchable
267
+ :virtualScroll="true"
268
+ />
269
+
270
+ <div v-if="selectedValue">
271
+ Selected: {{ selectedValue }}
272
+ </div>
273
+ </template>
274
+ ```
275
+
276
+
277
+
78
278
  ### Multi-Select
79
279
 
80
280
  ```vue
@@ -285,6 +485,615 @@ function clearSelection() {
285
485
  </template>
286
486
  ```
287
487
 
488
+ ---
489
+
490
+ ## ðŸŽŊ Two Ways to Specify Options
491
+
492
+ Smilodon Vue provides **two powerful approaches** for defining select options, each optimized for different use cases:
493
+
494
+ ### Method 1: Data-Driven (Object Arrays) 📊
495
+
496
+ **Use when**: You have structured data and want simple, declarative option rendering.
497
+
498
+ **Advantages**:
499
+ - ✅ Simple and declarative - Vue-friendly
500
+ - ✅ Auto-conversion from strings/numbers
501
+ - ✅ Perfect for basic dropdowns
502
+ - ✅ Works seamlessly with Vue reactivity
503
+ - ✅ Extremely performant (millions of items)
504
+ - ✅ Built-in search and filtering
505
+ - ✅ Full TypeScript type safety
506
+
507
+ **Examples**:
508
+
509
+ ```vue
510
+ <script setup lang="ts">
511
+ import { ref } from 'vue';
512
+ import { Select } from '@smilodon/vue';
513
+
514
+ // Example 1: Simple object array
515
+ const value = ref('');
516
+
517
+ const items = [
518
+ { value: '1', label: 'Apple' },
519
+ { value: '2', label: 'Banana' },
520
+ { value: '3', label: 'Cherry' }
521
+ ];
522
+ </script>
523
+
524
+ <template>
525
+ <Select
526
+ :items="items"
527
+ v-model="value"
528
+ placeholder="Select a fruit..."
529
+ />
530
+ </template>
531
+ ```
532
+
533
+ ```vue
534
+ <script setup lang="ts">
535
+ import { ref } from 'vue';
536
+ import { Select } from '@smilodon/vue';
537
+
538
+ // Example 2: With metadata and disabled options
539
+ const country = ref('');
540
+
541
+ const countries = [
542
+ { value: 'us', label: 'United States', disabled: false },
543
+ { value: 'ca', label: 'Canada', disabled: false },
544
+ { value: 'mx', label: 'Mexico', disabled: true }
545
+ ];
546
+ </script>
547
+
548
+ <template>
549
+ <Select
550
+ :items="countries"
551
+ v-model="country"
552
+ placeholder="Select a country..."
553
+ />
554
+ </template>
555
+ ```
556
+
557
+ ```vue
558
+ <script setup lang="ts">
559
+ import { ref } from 'vue';
560
+ import { Select } from '@smilodon/vue';
561
+
562
+ // Example 3: With grouping
563
+ const food = ref('');
564
+
565
+ const foods = [
566
+ { value: 'apple', label: 'Apple', group: 'Fruits' },
567
+ { value: 'banana', label: 'Banana', group: 'Fruits' },
568
+ { value: 'carrot', label: 'Carrot', group: 'Vegetables' },
569
+ { value: 'broccoli', label: 'Broccoli', group: 'Vegetables' }
570
+ ];
571
+ </script>
572
+
573
+ <template>
574
+ <Select
575
+ :items="foods"
576
+ v-model="food"
577
+ placeholder="Select food..."
578
+ />
579
+ </template>
580
+ ```
581
+
582
+ ```vue
583
+ <script setup lang="ts">
584
+ import { ref } from 'vue';
585
+ import { Select } from '@smilodon/vue';
586
+
587
+ // Example 4: Auto-conversion from strings
588
+ const color = ref('');
589
+ const colors = ['Red', 'Green', 'Blue', 'Yellow'];
590
+ </script>
591
+
592
+ <template>
593
+ <Select
594
+ :items="colors"
595
+ v-model="color"
596
+ placeholder="Select a color..."
597
+ />
598
+ </template>
599
+ ```
600
+
601
+ ```vue
602
+ <script setup lang="ts">
603
+ import { ref } from 'vue';
604
+ import { Select } from '@smilodon/vue';
605
+
606
+ // Example 5: Auto-conversion from numbers
607
+ const size = ref<number | string>('');
608
+ const sizes = [10, 20, 30, 40, 50];
609
+ </script>
610
+
611
+ <template>
612
+ <Select
613
+ :items="sizes"
614
+ v-model="size"
615
+ placeholder="Select size..."
616
+ />
617
+ </template>
618
+ ```
619
+
620
+ ```vue
621
+ <script setup lang="ts">
622
+ import { ref, computed } from 'vue';
623
+ import { Select } from '@smilodon/vue';
624
+
625
+ // Example 6: Large datasets with computed
626
+ const id = ref('');
627
+
628
+ const items = computed(() =>
629
+ Array.from({ length: 100_000 }, (_, i) => ({
630
+ value: i.toString(),
631
+ label: `Item ${i + 1}`
632
+ }))
633
+ );
634
+ </script>
635
+
636
+ <template>
637
+ <Select
638
+ :items="items"
639
+ v-model="id"
640
+ virtualized
641
+ placeholder="Select from 100K items..."
642
+ />
643
+ </template>
644
+ ```
645
+
646
+ ### Method 2: Component-Driven (Custom Renderers) ðŸŽĻ
647
+
648
+ **Use when**: You need rich, interactive option content with custom rendering.
649
+
650
+ **Advantages**:
651
+ - ✅ Full control over option rendering
652
+ - ✅ Use Vue's render function (h())
653
+ - ✅ Rich content (images, icons, badges, multi-line text)
654
+ - ✅ Custom styling with scoped CSS
655
+ - ✅ Reactive data binding
656
+ - ✅ Conditional rendering based on item data
657
+ - ✅ Access to Vue's composition API
658
+ - ✅ Perfect for complex UIs (user cards, product listings, etc.)
659
+
660
+ **How it works**: Provide a `customRenderer` function that uses Vue's `h()` function to return a VNode.
661
+
662
+ **Examples**:
663
+
664
+ ```vue
665
+ <script setup lang="ts">
666
+ import { ref, h } from 'vue';
667
+ import { Select, SelectItem } from '@smilodon/vue';
668
+
669
+ // Example 1: Simple custom template with icons
670
+ interface Language extends SelectItem {
671
+ icon: string;
672
+ description: string;
673
+ }
674
+
675
+ const lang = ref('');
676
+
677
+ const languages: Language[] = [
678
+ { value: 'js', label: 'JavaScript', icon: 'ðŸŸĻ', description: 'Dynamic scripting language' },
679
+ { value: 'py', label: 'Python', icon: '🐍', description: 'General-purpose programming' },
680
+ { value: 'rs', label: 'Rust', icon: 'ðŸĶ€', description: 'Systems programming language' }
681
+ ];
682
+
683
+ const languageRenderer = (item: Language, index: number) => {
684
+ return h('div', { style: 'display: flex; align-items: center; gap: 12px;' }, [
685
+ h('span', { style: 'font-size: 24px;' }, item.icon),
686
+ h('div', [
687
+ h('div', { style: 'font-weight: 600;' }, item.label),
688
+ h('div', { style: 'font-size: 12px; color: #6b7280;' }, item.description)
689
+ ])
690
+ ]);
691
+ };
692
+ </script>
693
+
694
+ <template>
695
+ <Select
696
+ :items="languages"
697
+ v-model="lang"
698
+ :custom-renderer="languageRenderer"
699
+ placeholder="Select a language..."
700
+ />
701
+ </template>
702
+ ```
703
+
704
+ ```vue
705
+ <script setup lang="ts">
706
+ import { ref, h } from 'vue';
707
+ import { Select, SelectItem } from '@smilodon/vue';
708
+
709
+ // Example 2: User selection with avatars
710
+ interface User extends SelectItem {
711
+ email: string;
712
+ avatar: string;
713
+ role: 'Admin' | 'User' | 'Moderator';
714
+ }
715
+
716
+ const userId = ref('');
717
+
718
+ const users: User[] = [
719
+ {
720
+ value: '1',
721
+ label: 'John Doe',
722
+ email: 'john@example.com',
723
+ avatar: 'https://i.pravatar.cc/150?img=1',
724
+ role: 'Admin'
725
+ },
726
+ {
727
+ value: '2',
728
+ label: 'Jane Smith',
729
+ email: 'jane@example.com',
730
+ avatar: 'https://i.pravatar.cc/150?img=2',
731
+ role: 'User'
732
+ },
733
+ {
734
+ value: '3',
735
+ label: 'Bob Johnson',
736
+ email: 'bob@example.com',
737
+ avatar: 'https://i.pravatar.cc/150?img=3',
738
+ role: 'Moderator'
739
+ }
740
+ ];
741
+
742
+ const userRenderer = (item: User) => {
743
+ return h('div', { style: 'display: flex; align-items: center; gap: 12px; padding: 4px 0;' }, [
744
+ h('img', {
745
+ src: item.avatar,
746
+ alt: item.label,
747
+ style: 'width: 40px; height: 40px; border-radius: 50%; object-fit: cover;'
748
+ }),
749
+ h('div', { style: 'flex: 1;' }, [
750
+ h('div', { style: 'font-weight: 600; color: #1f2937;' }, item.label),
751
+ h('div', { style: 'font-size: 13px; color: #6b7280;' }, item.email)
752
+ ]),
753
+ h('span', {
754
+ style: `
755
+ padding: 4px 8px;
756
+ background: ${item.role === 'Admin' ? '#dbeafe' : '#f3f4f6'};
757
+ color: ${item.role === 'Admin' ? '#1e40af' : '#374151'};
758
+ border-radius: 12px;
759
+ font-size: 11px;
760
+ font-weight: 600;
761
+ `
762
+ }, item.role)
763
+ ]);
764
+ };
765
+ </script>
766
+
767
+ <template>
768
+ <Select
769
+ :items="users"
770
+ v-model="userId"
771
+ :custom-renderer="userRenderer"
772
+ placeholder="Select a user..."
773
+ />
774
+ </template>
775
+ ```
776
+
777
+ ```vue
778
+ <script setup lang="ts">
779
+ import { ref, h } from 'vue';
780
+ import { Select, SelectItem } from '@smilodon/vue';
781
+
782
+ // Example 3: Product selection with images and pricing
783
+ interface Product extends SelectItem {
784
+ price: number;
785
+ stock: number;
786
+ image: string;
787
+ badge?: string;
788
+ }
789
+
790
+ const productId = ref('');
791
+
792
+ const products: Product[] = [
793
+ {
794
+ value: 'p1',
795
+ label: 'Premium Laptop',
796
+ price: 1299.99,
797
+ stock: 15,
798
+ image: 'https://via.placeholder.com/60',
799
+ badge: 'Best Seller'
800
+ },
801
+ {
802
+ value: 'p2',
803
+ label: 'Wireless Mouse',
804
+ price: 29.99,
805
+ stock: 150,
806
+ image: 'https://via.placeholder.com/60'
807
+ },
808
+ {
809
+ value: 'p3',
810
+ label: 'Mechanical Keyboard',
811
+ price: 89.99,
812
+ stock: 0,
813
+ image: 'https://via.placeholder.com/60',
814
+ badge: 'Out of Stock'
815
+ }
816
+ ];
817
+
818
+ const productRenderer = (item: Product) => {
819
+ return h('div', {
820
+ style: `display: flex; align-items: center; gap: 12px; opacity: ${item.stock === 0 ? '0.5' : '1'};`
821
+ }, [
822
+ h('img', {
823
+ src: item.image,
824
+ alt: item.label,
825
+ style: 'width: 60px; height: 60px; border-radius: 8px; object-fit: cover; border: 1px solid #e5e7eb;'
826
+ }),
827
+ h('div', { style: 'flex: 1;' }, [
828
+ h('div', { style: 'display: flex; align-items: center; gap: 8px;' }, [
829
+ h('span', { style: 'font-weight: 600; color: #1f2937;' }, item.label),
830
+ item.badge && h('span', {
831
+ style: `
832
+ padding: 2px 6px;
833
+ background: ${item.badge === 'Best Seller' ? '#dcfce7' : '#fee2e2'};
834
+ color: ${item.badge === 'Best Seller' ? '#166534' : '#991b1b'};
835
+ border-radius: 4px;
836
+ font-size: 10px;
837
+ font-weight: 600;
838
+ `
839
+ }, item.badge)
840
+ ]),
841
+ h('div', {
842
+ style: 'margin-top: 4px; display: flex; justify-content: space-between; align-items: center;'
843
+ }, [
844
+ h('span', { style: 'font-size: 16px; font-weight: 700; color: #059669;' }, `$${item.price.toFixed(2)}`),
845
+ h('span', { style: 'font-size: 12px; color: #6b7280;' },
846
+ item.stock > 0 ? `${item.stock} in stock` : 'Out of stock'
847
+ )
848
+ ])
849
+ ])
850
+ ]);
851
+ };
852
+ </script>
853
+
854
+ <template>
855
+ <Select
856
+ :items="products"
857
+ v-model="productId"
858
+ :custom-renderer="productRenderer"
859
+ placeholder="Select a product..."
860
+ />
861
+ </template>
862
+ ```
863
+
864
+ ```vue
865
+ <script setup lang="ts">
866
+ import { ref, h } from 'vue';
867
+ import { Select, SelectItem } from '@smilodon/vue';
868
+
869
+ // Example 4: Status indicators with conditional styling
870
+ interface Task extends SelectItem {
871
+ status: 'completed' | 'in-progress' | 'pending';
872
+ priority: 'high' | 'medium' | 'low';
873
+ assignee: string;
874
+ }
875
+
876
+ const taskId = ref('');
877
+
878
+ const tasks: Task[] = [
879
+ { value: 't1', label: 'Design Homepage', status: 'completed', priority: 'high', assignee: 'John' },
880
+ { value: 't2', label: 'API Integration', status: 'in-progress', priority: 'high', assignee: 'Jane' },
881
+ { value: 't3', label: 'Write Documentation', status: 'pending', priority: 'medium', assignee: 'Bob' },
882
+ { value: 't4', label: 'Bug Fixes', status: 'in-progress', priority: 'low', assignee: 'Alice' }
883
+ ];
884
+
885
+ const statusConfig = {
886
+ 'completed': { bg: '#dcfce7', color: '#166534', icon: '✓' },
887
+ 'in-progress': { bg: '#dbeafe', color: '#1e40af', icon: 'âŸģ' },
888
+ 'pending': { bg: '#fef3c7', color: '#92400e', icon: '○' }
889
+ };
890
+
891
+ const priorityColors = {
892
+ 'high': '#ef4444',
893
+ 'medium': '#f59e0b',
894
+ 'low': '#10b981'
895
+ };
896
+
897
+ const taskRenderer = (item: Task) => {
898
+ const status = statusConfig[item.status];
899
+ return h('div', { style: 'display: flex; align-items: center; gap: 10px; padding: 4px 0;' }, [
900
+ h('div', {
901
+ style: `
902
+ width: 24px;
903
+ height: 24px;
904
+ border-radius: 50%;
905
+ background: ${status.bg};
906
+ color: ${status.color};
907
+ display: flex;
908
+ align-items: center;
909
+ justify-content: center;
910
+ font-weight: bold;
911
+ `
912
+ }, status.icon),
913
+ h('div', { style: 'flex: 1;' }, [
914
+ h('div', { style: 'font-weight: 600; color: #1f2937;' }, item.label),
915
+ h('div', { style: 'font-size: 12px; color: #6b7280; margin-top: 2px;' }, `Assigned to ${item.assignee}`)
916
+ ]),
917
+ h('div', {
918
+ style: `
919
+ width: 8px;
920
+ height: 8px;
921
+ border-radius: 50%;
922
+ background: ${priorityColors[item.priority]};
923
+ `,
924
+ title: `${item.priority} priority`
925
+ })
926
+ ]);
927
+ };
928
+ </script>
929
+
930
+ <template>
931
+ <Select
932
+ :items="tasks"
933
+ v-model="taskId"
934
+ :custom-renderer="taskRenderer"
935
+ placeholder="Select a task..."
936
+ />
937
+ </template>
938
+ ```
939
+
940
+ ```vue
941
+ <script setup lang="ts">
942
+ import { ref, h } from 'vue';
943
+ import { Select, SelectItem } from '@smilodon/vue';
944
+
945
+ // Example 5: Using HTML string (simpler alternative)
946
+ interface Tag extends SelectItem {
947
+ color: string;
948
+ count: number;
949
+ }
950
+
951
+ const tag = ref('');
952
+
953
+ const tags: Tag[] = [
954
+ { value: 'react', label: 'React', color: 'blue', count: 1250 },
955
+ { value: 'vue', label: 'Vue', color: 'green', count: 850 },
956
+ { value: 'angular', label: 'Angular', color: 'red', count: 420 }
957
+ ];
958
+
959
+ // Using HTML string renderer (returned from custom prop)
960
+ const tagRenderer = (item: Tag) => {
961
+ return `
962
+ <div style="display: flex; align-items: center; justify-content: space-between; padding: 8px;">
963
+ <div style="display: flex; align-items: center; gap: 8px;">
964
+ <span style="width: 12px; height: 12px; border-radius: 50%; background: ${item.color};"></span>
965
+ <span style="font-weight: 600; color: #1f2937;">${item.label}</span>
966
+ </div>
967
+ <span style="font-size: 14px; color: #6b7280;">${item.count} posts</span>
968
+ </div>
969
+ `;
970
+ };
971
+ </script>
972
+
973
+ <template>
974
+ <Select
975
+ :items="tags"
976
+ v-model="tag"
977
+ :option-template="tagRenderer"
978
+ placeholder="Select a tag..."
979
+ />
980
+ </template>
981
+ ```
982
+
983
+ ### Comparison: When to Use Each Method
984
+
985
+ | Feature | Method 1: Object Arrays | Method 2: Custom Renderers |
986
+ |---------|------------------------|---------------------------|
987
+ | **Setup Complexity** | ⭐ Simple | ⭐⭐ Moderate |
988
+ | **Rendering Speed** | ⭐⭐⭐ Fastest | ⭐⭐ Fast |
989
+ | **Visual Customization** | ⭐⭐ Limited | ⭐⭐⭐ Unlimited |
990
+ | **Vue Integration** | ⭐⭐⭐ Seamless | ⭐⭐⭐ Seamless |
991
+ | **Reactivity** | ⭐⭐⭐ Full | ⭐⭐⭐ Full |
992
+ | **TypeScript Support** | ⭐⭐⭐ Full | ⭐⭐⭐ Full |
993
+ | **Performance (1M items)** | ⭐⭐⭐ Excellent | ⭐⭐ Good |
994
+ | **Learning Curve** | ⭐ Easy | ⭐⭐ Medium |
995
+
996
+ **Best Practices**:
997
+
998
+ ✅ **Use Method 1 (Object Arrays) when**:
999
+ - You need simple text-based options
1000
+ - Performance is critical (millions of items)
1001
+ - You want minimal code
1002
+ - Built-in search/filter is sufficient
1003
+ - Working with external APIs returning plain data
1004
+
1005
+ ✅ **Use Method 2 (Custom Renderers) when**:
1006
+ - You need images, icons, or badges
1007
+ - Options require multiple lines of text
1008
+ - Custom styling/layout is important
1009
+ - Conditional rendering based on data
1010
+ - Rich user experience is priority
1011
+ - Need reactive computed properties in rendering
1012
+
1013
+ ### Combining Both Methods
1014
+
1015
+ You can start with Method 1 and add Method 2 later as your UI evolves:
1016
+
1017
+ ```vue
1018
+ <script setup lang="ts">
1019
+ import { ref, h } from 'vue';
1020
+ import { Select } from '@smilodon/vue';
1021
+
1022
+ const value = ref('');
1023
+
1024
+ // Start simple
1025
+ const items = ['Option 1', 'Option 2', 'Option 3'];
1026
+
1027
+ // Later, add custom rendering without changing items
1028
+ const customRenderer = (item: any, index: number) => {
1029
+ return h('div', {
1030
+ style: `padding: 8px; background: ${index % 2 ? '#f9fafb' : 'white'};`
1031
+ }, [
1032
+ h('strong', item.label || item)
1033
+ ]);
1034
+ };
1035
+ </script>
1036
+
1037
+ <template>
1038
+ <Select
1039
+ :items="items"
1040
+ v-model="value"
1041
+ :custom-renderer="customRenderer"
1042
+ />
1043
+ </template>
1044
+ ```
1045
+
1046
+ ### Performance Tips
1047
+
1048
+ **For Method 1**:
1049
+ - Use `computed` to memoize large item arrays
1050
+ - Enable `virtualized` prop for 1000+ items
1051
+ - Enable `infiniteScroll` for dynamic loading
1052
+
1053
+ **For Method 2**:
1054
+ - Keep renderer function pure (no side effects)
1055
+ - Use `computed` for derived data
1056
+ - Avoid heavy computations in renderer
1057
+ - Cache renderer functions when possible
1058
+
1059
+ ```vue
1060
+ <script setup lang="ts">
1061
+ import { ref, computed, h } from 'vue';
1062
+ import { Select } from '@smilodon/vue';
1063
+
1064
+ const value = ref('');
1065
+
1066
+ // Memoize items with computed
1067
+ const items = computed(() =>
1068
+ Array.from({ length: 10000 }, (_, i) => ({
1069
+ value: i.toString(),
1070
+ label: `Item ${i + 1}`,
1071
+ description: `Description for item ${i + 1}`
1072
+ }))
1073
+ );
1074
+
1075
+ // Pure renderer function
1076
+ const renderer = (item: any, index: number) => {
1077
+ return h('div', [
1078
+ h('div', { style: 'font-weight: 600;' }, item.label),
1079
+ h('div', { style: 'font-size: 12px; color: #666;' }, item.description)
1080
+ ]);
1081
+ };
1082
+ </script>
1083
+
1084
+ <template>
1085
+ <Select
1086
+ :items="items"
1087
+ v-model="value"
1088
+ :custom-renderer="renderer"
1089
+ virtualized
1090
+ :estimated-item-height="60"
1091
+ />
1092
+ </template>
1093
+ ```
1094
+
1095
+ ---
1096
+
288
1097
  ## API Reference
289
1098
 
290
1099
  ### Props
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smilodon/vue",
3
- "version": "1.0.8",
3
+ "version": "1.1.1",
4
4
  "description": "Vue 3 adapter for @smilodon/core - Production-ready accessible select component",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",