-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathhorizontal-suggestions.jsx
More file actions
68 lines (61 loc) · 2.73 KB
/
horizontal-suggestions.jsx
File metadata and controls
68 lines (61 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import React from 'react'
import PropTypes from 'prop-types'
import {Text, Box, Flex, AspectRatio} from '@salesforce/retail-react-app/app/components/shared/ui'
import DynamicImage from '@salesforce/retail-react-app/app/components/dynamic-image'
import Link from '@salesforce/retail-react-app/app/components/link'
import {useStyleConfig} from '@chakra-ui/react'
const HorizontalSuggestions = ({suggestions, closeAndNavigate, dynamicImageProps}) => {
const styles = useStyleConfig('HorizontalSuggestions')
if (!suggestions) {
return null
}
return (
<Box data-testid="sf-horizontal-product-suggestions" sx={styles.container}>
<Flex sx={styles.flexContainer}>
{suggestions.map((suggestion, idx) => (
<Link
data-testid="product-tile"
to={suggestion.link}
key={idx}
onClick={() => closeAndNavigate(suggestion.link)}
>
<Box sx={styles.suggestionItem}>
{/* Product Image */}
<Box sx={styles.imageContainer}>
{suggestion.image ? (
<AspectRatio sx={styles.aspectRatio}>
<DynamicImage
src={`${suggestion.image}[?sw={width}&q=60]`}
widths={dynamicImageProps?.widths}
sx={styles.dynamicImage}
imageProps={{
alt: '',
loading: 'eager'
}}
/>
</AspectRatio>
) : null}
</Box>
<Text sx={styles.productName}>{suggestion.name}</Text>
{suggestion.price && (
<Text sx={styles.productPrice}>${suggestion.price}</Text>
)}
</Box>
</Link>
))}
</Flex>
</Box>
)
}
HorizontalSuggestions.propTypes = {
suggestions: PropTypes.array,
closeAndNavigate: PropTypes.func,
dynamicImageProps: PropTypes.object
}
export default HorizontalSuggestions