bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/whiteboard/annotation-factory/component.jsx

97 lines
2.7 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import StaticAnnotation from './static-annotation/component';
import ReactiveAnnotationContainer from './reactive-annotation/container';
import Ellipse from '../annotations/ellipse/component';
import Line from '../annotations/line/component';
import Poll from '../annotations/poll/component';
import Rectangle from '../annotations/rectangle/component';
import Text from '../annotations/text/container';
import Triangle from '../annotations/triangle/component';
import Pencil from '../annotations/pencil/component';
export default class AnnotationFactory extends Component {
static renderStaticAnnotation(annotationInfo, slideWidth, slideHeight, drawObject) {
return (
<StaticAnnotation
key={annotationInfo._id}
shapeId={annotationInfo._id}
drawObject={drawObject}
slideWidth={slideWidth}
slideHeight={slideHeight}
/>
);
}
static renderReactiveAnnotation(annotationInfo, slideWidth, slideHeight, drawObject) {
return (
<ReactiveAnnotationContainer
key={annotationInfo._id}
shapeId={annotationInfo._id}
drawObject={drawObject}
slideWidth={slideWidth}
slideHeight={slideHeight}
/>
);
}
constructor() {
super();
this.renderAnnotation = this.renderAnnotation.bind(this);
}
renderAnnotation(annotationInfo) {
const drawObject = this.props.annotationSelector[annotationInfo.annotationType];
if (annotationInfo.status === 'DRAW_END') {
return AnnotationFactory.renderStaticAnnotation(
annotationInfo,
this.props.slideWidth,
this.props.slideHeight,
drawObject,
);
}
return AnnotationFactory.renderReactiveAnnotation(
annotationInfo,
this.props.slideWidth,
this.props.slideHeight,
drawObject,
);
}
render() {
const { annotationsInfo } = this.props;
return (
<g>
{annotationsInfo ?
annotationsInfo.map(annotationInfo => this.renderAnnotation(annotationInfo))
: null }
</g>
);
}
}
AnnotationFactory.propTypes = {
// initial width and height of the slide are required
// to calculate the coordinates for each annotation
slideWidth: PropTypes.number.isRequired,
slideHeight: PropTypes.number.isRequired,
// array of annotations, optional
annotationsInfo: PropTypes.arrayOf(PropTypes.object).isRequired,
annotationSelector: PropTypes.objectOf(PropTypes.instanceOf(Function)).isRequired,
};
AnnotationFactory.defaultProps = {
annotationSelector: {
ellipse: Ellipse,
line: Line,
poll_result: Poll,
rectangle: Rectangle,
text: Text,
triangle: Triangle,
pencil: Pencil,
},
};