collective page images refactoring

This commit is contained in:
tmshv committed 2020-03-03 05:58:35 +03:00
1 parent 087a4b6172
commit a14db0e8da
6 files changed
+68 -66

No files matched your search

+9 -26
View File
@@ -1,40 +1,23 @@
import * as React from 'react'
import cx from 'classnames'
import './styles.css'
import { memo } from 'react'
export interface IImageProps {
export type ImageProps = {
style?: React.CSSProperties
imgStyle?: React.CSSProperties
src: string
alt: string
opa: boolean
set: Array<{
url: string
density: number
}>
alt?: string
srcSet?: string
}
export const Image: React.FC<IImageProps> = React.memo(props => {
const srcSet = props.set
.map(({ url, density }) => `${url} ${density}x`)
.join(' ')
export const Image: React.FC<ImageProps> = memo(props => {
return (
<picture style={props.style}>
<style jsx>{`
picture img {
display: block;
}
`}</style>
<picture className={'image'} style={props.style}>
<img
style={props.imgStyle}
className={cx({
opa: props.opa
})}
alt={props.alt}
src={props.src}
srcSet={srcSet}
srcSet={props.srcSet}
/>
</picture >
</picture>
)
})