@@ -2,6 +2,7 @@ import React, { useMemo, useState, useRef } from "react"
22import styled from "styled-components"
33import { useVirtualizer } from "@tanstack/react-virtual"
44import Flex from "@/components/templates/flex"
5+ import { Text } from "@/components/typography"
56import Search from "@/components/search"
67import Box from "@/components/templates/box"
78import { mergeRefs } from "@/utils"
@@ -15,6 +16,14 @@ const Container = styled(Flex)`
1516
1617const defaultEstimateSize = ( ) => 28
1718
19+ const DefaultNoSearchResultsComponent = ( ) => {
20+ return (
21+ < Flex padding = { [ 2 , 0 ] } justifyContent = "center" >
22+ < Text > No results were found</ Text >
23+ </ Flex >
24+ )
25+ }
26+
1827const Dropdown = ( {
1928 hideShadow,
2029 itemProps,
@@ -26,12 +35,15 @@ const Dropdown = ({
2635 Footer,
2736 value,
2837 hasSearch,
38+ renderComponent,
2939 searchMargin = [ 4 ] ,
3040 gap = 0 ,
3141 estimateSize = defaultEstimateSize ,
3242 close,
3343 containerRef,
3444 ref : forwardedRef ,
45+ showNoSearchResults = true ,
46+ NoSearchResultsComponent = DefaultNoSearchResultsComponent ,
3547 ...rest
3648} ) => {
3749 const [ searchValue , setSearchValue ] = useState ( "" )
@@ -41,7 +53,9 @@ const Dropdown = ({
4153
4254 const searchLowerCase = searchValue . toLowerCase ( )
4355
44- return items . filter ( ( { label, value : val } ) => {
56+ return items . filter ( ( { label, value : val , customFiltering } ) => {
57+ if ( typeof customFiltering === "function" )
58+ return customFiltering ( { searchValue, label, value : val } )
4559 if ( typeof label === "string" && label . toLowerCase ( ) . includes ( searchLowerCase ) ) return true
4660 if ( ! label && typeof val === "string" && val . toLowerCase ( ) . includes ( searchLowerCase ) )
4761 return true
@@ -80,6 +94,10 @@ const Dropdown = ({
8094 < Search data-testid = "dropdown-search" placeholder = "Search" onChange = { setSearchValue } />
8195 </ Box >
8296 ) }
97+ { typeof renderComponent === "function" && renderComponent ( { searchValue, filteredItems } ) }
98+ { showNoSearchResults && filteredItems . length === 0 && searchValue ? (
99+ < NoSearchResultsComponent />
100+ ) : null }
83101 < div
84102 ref = { mergeRefs ( ref , forwardedRef ) }
85103 style = { {
0 commit comments