-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Shopper Experience]
ImageTile
component (#967)
* Initial `ImageAndText` component * Rename to `ImageTile` component * Add basic test * PR Feedback * Update JSDocs * Update test * Restore `zzrf-001` config in test project * PR Feedback * Update JSDoc * Cleanup
- Loading branch information
Showing
6 changed files
with
95 additions
and
11 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
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
51 changes: 51 additions & 0 deletions
51
packages/template-retail-react-app/app/components/experience/image-tile/index.jsx
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,51 @@ | ||
/* | ||
* Copyright (c) 2023, Salesforce, 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 {Image} from '@chakra-ui/react' | ||
|
||
/** | ||
* Simple ImageTile component that can be used inside any Layout component. | ||
* @param image Object containing the image url, _type and focalPoint. | ||
* @returns {JSX.Element} | ||
*/ | ||
const ImageTile = ({image}) => { | ||
return ( | ||
<div className={'image-tile'}> | ||
<figure className={'image-tile-figure'}> | ||
<picture> | ||
<source srcSet={image?.src?.tablet} media="(min-width: 48em)" /> | ||
<source srcSet={image?.src?.desktop} media="(min-width: 64em)" /> | ||
<Image | ||
className={'image-tile-image'} | ||
data-testid={'image-tile-image'} | ||
src={image?.src?.mobile ? image?.src?.mobile : image?.url} | ||
ignoreFallback={true} | ||
alt={image?.alt} | ||
title={image?.alt} | ||
/> | ||
</picture> | ||
</figure> | ||
</div> | ||
) | ||
} | ||
|
||
ImageTile.propTypes = { | ||
image: PropTypes.shape({ | ||
_type: PropTypes.string, | ||
focalPoint: PropTypes.shape({ | ||
_type: PropTypes.string, | ||
x: PropTypes.number, | ||
y: PropTypes.number | ||
}), | ||
url: PropTypes.string, | ||
alt: PropTypes.string, | ||
src: PropTypes.string || PropTypes.object | ||
}) | ||
} | ||
|
||
export default ImageTile |
30 changes: 30 additions & 0 deletions
30
packages/template-retail-react-app/app/components/experience/image-tile/index.test.js
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,30 @@ | ||
/* | ||
* Copyright (c) 2023, 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 {renderWithProviders} from '../../../utils/test-utils' | ||
import ImageTile from './index' | ||
import {getAssetUrl} from 'pwa-kit-react-sdk/ssr/universal/utils' | ||
|
||
test('ImageTile renders without errors', () => { | ||
const {getByTestId} = renderWithProviders( | ||
<ImageTile | ||
image={{ | ||
_type: 'Image', | ||
focalPoint: { | ||
_type: 'Imagefocalpoint', | ||
x: 0.5, | ||
y: 0.5 | ||
}, | ||
url: `${getAssetUrl('static/img/hero.png')}` | ||
}} | ||
/> | ||
) | ||
|
||
const image = getByTestId('image-tile-image') | ||
|
||
expect(image).toHaveAttribute('src', `${getAssetUrl('static/img/hero.png')}`) | ||
}) |
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