-
Notifications
You must be signed in to change notification settings - Fork 531
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(recommend): introduce
FrequentlyBoughtTogether
UI component (#…
…6114) Co-authored-by: Dhaya <[email protected]> Co-authored-by: Aymeric Giraudet <[email protected]> Co-authored-by: Sarah Dayan <[email protected]>
- Loading branch information
1 parent
a5a87dd
commit 7d78f63
Showing
12 changed files
with
600 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ scripts/*/CHANGELOG.md | |
# private files | ||
.env | ||
.idea/ | ||
.vscode/ | ||
|
||
# Caches | ||
.eslintcache | ||
|
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
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
85 changes: 85 additions & 0 deletions
85
packages/instantsearch-ui-components/src/components/FrequentlyBoughtTogether.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,85 @@ | ||
/** @jsx createElement */ | ||
|
||
import { cx } from '../lib'; | ||
|
||
import { createDefaultHeaderComponent } from './recommend-shared/DefaultHeader'; | ||
import { createListViewComponent } from './recommend-shared/ListView'; | ||
|
||
import type { | ||
RecommendTranslations, | ||
Renderer, | ||
ComponentProps, | ||
RecommendComponentProps, | ||
} from '../types'; | ||
|
||
export type FrequentlyBoughtTogetherProps< | ||
TObject, | ||
TComponentProps extends Record<string, unknown> = Record<string, unknown> | ||
> = ComponentProps<'div'> & RecommendComponentProps<TObject, TComponentProps>; | ||
|
||
export function createFrequentlyBoughtTogetherComponent({ | ||
createElement, | ||
Fragment, | ||
}: Renderer) { | ||
return function FrequentlyBoughtTogether<TObject>( | ||
userProps: FrequentlyBoughtTogetherProps<TObject> | ||
) { | ||
const { | ||
classNames = {}, | ||
fallbackComponent: FallbackComponent = () => null, | ||
headerComponent: HeaderComponent = createDefaultHeaderComponent({ | ||
createElement, | ||
Fragment, | ||
}), | ||
itemComponent: ItemComponent, | ||
view: View = createListViewComponent({ createElement, Fragment }), | ||
items, | ||
status, | ||
translations: userTranslations, | ||
sendEvent, | ||
...props | ||
} = userProps; | ||
|
||
const translations: Required<RecommendTranslations> = { | ||
title: 'Frequently bought together', | ||
sliderLabel: 'Frequently bought together products', | ||
...userTranslations, | ||
}; | ||
|
||
if (items.length === 0 && status === 'idle') { | ||
return <FallbackComponent />; | ||
} | ||
|
||
return ( | ||
<section | ||
{...props} | ||
className={cx('ais-FrequentlyBoughtTogether', classNames.root)} | ||
> | ||
<HeaderComponent | ||
classNames={{ | ||
...classNames, | ||
title: cx('ais-FrequentlyBoughtTogether-title', classNames.title), | ||
}} | ||
recommendations={items} | ||
translations={translations} | ||
/> | ||
|
||
<View | ||
classNames={{ | ||
...classNames, | ||
container: cx( | ||
'ais-FrequentlyBoughtTogether-container', | ||
classNames.container | ||
), | ||
list: cx('ais-FrequentlyBoughtTogether-list', classNames.list), | ||
item: cx('ais-FrequentlyBoughtTogether-item', classNames.item), | ||
}} | ||
translations={translations} | ||
itemComponent={ItemComponent} | ||
items={items} | ||
sendEvent={sendEvent} | ||
/> | ||
</section> | ||
); | ||
}; | ||
} |
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
Oops, something went wrong.