Skip to content

Commit b483aa5

Browse files
author
Juli Ovechkina
authored
Merge pull request #40 from gravity-ui/berdysheva/mobile-support-background-media
feat(BackgroundMedia): add device support
2 parents 083e643 + 8501fc4 commit b483aa5

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

src/components/BackgroundMedia/__stories__/BackgroundMedia.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const DefaultTemplate: Story<FullProps> = (args) => (
2525
export const Image = DefaultTemplate.bind({});
2626
export const ImageSlider = DefaultTemplate.bind({});
2727
export const Video = DefaultTemplate.bind({});
28+
export const DeviceSupport = DefaultTemplate.bind({});
2829

2930
Image.args = data.image.content;
3031
ImageSlider.args = data.imageSlider.content;
3132
Video.args = data.video.content;
33+
DeviceSupport.args = data.deviceSupport.content;

src/components/BackgroundMedia/__stories__/data.json

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@
1818
"imageSlider": {
1919
"content": {
2020
"image": [
21-
"https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png",
22-
"https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-white.png"
21+
{
22+
"desktop": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png",
23+
"mobile": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-black.png",
24+
"alt": "Picture",
25+
"disableCompress": true
26+
},
27+
{
28+
"desktop": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-white.png",
29+
"mobile": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png",
30+
"alt": "Picture",
31+
"disableCompress": true
32+
}
2333
]
2434
}
2535
},
@@ -31,5 +41,26 @@
3141
"disableCompress": true
3242
}
3343
}
44+
},
45+
"deviceSupport": {
46+
"content": {
47+
"image": {
48+
"desktop": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-gray.png",
49+
"mobile": "https://storage.yandexcloud.net/cloud-www-assets/constructor/storybook/images/img-black.png",
50+
"alt": "Picture",
51+
"disableCompress": true
52+
},
53+
"video": {
54+
"src": [
55+
"https://storage.yandexcloud.net/cloud-www-assets/constructor/main/main-visual/main_video.mp4",
56+
"https://storage.yandexcloud.net/cloud-www-assets/constructor/main/main-visual/main_video.ogv",
57+
"https://storage.yandexcloud.net/cloud-www-assets/constructor/main/main-visual/main_video.webm",
58+
"https://storage.yandexcloud.net/cloud-www-assets/constructor/main/main-visual/mobile.png"
59+
],
60+
"loop": {
61+
"start": 0
62+
}
63+
}
64+
}
3465
}
3566
}

src/components/FullscreenImage/FullscreenImage.tsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@ export interface FullScreenImageProps extends ImageProps {
1515

1616
const b = block('FullScreenImage');
1717

18-
const FullScreenImage = ({
19-
src,
20-
alt,
21-
imageClassName,
22-
disableCompress,
23-
modalImageClass,
24-
imageStyle,
25-
}: FullScreenImageProps) => {
18+
const FullScreenImage = (props: FullScreenImageProps) => {
19+
const {imageClassName, modalImageClass, imageStyle} = props;
2620
const [isOpened, setIsOpened] = useState(false);
2721
const [isMouseEnter, setIsMouseEnter] = useState(false);
2822
const openModal = useCallback(() => setIsOpened(true), []);
@@ -38,12 +32,10 @@ const FullScreenImage = ({
3832
onMouseLeave={hideFullScreenIcon}
3933
>
4034
<Image
35+
{...props}
4136
className={b('image', imageClassName)}
42-
src={src}
43-
alt={alt}
4437
onClick={openModal}
4538
style={imageStyle}
46-
disableCompress={disableCompress}
4739
/>
4840
<div className={b('icon-wrapper', {visible: isMouseEnter})} onClick={openModal}>
4941
<Icon data={FullScreen} width={18} height={18} className={b('icon')} />
@@ -60,12 +52,7 @@ const FullScreenImage = ({
6052
className={b('icon', {hover: true})}
6153
/>
6254
</div>
63-
<Image
64-
className={b('modal-image', modalImageClass)}
65-
src={src}
66-
alt={alt}
67-
disableCompress={disableCompress}
68-
/>
55+
<Image {...props} className={b('modal-image', modalImageClass)} />
6956
</div>
7057
</Modal>
7158
)}

src/models/constructor-items/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export interface MediaComponentYoutubeProps {
220220
}
221221

222222
export interface MediaComponentImageProps {
223-
image: ImageProps | ImageProps[];
223+
image: ImageProps | ImageProps[] | ImageDeviceProps;
224224
video?: MediaVideoProps;
225225
parallax?: boolean;
226226
height?: number;

src/stories/COMMON_TYPES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
# `Media`— Image/video/DataLens
5959

6060
- `color?: string` — Background color
61-
- [`image?: ImageObjectProps | ImageObjectProps[]` —Background image](#ImageObjectProps)
61+
- [`image?: ImageObjectProps | ImageObjectProps[] | ImageDeviceProps` Background image](#ImageObjectProps)
6262
- `parallax?: bool` — Enable/disable the parallax effect
6363
- [`video?: Video` — Video](#Video)
6464
- `youtube?: url` — Link to a video on YouTube

0 commit comments

Comments
 (0)