Skip to content

Commit e279ae4

Browse files
add search functionality for aws service docs (#23)
Co-authored-by: Brian Rinaldi <[email protected]>
1 parent 42fcef9 commit e279ae4

File tree

4 files changed

+165
-2
lines changed

4 files changed

+165
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
import { getCollection } from 'astro:content';
3+
import { SearchableAwsServices } from './SearchableAwsServices.tsx';
4+
5+
const allServices = await getCollection('docs', ({ id }) => {
6+
return id.startsWith('aws/services/') && !id.includes('/index');
7+
});
8+
9+
const sortedServices = allServices.sort((a, b) => {
10+
const titleA = a.data.title || a.data.linkTitle || '';
11+
const titleB = b.data.title || b.data.linkTitle || '';
12+
return titleA.localeCompare(titleB);
13+
});
14+
15+
const serviceData = sortedServices.map(service => {
16+
const title = service.data.title || service.data.linkTitle || 'Unknown Service';
17+
const description = service.data.description || `Implementation details for ${title} API`;
18+
19+
const href = `/${service.id}`;
20+
21+
return {
22+
title,
23+
description,
24+
href
25+
};
26+
});
27+
---
28+
29+
<SearchableAwsServices services={serviceData} client:load />
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React, { useState, useMemo } from 'react';
2+
import { ServiceBox } from './ServiceBox.tsx';
3+
4+
interface Service {
5+
title: string;
6+
description: string;
7+
href: string;
8+
}
9+
10+
interface SearchableAwsServicesProps {
11+
services: Service[];
12+
}
13+
14+
export const SearchableAwsServices: React.FC<SearchableAwsServicesProps> = ({ services }) => {
15+
const [searchTerm, setSearchTerm] = useState('');
16+
17+
const filteredServices = useMemo(() => {
18+
if (!searchTerm.trim()) {
19+
return services;
20+
}
21+
22+
const lowercaseSearch = searchTerm.toLowerCase();
23+
return services.filter(service =>
24+
service.title.toLowerCase().includes(lowercaseSearch) ||
25+
service.description.toLowerCase().includes(lowercaseSearch)
26+
);
27+
}, [services, searchTerm]);
28+
29+
return (
30+
<div className="searchable-services">
31+
<div className="search-container">
32+
<div className="search-input-wrapper">
33+
<svg
34+
className="search-icon"
35+
fill="none"
36+
stroke="currentColor"
37+
viewBox="0 0 24 24"
38+
xmlns="http://www.w3.org/2000/svg"
39+
>
40+
<path
41+
strokeLinecap="round"
42+
strokeLinejoin="round"
43+
strokeWidth={2}
44+
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
45+
/>
46+
</svg>
47+
<input
48+
type="text"
49+
placeholder="Search for Service Name ..."
50+
value={searchTerm}
51+
onChange={(e) => setSearchTerm(e.target.value)}
52+
className="search-input"
53+
/>
54+
</div>
55+
</div>
56+
57+
{filteredServices.length === 0 && searchTerm.trim() ? (
58+
<div className="no-results">
59+
<p>No services found matching "{searchTerm}"</p>
60+
</div>
61+
) : (
62+
<div className="service-grid">
63+
{filteredServices.map((service, index) => (
64+
<ServiceBox
65+
key={`${service.href}-${index}`}
66+
title={service.title}
67+
description={service.description}
68+
href={service.href}
69+
/>
70+
))}
71+
</div>
72+
)}
73+
</div>
74+
);
75+
};

src/content/docs/aws/services/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ sidebar:
66
order: 3
77
---
88

9-
import DynamicAwsServices from '../../../../components/DynamicAwsServices.astro';
9+
import SearchableAwsServices from '../../../../components/SearchableAwsServices.astro';
1010

1111
Browse LocalStack's implemented AWS services and explore their comprehensive feature sets. Each service provides detailed documentation on APIs, configuration options, and practical examples to help you get started quickly.
1212

13-
<DynamicAwsServices />
13+
<SearchableAwsServices />

src/styles/global.css

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,62 @@
4949
gap: 1rem;
5050
margin-top: 2rem;
5151
}
52+
53+
/* Search styles */
54+
.searchable-services {
55+
margin-top: 2rem;
56+
}
57+
58+
.search-container {
59+
margin-bottom: 2rem;
60+
}
61+
62+
.search-input-wrapper {
63+
position: relative;
64+
max-width: 600px;
65+
margin: 0 auto;
66+
}
67+
68+
.search-icon {
69+
position: absolute;
70+
left: 1rem;
71+
top: 50%;
72+
transform: translateY(-50%);
73+
width: 1.25rem;
74+
height: 1.25rem;
75+
color: var(--sl-color-gray-3);
76+
pointer-events: none;
77+
z-index: 1;
78+
}
79+
80+
.search-input {
81+
width: 100%;
82+
padding: 1rem 1rem 1rem 3rem;
83+
border: 2px solid var(--sl-color-gray-5);
84+
border-radius: 2rem;
85+
background-color: var(--sl-color-bg-nav);
86+
color: var(--sl-color-white);
87+
font-size: 1rem;
88+
transition: all 0.2s ease;
89+
outline: none;
90+
}
91+
92+
.search-input::placeholder {
93+
color: var(--sl-color-gray-3);
94+
}
95+
96+
.search-input:focus {
97+
border-color: var(--sl-color-accent);
98+
box-shadow: 0 0 0 3px rgba(var(--sl-color-accent-rgb), 0.1);
99+
}
100+
101+
.no-results {
102+
text-align: center;
103+
padding: 2rem;
104+
color: var(--sl-color-gray-2);
105+
}
106+
107+
.no-results p {
108+
margin: 0;
109+
font-size: 1.125rem;
110+
}

0 commit comments

Comments
 (0)