Skip to content

Commit 727d79a

Browse files
committed
docs: add search to demos
Closes #904
1 parent 843c868 commit 727d79a

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

projects/demos/app/demo-app.component.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface Demo {
1818
label: string;
1919
path: string;
2020
sources?: Source[];
21+
tags: string[];
2122
}
2223

2324
async function getSources(folder: string): Promise<Source[]> {
@@ -82,9 +83,11 @@ const dependencyVersions: any = {
8283
})
8384
export class DemoAppComponent implements OnInit {
8485
demos: Demo[] = [];
86+
filteredDemos: Demo[] = [];
8587
activeDemo: Demo;
8688
isMenuVisible = false;
8789
firstDemoLoaded = false;
90+
searchText = '';
8891

8992
constructor(private router: Router, analytics: Angulartics2GoogleAnalytics) {
9093
analytics.startTracking();
@@ -97,8 +100,10 @@ export class DemoAppComponent implements OnInit {
97100
.filter(route => route.path !== '**')
98101
.map(route => ({
99102
path: route.path,
100-
label: route.data['label']
103+
tags: route.data.tags || [],
104+
label: route.data.label
101105
}));
106+
this.updateFilteredDemos();
102107

103108
this.router.events
104109
.pipe(filter(event => event instanceof NavigationEnd))
@@ -123,6 +128,16 @@ export class DemoAppComponent implements OnInit {
123128
});
124129
}
125130

131+
updateFilteredDemos() {
132+
this.filteredDemos = this.demos.filter(
133+
demo =>
134+
!this.searchText ||
135+
[demo.label.toLowerCase(), ...demo.tags].some(tag =>
136+
tag.includes(this.searchText.toLowerCase())
137+
)
138+
);
139+
}
140+
126141
editInStackblitz(demo: Demo): void {
127142
const files: {
128143
[path: string]: string;

projects/demos/app/demo-app.css

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ h3 {
1616
margin-top: 15px;
1717
}
1818

19+
.sidebar-nav {
20+
padding-left: 5px;
21+
}
22+
1923
.sidebar-nav h4 {
2024
margin-bottom: 20px;
2125
}

projects/demos/app/demo-app.html

+15-5
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123

124124
<div class="container-fluid">
125125
<div class="row fill-height">
126-
<div class="col-md-9 fill-height scroll-y" perfectScrollbar>
126+
<div class="col-md-9 col-xl-10 fill-height scroll-y" perfectScrollbar>
127127
<div class="card" *ngIf="firstDemoLoaded; else loading">
128128
<div class="card-header">
129129
<div class="row">
@@ -166,10 +166,19 @@
166166
</div>
167167
</div>
168168
</div>
169-
<div class="col-md-3 fill-height sidebar-nav scroll-y" perfectScrollbar>
170-
<h4>Demos</h4>
171-
<ul class="list-unstyled">
172-
<li *ngFor="let demo of demos">
169+
<div
170+
class="col-md-3 col-xl-2 fill-height sidebar-nav scroll-y"
171+
perfectScrollbar
172+
>
173+
<input
174+
type="search"
175+
class="form-control"
176+
placeholder="Search demos..."
177+
[(ngModel)]="searchText"
178+
(ngModelChange)="updateFilteredDemos()"
179+
/>
180+
<ul class="list-unstyled spacer-top">
181+
<li *ngFor="let demo of filteredDemos">
173182
<a
174183
[routerLink]="[demo.path]"
175184
[class.active]="activeDemo?.path === demo.path"
@@ -178,6 +187,7 @@ <h4>Demos</h4>
178187
</a>
179188
</li>
180189
</ul>
190+
<em *ngIf="filteredDemos.length === 0">No matching demos found</em>
181191
</div>
182192
</div>
183193
</div>

projects/demos/app/demo-app.module.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import { DemoComponent as DefaultDemoComponent } from './demo-modules/kitchen-si
1313
import { DemoModule as DefaultDemoModule } from './demo-modules/kitchen-sink/module';
1414
import { environment } from '../environments/environment';
1515
import { CustomHammerConfig } from './hammer-config';
16+
import { FormsModule } from '@angular/forms';
1617

1718
@NgModule({
1819
declarations: [DemoAppComponent],
1920
imports: [
2021
BrowserModule,
2122
BrowserAnimationsModule,
23+
FormsModule,
2224
NgbTabsetModule,
2325
NgbCollapseModule,
2426
DefaultDemoModule,
@@ -130,7 +132,8 @@ import { CustomHammerConfig } from './hammer-config';
130132
path: 'before-view-render',
131133
loadChildren: './demo-modules/before-view-render/module#DemoModule',
132134
data: {
133-
label: 'Before view render'
135+
label: 'Before view render',
136+
tags: ['disable']
134137
}
135138
},
136139
{
@@ -144,7 +147,8 @@ import { CustomHammerConfig } from './hammer-config';
144147
path: 'i18n',
145148
loadChildren: './demo-modules/i18n/module#DemoModule',
146149
data: {
147-
label: 'Internationalisation'
150+
label: 'Internationalisation',
151+
tags: ['translation', 'i18n', 'translate', 'locale']
148152
}
149153
},
150154
{
@@ -232,7 +236,8 @@ import { CustomHammerConfig } from './hammer-config';
232236
path: 'context-menu',
233237
loadChildren: './demo-modules/context-menu/module#DemoModule',
234238
data: {
235-
label: 'Context menu'
239+
label: 'Context menu',
240+
tags: ['right click']
236241
}
237242
},
238243
{

0 commit comments

Comments
 (0)