Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Added 'hint' prop support

Blue Mouse65b54feb6920
diff --git a/app/ui/Select.tsx b/app/ui/Select.tsx
index 3dd9547bb..71590fa31 100644
--- a/app/ui/Select.tsx
+++ b/app/ui/Select.tsx
@@ -1,12 +1,21 @@
import React, { Fragment, Key, memo } from 'react'
import cx from 'clsx'
-import { Listbox, Transition } from '@headlessui/react'
+import {
+ Listbox,
+ Transition,
+ Description,
+ Label,
+ ListboxButton,
+ ListboxOptions,
+ ListboxOption,
+} from '@headlessui/react'
import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/24/solid'
import _map from 'lodash/map'
interface ISelect<T> {
title?: string
label?: string
+ hint?: string | React.ReactNode
className?: string
labelClassName?: string
buttonClassName?: string
@@ -22,6 +31,7 @@ interface ISelect<T> {
function Select<T>({
title,
label,
+ hint,
className,
items = [],
labelExtractor,
@@ -34,15 +44,15 @@ function Select<T>({
labelClassName,
}: ISelect<T>): React.ReactNode {
return (
- // @ts-ignore
+ // @ts-expect-error
<Listbox id={id || ''} value={title} onChange={onSelect}>
{({ open }) => (
<>
- <Listbox.Label className='block whitespace-pre-line text-sm font-medium text-gray-700 dark:text-gray-100'>
+ <Label className='block whitespace-pre-line text-sm font-medium text-gray-700 dark:text-gray-100'>
{label}
- </Listbox.Label>
+ </Label>
<div className={cx('relative mt-1', className)}>
- <Listbox.Button
+ <ListboxButton
className={cx(
'relative w-full cursor-default rounded-md border border-gray-300 bg-white py-2 pl-3 pr-10 text-left shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 dark:border-gray-800 dark:bg-slate-800 dark:text-gray-50 sm:text-sm',
buttonClassName,
@@ -58,7 +68,7 @@ function Select<T>({
<span className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2'>
<ChevronUpDownIcon className='h-5 w-5 text-gray-400' aria-hidden='true' />
</span>
- </Listbox.Button>
+ </ListboxButton>
<Transition
show={open}
@@ -67,12 +77,12 @@ function Select<T>({
leaveFrom='opacity-100'
leaveTo='opacity-0'
>
- <Listbox.Options
+ <ListboxOptions
static
className='absolute z-10 mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none dark:bg-slate-800 sm:text-sm'
>
{_map(items, (item, index) => (
- <Listbox.Option
+ <ListboxOption
key={keyExtractor ? keyExtractor(item, index) : (item as Key)}
className={({ active }) =>
cx('relative cursor-default select-none py-2 pl-8 pr-4 dark:text-white', {
@@ -116,11 +126,16 @@ function Select<T>({
)}
</>
)}
- </Listbox.Option>
+ </ListboxOption>
))}
- </Listbox.Options>
+ </ListboxOptions>
</Transition>
</div>
+ {hint && (
+ <Description className='mt-2 whitespace-pre-line text-sm text-gray-500 dark:text-gray-300'>
+ {hint}
+ </Description>
+ )}
</>
)}
</Listbox>