mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
even better list dropdowns
This commit is contained in:
1 parent
6feef930b9
commit
3c83d51110
5 files changed
+114
-5
No files matched your search
@@ -27,13 +27,13 @@ export const ListDropdown = ({
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<Listbox.Options className="absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-brand-secondary py-1 text-base shadow-lg focus:outline-none sm:text-sm">
|
||||
<Listbox.Options className="absolute mt-1 max-h-60 w-full overflow-auto rounded-md bg-brand-secondary py-1 text-base shadow-lg focus:outline-none sm:text-sm z-10">
|
||||
{list.map((item, itemIdx) => (
|
||||
<Listbox.Option
|
||||
key={itemIdx}
|
||||
className={({ active }) =>
|
||||
`relative cursor-pointer select-none py-2 pl-10 pr-4 text-white ${
|
||||
active ? 'bg-brand-secondary-400' : ''
|
||||
active ? 'text-white' : 'text-gray-400'
|
||||
}`
|
||||
}
|
||||
value={item}
|
||||
@@ -48,7 +48,7 @@ export const ListDropdown = ({
|
||||
{Object.values(item)[0]}
|
||||
</span>
|
||||
{selected ? (
|
||||
<span className="absolute inset-y-0 left-0 flex items-center pl-3 text-amber-600">
|
||||
<span className="absolute inset-y-0 left-0 flex items-center pl-3">
|
||||
<FontAwesomeIcon icon={faCheck} aria-hidden="true"/>
|
||||
</span>
|
||||
) : null}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import { Fragment, useState } from 'react'
|
||||
import { Combobox, Transition } from '@headlessui/react'
|
||||
import { faCheck, faChevronDown } from '@fortawesome/pro-solid-svg-icons'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
|
||||
interface ListDropdownProps {
|
||||
list: {[key: string] : string}[];
|
||||
}
|
||||
export const ListSearchDropdown = ({
|
||||
list
|
||||
}:ListDropdownProps) => {
|
||||
const [selected, setSelected] = useState(list[0])
|
||||
const [query, setQuery] = useState('')
|
||||
|
||||
const filteredList =
|
||||
query === ''
|
||||
? list
|
||||
: list.filter((item) =>
|
||||
Object.values(item)[0]
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, '')
|
||||
.includes(query.toLowerCase().replace(/\s+/g, ''))
|
||||
)
|
||||
|
||||
return (
|
||||
<Combobox value={selected} onChange={setSelected}>
|
||||
<div className="relative mt-1">
|
||||
<div className="relative w-full cursor-default overflow-hidden rounded-md text-left shadow-md sm:text-sm">
|
||||
<Combobox.Input
|
||||
className="w-full border-none py-2 pl-3 pr-10 text-sm leading-5 bg-brand-secondary text-white outline-none outline-offset-0 transition-all duration-150 ease-in-out focus:outline-brand-primary"
|
||||
displayValue={(item: {[key: string] : string}) => Object.values(item)[0]}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
<Combobox.Button className="absolute inset-y-0 right-0 flex items-center pr-2">
|
||||
<FontAwesomeIcon icon={faChevronDown} 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-60 w-full overflow-auto rounded-md bg-brand-secondary py-1 text-base shadow-lg focus:outline-none sm:text-sm z-10">
|
||||
{filteredList.length === 0 && query !== '' ? (
|
||||
<div className="relative cursor-default select-none px-4 py-2 text-white">
|
||||
Nothing found.
|
||||
</div>
|
||||
) : (
|
||||
filteredList.map((item, itemIdx) => (
|
||||
<Combobox.Option
|
||||
key={itemIdx}
|
||||
className={({ active }) =>
|
||||
`relative cursor-pointer select-none py-2 pl-10 pr-4 ${
|
||||
active ? 'text-white' : 'text-gray-400'
|
||||
}`
|
||||
}
|
||||
value={item}
|
||||
>
|
||||
{({ selected, active }) => (
|
||||
<>
|
||||
<span
|
||||
className={`block truncate ${
|
||||
selected ? 'font-medium' : 'font-normal'
|
||||
}`}
|
||||
>
|
||||
{Object.values(item)[0]}
|
||||
</span>
|
||||
{selected ? (
|
||||
<span
|
||||
className={`absolute inset-y-0 left-0 flex items-center pl-3 ${
|
||||
active ? 'text-white' : 'text-teal-600'
|
||||
}`}
|
||||
>
|
||||
<FontAwesomeIcon icon={faCheck} aria-hidden="true"/>
|
||||
</span>
|
||||
) : null}
|
||||
</>
|
||||
)}
|
||||
</Combobox.Option>
|
||||
))
|
||||
)}
|
||||
</Combobox.Options>
|
||||
</Transition>
|
||||
</div>
|
||||
</Combobox>
|
||||
)
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { ItemPicker } from "./ItemPicker";
|
||||
import { Textarea } from "./Textarea";
|
||||
import { TransitionDialogue } from "./TransitionDialogue";
|
||||
import { ListDropdown } from "./ListDropdown"
|
||||
import { ListSearchDropdown } from "./ListSearchDropdown"
|
||||
import { LoadingBar } from "./LoadingBar";
|
||||
import { LoadingDots, LoadingDotsBricks, LoadingDotsTyping } from "./LoadingDots";
|
||||
|
||||
@@ -24,6 +25,7 @@ export {
|
||||
Input,
|
||||
InputVector,
|
||||
ListDropdown,
|
||||
ListSearchDropdown,
|
||||
LoadingBar,
|
||||
LoadingDots,
|
||||
LoadingDotsBricks,
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
H5,
|
||||
Label,
|
||||
ListDropdown,
|
||||
ListSearchDropdown,
|
||||
TransitionDialogue,
|
||||
Textarea
|
||||
} from "~/components";
|
||||
@@ -43,7 +44,7 @@ export const DialogueTTS = ()=>{
|
||||
>
|
||||
<div className="flex flex-col">
|
||||
<Label className="mb-1">Select a Voice</Label>
|
||||
<ListDropdown list={testdata}/>
|
||||
<ListSearchDropdown list={testdata}/>
|
||||
|
||||
<div className="flex w-full justify-between mt-4">
|
||||
<Label>What would you like to say?</Label>
|
||||
|
||||
@@ -3,6 +3,8 @@ import {
|
||||
Button,
|
||||
ButtonLink,
|
||||
H1,H2,H3,H4,H5,H6,P,Label,
|
||||
ListDropdown,
|
||||
ListSearchDropdown,
|
||||
LoadingBar,
|
||||
LoadingDotsTyping,
|
||||
LoadingDotsBricks,
|
||||
@@ -13,6 +15,15 @@ export default function ComponentLibrary () {
|
||||
const [progress, setProgress] = useState(0);
|
||||
const loopRef = useRef<NodeJS.Timeout | null>(null);
|
||||
|
||||
const testdata = [
|
||||
{ name: 'Wade Cooper' },
|
||||
{ name: 'Arlene Mccoy' },
|
||||
{ name: 'Devon Webb' },
|
||||
{ name: 'Tom Cook' },
|
||||
{ name: 'Tanya Fox' },
|
||||
{ name: 'Hellen Schmidt' },
|
||||
]
|
||||
|
||||
const pushProgressBar: ()=>void = useCallback(()=>{
|
||||
loopRef.current = setInterval(function timer(){
|
||||
setProgress((curr)=>{
|
||||
@@ -72,6 +83,12 @@ export default function ComponentLibrary () {
|
||||
<ButtonLink to="/">Back to /</ButtonLink>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 mb-4 max-w-2xl">
|
||||
<H4>List Dropdowns</H4>
|
||||
<ListDropdown list={testdata}/>
|
||||
<ListSearchDropdown list={testdata}/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 mb-4">
|
||||
<H4>Loading Dots</H4>
|
||||
<div className="flex gap-2">
|
||||
@@ -84,7 +101,7 @@ export default function ComponentLibrary () {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 mb-4">
|
||||
<div className="flex flex-col gap-2 mb-4 max-w-2xl">
|
||||
<H4>Loading Bar</H4>
|
||||
<div className="flex gap-2 items-center">
|
||||
<LoadingBar
|
||||
|
||||
Reference in new issue
Block a user