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

-22
View File
@@ -1,22 +0,0 @@
import React from 'react'
import { Image } from './Image'
export const CollectiveImage = (props) => (
<div
style={props.style}
>
<Image
src={props.data.src}
alt={props.data.alt}
set={props.data.set}
opa={false}
style={{
marginBottom: 'var(--double-margin)',
}}
imgStyle={{
width: '100%',
borderRadius: 'var(--radius)',
}}
/>
</div>
)
+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>
)
})
+7
View File
@@ -0,0 +1,7 @@
.image {
display: block;
}
.image img {
display: block;
}