box-ui-elements
Version:
Box UI Elements
56 lines (50 loc) • 1.46 kB
JavaScript
/**
* @flow
* @file Base class for the Open With ES6 wrapper
* @author Box
*/
import 'regenerator-runtime/runtime';
import * as React from 'react';
import { createRoot } from 'react-dom/client';
import ES6Wrapper from './ES6Wrapper';
import ContentOpenWithReactComponent from '../content-open-with';
class ContentOpenWith extends ES6Wrapper {
/**
* Callback for executing an integration
*
* @return {void}
*/
onExecute = (appIntegrationId: string): void => {
this.emit('execute', appIntegrationId);
};
/**
* Callback when an error occurs while loading or executing integrations
*
* @return {void}
*/
onError = (error: Error): void => {
this.emit('error', error);
};
/** @inheritdoc */
render() {
if (!this.root) {
this.root = createRoot(this.container);
}
this.root.render(
<ContentOpenWithReactComponent
componentRef={this.setComponent}
fileId={this.id}
language={this.language}
messages={this.messages}
onError={this.onError}
onExecute={this.onExecute}
onInteraction={this.onInteraction}
token={this.token}
{...this.options}
/>,
);
}
}
global.Box = global.Box || {};
global.Box.ContentOpenWith = ContentOpenWith;
export default ContentOpenWith;