UNPKG

1.8 kBTypeScriptView Raw
1import * as React from 'react';
2
3import { VDomModel, VDomRenderer } from '@jupyterlab/apputils';
4
5import { IFontFaceOptions } from '.';
6
7import '../style/license.css';
8
9const WRAPPER_CLASS = 'jp-LicenseViewer-wrapper';
10const LICENSE_CLASS = 'jp-LicenseViewer';
11
12export class LicenseViewer extends VDomRenderer<LicenseViewer.Model> {
13 constructor(options: LicenseViewer.IOptions) {
14 super(new LicenseViewer.Model(options));
15 }
16 protected render(): React.ReactElement<any> {
17 this.addClass(WRAPPER_CLASS);
18 let m = this.model;
19
20 // Bail if there is no model.
21 if (!m) {
22 return <></>;
23 }
24
25 const text = m.licenseText ? <pre>{m.licenseText}</pre> : <></>;
26
27 return (
28 <div className={LICENSE_CLASS}>
29 <h1>{m.font.name}</h1>
30 <h2>{m.font.license.name}</h2>
31 {text}
32 </div>
33 );
34 }
35}
36
37export namespace LicenseViewer {
38 export interface IOptions {
39 font: IFontFaceOptions;
40 }
41
42 export class Model extends VDomModel {
43 private _font: IFontFaceOptions;
44 private _licenseText: string;
45 private _licenseTextPromise: Promise<string>;
46
47 constructor(options: IOptions) {
48 super();
49 this.font = options.font;
50 console.log(this._font);
51 }
52
53 get font() {
54 return this._font;
55 }
56
57 set font(font) {
58 this._font = font;
59 this.stateChanged.emit(void 0);
60 this._licenseTextPromise = new Promise(async (resolve, reject) => {
61 console.log('awaiting');
62 this._licenseText = await this._font.license.text();
63 console.log('resolved');
64 this.stateChanged.emit(void 0);
65 resolve(this._licenseText);
66 });
67 }
68
69 get licenseText() {
70 return this._licenseText;
71 }
72
73 get licenseTextPromise() {
74 return this._licenseTextPromise;
75 }
76 }
77}