Skip to content

Commit 516a9a8

Browse files
authored
feat(Media): add fullscreen video (#345)
1 parent bfab840 commit 516a9a8

File tree

27 files changed

+212
-111
lines changed

27 files changed

+212
-111
lines changed

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
- Add it to `enum` or `selectCases` in the `schema/index.ts` file.
185185

186186
6. In the block directory, add the `README.md` file with a description of input parameters.
187-
7. In the block directory add storybook demo in `__stories__` folder. (All demo content for story should be placed in `data.json` at story dir)
187+
7. In the block directory add storybook demo in `__stories__` folder. All demo content for story should be placed in `data.json` at story dir. The generic `Story` must accept the type of block props, otherwise incorrect block props will be displayed in Storybook.
188188

189189
### Themes
190190

src/blocks/Media/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Media block
88

99
[`button: Button` — Button](?path=/story/information--common-types&viewMode=docs#button---button)
1010

11-
[`media: Media` — Media description](?path=/story/information--common-types&viewMode=docs#media---picvideodatalens)
11+
[`media: Media` — Media description](?path=/story/information--common-types&viewMode=docs#common-types)
1212

1313
`direction: 'media-content' | 'content-media'` — Relative position of media and content.
1414

src/blocks/Tabs/Tabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, {Fragment, useContext, useRef, useState} from 'react';
33
import AnimateBlock from '../../components/AnimateBlock/AnimateBlock';
44
import BlockHeader from '../../components/BlockHeader/BlockHeader';
55
import ButtonTabs, {ButtonTabsItemProps} from '../../components/ButtonTabs/ButtonTabs';
6-
import FullScreenImage from '../../components/FullscreenImage/FullscreenImage';
6+
import FullscreenImage from '../../components/FullscreenImage/FullscreenImage';
77
import {getMediaImage} from '../../components/Media/Image/utils';
88
import Media from '../../components/Media/Media';
99
import {getHeight} from '../../components/VideoBlock/VideoBlock';
@@ -95,7 +95,7 @@ export const TabsBlock = ({
9595
</div>
9696
{imageProps && (
9797
<Fragment>
98-
<FullScreenImage {...imageProps} imageClassName={b('image')} />
98+
<FullscreenImage {...imageProps} imageClassName={b('image')} />
9999
</Fragment>
100100
)}
101101
{activeTabData?.caption && <p className={b('caption')}>{activeTabData.caption}</p>}
File renamed without changes.

src/components/FullscreenImage/FullscreenImage.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Image, {ImageProps} from '../Image/Image';
88

99
import i18n from './i18n';
1010

11-
import './FullScreenImage.scss';
11+
import './FullscreenImage.scss';
1212

1313
export interface FullScreenImageProps extends ImageProps {
1414
imageClassName?: string;
@@ -20,22 +20,22 @@ const b = block('FullScreenImage');
2020
const FULL_SCREEN_ICON_SIZE = 18;
2121
const CLOSE_ICON_SIZE = 30;
2222

23-
const FullScreenImage = (props: FullScreenImageProps) => {
23+
const FullscreenImage = (props: FullScreenImageProps) => {
2424
const {imageClassName, modalImageClass, imageStyle, alt = i18n('img-alt')} = props;
2525
const [isOpened, setIsOpened] = useState(false);
2626
const [isMouseEnter, setIsMouseEnter] = useState(false);
2727

2828
const openModal = () => setIsOpened(true);
2929
const closeModal = () => setIsOpened(false);
30-
const showFullScreenIcon = () => setIsMouseEnter(true);
31-
const hideFullScreenIcon = () => setIsMouseEnter(false);
30+
const showFullscreenIcon = () => setIsMouseEnter(true);
31+
const hideFullscreenIcon = () => setIsMouseEnter(false);
3232

3333
return (
3434
<div className={b()}>
3535
<div
3636
className={b('image-wrapper')}
37-
onMouseEnter={showFullScreenIcon}
38-
onMouseLeave={hideFullScreenIcon}
37+
onMouseEnter={showFullscreenIcon}
38+
onMouseLeave={hideFullscreenIcon}
3939
>
4040
<Image
4141
{...props}
@@ -72,4 +72,4 @@ const FullScreenImage = (props: FullScreenImageProps) => {
7272
);
7373
};
7474

75-
export default FullScreenImage;
75+
export default FullscreenImage;

src/components/FullscreenImage/__stories__/FullScreenImage.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@ import React from 'react';
33
import {Meta, Story} from '@storybook/react/types-6-0';
44

55
import {COMPONENTS, MEDIA} from '../../../demo/constants';
6-
import FullScreenImage, {FullScreenImageProps} from '../FullscreenImage';
6+
import FullscreenImage, {FullScreenImageProps} from '../FullscreenImage';
77

88
import data from './data.json';
99

1010
export default {
11-
component: FullScreenImage,
12-
title: `${COMPONENTS}/${MEDIA}/FullScreenImage`,
11+
component: FullscreenImage,
12+
title: `${COMPONENTS}/${MEDIA}/FullscreenImage`,
1313
} as Meta;
1414

1515
const DefaultTemplate: Story<FullScreenImageProps> = (args) => (
1616
<div style={{maxWidth: '500px'}}>
17-
<FullScreenImage {...args} />
17+
<FullscreenImage {...args} />
1818
</div>
1919
);
2020

File renamed without changes.

src/components/FullscreenMedia/FullScreenMedia.tsx renamed to src/components/FullscreenMedia/FullscreenMedia.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ import {FullScreen, PreviewClose} from '../../icons';
77
import {block} from '../../utils';
88
import {MediaAllProps} from '../Media/Media';
99

10-
import './FullScreenMedia.scss';
10+
import './FullscreenMedia.scss';
1111

1212
export type ChildMediaRenderProps = Pick<
1313
MediaAllProps,
14-
'fullScreen' | 'imageClassName' | 'videoClassName' | 'youtubeClassName' | 'className'
14+
| 'fullScreen'
15+
| 'fullscreen'
16+
| 'imageClassName'
17+
| 'videoClassName'
18+
| 'youtubeClassName'
19+
| 'className'
1520
>;
1621

1722
export interface FullScreenMediaProps {
23+
/**
24+
* @deprecated use showFullscreenIcon
25+
*/
1826
showFullScreenIcon?: boolean;
27+
showFullscreenIcon?: boolean;
1928
children: (props?: ChildMediaRenderProps) => JSX.Element;
2029
}
2130

@@ -25,7 +34,15 @@ const CLOSE_ICON_SIZE = 30;
2534

2635
const getMediaClass = (type: string) => b('modal-media', {type});
2736

28-
const FullScreenMedia = ({children, showFullScreenIcon = true}: FullScreenMediaProps) => {
37+
// TODO delete along with showFullScreenIcon props
38+
const getShowFullscreenIcon = ({showFullScreenIcon = true, showFullscreenIcon = true}) =>
39+
showFullScreenIcon && showFullscreenIcon;
40+
41+
const FullscreenMedia = ({
42+
children,
43+
showFullScreenIcon = true,
44+
showFullscreenIcon = true,
45+
}: FullScreenMediaProps) => {
2946
const [isOpened, setIsOpened] = useState(false);
3047
const isMobile = useContext(MobileContext);
3148

@@ -43,7 +60,7 @@ const FullScreenMedia = ({children, showFullScreenIcon = true}: FullScreenMediaP
4360
<div className={b()}>
4461
<div className={b('media-wrapper')} onClickCapture={openModal}>
4562
{children({className: b('inline-media')})}
46-
{showFullScreenIcon && (
63+
{getShowFullscreenIcon({showFullScreenIcon, showFullscreenIcon}) && (
4764
<div className={b('icon-wrapper')} onClickCapture={openModal}>
4865
<Icon
4966
data={FullScreen}
@@ -78,4 +95,4 @@ const FullScreenMedia = ({children, showFullScreenIcon = true}: FullScreenMediaP
7895
);
7996
};
8097

81-
export default FullScreenMedia;
98+
export default FullscreenMedia;

src/components/FullscreenMedia/__stories__/FullScreenMedia.stories.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
3+
import {Meta, Story} from '@storybook/react/types-6-0';
4+
5+
import {COMPONENTS, MEDIA} from '../../../demo/constants';
6+
import Media from '../../Media/Media';
7+
import FullscreenMedia, {FullScreenMediaProps} from '../FullscreenMedia';
8+
9+
import data from './data.json';
10+
11+
export default {
12+
component: FullscreenMedia,
13+
title: `${COMPONENTS}/${MEDIA}/FullscreenMedia`,
14+
} as Meta;
15+
16+
const DefaultTemplate: Story<FullScreenMediaProps> = (args) => (
17+
<div style={{maxWidth: '500px'}}>
18+
<FullscreenMedia {...args}>
19+
{(fullscreenMediaProps = {}) => (
20+
<Media {...data.default.content} {...fullscreenMediaProps} />
21+
)}
22+
</FullscreenMedia>
23+
</div>
24+
);
25+
26+
export const Default = DefaultTemplate.bind({});
27+
28+
Default.args = {};

0 commit comments

Comments
 (0)