diff --git a/components/badges/actions/Combobox.hooks.ts b/components/badges/actions/Combobox.hooks.ts new file mode 100644 index 0000000..98ad95e --- /dev/null +++ b/components/badges/actions/Combobox.hooks.ts @@ -0,0 +1,8 @@ +import { useState } from 'react' + +import type { ActionListItem } from './actions' + +export const useActionsComboboxState = () => { + const [value, setValue] = useState(null) + return { value, onChange: (item: ActionListItem) => setValue(item) } +} diff --git a/components/badges/actions/Combobox.tsx b/components/badges/actions/Combobox.tsx new file mode 100644 index 0000000..452b2a6 --- /dev/null +++ b/components/badges/actions/Combobox.tsx @@ -0,0 +1,106 @@ +import { Combobox, Transition } from '@headlessui/react' +import clsx from 'clsx' +import { FormControl } from 'components/FormControl' +import { matchSorter } from 'match-sorter' +import { Fragment, useEffect, useState } from 'react' +import { FaChevronDown, FaInfoCircle } from 'react-icons/fa' + +import type { MintRule } from '../creation/ImageUploadDetails' +import type { ActionListItem } from './actions' +import { BY_KEY_ACTION_LIST, BY_KEYS_ACTION_LIST, BY_MINTER_ACTION_LIST } from './actions' + +export interface ActionsComboboxProps { + value: ActionListItem | null + onChange: (item: ActionListItem) => void + mintRule?: MintRule +} + +export const ActionsCombobox = ({ value, onChange, mintRule }: ActionsComboboxProps) => { + const [search, setSearch] = useState('') + const [ACTION_LIST, SET_ACTION_LIST] = useState(BY_KEY_ACTION_LIST) + + useEffect(() => { + if (mintRule === 'by_keys') { + SET_ACTION_LIST(BY_KEYS_ACTION_LIST) + } else if (mintRule === 'by_minter') { + SET_ACTION_LIST(BY_MINTER_ACTION_LIST) + } else { + SET_ACTION_LIST(BY_KEY_ACTION_LIST) + } + }, [mintRule]) + + const filtered = + search === '' ? ACTION_LIST : matchSorter(ACTION_LIST, search, { keys: ['id', 'name', 'description'] }) + + return ( + +
+ val?.name ?? ''} + id="message-type" + onChange={(event) => setSearch(event.target.value)} + placeholder="Select action" + /> + + + {({ open }) => + + setSearch('')} as={Fragment}> + + {filtered.length < 1 && ( + + Action not found + + )} + {filtered.map((entry) => ( + + clsx('flex relative flex-col py-2 px-4 space-y-1 cursor-pointer', { 'bg-stargaze-80': active }) + } + value={entry} + > + {entry.name} + {entry.description} + + ))} + + +
+ + {value && ( +
+
+ +
+ {value.description} +
+ )} +
+ ) +}