-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Split searchbox into several compound components
- Loading branch information
Showing
16 changed files
with
651 additions
and
766 deletions.
There are no files selected for viewing
312 changes: 0 additions & 312 deletions
312
src/components/pagination/__snapshots__/pagination.spec.tsx.snap
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
src/components/search-box/components/attribute-suggestions.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import clsx from 'clsx'; | ||
import Highlighter from 'react-highlight-words'; | ||
import { AttributeSuggestionsProps } from '../search-box.types'; | ||
import { SuggestResponseAttributeSuggestions } from '@bloomreach/discovery-web-sdk'; | ||
import { FloatingUIContext } from '../../../contexts'; | ||
import { useContext } from 'react'; | ||
|
||
export const AttributeSuggestions = (props: AttributeSuggestionsProps) => { | ||
const { inputValue, group, classNames, labels, onAttributeSelect, offset } = props; | ||
|
||
const floatingUIContext = useContext(FloatingUIContext); | ||
|
||
if (!floatingUIContext) { | ||
throw new Error('Floating UI Provider is not provided'); | ||
} | ||
|
||
const attributeItemProps = ( | ||
index: number, | ||
offset: number, | ||
query: SuggestResponseAttributeSuggestions, | ||
) => { | ||
const { getItemProps, listRef, handleAttributeSelect } = floatingUIContext; | ||
|
||
return getItemProps({ | ||
ref(node) { | ||
listRef.current[index + offset] = node; | ||
}, | ||
onClick(event) { | ||
handleAttributeSelect(); | ||
onAttributeSelect?.(query, event); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div | ||
className={clsx( | ||
'lui-suggestions-category', | ||
'lui-suggestions-attribute-suggestions', | ||
classNames?.attributeSuggestions, | ||
)} | ||
> | ||
<h1>{labels?.attributeSuggestions ?? 'Brand Suggestions'}</h1> | ||
<ul> | ||
{group.map((attribute, index) => ( | ||
<li | ||
className={clsx( | ||
'lui-suggestions-item', | ||
'lui-suggestions-attribute-suggestion', | ||
classNames?.attributeSuggestion, | ||
)} | ||
key={attribute.name} | ||
{...attributeItemProps(index, offset, attribute)} | ||
> | ||
<Highlighter | ||
highlightClassName="lui-suggestions-highlight" | ||
searchWords={[inputValue]} | ||
textToHighlight={attribute.name} | ||
/> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.