-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
877 lines (855 loc) · 36.8 KB
/
Copy pathindex.html
File metadata and controls
877 lines (855 loc) · 36.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>smart-search-web-component — Demo</title>
<link rel="stylesheet" href="./demo/styles.css" />
<script type="module" src="./demo/main.ts"></script>
</head>
<body>
<div class="layout">
<!-- Header -->
<header class="header">
<a class="header-logo" href="#">
<svg
width="22"
height="22"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="8" />
<path d="m21 21-4.35-4.35" />
<path d="M11 8v6M8 11h6" />
</svg>
<span class="header-title">smart-search</span>
</a>
<span class="header-badge">Web Component</span>
<div class="header-spacer"></div>
<a
class="header-link"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/getting-started.md"
target="_blank"
rel="noopener"
>Docs</a
>
<a
class="header-link"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/api-reference.md"
target="_blank"
rel="noopener"
>API</a
>
<a
class="header-link"
href="https://github.com/kulapoo/smart-search-web-component"
target="_blank"
rel="noopener"
aria-label="GitHub repository"
><svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<path
d="M12 2C6.477 2 2 6.477 2 12c0 4.418 2.865 8.166 6.839 9.489.5.092.682-.217.682-.482 0-.237-.009-.868-.013-1.703-2.782.604-3.369-1.341-3.369-1.341-.454-1.154-1.11-1.462-1.11-1.462-.908-.62.069-.608.069-.608 1.003.07 1.531 1.03 1.531 1.03.892 1.529 2.341 1.087 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.11-4.555-4.943 0-1.091.39-1.984 1.029-2.683-.103-.253-.446-1.27.098-2.647 0 0 .84-.269 2.75 1.025A9.578 9.578 0 0 1 12 6.836c.85.004 1.705.114 2.504.336 1.909-1.294 2.747-1.025 2.747-1.025.546 1.377.202 2.394.1 2.647.64.699 1.028 1.592 1.028 2.683 0 3.842-2.339 4.687-4.566 4.935.359.309.678.919.678 1.852 0 1.336-.012 2.415-.012 2.743 0 .267.18.578.688.48C19.138 20.163 22 16.418 22 12c0-5.523-4.477-10-10-10z"
/></svg
></a>
</header>
<!-- Mobile nav strip (visible < 900px) -->
<nav class="mobile-nav" aria-label="Jump to section">
<a class="mobile-nav-link active" href="#basic">Basic</a>
<a class="mobile-nav-link" href="#filters">Filters</a>
<a class="mobile-nav-link" href="#dark">Dark Mode</a>
<a class="mobile-nav-link" href="#brands">Brands</a>
<a class="mobile-nav-link" href="#custom-renderer">Custom Renderer</a>
<a class="mobile-nav-link" href="#multiselect">Multi-select</a>
<a class="mobile-nav-link" href="#static">Static Options</a>
<a class="mobile-nav-link" href="#events">Events</a>
</nav>
<!-- Sidebar -->
<nav class="sidebar">
<div class="sidebar-section">
<div class="sidebar-label">Examples</div>
<a class="sidebar-link active" href="#basic"><span class="sidebar-dot"></span> Basic</a>
<a class="sidebar-link" href="#filters"><span class="sidebar-dot"></span> With Filters</a>
<a class="sidebar-link" href="#dark"><span class="sidebar-dot"></span> Dark Theme</a>
<a class="sidebar-link" href="#brands"><span class="sidebar-dot"></span> Brand Themes</a>
<a class="sidebar-link" href="#custom-renderer"><span class="sidebar-dot"></span> Custom Renderer</a>
<a class="sidebar-link" href="#multiselect"><span class="sidebar-dot"></span> Multi-select</a>
<a class="sidebar-link" href="#static"><span class="sidebar-dot"></span> Static Options</a>
<a class="sidebar-link" href="#events"><span class="sidebar-dot"></span> Events Log</a>
</div>
<div class="sidebar-section" style="margin-top: 20px">
<div class="sidebar-label">Docs</div>
<a
class="sidebar-link"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/getting-started.md"
target="_blank"
rel="noopener"
>Getting Started</a
>
<a
class="sidebar-link"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/api-reference.md"
target="_blank"
rel="noopener"
>API Reference</a
>
<a
class="sidebar-link"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/theming.md"
target="_blank"
rel="noopener"
>Theming</a
>
<a
class="sidebar-link"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/advanced-usage.md"
target="_blank"
rel="noopener"
>Advanced Usage</a
>
</div>
</nav>
<main class="main">
<section class="hero">
<div class="hero-eyebrow">
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.5"
stroke-linecap="round"
stroke-linejoin="round"
>
<polygon
points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"
/>
</svg>
~11 kB gzipped · Framework-agnostic · Web Components
</div>
<h1>Smart Search<br /><span>for the open web</span></h1>
<p class="hero-sub">
A lightweight, production-ready search input built with Custom Elements and Shadow DOM. Drop it into React,
Vue, Svelte, Angular, or plain HTML — no framework required.
</p>
<div class="hero-actions">
<a
class="btn btn-primary"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/getting-started.md"
target="_blank"
rel="noopener"
>
<svg
width="14"
height="14"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.5"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M5 12h14M12 5l7 7-7 7" />
</svg>
Get Started
</a>
<a
class="btn btn-outline"
href="https://github.com/kulapoo/smart-search-web-component/blob/main/docs/api-reference.md"
target="_blank"
rel="noopener"
>API Reference</a
>
</div>
<div class="feature-grid">
<div class="feature-pill">
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z" />
<line x1="4" y1="22" x2="4" y2="15" />
</svg>
Filter chips
</div>
<div class="feature-pill">
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<rect x="2" y="3" width="20" height="14" rx="2" />
<path d="M8 21h8M12 17v4" />
</svg>
Keyboard nav
</div>
<div class="feature-pill">
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
</svg>
Dark mode
</div>
<div class="feature-pill">
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 20h9" />
<path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" />
</svg>
Custom renderers
</div>
<div class="feature-pill">
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<polyline points="9 11 12 14 22 4" />
<path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11" />
</svg>
Multi-select
</div>
<div class="feature-pill">
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z" />
<polyline points="13 2 13 9 20 9" />
</svg>
Form integration
</div>
<div class="feature-pill">
<svg
width="15"
height="15"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M20.24 12.24a6 6 0 0 0-8.49-8.49L5 10.5V19h8.5z" />
<line x1="16" y1="8" x2="2" y2="22" />
<line x1="17.5" y1="15" x2="9" y2="15" />
</svg>
~11 kB gzipped
</div>
</div>
</section>
<!-- 1. Basic -->
<section class="section" id="basic">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="11" cy="11" r="8" />
<path d="m21 21-4.35-4.35" />
</svg>
</div>
<h2 class="section-title">Basic</h2>
</div>
<p class="section-desc">
Set a <code>datasource</code> URL with a <code>{{q}}</code> placeholder and provide a
<code>transformResponse</code> function to map the API response. Type to search DummyJSON products.
</p>
<div class="demo-card">
<div class="demo-split">
<div class="demo-pane">
<span class="demo-pane-label">Live</span>
<div class="demo-component">
<smart-search
id="demo-basic"
highlight-matches="false"
placeholder="Search products..."
datasource="https://dummyjson.com/products/search?{{q}}"
debounce="300"
></smart-search>
</div>
</div>
<div class="code-pane">
<div class="code-header">
<div class="code-dots">
<span class="code-dot"></span><span class="code-dot"></span><span class="code-dot"></span>
</div>
<span class="code-filename">index.html</span>
</div>
<pre><span class="t-tag"><smart-search</span>
<span class="t-attr">placeholder</span>=<span class="t-val">"Search products..."</span>
<span class="t-attr">datasource</span>=<span class="t-val">"https://api.example.com/search?{{q}}"</span>
<span class="t-attr">debounce</span>=<span class="t-val">"300"</span>
<span class="t-tag">></smart-search></span>
<span class="t-tag"><script </span><span class="t-attr">type</span>=<span class="t-val">"module"</span><span class="t-tag">></span>
<span class="t-kw">const</span> el = document.<span class="t-fn">querySelector</span>(<span class="t-str">'smart-search'</span>)
el.<span class="t-attr">transformResponse</span> = (json) =>
json.products.<span class="t-fn">map</span>((p) => ({
value: <span class="t-fn">String</span>(p.id),
label: p.title,
description: p.category,
group: p.category,
}))
el.<span class="t-fn">addEventListener</span>(<span class="t-str">'ss-menu-select'</span>, (e) => {
console.<span class="t-fn">log</span>(<span class="t-str">'selected:'</span>, e.detail.result)
})
<span class="t-tag"></script></span></pre>
</div>
</div>
</div>
</section>
<!-- 2. Filters -->
<section class="section" id="filters">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3" />
</svg>
</div>
<h2 class="section-title">With Filters</h2>
</div>
<p class="section-desc">
Pass a <code>filters</code> JSON array to show toggleable filter chips above the results. Active filters
append <code>field=value</code> to the query string sent to your API.
</p>
<div class="demo-card">
<div class="demo-split">
<div class="demo-pane">
<span class="demo-pane-label">Live</span>
<div class="demo-component">
<smart-search
id="demo-filters"
placeholder="Search products..."
datasource="https://dummyjson.com/products/search?{{q}}"
debounce="300"
></smart-search>
</div>
</div>
<div class="code-pane">
<div class="code-header">
<div class="code-dots">
<span class="code-dot"></span><span class="code-dot"></span><span class="code-dot"></span>
</div>
<span class="code-filename">index.html</span>
</div>
<pre><span class="t-tag"><smart-search</span>
<span class="t-attr">datasource</span>=<span class="t-val">"https://api.example.com/search?{{q}}"</span>
<span class="t-attr">filters</span>=<span class="t-val">'[
{"field":"category","value":"smartphones",
"label":"Smartphones"},
{"field":"category","value":"laptops",
"label":"Laptops"}
]'</span>
<span class="t-tag">></smart-search></span>
<span class="t-cm">// Active filters compose the query:</span>
<span class="t-cm">// ?q=phone&category=smartphones</span>
el.<span class="t-fn">addEventListener</span>(<span class="t-str">'ss-filter-change'</span>, (e) => {
console.<span class="t-fn">log</span>(e.detail.filters)
<span class="t-cm">// [{ field: 'category', value: 'smartphones' }]</span>
})</pre>
</div>
</div>
</div>
</section>
<!-- 3. Dark Theme -->
<section class="section" id="dark">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" />
</svg>
</div>
<h2 class="section-title">Dark Theme</h2>
</div>
<p class="section-desc">
Add <code>theme="dark"</code> for the built-in dark palette. <code>theme="auto"</code> (default) follows
<code>prefers-color-scheme</code>. All colors are overridable via CSS custom properties.
</p>
<div class="demo-card">
<div class="demo-split">
<div class="demo-pane demo-pane-dark">
<span class="demo-pane-label demo-pane-label-dark">Live</span>
<div class="demo-component">
<smart-search
id="demo-dark"
placeholder="Search products..."
datasource="https://dummyjson.com/products/search?{{q}}"
debounce="300"
theme="dark"
></smart-search>
</div>
</div>
<div class="code-pane">
<div class="code-header">
<div class="code-dots">
<span class="code-dot"></span><span class="code-dot"></span><span class="code-dot"></span>
</div>
<span class="code-filename">index.html</span>
</div>
<pre><span class="t-cm"><!-- Built-in dark palette --></span>
<span class="t-tag"><smart-search</span>
<span class="t-attr">theme</span>=<span class="t-val">"dark"</span>
<span class="t-attr">datasource</span>=<span class="t-val">"..."</span>
<span class="t-tag">></smart-search></span>
<span class="t-cm"><!-- Follow system preference --></span>
<span class="t-tag"><smart-search</span> <span class="t-attr">theme</span>=<span class="t-val">"auto"</span><span class="t-tag">></smart-search></span>
<span class="t-cm">/* Override via CSS custom properties */</span>
<span class="t-fn">smart-search</span> {
<span class="t-attr">--ss-accent</span>: <span class="t-val">#7c3aed</span>;
<span class="t-attr">--ss-radius</span>: <span class="t-val">6px</span>;
<span class="t-attr">--ss-input-height</span>: <span class="t-val">44px</span>;
}</pre>
</div>
</div>
</div>
</section>
<!-- 4. Brand Themes -->
<section class="section" id="brands">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="13.5" cy="6.5" r="2.5" />
<circle cx="17.5" cy="10.5" r="2.5" />
<circle cx="8.5" cy="7.5" r="2.5" />
<circle cx="6.5" cy="12.5" r="2.5" />
<path d="M12 22C6.5 22 2 17.5 2 12S6.5 2 12 2" />
<path d="M22 12c0 5.5-4.5 10-10 10" />
</svg>
</div>
<h2 class="section-title">Brand Themes</h2>
</div>
<p class="section-desc">
Override any CSS token per instance to match your brand. Set custom properties directly on the element
— they cascade into the Shadow DOM automatically.
</p>
<div class="demo-card">
<div class="demo-split">
<div class="demo-pane">
<span class="demo-pane-label">Live — three brand palettes, one component</span>
<div class="demo-component">
<div class="brand-rows">
<div class="brand-row">
<span class="brand-row-label">Violet — SaaS / Fintech</span>
<smart-search
id="demo-brand-violet"
placeholder="Search technologies..."
style="
--ss-accent: #7c3aed;
--ss-accent-ring: rgba(124, 58, 237, 0.2);
--ss-active: #ede9fe;
--ss-chip-active-bg: #7c3aed;
--ss-mark-bg: #ddd6fe;
"
></smart-search>
</div>
<div class="brand-row">
<span class="brand-row-label">Emerald — Health / Eco</span>
<smart-search
id="demo-brand-emerald"
placeholder="Search technologies..."
style="
--ss-accent: #059669;
--ss-accent-ring: rgba(5, 150, 105, 0.2);
--ss-active: #d1fae5;
--ss-chip-active-bg: #059669;
--ss-mark-bg: #a7f3d0;
"
></smart-search>
</div>
<div class="brand-row">
<span class="brand-row-label">Rose — Fashion / E-commerce</span>
<smart-search
id="demo-brand-rose"
placeholder="Search technologies..."
style="
--ss-accent: #e11d48;
--ss-accent-ring: rgba(225, 29, 72, 0.2);
--ss-active: #ffe4e6;
--ss-chip-active-bg: #e11d48;
--ss-mark-bg: #fecdd3;
"
></smart-search>
</div>
</div>
</div>
</div>
<div class="code-pane">
<div class="code-header">
<div class="code-dots">
<span class="code-dot"></span><span class="code-dot"></span><span class="code-dot"></span>
</div>
<span class="code-filename">styles.css</span>
</div>
<pre><span class="t-cm">/* Violet — SaaS / Fintech */</span>
<span class="t-fn">#violet-search</span> {
<span class="t-attr">--ss-accent</span>: <span class="t-val">#7c3aed</span>;
<span class="t-attr">--ss-accent-ring</span>: <span class="t-val">rgba(124, 58, 237, 0.2)</span>;
<span class="t-attr">--ss-active</span>: <span class="t-val">#ede9fe</span>;
}
<span class="t-cm">/* Emerald — Health / Eco */</span>
<span class="t-fn">#emerald-search</span> {
<span class="t-attr">--ss-accent</span>: <span class="t-val">#059669</span>;
<span class="t-attr">--ss-accent-ring</span>: <span class="t-val">rgba(5, 150, 105, 0.2)</span>;
<span class="t-attr">--ss-active</span>: <span class="t-val">#d1fae5</span>;
}
<span class="t-cm">/* Rose — Fashion / E-commerce */</span>
<span class="t-fn">#rose-search</span> {
<span class="t-attr">--ss-accent</span>: <span class="t-val">#e11d48</span>;
<span class="t-attr">--ss-accent-ring</span>: <span class="t-val">rgba(225, 29, 72, 0.2)</span>;
<span class="t-attr">--ss-active</span>: <span class="t-val">#ffe4e6</span>;
}
<span class="t-cm">/* Or set inline on the element: */</span>
<span class="t-tag"><smart-search</span>
<span class="t-attr">style</span>=<span class="t-val">"--ss-accent:#7c3aed;
--ss-active:#ede9fe"</span>
<span class="t-tag">></smart-search></span></pre>
</div>
</div>
</div>
</section>
<!-- 5. Custom Renderer (was 4) -->
<section class="section" id="custom-renderer">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M12 20h9" />
<path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" />
</svg>
</div>
<h2 class="section-title">Custom Renderer</h2>
</div>
<p class="section-desc">
Use <code>resultItemRenderer</code> to return any DOM node as the result content. CSS tokens like
<code>--ss-accent</code> are available inside rendered nodes.
</p>
<div class="demo-card">
<div class="demo-split">
<div class="demo-pane">
<span class="demo-pane-label">Live — product cards with thumbnail & price</span>
<div class="demo-component">
<smart-search
id="demo-custom"
placeholder="Search products..."
datasource="https://dummyjson.com/products/search?{{q}}"
debounce="300"
menu-max-height="420"
></smart-search>
</div>
</div>
<div class="code-pane">
<div class="code-header">
<div class="code-dots">
<span class="code-dot"></span><span class="code-dot"></span><span class="code-dot"></span>
</div>
<span class="code-filename">main.js</span>
</div>
<pre>el.<span class="t-attr">resultItemRenderer</span> = (result) => {
<span class="t-kw">const</span> { metadata } = result
<span class="t-kw">const</span> card = document.<span class="t-fn">createElement</span>(<span class="t-str">'div'</span>)
card.style.cssText =
<span class="t-str">'display:flex;gap:12px;align-items:center'</span>
<span class="t-kw">const</span> img = document.<span class="t-fn">createElement</span>(<span class="t-str">'img'</span>)
img.src = metadata.thumbnail
img.width = 44; img.height = 44
img.style.cssText =
<span class="t-str">'border-radius:6px;object-fit:cover'</span>
<span class="t-kw">const</span> info = document.<span class="t-fn">createElement</span>(<span class="t-str">'div'</span>)
info.innerHTML = <span class="t-str">`
<strong>${result.label}</strong>
<div style="color:var(--ss-accent)">
$${metadata.price}
</div>`</span>
card.<span class="t-fn">append</span>(img, info)
<span class="t-kw">return</span> card
}</pre>
</div>
</div>
</div>
</section>
<!-- 5. Multi-select -->
<section class="section" id="multiselect">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<polyline points="9 11 12 14 22 4" />
<path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11" />
</svg>
</div>
<h2 class="section-title">Multi-select</h2>
</div>
<p class="section-desc">
Add the <code>multiselect</code> attribute to enable selecting multiple items. Selected items appear as
chips in the input. Listen to <code>ss-multiselect-change</code> or read
<code>el.selectedItems</code> directly.
</p>
<div class="demo-card">
<div class="demo-split">
<div class="demo-pane">
<span class="demo-pane-label">Live</span>
<div class="demo-component demo-component--multiselect">
<smart-search
id="demo-multiselect"
placeholder="Select products..."
datasource="https://dummyjson.com/products/search?{{q}}"
debounce="300"
multiselect
close-menu-on-select="false"
></smart-search>
<div id="demo-multiselect-selected" class="multiselect-selected-output" aria-live="polite"></div>
</div>
</div>
<div class="code-pane">
<div class="code-header">
<div class="code-dots">
<span class="code-dot"></span><span class="code-dot"></span><span class="code-dot"></span>
</div>
<span class="code-filename">index.html</span>
</div>
<pre><span class="t-tag"><smart-search</span>
<span class="t-attr">multiselect</span>
<span class="t-attr">close-menu-on-select</span>=<span class="t-val">"false"</span>
<span class="t-attr">datasource</span>=<span class="t-val">"..."</span>
<span class="t-tag">></smart-search></span>
el.<span class="t-fn">addEventListener</span>(
<span class="t-str">'ss-multiselect-change'</span>,
(e) => {
<span class="t-cm">// e.detail.items: SearchResult[]</span>
console.<span class="t-fn">log</span>(e.detail.items)
}
)
<span class="t-cm">// Read state directly</span>
<span class="t-kw">const</span> selected = el.selectedItems</pre>
</div>
</div>
</div>
</section>
<!-- 6. Static Options -->
<section class="section" id="static">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<ellipse cx="12" cy="5" rx="9" ry="3" />
<path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3" />
<path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5" />
</svg>
</div>
<h2 class="section-title">Static Options</h2>
</div>
<p class="section-desc">
Pre-load an <code>options</code> array for purely client-side filtering — no network requests. The
component filters by <code>label</code> and <code>description</code> as you type.
</p>
<div class="demo-card">
<div class="demo-split">
<div class="demo-pane">
<span class="demo-pane-label">Live — no network requests</span>
<div class="demo-component">
<smart-search
placeholder="Search languages..."
options='[{"value":"js","label":"JavaScript","description":"Dynamic web scripting language","group":"Frontend"},{"value":"ts","label":"TypeScript","description":"Typed superset of JavaScript","group":"Frontend"},{"value":"react","label":"React","description":"UI component library","group":"Frontend"},{"value":"vue","label":"Vue","description":"Progressive JavaScript framework","group":"Frontend"},{"value":"svelte","label":"Svelte","description":"Compiler-based UI framework","group":"Frontend"},{"value":"go","label":"Go","description":"Statically typed, compiled language","group":"Backend"},{"value":"rust","label":"Rust","description":"Systems programming language","group":"Backend"},{"value":"python","label":"Python","description":"General-purpose scripting language","group":"Backend"},{"value":"node","label":"Node.js","description":"JavaScript runtime for servers","group":"Backend"}]'
></smart-search>
</div>
</div>
<div class="code-pane">
<div class="code-header">
<div class="code-dots">
<span class="code-dot"></span><span class="code-dot"></span><span class="code-dot"></span>
</div>
<span class="code-filename">index.html</span>
</div>
<pre>
<span class="t-tag"><smart-search</span>
<span class="t-attr">placeholder</span>=<span class="t-val">"Search languages..."</span>
<span class="t-attr">options</span>=<span class="t-val">'[
{
"value": "js",
"label": "JavaScript",
"description": "Web scripting",
"group": "Frontend"
},
{
"value": "go",
"label": "Go",
"description": "Systems language",
"group": "Backend"
}
]'</span>
<span class="t-tag">></smart-search></span>
<span class="t-cm">// Or set programmatically:</span>
el.options = myItems
</pre>
</div>
</div>
</div>
</section>
<!-- 7. Events Log -->
<section class="section" id="events">
<div class="section-header">
<div class="section-icon">
<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
>
<polyline points="22 12 18 12 15 21 9 3 6 12 2 12" />
</svg>
</div>
<h2 class="section-title">Events Log</h2>
</div>
<p class="section-desc">
All interactions fire custom events on the element. Type, select, toggle a filter, or open the menu to see
them stream in the log below.
</p>
<div class="demo-card">
<div class="events-layout">
<div class="events-demo-pane">
<smart-search
id="demo-events"
placeholder="Interact to see events..."
datasource="https://dummyjson.com/products/search?{{q}}"
debounce="300"
filters='[{"field":"category","value":"smartphones","label":"Smartphones"},{"field":"category","value":"laptops","label":"Laptops"}]'
></smart-search>
</div>
<div class="event-log" id="event-log">
<div class="log-empty">Events will appear here as you interact…</div>
</div>
</div>
</div>
</section>
</main>
</div>
<script>
const sidebarLinks = document.querySelectorAll('.sidebar-link[href^="#"]')
const mobileLinks = document.querySelectorAll('.mobile-nav-link[href^="#"]')
const observer = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (entry.isIntersecting) {
const id = entry.target.id
sidebarLinks.forEach((l) => l.classList.remove("active"))
const sLink = document.querySelector(`.sidebar-link[href="#${id}"]`)
if (sLink) sLink.classList.add("active")
mobileLinks.forEach((l) => l.classList.remove("active"))
const mLink = document.querySelector(`.mobile-nav-link[href="#${id}"]`)
if (mLink) {
mLink.classList.add("active")
mLink.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" })
}
}
}
},
{ rootMargin: "-20% 0px -70% 0px" },
)
document.querySelectorAll(".section[id]").forEach((s) => observer.observe(s))
</script>
</body>
</html>