|
| 1 | +import React, { useState, useMemo } from 'react'; |
| 2 | +import { ServiceBox } from './ServiceBox.tsx'; |
| 3 | + |
| 4 | +interface Feature { |
| 5 | + title: string; |
| 6 | + description: string; |
| 7 | + href: string; |
| 8 | +} |
| 9 | + |
| 10 | +interface SearchableSnowflakeFeaturesProps { |
| 11 | + features: Feature[]; |
| 12 | +} |
| 13 | + |
| 14 | +export const SearchableSnowflakeFeatures: React.FC<SearchableSnowflakeFeaturesProps> = ({ features }) => { |
| 15 | + const [searchTerm, setSearchTerm] = useState(''); |
| 16 | + |
| 17 | + const filteredFeatures = useMemo(() => { |
| 18 | + if (!searchTerm.trim()) { |
| 19 | + return features; |
| 20 | + } |
| 21 | + |
| 22 | + const lowercaseSearch = searchTerm.toLowerCase(); |
| 23 | + return features.filter(feature => |
| 24 | + feature.title.toLowerCase().includes(lowercaseSearch) || |
| 25 | + feature.description.toLowerCase().includes(lowercaseSearch) |
| 26 | + ); |
| 27 | + }, [features, 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 Snowflake Feature ..." |
| 50 | + value={searchTerm} |
| 51 | + onChange={(e) => setSearchTerm(e.target.value)} |
| 52 | + className="search-input" |
| 53 | + /> |
| 54 | + </div> |
| 55 | + </div> |
| 56 | + |
| 57 | + {filteredFeatures.length === 0 && searchTerm.trim() ? ( |
| 58 | + <div className="no-results"> |
| 59 | + <p>No features found matching "{searchTerm}"</p> |
| 60 | + </div> |
| 61 | + ) : ( |
| 62 | + <div className="service-grid"> |
| 63 | + {filteredFeatures.map((feature, index) => ( |
| 64 | + <ServiceBox |
| 65 | + key={`${feature.href}-${index}`} |
| 66 | + title={feature.title} |
| 67 | + description={feature.description} |
| 68 | + href={feature.href} |
| 69 | + /> |
| 70 | + ))} |
| 71 | + </div> |
| 72 | + )} |
| 73 | + </div> |
| 74 | + ); |
| 75 | +}; |
0 commit comments