|
| 1 | +'use client'; |
| 2 | +import { AutoComplete, AutoCompleteEmpty, AutoCompleteInput, AutoCompleteList, AutoCompleteOption, AutoCompletePopup, AutoCompletePortal, AutoCompletePositioner } from '@/components/ui/autocomplete'; |
| 3 | +import { Label } from '@/components/ui/label'; |
| 4 | +import type { AutoCompleteCompleteEvent } from 'primereact/autocomplete'; |
| 5 | +import * as React from 'react'; |
| 6 | + |
| 7 | +export default function Preview() { |
| 8 | + const [filtered, setFiltered] = React.useState<string[]>([]); |
| 9 | + |
| 10 | + const search = (event: AutoCompleteCompleteEvent) => { |
| 11 | + const query = event.query.toLowerCase(); |
| 12 | + |
| 13 | + setFiltered(query ? options.filter((item) => item.toLowerCase().includes(query)) : [...options]); |
| 14 | + }; |
| 15 | + |
| 16 | + return ( |
| 17 | + <div className="flex justify-center"> |
| 18 | + <div className="flex flex-col"> |
| 19 | + <Label>Search tutorials</Label> |
| 20 | + <AutoComplete options={filtered} onComplete={search} className="w-full md:w-72 mt-2"> |
| 21 | + <AutoCompleteInput placeholder="Search..." className="w-full" /> |
| 22 | + <AutoCompletePortal> |
| 23 | + <AutoCompletePositioner> |
| 24 | + <AutoCompletePopup> |
| 25 | + <AutoCompleteList> |
| 26 | + {filtered.map((item, index) => ( |
| 27 | + <AutoCompleteOption key={item} index={index} uKey={item}> |
| 28 | + {item} |
| 29 | + </AutoCompleteOption> |
| 30 | + ))} |
| 31 | + <AutoCompleteEmpty className="text-sm">No results found</AutoCompleteEmpty> |
| 32 | + </AutoCompleteList> |
| 33 | + </AutoCompletePopup> |
| 34 | + </AutoCompletePositioner> |
| 35 | + </AutoCompletePortal> |
| 36 | + </AutoComplete> |
| 37 | + <small className="text-surface-500 mt-1.5 opacity-75"> |
| 38 | + Type <em className="underline">react</em> to see suggestions |
| 39 | + </small> |
| 40 | + </div> |
| 41 | + </div> |
| 42 | + ); |
| 43 | +} |
| 44 | + |
| 45 | +const options: string[] = [ |
| 46 | + 'responsive design fundamentals', |
| 47 | + 'redux toolkit crash course', |
| 48 | + 'real-time chat app tutorial', |
| 49 | + 'reading json files in node', |
| 50 | + 'react hooks tutorial', |
| 51 | + 'react server components explained', |
| 52 | + 'react vs vue 2024', |
| 53 | + 'react native crash course', |
| 54 | + 'react 19 new features', |
| 55 | + 'react context api best practices', |
| 56 | + 'react testing library guide', |
| 57 | + 'react router v7 tutorial', |
| 58 | + 'react performance optimization', |
| 59 | + 'react suspense and lazy loading', |
| 60 | + 'react state management comparison', |
| 61 | + 'react form validation', |
| 62 | + 'react design patterns', |
| 63 | + 'react authentication tutorial', |
| 64 | + 'react with typescript beginner', |
| 65 | + 'react animation libraries', |
| 66 | + 'react deploy to production' |
| 67 | +]; |
0 commit comments