From 634ae90a8c50eae4adea5f592c9dc79c9ec32d88 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Fri, 12 Apr 2024 21:56:16 -0500 Subject: [PATCH] prototype combobox --- app/forms/disk-attach.tsx | 37 +++++++++++++++++++++++++++++++++++++ app/ui/lib/Combobox.tsx | 9 +++++++++ 2 files changed, 46 insertions(+) create mode 100644 app/ui/lib/Combobox.tsx diff --git a/app/forms/disk-attach.tsx b/app/forms/disk-attach.tsx index f7995fd307..bfe2a4a7bf 100644 --- a/app/forms/disk-attach.tsx +++ b/app/forms/disk-attach.tsx @@ -5,7 +5,12 @@ * * Copyright Oxide Computer Company */ +import { Combobox } from '@headlessui/react' +import cn from 'classnames' +import { useState } from 'react' + import { useApiQuery, type ApiError } from '@oxide/api' +import { DirectionDownIcon } from '@oxide/design-system/icons/react' import { ListboxField } from '~/components/form/fields/ListboxField' import { SideModalForm } from '~/components/form/SideModalForm' @@ -42,6 +47,13 @@ export function AttachDiskSideModalForm({ (d) => d.state.state === 'detached' ) || [] + const [selectedDisk, setSelectedDisk] = useState(detachedDisks[0]) + const [query, setQuery] = useState('') + const filteredDisks = + query === '' + ? detachedDisks + : detachedDisks.filter((d) => d.name.includes(query.toLowerCase())) + const form = useForm({ defaultValues }) return ( @@ -62,6 +74,31 @@ export function AttachDiskSideModalForm({ required control={form.control} /> + +
+ +
+ setQuery(event.target.value)} + /> + + +
+ + {filteredDisks.map((d) => ( + cn('ox-menu-item', active && 'is-highlighted')} + > + {d.name} + + ))} + +
+
) } diff --git a/app/ui/lib/Combobox.tsx b/app/ui/lib/Combobox.tsx new file mode 100644 index 0000000000..c2e0787768 --- /dev/null +++ b/app/ui/lib/Combobox.tsx @@ -0,0 +1,9 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at https://mozilla.org/MPL/2.0/. + * + * Copyright Oxide Computer Company + */ + +export function Combobox() {}