-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mespapiers): Add RotateImage component
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/cozy-mespapiers-lib/src/components/ModelSteps/widgets/RotateImage.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,39 @@ | ||
import PropTypes from 'prop-types' | ||
import React, { forwardRef } from 'react' | ||
|
||
import { useRotatedImage } from '../../Hooks/useRotatedImage' | ||
|
||
const RotateImage = forwardRef( | ||
({ image, onLoaded, rotation, a11n, ...props }, ref) => { | ||
const src = useRotatedImage(image, rotation) ?? {} | ||
|
||
return ( | ||
<img | ||
ref={ref} | ||
onLoad={onLoaded} | ||
src={src} | ||
style={{ maxWidth: '100%', maxHeight: 'inherit' }} | ||
{...a11n} | ||
{...props} | ||
/> | ||
) | ||
} | ||
) | ||
RotateImage.displayName = 'RotateImage' | ||
|
||
RotateImage.propTypes = { | ||
image: PropTypes.string, | ||
onLoaded: PropTypes.func, | ||
rotation: PropTypes.number, | ||
alt: PropTypes.string, | ||
a11n: PropTypes.object | ||
} | ||
|
||
RotateImage.defaultProps = { | ||
onLoaded: () => {}, | ||
rotation: 0, | ||
alt: '', | ||
a11n: {} | ||
} | ||
|
||
export default RotateImage |