Skip to content

Commit 5b0c26d

Browse files
author
Juli Ovechkina
authored
feat: add iframe to media (#698)
1 parent 87fb74f commit 5b0c26d

File tree

14 files changed

+247
-9
lines changed

14 files changed

+247
-9
lines changed

.storybook/stories/documentation/Types.mdx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ import { Meta } from '@storybook/blocks';
5252

5353
---
5454

55-
# <a name="DataLens">`DataLens`</a> — DataLens chart
56-
57-
- `id: string` — Chart ID
58-
- `theme: dark | light` — Chart theme
59-
60-
---
61-
6255
# <a name="Media">`Media`</a> — Image/video/DataLens/Youtube
6356

6457
- `color?: string` — Background color
@@ -70,6 +63,24 @@ import { Meta } from '@storybook/blocks';
7063
- `previewImg?: string`
7164
- `dataLens?: string |` [DataLens](#DataLens)
7265
- `fullscreen?: boolean` — Enabling full-screen mode for image or video. Default true - for multiple images, false - for single image, video. It doesn't work with dataLens and youtube
66+
- `iframe?: [Iframe](#Iframe)`
67+
68+
69+
---
70+
71+
# <a name="DataLens">`DataLens`</a> — DataLens chart
72+
73+
- `id: string` — Chart ID
74+
- `theme: dark | light` — Chart theme
75+
76+
---
77+
78+
# <a name="Iframe">`Iframe`</a>
79+
80+
- `src: string` — Iframe link
81+
- `name?: string` — Iframe name
82+
83+
You can add all attributes which `<iframe>` can take. See more info [here](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe)
7384

7485
---
7586

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Sub-blocks are components that can be used in the block `children` property. In
184184

185185
1. In the `src/blocks` or `src/sub-blocks` directory, create a folder with the block or sub-block code.
186186

187-
2. Add the block or sub-block name to enum `BlockType` or`SubBlockType` and describe its properties in the `src/models/blocks.ts` or `src/models/sub-blocks.ts` file in a similar way to the existing ones.
187+
2. Add the block or sub-block name to enum `BlockType` or`SubBlockType` and describe its properties in the `src/models/constructor-items/blocks.ts` or `src/models/constructor-items/sub-blocks.ts` file in a similar way to the existing ones.
188188

189189
3. Add export for the block in the `src/blocks/index.ts` file and for the sub-block in the `src/sub-blocks/index.ts` file.
190190

src/blocks/Media/__stories__/Media.stories.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,59 @@ const DirectionTemplate: StoryFn<MediaBlockModel> = (args) => (
142142
/>
143143
);
144144

145+
const IframeTemplate: StoryFn<MediaBlockModel> = (args) => (
146+
<PageConstructor
147+
content={{
148+
blocks: [
149+
{
150+
...args,
151+
...data.iframe.default.content,
152+
title: data.size.defaultMediaTitle,
153+
},
154+
{
155+
...args,
156+
...data.iframe.default.content,
157+
largeMedia: true,
158+
title: data.size.largeMediaTitle,
159+
},
160+
{
161+
...args,
162+
...data.iframe.default.content,
163+
mediaOnly: true,
164+
description: undefined,
165+
title: data.size.mediaOnlyTitle,
166+
},
167+
{
168+
...args,
169+
...data.iframe.withoutMargins.content,
170+
title: data.iframe.withoutMargins.defaultMediaTitle,
171+
},
172+
{
173+
...args,
174+
...data.iframe.withoutMargins.content,
175+
largeMedia: true,
176+
title: data.iframe.withoutMargins.largeMediaTitle,
177+
},
178+
{
179+
...args,
180+
...data.iframe.withoutMargins.content,
181+
mediaOnly: true,
182+
description: undefined,
183+
title: data.iframe.withoutMargins.mediaOnlyTitle,
184+
},
185+
],
186+
}}
187+
/>
188+
);
189+
145190
export const Default = DefaultTemplate.bind({});
146191
export const ImageSlider = ImageSliderTemplate.bind({});
147192
export const Video = VideoTemplate.bind({});
148193
export const DataLens = ImageSliderTemplate.bind({});
149194
export const Size = SizeTemplate.bind({});
150195
export const Direction = DirectionTemplate.bind({});
151196
export const WithoutShadow = ImageSliderTemplate.bind({});
197+
export const Iframe = IframeTemplate.bind({});
152198

153199
const DefaultArgs = {
154200
...data.default.content,
@@ -166,11 +212,13 @@ DataLens.args = {
166212
...DefaultArgs,
167213
...data.dataLens.content,
168214
} as MediaBlockProps;
169-
170215
Size.args = DefaultArgs as MediaBlockProps;
171216
Direction.args = DefaultArgs as MediaBlockProps;
172217
WithoutShadow.args = {
173218
...DefaultArgs,
174219
...data.withoutShadow.content,
175220
disableShadow: true,
176221
} as MediaBlockProps;
222+
Iframe.args = {
223+
...DefaultArgs,
224+
} as MediaBlockProps;

src/blocks/Media/__stories__/data.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,48 @@
279279
}
280280
}
281281
},
282+
"iframe": {
283+
"default": {
284+
"content": {
285+
"media": {
286+
"light": {
287+
"iframe": {
288+
"src": "https://www.google.com/maps/embed/",
289+
"name": "iframe"
290+
}
291+
},
292+
"dark": {
293+
"dataLens": {
294+
"id": "m2bzon9y39lck",
295+
"theme": "dark"
296+
}
297+
}
298+
}
299+
}
300+
},
301+
"withoutMargins": {
302+
"defaultMediaTitle": "Media Iframe without margins",
303+
"largeMediaTitle": "Large Media Iframe without margins",
304+
"mediaOnlyTitle": "Media Iframe Only without margins",
305+
"content": {
306+
"media": {
307+
"light": {
308+
"iframe": {
309+
"src": "https://www.google.com/maps/embed/",
310+
"name": "iframe"
311+
},
312+
"margins": false
313+
},
314+
"dark": {
315+
"dataLens": {
316+
"id": "m2bzon9y39lck",
317+
"theme": "dark"
318+
}
319+
}
320+
}
321+
}
322+
}
323+
},
282324
"size": {
283325
"defaultMediaTitle": "Default Media",
284326
"largeMediaTitle": "Large Media",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@import '../../../../styles/variables.scss';
2+
@import '../../../../styles/mixins';
3+
4+
$block: '.#{$ns}media-component-iframe';
5+
6+
#{$block} {
7+
overflow: hidden;
8+
9+
&_margins {
10+
margin: $indentSM;
11+
12+
#{$block}__item {
13+
border-radius: 0;
14+
}
15+
}
16+
17+
#{$block}__iframe {
18+
border-radius: 0;
19+
}
20+
21+
&__item {
22+
width: 100%;
23+
height: 100%;
24+
}
25+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
3+
import {MediaComponentIframeProps} from '../../../models';
4+
import {block} from '../../../utils';
5+
6+
import i18n from './i18n';
7+
8+
import './Iframe.scss';
9+
10+
const b = block('media-component-iframe');
11+
12+
const Iframe = (props: MediaComponentIframeProps) => {
13+
const {iframe, margins = true} = props;
14+
const {height = 400, src, width, name, title} = iframe;
15+
16+
return iframe ? (
17+
<div className={b({margins})} style={{height}}>
18+
<iframe
19+
className={b('item')}
20+
loading="lazy"
21+
title={title || i18n('iframe-title')}
22+
frameBorder={0}
23+
src={src}
24+
width={width}
25+
height={height}
26+
name={name}
27+
/>
28+
</div>
29+
) : null;
30+
};
31+
32+
export default Iframe;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"iframe-title": "Datalens frame"
3+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {registerKeyset} from '../../../../utils/registerKeyset';
2+
3+
import en from './en.json';
4+
import ru from './ru.json';
5+
6+
const COMPONENT = 'Iframe';
7+
8+
export default registerKeyset({en, ru}, COMPONENT);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"iframe-title": "Фрейм данных"
3+
}

