Skip to content

Commit ca33424

Browse files
committed
fix(example): convert example to typescript
1 parent c017399 commit ca33424

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import React from 'react';
22
import Resizable from '../lib/Resizable';
33
import ResizableBox from '../lib/ResizableBox';
4+
import type {ResizeCallbackData} from '../lib/propTypes';
45
import 'style-loader!css-loader!../css/styles.css';
56

6-
/* global __VERSION__, __GIT_TAG__, __GIT_COMMIT__ */
7+
declare const __VERSION__: string;
8+
declare const __GIT_TAG__: string;
9+
declare const __GIT_COMMIT__: string;
710

811
// Update the version badge in the header
912
function updateVersionBadge() {
@@ -23,7 +26,7 @@ if (typeof document !== 'undefined') {
2326
}
2427
}
2528

26-
const CustomResizeHandle = React.forwardRef((props, ref) => {
29+
const CustomResizeHandle = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement> & {handleAxis?: string}>((props, ref) => {
2730
const {handleAxis, ...restProps} = props;
2831
return (
2932
<div
@@ -34,8 +37,17 @@ const CustomResizeHandle = React.forwardRef((props, ref) => {
3437
);
3538
});
3639

37-
export default class ExampleLayout extends React.Component<{}, {width: number, height: number}> {
38-
state = {
40+
type State = {
41+
width: number;
42+
height: number;
43+
absoluteWidth: number;
44+
absoluteHeight: number;
45+
absoluteLeft: number;
46+
absoluteTop: number;
47+
};
48+
49+
export default class ExampleLayout extends React.Component<{}, State> {
50+
state: State = {
3951
width: 200,
4052
height: 200,
4153
absoluteWidth: 200,
@@ -49,12 +61,12 @@ export default class ExampleLayout extends React.Component<{}, {width: number, h
4961
};
5062

5163
// On top layout
52-
onFirstBoxResize = (event, {element, size, handle}) => {
64+
onFirstBoxResize = (_event: React.SyntheticEvent, {size}: ResizeCallbackData) => {
5365
this.setState({width: size.width, height: size.height});
5466
};
5567

5668
// On bottom layout. Used to resize the center element around its flex parent.
57-
onResizeAbsolute = (event, {element, size, handle}) => {
69+
onResizeAbsolute = (_event: React.SyntheticEvent, {size, handle}: ResizeCallbackData) => {
5870
this.setState((state) => {
5971
let newLeft = state.absoluteLeft;
6072
let newTop = state.absoluteTop;

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828
bail: isProduction,
2929
context: __dirname,
3030
entry: {
31-
test: "./examples/example.js",
31+
test: "./examples/example.tsx",
3232
},
3333
output: {
3434
path: path.join(__dirname, "examples"),

0 commit comments

Comments
 (0)