📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
redesign multiselet
Blue Mousee8623d1ba515
diff --git a/web/app/ui/MultiSelect.tsx b/web/app/ui/MultiSelect.tsxindex ffe1a666e..9fe72be19 100644--- a/web/app/ui/MultiSelect.tsx+++ b/web/app/ui/MultiSelect.tsx@@ -1,4 +1,3 @@-import { MagnifyingGlassIcon } from '@heroicons/react/24/outline'import { ChevronDownIcon } from '@heroicons/react/24/solid'import cx from 'clsx'import _includes from 'lodash/includes'@@ -32,125 +31,163 @@ const MultiSelect = ({placholder = 'Select...',className,itemExtractor,- searchPlaseholder = 'Search...',onSearch,}: MultiSelectProps) => {- const [selected, setSelected] = useState(false)+ const [isOpen, setIsOpen] = useState(false)+ const [searchValue, setSearchValue] = useState('')const dropdownRef = useRef<HTMLDivElement>(null)+ const inputRef = useRef<HTMLInputElement>(null)useEffect(() => {const handleClickOutside = (event: MouseEvent) => {if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {- setSelected(false)+ setIsOpen(false)+ setSearchValue('')+ if (onSearch) {+ onSearch('')+ }}}- if (selected) {- document.addEventListener('mousedown', handleClickOutside)+ document.addEventListener('mousedown', handleClickOutside)+ return () => document.removeEventListener('mousedown', handleClickOutside)+ }, [onSearch])++ const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {+ const value = e.target.value+ setSearchValue(value)+ if (onSearch) {+ onSearch(value)}+ }++ const handleFocus = () => {+ setIsOpen(true)+ }- return () => {- document.removeEventListener('mousedown', handleClickOutside)+ const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {+ if (e.key === 'Escape') {+ setIsOpen(false)+ setSearchValue('')+ if (onSearch) {+ onSearch('')+ }+ inputRef.current?.blur()}- }, [selected])+ }++ const handleSelectItem = (item: any) => {+ onSelect(item)+ setSearchValue('')+ if (onSearch) {+ onSearch('')+ }+ }return (- <div ref={dropdownRef} className={cx('relative flex w-full flex-col items-center', className)}>- <div className='w-full'>- <div className='relative flex flex-col items-center'>- <div- className='w-full cursor-pointer'- onClick={() => {- setSelected(!selected)- }}- >- <div className='relative w-full rounded-md border border-gray-300 bg-white py-2 pr-10 pl-3 text-left font-medium hover:bg-gray-50 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:ring-offset-gray-100 focus:outline-hidden sm:text-sm dark:border-gray-800 dark:bg-slate-800 dark:text-gray-50 dark:hover:bg-slate-700'>- <div className='flex flex-auto flex-wrap gap-1'>- {!_isEmpty(label) ? (- _map(label, (item) => (- <div- key={keyExtractor ? keyExtractor(item) : item}- className='inline-flex items-center gap-1 rounded-md bg-indigo-100 px-2 py-1 text-xs font-medium text-indigo-700 dark:bg-slate-600 dark:text-gray-50'+ <div ref={dropdownRef} className={cx('relative flex w-full flex-col', className)}>+ {/* Search input as the dropdown trigger */}+ <div className='relative'>+ <input+ ref={inputRef}+ type='text'+ className='w-full cursor-text rounded-md border border-gray-300 bg-white py-2 pr-8 pl-3 text-sm transition-colors placeholder:text-gray-400 focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 focus:outline-hidden dark:border-gray-700 dark:bg-slate-800 dark:text-gray-50 dark:placeholder:text-gray-500'+ placeholder={placholder}+ value={searchValue}+ onChange={handleInputChange}+ onFocus={handleFocus}+ onKeyDown={handleKeyDown}+ />+ <span className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2'>+ <ChevronDownIcon+ className={cx('h-5 w-5 text-gray-400 transition-transform', {+ 'rotate-180': isOpen,+ })}+ aria-hidden='true'+ />+ </span>++ {/* Dropdown menu */}+ {isOpen ? (+ <div className='absolute top-full z-50 mt-1 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-sm shadow-lg ring-1 ring-black/10 focus:outline-hidden dark:bg-slate-800'>+ {/* Options list */}+ <div className='px-1'>+ {_isEmpty(items) ? (+ <div className='px-3 py-2 text-gray-500 dark:text-gray-400'>No options available</div>+ ) : (+ _map(items, (item) => {+ const isSelected = _includes(label, item)+ return (+ <button+ type='button'+ key={keyExtractor ? `${keyExtractor(item)}select` : `${item}select`}+ onClick={() => handleSelectItem(item)}+ className={cx(+ 'relative flex w-full cursor-pointer items-center gap-2 rounded-md py-2 pr-4 pl-3 text-left text-sm transition-colors select-none',+ {+ 'bg-indigo-50 dark:bg-indigo-900/30': isSelected,+ 'hover:bg-gray-100 dark:hover:bg-slate-700': !isSelected,+ 'text-gray-900 dark:text-white': isSelected,+ 'text-gray-700 dark:text-gray-50': !isSelected,+ },+ )}>- <div className='flex items-center gap-1 whitespace-nowrap'>- {labelExtractor ? labelExtractor(item) : item}- </div>- <button- type='button'- onClick={(e) => {- e.preventDefault()- e.stopPropagation()- onRemove(item)- }}- className='inline-flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-full text-indigo-400 hover:bg-indigo-200 hover:text-indigo-500 focus:bg-indigo-500 focus:text-white focus:outline-hidden dark:text-gray-300 dark:hover:bg-slate-500 dark:hover:text-gray-100'- >- <span className='sr-only'>Remove</span>- <svg className='h-2 w-2' stroke='currentColor' fill='none' viewBox='0 0 8 8'>- <path strokeLinecap='round' strokeWidth='1.5' d='m1 1 6 6m0-6-6 6' />- </svg>- </button>- </div>- ))- ) : (- <span className='block truncate text-gray-500 dark:text-gray-400'>{placholder}</span>- )}- </div>- <div className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2'>- <ChevronDownIcon- className={cx('h-5 w-5 transform-gpu text-gray-400 transition-transform', {- 'rotate-180': selected,- })}- aria-hidden='true'- />- </div>- </div>- </div>- {selected ? (- <div className='absolute z-50 mt-1 max-h-60 w-full min-w-max overflow-auto rounded-md bg-gray-50 py-1 text-base ring-1 ring-black/10 focus:outline-hidden sm:text-sm dark:bg-slate-800'>- <div className='flex w-full flex-col'>- {onSearch ? (- <div className='relative mx-1 mb-1'>- <input- className='w-full rounded-md border border-gray-300 bg-white py-2 pr-10 pl-3 text-sm focus:border-indigo-500 focus:ring-1 focus:ring-indigo-500 focus:outline-hidden dark:border-gray-600 dark:bg-slate-700 dark:text-gray-50'- placeholder={searchPlaseholder}- onChange={(e) => {- e.preventDefault()- e.stopPropagation()- onSearch(e.target.value || '')- }}- type='text'- />- <div className='pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3'>- <MagnifyingGlassIcon className='h-4 w-4 text-gray-400' aria-hidden='true' />- </div>- </div>- ) : null}- {_map(items, (item) => (- <div- key={keyExtractor ? `${keyExtractor(item)}select` : `${item}select`}- onClick={() => onSelect(item)}- className={cx('relative mx-1 cursor-pointer rounded-md py-2 pr-4 pl-3 text-sm select-none', {- 'bg-gray-300 dark:bg-slate-600': _includes(label, item),- 'hover:bg-gray-200 dark:hover:bg-slate-700': !_includes(label, item),- 'text-gray-900 dark:text-white': _includes(label, item),- 'text-gray-700 dark:text-gray-50': !_includes(label, item),- })}- >- <div className='flex w-full items-center gap-2 whitespace-nowrap'>- <div className='flex min-w-0 flex-1 items-center gap-2'>+ <span className='flex min-w-0 flex-1 items-center gap-2'>{itemExtractor ? itemExtractor(item) : item}- </div>- {_includes(label, item) ? (- <span className='h-2 w-2 flex-shrink-0 rounded-full bg-indigo-600 dark:bg-indigo-400' />+ </span>+ {isSelected ? (+ <span className='ml-auto flex h-4 w-4 shrink-0 items-center justify-center'>+ <svg+ className='h-4 w-4 text-indigo-600 dark:text-indigo-400'+ viewBox='0 0 20 20'+ fill='currentColor'+ >+ <path+ fillRule='evenodd'+ d='M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z'+ clipRule='evenodd'+ />+ </svg>+ </span>) : null}- </div>- </div>- ))}- </div>+ </button>+ )+ })+ )}</div>- ) : null}- </div>+ </div>+ ) : null}</div>++ {/* Selected items displayed below the selector */}+ {!_isEmpty(label) ? (+ <div className='mt-2 flex flex-wrap gap-2'>+ {_map(label, (item) => (+ <span+ key={keyExtractor ? keyExtractor(item) : item}+ className='inline-flex items-center gap-1.5 rounded-md bg-gray-100 py-1.5 pr-2 pl-2.5 text-sm font-medium text-gray-700 dark:bg-slate-700 dark:text-gray-200'+ >+ <span className='flex items-center gap-1.5'>{labelExtractor ? labelExtractor(item) : item}</span>+ <button+ type='button'+ onClick={(e) => {+ e.preventDefault()+ e.stopPropagation()+ onRemove(item)+ }}+ className='inline-flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-gray-400 hover:bg-gray-200 hover:text-gray-600 focus:bg-gray-300 focus:text-gray-700 focus:outline-hidden dark:text-gray-400 dark:hover:bg-slate-600 dark:hover:text-gray-200'+ >+ <span className='sr-only'>Remove</span>+ <svg className='h-2.5 w-2.5' stroke='currentColor' fill='none' viewBox='0 0 8 8'>+ <path strokeLinecap='round' strokeWidth='1.5' d='m1 1 6 6m0-6-6 6' />+ </svg>+ </button>+ </span>+ ))}+ </div>+ ) : null}++ {/* Hint text */}{hint ? <p className='mt-2 text-sm whitespace-pre-line text-gray-500 dark:text-gray-300'>{hint}</p> : null}</div>)