-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWidget.tsx
More file actions
77 lines (68 loc) · 2.29 KB
/
Copy pathWidget.tsx
File metadata and controls
77 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { Component, CSSProperties } from "react";
import { headerStyles, widgetStyles } from "./Widget.styles";
/**
* Defined a widget, it's also a react component.
* For more information about react component, please refer to https://reactjs.org/docs/react-component.html
* T is the model type of the widget.
*/
export abstract class Widget<T> extends Component<{}, T> {
constructor(props: any) {
super(props);
this.state = {} as T;
}
/**
* This method is invoked immediately after a component is mounted.
* It's a good place to fetch data from server.
* For more information about react lifecycle, please refer to https://reactjs.org/docs/react-component.html#componentdidmount
*/
async componentDidMount() {
this.setState(await this.getData());
}
/**
* Define your widget layout, you can edit the code here to customize your widget.
*/
render() {
return (
<div style={{ ...widgetStyles(), ...this.customiseWidgetStyle() }}>
{this.headerContent() && <div style={headerStyles}>{this.headerContent()}</div>}
{this.bodyContent() !== undefined && this.bodyContent()}
{this.bodyContent() !== undefined && this.footerContent()}
</div>
);
}
/**
* Get data required by the widget, you can get data from a api call or static data stored in a file. Override this method according to your needs.
* @returns data for the widget
*/
protected async getData<K extends keyof T>(): Promise<Pick<T, K>> {
return {} as Pick<T, K>;
}
/**
* Override this method to customize the widget header.
* @returns JSX component for the widget body
*/
protected headerContent(): JSX.Element | undefined {
return undefined;
}
/**
* Override this method to customize the widget body.
* @returns JSX component for the widget body
*/
protected bodyContent(): JSX.Element | undefined {
return undefined;
}
/**
* Override this method to customize the widget footer.
* @returns react node for the widget footer
*/
protected footerContent(): JSX.Element | undefined {
return undefined;
}
/**
* Override this method to customize the widget style.
* @returns custom style for the widget
*/
protected customiseWidgetStyle(): CSSProperties | undefined {
return undefined;
}
}