diff --git a/bun.lockb b/bun.lockb index 2269956..6c10088 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 9408e19..7ee1ff8 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,12 @@ "preview": "vite preview" }, "dependencies": { + "@headlessui/react": "^1.7.17", + "@heroicons/react": "^2.0.18", + "@tanstack/react-query": "^4.35.3", "react": "^18.2.0", - "react-dom": "^18.2.0" + "react-dom": "^18.2.0", + "react-select": "^5.7.5" }, "devDependencies": { "@types/react": "^18.0.37", diff --git a/src/ComboBox.tsx b/src/ComboBox.tsx new file mode 100644 index 0000000..1aba514 --- /dev/null +++ b/src/ComboBox.tsx @@ -0,0 +1,110 @@ +/* + This example requires some changes to your config: + + ``` + // tailwind.config.js + module.exports = { + // ... + plugins: [ + // ... + require('@tailwindcss/forms'), + ], + } + ``` +*/ +import {useMemo, useState} from 'react' +import {CheckIcon, ChevronUpDownIcon} from '@heroicons/react/20/solid' +import {Combobox} from '@headlessui/react' +import {useQuery} from "@tanstack/react-query"; + +function classNames(...classes: any[]) { + return classes.filter(Boolean).join(' ') +} + +export default function Example() { + const {data: options} = useQuery({ + queryKey: ['obsidian-metadata'], + initialData: [], + queryFn: async () => { + const response = await fetch("http://100.115.154.44:9002/metadata") + const fullData: any[] = await response.json(); + + return fullData.map(md => ({ + id: md.relativePath, + name: md.fileName + })); + }, + }); + + const [query, setQuery] = useState('') + const [selectedPerson, setSelectedPerson] = useState(null) + + const filteredOptions = + useMemo(() => { + return query === '' + ? options + : options.filter((option) => { + return option.name.toLowerCase().includes(query.toLowerCase()) + }) + }, [query, options]) + + return ( + + Assigned to +
+ setQuery(event.target.value)} + displayValue={(person: (typeof filteredOptions)[number]) => person?.name} + /> + + + + {filteredOptions.length > 0 && ( + + {filteredOptions.map((person) => ( + + classNames( + 'relative cursor-default select-none py-2 pl-3 pr-9', + active ? 'bg-indigo-600 text-white' : 'text-gray-900' + ) + } + > + {({ active, selected }) => ( + <> +
+ {person.name} + + {person.id} + +
+ + {selected && ( + + + )} + + )} +
+ ))} +
+ )} +
+
+ ) +} diff --git a/src/main.tsx b/src/main.tsx index dbe7f6b..ff6a505 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,10 +1,15 @@ import React from 'react' import ReactDOM from 'react-dom/client' -import App from './App.tsx' import './index.css' +import Combobox from "./ComboBox.tsx"; +import {QueryClient, QueryClientProvider} from "@tanstack/react-query"; + +const queryClient = new QueryClient() ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( - + + + , )