2019-01-08 02:12:28 +08:00
|
|
|
import React from 'react';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2019-02-08 01:47:28 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2021-11-09 01:44:34 +08:00
|
|
|
import Styled from './styles';
|
2022-02-15 22:42:02 +08:00
|
|
|
import { ACTIONS } from '/imports/ui/components/layout/enums';
|
2019-01-08 02:12:28 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
fullscreenButton: {
|
|
|
|
id: 'app.fullscreenButton.label',
|
|
|
|
description: 'Fullscreen label',
|
|
|
|
},
|
2020-10-04 10:06:54 +08:00
|
|
|
fullscreenUndoButton: {
|
|
|
|
id: 'app.fullscreenUndoButton.label',
|
|
|
|
description: 'Undo fullscreen label',
|
|
|
|
},
|
2019-01-08 02:12:28 +08:00
|
|
|
});
|
|
|
|
|
2019-02-08 01:47:28 +08:00
|
|
|
const propTypes = {
|
2021-07-13 03:47:06 +08:00
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2021-11-20 03:26:04 +08:00
|
|
|
fullscreenRef: PropTypes.instanceOf(Element),
|
2019-02-08 01:47:28 +08:00
|
|
|
dark: PropTypes.bool,
|
2019-07-24 06:24:31 +08:00
|
|
|
bottom: PropTypes.bool,
|
|
|
|
isIphone: PropTypes.bool,
|
|
|
|
isFullscreen: PropTypes.bool,
|
2019-02-08 01:47:28 +08:00
|
|
|
elementName: PropTypes.string,
|
2021-11-20 03:26:04 +08:00
|
|
|
handleToggleFullScreen: PropTypes.func.isRequired,
|
2021-08-26 04:31:52 +08:00
|
|
|
color: PropTypes.string,
|
|
|
|
fullScreenStyle: PropTypes.bool,
|
2019-02-08 01:47:28 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
dark: false,
|
2019-07-24 06:24:31 +08:00
|
|
|
bottom: false,
|
|
|
|
isIphone: false,
|
|
|
|
isFullscreen: false,
|
2019-02-08 01:47:28 +08:00
|
|
|
elementName: '',
|
2021-08-26 04:31:52 +08:00
|
|
|
color: 'default',
|
|
|
|
fullScreenStyle: true,
|
2021-11-20 03:26:04 +08:00
|
|
|
fullscreenRef: null,
|
2019-02-08 01:47:28 +08:00
|
|
|
};
|
|
|
|
|
2019-02-07 05:12:59 +08:00
|
|
|
const FullscreenButtonComponent = ({
|
2019-03-12 00:21:12 +08:00
|
|
|
intl,
|
|
|
|
dark,
|
2019-07-24 03:56:39 +08:00
|
|
|
bottom,
|
2019-03-12 00:21:12 +08:00
|
|
|
elementName,
|
2021-07-06 19:28:17 +08:00
|
|
|
elementId,
|
2021-07-13 03:47:06 +08:00
|
|
|
elementGroup,
|
2019-06-17 23:55:53 +08:00
|
|
|
isIphone,
|
2019-07-24 03:56:39 +08:00
|
|
|
isFullscreen,
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch,
|
2021-07-06 19:28:17 +08:00
|
|
|
currentElement,
|
2021-07-13 03:47:06 +08:00
|
|
|
currentGroup,
|
2021-08-26 04:31:52 +08:00
|
|
|
color,
|
|
|
|
fullScreenStyle,
|
2021-11-20 03:26:04 +08:00
|
|
|
fullscreenRef,
|
|
|
|
handleToggleFullScreen,
|
2019-02-07 05:12:59 +08:00
|
|
|
}) => {
|
2019-06-17 23:55:53 +08:00
|
|
|
if (isIphone) return null;
|
|
|
|
|
2021-07-13 03:47:06 +08:00
|
|
|
const formattedLabel = (fullscreen) => (fullscreen
|
|
|
|
? intl.formatMessage(
|
|
|
|
intlMessages.fullscreenUndoButton,
|
|
|
|
({ 0: elementName || '' }),
|
|
|
|
)
|
|
|
|
: intl.formatMessage(
|
|
|
|
intlMessages.fullscreenButton,
|
|
|
|
({ 0: elementName || '' }),
|
|
|
|
)
|
|
|
|
);
|
2019-02-07 05:12:59 +08:00
|
|
|
|
2021-06-25 00:47:16 +08:00
|
|
|
const handleClick = () => {
|
2021-11-20 03:26:04 +08:00
|
|
|
handleToggleFullScreen(fullscreenRef);
|
2021-08-05 12:22:07 +08:00
|
|
|
const newElement = (elementId === currentElement) ? '' : elementId;
|
|
|
|
const newGroup = (elementGroup === currentGroup) ? '' : elementGroup;
|
2021-07-06 00:52:25 +08:00
|
|
|
|
2021-08-05 19:03:24 +08:00
|
|
|
layoutContextDispatch({
|
2021-08-05 12:22:07 +08:00
|
|
|
type: ACTIONS.SET_FULLSCREEN_ELEMENT,
|
|
|
|
value: {
|
|
|
|
element: newElement,
|
|
|
|
group: newGroup,
|
|
|
|
},
|
|
|
|
});
|
2021-07-13 03:47:06 +08:00
|
|
|
};
|
2021-06-25 00:47:16 +08:00
|
|
|
|
2019-02-07 05:12:59 +08:00
|
|
|
return (
|
2021-11-09 01:44:34 +08:00
|
|
|
<Styled.FullscreenButtonWrapper
|
|
|
|
theme={dark ? 'dark' : 'light'}
|
|
|
|
position={bottom ? 'bottom' : 'top'}
|
|
|
|
>
|
|
|
|
<Styled.FullscreenButton
|
2021-08-26 04:31:52 +08:00
|
|
|
color={color || 'default'}
|
2019-07-24 03:56:39 +08:00
|
|
|
icon={!isFullscreen ? 'fullscreen' : 'exit_fullscreen'}
|
2019-02-07 05:12:59 +08:00
|
|
|
size="sm"
|
2021-06-25 00:47:16 +08:00
|
|
|
onClick={() => handleClick()}
|
2020-10-04 10:06:54 +08:00
|
|
|
label={formattedLabel(isFullscreen)}
|
2019-02-07 05:12:59 +08:00
|
|
|
hideLabel
|
2021-11-09 01:44:34 +08:00
|
|
|
isStyled={fullScreenStyle}
|
2023-03-29 22:16:47 +08:00
|
|
|
data-test="webcamFullscreenButton"
|
2019-02-07 05:12:59 +08:00
|
|
|
/>
|
2021-11-09 01:44:34 +08:00
|
|
|
</Styled.FullscreenButtonWrapper>
|
2019-02-07 05:12:59 +08:00
|
|
|
);
|
|
|
|
};
|
2019-01-08 02:12:28 +08:00
|
|
|
|
2019-02-08 01:47:28 +08:00
|
|
|
FullscreenButtonComponent.propTypes = propTypes;
|
|
|
|
FullscreenButtonComponent.defaultProps = defaultProps;
|
|
|
|
|
2019-01-08 02:12:28 +08:00
|
|
|
export default injectIntl(FullscreenButtonComponent);
|