11import { Popover , Transition } from '@headlessui/react'
22import classNames from 'classnames'
3- import React , { ReactNode , useRef } from 'react'
3+ import React , { ReactNode , useRef , useEffect } from 'react'
44import { ChevronDownIcon } from '@heroicons/react/20/solid'
55import { popover , BlurMenuButtonOnEscape } from './popover'
66import { useSearchableItems } from '../hooks/use-searchable-items'
@@ -16,7 +16,7 @@ export const TabWrapper = ({
1616} ) => (
1717 < div
1818 className = { classNames (
19- 'flex text-xs font-medium text-gray-500 dark:text-gray-400 space-x-2 items-baseline ' ,
19+ 'flex items-baseline gap-x-3 text-xs font-medium text-gray-500 dark:text-gray-400' ,
2020 className
2121 ) }
2222 >
@@ -32,12 +32,15 @@ const TabButtonText = ({
3232 active : boolean
3333} ) => (
3434 < span
35- className = { classNames ( 'truncate text-left transition-colors duration-150' , {
36- 'hover:text-indigo-700 dark:hover:text-indigo-400 cursor-pointer' :
37- ! active ,
38- 'text-indigo-600 dark:text-indigo-500 font-bold underline decoration-2 decoration-indigo-600 dark:decoration-indigo-500' :
39- active
40- } ) }
35+ className = { classNames (
36+ '-mb-px pb-4 truncate text-left text-xs font-semibold uppercase transition-colors duration-150' ,
37+ {
38+ 'text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 cursor-pointer' :
39+ ! active ,
40+ 'border-b-2 border-gray-900 dark:border-gray-100 text-gray-900 dark:text-gray-100' :
41+ active
42+ }
43+ ) }
4144 >
4245 { children }
4346 </ span >
@@ -54,7 +57,10 @@ export const TabButton = ({
5457 onClick : ( ) => void
5558 active : boolean
5659} ) => (
57- < button className = { classNames ( 'rounded-sm' , className ) } onClick = { onClick } >
60+ < button
61+ className = { classNames ( 'flex rounded-sm' , className ) }
62+ onClick = { onClick }
63+ >
5864 < TabButtonText active = { active } > { children } </ TabButtonText >
5965 </ button >
6066)
@@ -84,19 +90,16 @@ export const DropdownTabButton = ({
8490 >
8591 < TabButtonText active = { active } > { children } </ TabButtonText >
8692
87- < div
88- className = "flex self-stretch -mr-1 ml-1 items-center"
89- aria-hidden = "true"
90- >
91- < ChevronDownIcon className = "h-4 w-4" />
93+ < div className = "ml-1 pb-4" aria-hidden = "true" >
94+ < ChevronDownIcon className = "size-4" />
9295 </ div >
9396 </ Popover . Button >
9497
9598 < Transition
9699 as = "div"
97100 { ...popover . transition . props }
98101 className = { classNames (
99- popover . transition . classNames . fullwidth ,
102+ popover . transition . classNames . left ,
100103 'mt-2' ,
101104 transitionClassName
102105 ) }
@@ -115,15 +118,9 @@ type ItemsProps = {
115118 closeDropdown : ( ) => void
116119 options : Array < { selected : boolean ; onClick : ( ) => void ; label : string } >
117120 searchable ?: boolean
118- collectionTitle ?: string
119121}
120122
121- const Items = ( {
122- options,
123- searchable,
124- collectionTitle,
125- closeDropdown
126- } : ItemsProps ) => {
123+ const Items = ( { options, searchable, closeDropdown } : ItemsProps ) => {
127124 const {
128125 filteredData,
129126 showableData,
@@ -136,7 +133,7 @@ const Items = ({
136133 countOfMoreToShow
137134 } = useSearchableItems ( {
138135 data : options ,
139- maxItemsInitially : searchable ? 5 : options . length ,
136+ maxItemsInitially : searchable ? 10 : options . length ,
140137 itemMatchesSearchValue : ( option , trimmedSearchString ) =>
141138 option . label . toLowerCase ( ) . includes ( trimmedSearchString . toLowerCase ( ) )
142139 } )
@@ -148,24 +145,32 @@ const Items = ({
148145 popover . items . classNames . hoverLink
149146 )
150147
148+ useEffect ( ( ) => {
149+ if ( searchable && showSearch && searchRef . current ) {
150+ const timeoutId = setTimeout ( ( ) => {
151+ searchRef . current ?. focus ( )
152+ } , 100 )
153+ return ( ) => clearTimeout ( timeoutId )
154+ }
155+ } , [ searchable , showSearch , searchRef ] )
156+
151157 return (
152158 < >
153159 { searchable && showSearch && (
154- < div className = "flex items-center py-2 px-4" >
155- { collectionTitle && (
156- < div className = "text-sm font-bold uppercase text-indigo-500 dark:text-indigo-400 mr-4" >
157- { collectionTitle }
158- </ div >
159- ) }
160+ < div className = "flex items-center p-1" >
160161 < SearchInput
161162 searchRef = { searchRef }
162163 placeholderUnfocused = "Press / to search"
163- className = "ml-auto w-full py-1 "
164+ className = "w-full !max-w-none "
164165 onSearch = { handleSearchInput }
165166 />
166167 </ div >
167168 ) }
168- < div className = { 'max-h-[210px] overflow-y-scroll' } >
169+ < div
170+ className = {
171+ 'max-h-[224px] overflow-y-scroll flex flex-col gap-y-0.5 p-1'
172+ }
173+ >
169174 { showableData . map ( ( { selected, label, onClick } , index ) => {
170175 return (
171176 < button
@@ -177,7 +182,7 @@ const Items = ({
177182 data-selected = { selected }
178183 className = { itemClassName }
179184 >
180- { label }
185+ < span className = "line-clamp-1" > { label } </ span >
181186 </ button >
182187 )
183188 } ) }
@@ -186,7 +191,7 @@ const Items = ({
186191 onClick = { handleShowAll }
187192 className = { classNames (
188193 itemClassName ,
189- 'w-full text-left font-bold hover:text-indigo-700 dark:hover:text-indigo-500 '
194+ 'w-full text-left text-gray-500 dark:text-gray-400 hover:text-gray-800 dark:hover:text-gray-200 '
190195 ) }
191196 >
192197 { `Show ${ countOfMoreToShow } more` }
@@ -197,11 +202,14 @@ const Items = ({
197202 < button
198203 className = { classNames (
199204 itemClassName ,
200- 'w-full text-left font-bold hover:text-indigo-700 dark:hover:text-indigo-500 '
205+ 'w-full text-left !justify-start '
201206 ) }
202207 onClick = { handleClearSearch }
203208 >
204- No items found. Clear search to show all.
209+ No items found.{ ' ' }
210+ < span className = "ml-1 text-indigo-600 dark:text-indigo-400 hover:text-indigo-700 dark:hover:text-indigo-500" >
211+ Click to clear search.
212+ </ span >
205213 </ button >
206214 ) }
207215 </ div >
0 commit comments