From 3c83d51110adf204b7ff57a35c15b687417ca1d2 Mon Sep 17 00:00:00 2001 From: wil Date: Wed, 3 Apr 2024 13:45:33 -0400 Subject: [PATCH] even better list dropdowns --- app/components/ListDropdown.tsx | 6 +- app/components/ListSearchDropdown.tsx | 89 +++++++++++++++++++ app/components/index.tsx | 2 + .../comps/DialogueTTS/DialogueTTS.tsx | 3 +- app/routes/ComponentLibrary.tsx | 19 +++- 5 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 app/components/ListSearchDropdown.tsx diff --git a/app/components/ListDropdown.tsx b/app/components/ListDropdown.tsx index 2a0661e99f..5bb2af5fc3 100644 --- a/app/components/ListDropdown.tsx +++ b/app/components/ListDropdown.tsx @@ -27,13 +27,13 @@ export const ListDropdown = ({ leaveFrom="opacity-100" leaveTo="opacity-0" > - + {list.map((item, itemIdx) => ( `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]} {selected ? ( - + ) : null} diff --git a/app/components/ListSearchDropdown.tsx b/app/components/ListSearchDropdown.tsx new file mode 100644 index 0000000000..cf2756c238 --- /dev/null +++ b/app/components/ListSearchDropdown.tsx @@ -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 ( + +
+
+ Object.values(item)[0]} + onChange={(event) => setQuery(event.target.value)} + /> + + +
+ setQuery('')} + > + + {filteredList.length === 0 && query !== '' ? ( +
+ Nothing found. +
+ ) : ( + filteredList.map((item, itemIdx) => ( + + `relative cursor-pointer select-none py-2 pl-10 pr-4 ${ + active ? 'text-white' : 'text-gray-400' + }` + } + value={item} + > + {({ selected, active }) => ( + <> + + {Object.values(item)[0]} + + {selected ? ( + + + ) : null} + + )} + + )) + )} +
+
+
+
+ ) +} \ No newline at end of file diff --git a/app/components/index.tsx b/app/components/index.tsx index 6f375b52e6..8a2451ce4b 100644 --- a/app/components/index.tsx +++ b/app/components/index.tsx @@ -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, diff --git a/app/pages/PageEnigma/comps/DialogueTTS/DialogueTTS.tsx b/app/pages/PageEnigma/comps/DialogueTTS/DialogueTTS.tsx index c39cceb105..5f46c5d125 100644 --- a/app/pages/PageEnigma/comps/DialogueTTS/DialogueTTS.tsx +++ b/app/pages/PageEnigma/comps/DialogueTTS/DialogueTTS.tsx @@ -8,6 +8,7 @@ import { H5, Label, ListDropdown, + ListSearchDropdown, TransitionDialogue, Textarea } from "~/components"; @@ -43,7 +44,7 @@ export const DialogueTTS = ()=>{ >
- +
diff --git a/app/routes/ComponentLibrary.tsx b/app/routes/ComponentLibrary.tsx index c0e6719021..d544d4666d 100644 --- a/app/routes/ComponentLibrary.tsx +++ b/app/routes/ComponentLibrary.tsx @@ -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(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 () { Back to /
+
+

List Dropdowns

+ + +
+

Loading Dots

@@ -84,7 +101,7 @@ export default function ComponentLibrary () {
-
+

Loading Bar