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

237 lines
6.2 KiB
React
Raw Normal View History

2018-08-23 01:49:33 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
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;
export default class ZoomTool extends Component {
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>
</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-06 22:03:30 +08:00
stateValue: props.value,
initialStateValue: props.value,
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-06 22:03:30 +08:00
const { value } = this.props;
const { stateValue } = this.state;
const isDifferent = value !== stateValue;
if (isDifferent) this.onChanger(value);
2018-08-23 01:49:33 +08:00
}
2019-02-06 22:03:30 +08:00
onChanger(val) {
2018-08-23 01:49:33 +08:00
const {
maxBound,
minBound,
change,
2019-02-06 22:03:30 +08:00
value,
2018-08-23 01:49:33 +08:00
} = this.props;
2019-02-06 22:03:30 +08:00
const { stateValue } = this.state;
let newValue = val;
const isDifferent = newValue !== stateValue;
2018-08-23 01:49:33 +08:00
if (newValue <= minBound) {
newValue = minBound;
} else if (newValue >= maxBound) {
newValue = maxBound;
}
2019-02-06 22:03:30 +08:00
const propsIsDifferente = value !== newValue;
2018-08-23 01:49:33 +08:00
if (isDifferent && propsIsDifferente) {
2019-02-06 22:03:30 +08:00
this.setState({ stateValue: newValue }, () => {
2018-08-23 01:49:33 +08:00
change(newValue);
});
}
2019-02-06 22:03:30 +08:00
if (isDifferent && !propsIsDifferente) this.setState({ stateValue: newValue });
2018-08-23 01:49:33 +08:00
}
increment() {
const {
step,
} = this.props;
2019-02-06 22:03:30 +08:00
const { stateValue } = this.state;
const increaseZoom = stateValue + 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-06 22:03:30 +08:00
const { stateValue } = this.state;
const decreaseZoom = stateValue - 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() {
const { stateValue, initialStateValue } = this.state;
if (stateValue !== initialStateValue) this.onChanger(initialStateValue);
}
2018-08-23 01:49:33 +08:00
render() {
const {
value,
minBound,
maxBound,
} = this.props;
2019-02-06 22:03:30 +08:00
const { stateValue } = 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}
value={value}
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
role="button"
label="-"
icon="minus"
2019-02-06 22:03:30 +08:00
onClick={() => { }}
2018-09-28 22:42:07 +08:00
disabled={(value <= minBound)}
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-06 22:03:30 +08:00
role="button"
2018-12-05 19:40:35 +08:00
aria-labelledby="zoomIndicator"
2019-02-06 22:03:30 +08:00
aria-describedby={stateValue}
color="default"
customIcon={`${stateValue}%`}
size="md"
onClick={() => this.resetZoom()}
label="Reset Zoom"
hideLabel
className={styles.prevSlide}
/>
2018-08-23 01:49:33 +08:00
),
2018-09-28 22:42:07 +08:00
(
<HoldButton
key="zoom-tool-3"
exec={this.increment}
value={value}
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
role="button"
label="+"
icon="plus"
2019-02-06 22:03:30 +08:00
onClick={() => { }}
2018-09-28 22:42:07 +08:00
disabled={(value >= maxBound)}
className={styles.skipSlide}
hideLabel
/>
</HoldButton>
),
2018-08-23 01:49:33 +08:00
]
);
}
}
const propTypes = {
value: PropTypes.number.isRequired,
change: PropTypes.func.isRequired,
minBound: PropTypes.number.isRequired,
maxBound: PropTypes.number.isRequired,
step: PropTypes.number.isRequired,
};
ZoomTool.propTypes = propTypes;