bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/presentation/presentation-toolbar/zoom-tool/component.jsx

251 lines
6.7 KiB
React
Raw Normal View History

2018-08-23 01:49:33 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
2019-02-07 00:42:12 +08:00
import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
2018-08-23 01:49:33 +08:00
import Button from '/imports/ui/components/button/component';
import { styles } from '../styles.scss';
2018-09-28 22:42:07 +08:00
import HoldButton from './holdButton/component';
2018-08-23 01:49:33 +08:00
2018-08-29 00:09:52 +08:00
const DELAY_MILLISECONDS = 200;
2018-08-23 01:49:33 +08:00
const STEP_TIME = 100;
2019-02-07 00:42:12 +08:00
const intlMessages = defineMessages({
resetZoomLabel: {
id: 'app.presentation.presentationToolbar.zoomReset',
description: 'Reset zoom button label',
},
});
class ZoomTool extends Component {
2018-08-23 01:49:33 +08:00
static renderAriaLabelsDescs() {
return (
2018-08-29 00:09:52 +08:00
<div hidden key="hidden-div">
2018-08-23 01:49:33 +08:00
<div id="zoomInLabel">
<FormattedMessage
id="app.presentation.presentationToolbar.zoomInLabel"
2018-12-05 19:40:35 +08:00
description="Aria label for increment zoom level"
defaultMessage="Increment zoom"
2018-08-23 01:49:33 +08:00
/>
</div>
<div id="zoomInDesc">
<FormattedMessage
id="app.presentation.presentationToolbar.zoomInDesc"
2018-12-05 19:40:35 +08:00
description="Aria description for increment zoom level"
defaultMessage="Increment zoom"
2018-08-23 01:49:33 +08:00
/>
</div>
<div id="zoomOutLabel">
<FormattedMessage
id="app.presentation.presentationToolbar.zoomOutLabel"
2018-12-05 19:40:35 +08:00
description="Aria label for decrement zoom level"
defaultMessage="Decrement zoom"
2018-08-23 01:49:33 +08:00
/>
</div>
<div id="zoomOutDesc">
<FormattedMessage
id="app.presentation.presentationToolbar.zoomOutDesc"
2018-12-05 19:40:35 +08:00
description="Aria description for decrement zoom level"
defaultMessage="Decrement zoom"
2018-08-23 01:49:33 +08:00
/>
</div>
<div id="zoomIndicator">
<FormattedMessage
id="app.presentation.presentationToolbar.zoomIndicator"
2018-12-05 19:40:35 +08:00
description="Aria label for current zoom level"
defaultMessage="Current zoom level"
2018-08-23 01:49:33 +08:00
/>
</div>
2019-02-07 00:42:12 +08:00
<div id="zoomReset">
<FormattedMessage
id="app.presentation.presentationToolbar.zoomReset"
description="Aria label for reset zoom level"
defaultMessage="Reset zoom level"
/>
</div>
2018-08-23 01:49:33 +08:00
</div>
);
}
2019-02-06 22:03:30 +08:00
2018-08-23 01:49:33 +08:00
constructor(props) {
super(props);
this.increment = this.increment.bind(this);
this.decrement = this.decrement.bind(this);
this.mouseDownHandler = this.mouseDownHandler.bind(this);
this.mouseUpHandler = this.mouseUpHandler.bind(this);
this.execInterval = this.execInterval.bind(this);
this.onChanger = this.onChanger.bind(this);
this.setInt = 0;
this.state = {
2019-02-07 00:05:24 +08:00
stateZoomValue: props.zoomValue,
initialstateZoomValue: props.zoomValue,
2018-08-23 01:49:33 +08:00
mouseHolding: false,
};
}
2019-02-06 22:03:30 +08:00
2018-08-23 01:49:33 +08:00
componentDidUpdate() {
2019-02-07 00:05:24 +08:00
const { zoomValue } = this.props;
const { stateZoomValue } = this.state;
const isDifferent = zoomValue !== stateZoomValue;
if (isDifferent) this.onChanger(zoomValue);
2018-08-23 01:49:33 +08:00
}
2019-02-07 00:05:24 +08:00
onChanger(value) {
2018-08-23 01:49:33 +08:00
const {
maxBound,
minBound,
change,
2019-02-07 00:05:24 +08:00
zoomValue,
2018-08-23 01:49:33 +08:00
} = this.props;
2019-02-07 00:05:24 +08:00
const { stateZoomValue } = this.state;
let newValue = value;
const isDifferent = newValue !== stateZoomValue;
2018-08-23 01:49:33 +08:00
if (newValue <= minBound) {
newValue = minBound;
} else if (newValue >= maxBound) {
newValue = maxBound;
}
2019-02-07 00:05:24 +08:00
const propsIsDifferente = zoomValue !== newValue;
2018-08-23 01:49:33 +08:00
if (isDifferent && propsIsDifferente) {
2019-02-07 00:05:24 +08:00
this.setState({ stateZoomValue: newValue }, () => {
2018-08-23 01:49:33 +08:00
change(newValue);
});
}
2019-02-07 00:05:24 +08:00
if (isDifferent && !propsIsDifferente) this.setState({ stateZoomValue: newValue });
2018-08-23 01:49:33 +08:00
}
increment() {
const {
step,
} = this.props;
2019-02-07 00:05:24 +08:00
const { stateZoomValue } = this.state;
const increaseZoom = stateZoomValue + step;
2018-08-23 01:49:33 +08:00
this.onChanger(increaseZoom);
}
2019-02-06 22:03:30 +08:00
2018-08-23 01:49:33 +08:00
decrement() {
const {
step,
} = this.props;
2019-02-07 00:05:24 +08:00
const { stateZoomValue } = this.state;
const decreaseZoom = stateZoomValue - step;
2018-08-23 01:49:33 +08:00
this.onChanger(decreaseZoom);
}
execInterval(inc) {
2019-02-06 22:03:30 +08:00
const { mouseHolding } = this.state;
2018-08-23 01:49:33 +08:00
const exec = inc ? this.increment : this.decrement;
const interval = () => {
clearInterval(this.setInt);
this.setInt = setInterval(exec, STEP_TIME);
};
setTimeout(() => {
2019-02-06 22:03:30 +08:00
if (mouseHolding) {
2018-08-23 01:49:33 +08:00
interval();
}
}, DELAY_MILLISECONDS);
}
mouseDownHandler(bool) {
this.setState({
mouseHolding: true,
}, () => {
this.execInterval(bool);
});
}
mouseUpHandler() {
this.setState({
mouseHolding: false,
}, () => clearInterval(this.setInt));
}
2019-02-06 22:03:30 +08:00
resetZoom() {
2019-02-07 00:05:24 +08:00
const { stateZoomValue, initialstateZoomValue } = this.state;
if (stateZoomValue !== initialstateZoomValue) this.onChanger(initialstateZoomValue);
2019-02-06 22:03:30 +08:00
}
2018-08-23 01:49:33 +08:00
render() {
const {
2019-02-07 00:05:24 +08:00
zoomValue,
2018-08-23 01:49:33 +08:00
minBound,
maxBound,
2019-02-07 00:42:12 +08:00
intl,
2018-08-23 01:49:33 +08:00
} = this.props;
2019-02-07 00:05:24 +08:00
const { stateZoomValue } = this.state;
2018-08-23 01:49:33 +08:00
return (
[
ZoomTool.renderAriaLabelsDescs(),
2018-09-28 22:42:07 +08:00
(
<HoldButton
key="zoom-tool-1"
exec={this.decrement}
2019-02-07 00:05:24 +08:00
value={zoomValue}
2018-09-28 22:42:07 +08:00
minBound={minBound}
>
<Button
key="zoom-tool-1"
2018-12-05 19:40:35 +08:00
aria-labelledby="zoomOutLabel"
aria-describedby="zoomOutDesc"
2018-09-28 22:42:07 +08:00
label="-"
icon="minus"
2019-02-06 22:03:30 +08:00
onClick={() => { }}
2019-02-07 00:05:24 +08:00
disabled={(zoomValue <= minBound)}
2018-09-28 22:42:07 +08:00
className={styles.prevSlide}
hideLabel
/>
</HoldButton>
),
2018-08-23 01:49:33 +08:00
(
2019-02-06 22:03:30 +08:00
<Button
2018-08-23 01:49:33 +08:00
key="zoom-tool-2"
2019-02-07 00:42:12 +08:00
aria-labelledby="zoomReset"
2019-02-07 00:05:24 +08:00
aria-describedby={stateZoomValue}
2019-02-06 22:03:30 +08:00
color="default"
2019-02-07 00:05:24 +08:00
customIcon={`${stateZoomValue}%`}
2019-02-06 22:03:30 +08:00
size="md"
onClick={() => this.resetZoom()}
2019-02-07 00:42:12 +08:00
label={intl.formatMessage(intlMessages.resetZoomLabel)}
2019-02-06 22:03:30 +08:00
hideLabel
2019-02-07 00:05:24 +08:00
className={styles.zoomPercentageDisplay}
2019-02-06 22:03:30 +08:00
/>
2018-08-23 01:49:33 +08:00
),
2018-09-28 22:42:07 +08:00
(
<HoldButton
key="zoom-tool-3"
exec={this.increment}
2019-02-07 00:05:24 +08:00
value={zoomValue}
2018-09-28 22:42:07 +08:00
maxBound={maxBound}
>
<Button
key="zoom-tool-3"
2018-12-05 19:40:35 +08:00
aria-labelledby="zoomInLabel"
aria-describedby="zoomInDesc"
2018-09-28 22:42:07 +08:00
label="+"
icon="plus"
2019-02-06 22:03:30 +08:00
onClick={() => { }}
2019-02-07 00:05:24 +08:00
disabled={(zoomValue >= maxBound)}
2018-09-28 22:42:07 +08:00
className={styles.skipSlide}
hideLabel
/>
</HoldButton>
),
2018-08-23 01:49:33 +08:00
]
);
}
}
const propTypes = {
2019-02-07 00:05:24 +08:00
zoomValue: PropTypes.number.isRequired,
2018-08-23 01:49:33 +08:00
change: PropTypes.func.isRequired,
minBound: PropTypes.number.isRequired,
maxBound: PropTypes.number.isRequired,
step: PropTypes.number.isRequired,
};
ZoomTool.propTypes = propTypes;
2019-02-07 00:42:12 +08:00
export default injectIntl(ZoomTool);