src/components/Media/Media.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import YoutubeBlock from '../VideoBlock/VideoBlock';
66

77
import DataLens from './DataLens/DataLens';
88
import FullscreenVideo from './FullscreenVideo/FullscreenVideo';
9+
import Iframe from './Iframe/Iframe';
910
import Image, {ImageAdditionProps} from './Image/Image';
1011
import Video, {VideoAdditionProps} from './Video/Video';
1112

@@ -45,6 +46,8 @@ export const Media = (props: MediaAllProps) => {
4546
ratio,
4647
autoplay,
4748
onImageLoad,
49+
iframe,
50+
margins,
4851
} = props;
4952

5053
const [hasVideoFallback, setHasVideoFallback] = useState(false);
@@ -116,12 +119,17 @@ export const Media = (props: MediaAllProps) => {
116119
result = <DataLens dataLens={dataLens} />;
117120
}
118121

122+
if (iframe) {
123+
result = <Iframe iframe={iframe} margins={margins} />;
124+
}
125+
119126
return result;
120127
}, [
121128
image,
122129
video,
123130
youtube,
124131
dataLens,
132+
iframe,
125133
parallax,
126134
height,
127135
imageClassName,
@@ -141,6 +149,7 @@ export const Media = (props: MediaAllProps) => {
141149
ratio,
142150
youtubeClassName,
143151
autoplay,
152+
margins,
144153
]);
145154

146155
return (

0 commit comments

Comments
 (0)