-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adds space-finder autocomplete combobox #268
Changes from 1 commit
c786c8e
0b6c319
39a6639
8f1e7a2
e887d52
3d93a88
814f789
a1e9d51
02c257a
ed1e2d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { Fragment, useState } from 'react' | ||
import { Combobox, Transition } from '@headlessui/react' | ||
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/20/solid' | ||
|
||
export function SpaceFinder ({ spaces, selected, setSelected, className }) { | ||
const [query, setQuery] = useState('') | ||
|
||
console.log('space', query, selected) | ||
|
||
const filtered = | ||
query === '' | ||
? spaces | ||
: spaces.filter((space) => | ||
(space.name() || space.did()) | ||
.toLowerCase() | ||
.replace(/\s+/g, '') | ||
.includes(query.toLowerCase().replace(/\s+/g, '')) | ||
) | ||
|
||
return ( | ||
<div className={className}> | ||
<Combobox value={selected} onChange={setSelected} by={(a, b) => a.sameAs(b)}> | ||
<div className="relative mt-1"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm down to merge this as-is, but just a note that we'll need to translate this Tailwind styling to CSS-variable-based styling before we ship this package for real |
||
<div className="relative w-full cursor-default overflow-hidden rounded-lg bg-white text-left shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75 focus-visible:ring-offset-2 focus-visible:ring-offset-teal-300 sm:text-sm"> | ||
<Combobox.Input | ||
className="w-full border-none py-2 pl-3 pr-10 text-sm leading-5 text-gray-900 focus:ring-0 text-black" | ||
displayValue={(space) => space.name() || space.did()} | ||
onChange={(event) => setQuery(event.target.value)} | ||
/> | ||
<Combobox.Button className="absolute inset-y-0 right-0 flex items-center pr-2"> | ||
<ChevronUpDownIcon | ||
className="h-5 w-5 text-gray-400" | ||
aria-hidden="true" | ||
/> | ||
</Combobox.Button> | ||
</div> | ||
<Transition | ||
as={Fragment} | ||
leave="transition ease-in duration-100" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
afterLeave={() => setQuery('')} | ||
> | ||
<Combobox.Options className="absolute mt-1 max-h-44 w-full bg-white overflow-auto rounded-md py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm" static> | ||
{filtered.length === 0 && query !== '' ? ( | ||
<div className="relative cursor-default select-none py-2 px-4 font-mono text-xs text-red-500"> | ||
(╯°□°)╯︵ ┻━┻ | ||
</div> | ||
) : ( | ||
filtered.map((space) => ( | ||
<Combobox.Option | ||
key={space.did()} | ||
className={({ active }) => | ||
`relative cursor-default select-none py-2 pl-10 pr-4 ${ | ||
active ? 'bg-teal-600 text-white' : 'text-gray-900' | ||
}` | ||
} | ||
value={space} | ||
> | ||
{({ selected, active }) => ( | ||
<> | ||
<span | ||
className={`block truncate ${ | ||
selected ? 'font-medium' : 'font-normal' | ||
}`} | ||
> | ||
{space.name() || space.did()} | ||
</span> | ||
{selected ? ( | ||
<span | ||
className={`absolute inset-y-0 left-0 flex items-center pl-3 ${ | ||
active ? 'text-white' : 'text-teal-600' | ||
}`} | ||
> | ||
<CheckIcon className="h-5 w-5" aria-hidden="true" /> | ||
</span> | ||
) : null} | ||
</> | ||
)} | ||
</Combobox.Option> | ||
)) | ||
)} | ||
</Combobox.Options> | ||
</Transition> | ||
</div> | ||
</Combobox> | ||
</div> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.