import { Component, ChangeDetectionStrategy, signal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { SearchBarComponent, SearchSuggestion } from '../../../../../ui-essentials/src/lib/components/forms/search';
import {
faSearch,
faMicrophone,
faCamera,
faFilter,
faUser,
faFile,
faFolder,
faTag,
faHeart,
faStar
} from '@fortawesome/free-solid-svg-icons';
@Component({
selector: 'ui-search-demo',
standalone: true,
imports: [
CommonModule,
FormsModule,
SearchBarComponent
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
Search Bar Component Showcase
Interactive Controls
@if (lastAction()) {
Last action: {{ lastAction() }}
}
Code Examples
Basic Usage:
<ui-search-bar
placeholder="Search..."
[(ngModel)]="searchValue"
(searchChange)="onSearchChange($event)"
(searchSubmit)="onSearchSubmit($event)">
</ui-search-bar>
With Suggestions:
<ui-search-bar
placeholder="Search with suggestions..."
[suggestions]="suggestions"
[(ngModel)]="searchValue"
(suggestionSelect)="onSuggestionSelect($event)">
</ui-search-bar>
With Icons:
<ui-search-bar
placeholder="Search with icons..."
[leadingIcon]="faSearch"
[trailingIcons]="iconButtons"
variant="filled"
size="lg"
(trailingIconClick)="onIconClick($event)">
</ui-search-bar>
`,
styles: [`
h2 {
color: hsl(279, 14%, 11%);
font-size: 2rem;
margin-bottom: 2rem;
border-bottom: 2px solid hsl(258, 100%, 47%);
padding-bottom: 0.5rem;
}
h3 {
color: hsl(279, 14%, 25%);
font-size: 1.5rem;
margin-bottom: 1rem;
}
h4 {
color: hsl(279, 14%, 35%);
font-size: 1.2rem;
margin-bottom: 0.5rem;
}
pre {
margin: 0;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
line-height: 1.4;
}
code {
color: hsl(279, 14%, 15%);
}
section {
border: 1px solid #e9ecef;
padding: 1.5rem;
border-radius: 8px;
background: #ffffff;
}
button:hover {
opacity: 0.9;
transform: translateY(-1px);
}
`]
})
export class SearchDemoComponent {
// FontAwesome icons
protected readonly faSearch = faSearch;
protected readonly faMicrophone = faMicrophone;
protected readonly faCamera = faCamera;
protected readonly faFilter = faFilter;
protected readonly faUser = faUser;
protected readonly faFile = faFile;
protected readonly faFolder = faFolder;
protected readonly faTag = faTag;
protected readonly faHeart = faHeart;
protected readonly faStar = faStar;
// Basic search values
basicSearch1 = signal('');
basicSearch2 = signal('');
basicSearch3 = signal('');
// Size variants
sizeSmall = signal('');
sizeMedium = signal('');
sizeLarge = signal('');
// Variant styles
variantOutlined = signal('');
variantFilled = signal('');
variantElevated = signal('');
// Icon searches
iconSearch1 = signal('');
iconSearch2 = signal('');
iconSearch3 = signal('');
// Suggestion searches
suggestionSearch1 = signal('');
suggestionSearch2 = signal('');
// State searches
stateDisabled = signal('Disabled value');
stateReadonly = signal('Readonly value');
stateError = signal('');
stateHelper = signal('');
// Advanced searches
advancedSearch1 = signal('');
advancedSearch2 = signal('');
advancedSearch3 = signal('');
// Control states
globalDisabled = signal(false);
lastAction = signal('');
// Icon configurations
basicTrailingIcons = [
{
id: 'mic',
icon: faMicrophone,
label: 'Voice search',
disabled: false
}
];
multipleTrailingIcons = [
{
id: 'mic',
icon: faMicrophone,
label: 'Voice search',
disabled: false
},
{
id: 'camera',
icon: faCamera,
label: 'Image search',
disabled: false
},
{
id: 'filter',
icon: faFilter,
label: 'Filter results',
disabled: false
}
];
// Search suggestions
suggestions: SearchSuggestion[] = [
{ id: '1', text: 'Angular components', icon: faFile },
{ id: '2', text: 'TypeScript interfaces', icon: faFile },
{ id: '3', text: 'SCSS mixins', icon: faFile },
{ id: '4', text: 'Design tokens', icon: faTag },
{ id: '5', text: 'Material Design', icon: faHeart },
{ id: '6', text: 'Component library', icon: faFolder },
{ id: '7', text: 'UI patterns', icon: faStar },
{ id: '8', text: 'Accessibility guidelines', icon: faFile }
];
categorizedSuggestions: SearchSuggestion[] = [
{ id: '1', text: 'User profile', category: 'Users', icon: faUser },
{ id: '2', text: 'Project documentation', category: 'Files', icon: faFile },
{ id: '3', text: 'Design system', category: 'Files', icon: faFolder },
{ id: '4', text: 'Component library', category: 'Code', icon: faTag },
{ id: '5', text: 'UI components', category: 'Code', icon: faTag },
{ id: '6', text: 'Admin settings', category: 'Settings', icon: faFilter }
];
onSearchChange(searchId: string, value: string): void {
this.lastAction.set(`Search changed: ${searchId} = "${value}"`);
console.log(`Search ${searchId} changed:`, value);
}
onSearchSubmit(searchId: string, value: string): void {
this.lastAction.set(`Search submitted: ${searchId} = "${value}"`);
console.log(`Search ${searchId} submitted:`, value);
}
onSuggestionSelect(suggestion: SearchSuggestion): void {
this.lastAction.set(`Suggestion selected: "${suggestion.text}" (${suggestion.id})`);
console.log('Suggestion selected:', suggestion);
}
onTrailingIconClick(iconData: {id: string, icon: any}): void {
this.lastAction.set(`Icon clicked: ${iconData.id}`);
console.log('Trailing icon clicked:', iconData);
}
clearAllSearches(): void {
this.basicSearch1.set('');
this.basicSearch2.set('');
this.basicSearch3.set('');
this.sizeSmall.set('');
this.sizeMedium.set('');
this.sizeLarge.set('');
this.variantOutlined.set('');
this.variantFilled.set('');
this.variantElevated.set('');
this.iconSearch1.set('');
this.iconSearch2.set('');
this.iconSearch3.set('');
this.suggestionSearch1.set('');
this.suggestionSearch2.set('');
this.stateError.set('');
this.stateHelper.set('');
this.advancedSearch1.set('');
this.advancedSearch2.set('');
this.advancedSearch3.set('');
this.lastAction.set('All searches cleared');
}
fillSampleSearches(): void {
this.basicSearch1.set('Sample search');
this.basicSearch2.set('Labeled search');
this.basicSearch3.set('Required search');
this.sizeSmall.set('Small');
this.sizeMedium.set('Medium');
this.sizeLarge.set('Large');
this.variantOutlined.set('Outlined');
this.variantFilled.set('Filled');
this.variantElevated.set('Elevated');
this.iconSearch1.set('User search');
this.iconSearch2.set('Voice search');
this.iconSearch3.set('Multi-icon search');
this.suggestionSearch1.set('Angular');
this.suggestionSearch2.set('Design');
this.stateError.set('Error text');
this.stateHelper.set('Helper text');
this.advancedSearch1.set('Advanced');
this.advancedSearch2.set('Focused');
this.advancedSearch3.set('Limited');
this.lastAction.set('All searches filled with sample data');
}
toggleStates(): void {
this.globalDisabled.update(disabled => !disabled);
this.lastAction.set(`Global state: ${this.globalDisabled() ? 'disabled' : 'enabled'}`);
}
getCurrentValues(): string {
const values = {
basic: {
search1: this.basicSearch1(),
search2: this.basicSearch2(),
search3: this.basicSearch3()
},
sizes: {
small: this.sizeSmall(),
medium: this.sizeMedium(),
large: this.sizeLarge()
},
variants: {
outlined: this.variantOutlined(),
filled: this.variantFilled(),
elevated: this.variantElevated()
},
icons: {
icon1: this.iconSearch1(),
icon2: this.iconSearch2(),
icon3: this.iconSearch3()
},
suggestions: {
suggestion1: this.suggestionSearch1(),
suggestion2: this.suggestionSearch2()
},
states: {
disabled: this.stateDisabled(),
readonly: this.stateReadonly(),
error: this.stateError(),
helper: this.stateHelper()
},
advanced: {
advanced1: this.advancedSearch1(),
advanced2: this.advancedSearch2(),
advanced3: this.advancedSearch3()
},
controls: {
globalDisabled: this.globalDisabled(),
lastAction: this.lastAction()
}
};
return JSON.stringify(values, null, 2);
}
}