Skip to content

Commit 9cacc86

Browse files
committed
chore: fix resize library error in react 19
1 parent eadab20 commit 9cacc86

11 files changed

Lines changed: 163 additions & 176 deletions

File tree

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
[
2-
{ "classnames": { "version": "2.5.1", "url": null } },
3-
{ "react-resize-detector": { "version": "9.1.1", "url": null } },
4-
{ "signature_pad": { "version": "4.0.0", "url": null } }
5-
]
1+
[{ "classnames": { "version": "2.5.1", "url": null } }, { "signature_pad": { "version": "4.0.0", "url": null } }]

packages/customWidgets/signature-web/dependencies.txt

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,41 +33,6 @@ SOFTWARE.
3333

3434
---
3535

36-
Name: react-resize-detector
37-
Version: 9.1.1
38-
License: MIT
39-
Private: false
40-
Description: React resize detector
41-
Repository: git+https://github.com/maslianok/react-resize-detector.git
42-
Author: Vitalii Maslianok <maslianok@gmail.com> (https://github.com/maslianok)
43-
Homepage: https://github.com/maslianok/react-resize-detector
44-
License Copyright:
45-
===
46-
47-
The MIT License (MIT)
48-
49-
Copyright (c) 2023 Vitalii Maslianok
50-
51-
Permission is hereby granted, free of charge, to any person obtaining a copy
52-
of this software and associated documentation files (the "Software"), to deal
53-
in the Software without restriction, including without limitation the rights
54-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55-
copies of the Software, and to permit persons to whom the Software is
56-
furnished to do so, subject to the following conditions:
57-
58-
The above copyright notice and this permission notice shall be included in all
59-
copies or substantial portions of the Software.
60-
61-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67-
SOFTWARE.
68-
69-
---
70-
7136
Name: signature_pad
7237
Version: 4.0.0
7338
License: MIT

packages/customWidgets/signature-web/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
},
3838
"dependencies": {
3939
"classnames": "^2.5.1",
40-
"react-resize-detector": "^9.1.1",
4140
"signature_pad": "4.0.0"
4241
},
4342
"devDependencies": {

packages/customWidgets/signature-web/src/components/Signature.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { PureComponent, ReactNode } from "react";
2-
3-
// @ts-expect-error signature_pad has no types
4-
import SignaturePad, { IOptions } from "signature_pad";
2+
import SignaturePad, { Options } from "signature_pad";
53
import classNames from "classnames";
6-
import ReactResizeDetector from "react-resize-detector";
74

85
import { Alert } from "./Alert";
96
import { Grid } from "./Grid";
@@ -31,8 +28,7 @@ export type penOptions = "fountain" | "ballpoint" | "marker";
3128

3229
export class Signature extends PureComponent<SignatureProps> {
3330
private canvasNode: HTMLCanvasElement | null = null;
34-
// @ts-expect-error signature_pad has no types
35-
private signaturePad: SignaturePad;
31+
private signaturePad: SignaturePad | undefined;
3632

3733
render(): ReactNode {
3834
const { className, alertMessage, wrapperStyle } = this.props;
@@ -43,6 +39,7 @@ export class Signature extends PureComponent<SignatureProps> {
4339
className={classNames("widget-signature", className)}
4440
classNameInner="widget-signature-wrapper form-control mx-textarea-input mx-textarea"
4541
style={wrapperStyle}
42+
onResize={this.onResize}
4643
>
4744
<Alert bootstrapStyle="danger">{alertMessage}</Alert>
4845
<Grid {...this.props} />
@@ -52,7 +49,6 @@ export class Signature extends PureComponent<SignatureProps> {
5249
this.canvasNode = node;
5350
}}
5451
/>
55-
<ReactResizeDetector handleWidth handleHeight onResize={this.onResize} />
5652
</SizeContainer>
5753
);
5854
}
@@ -61,6 +57,7 @@ export class Signature extends PureComponent<SignatureProps> {
6157
if (this.canvasNode) {
6258
this.signaturePad = new SignaturePad(this.canvasNode, {
6359
penColor: this.props.penColor,
60+
// @ts-expect-error // looks like this never worked, there is no onEnd in SignaturePad code
6461
onEnd: this.handleSignEnd,
6562
...this.signaturePadOptions()
6663
});
@@ -87,7 +84,7 @@ export class Signature extends PureComponent<SignatureProps> {
8784
}
8885

8986
private onResize = (): void => {
90-
if (this.canvasNode) {
87+
if (this.canvasNode && this.signaturePad) {
9188
const data = this.signaturePad.toData();
9289
this.canvasNode.width =
9390
this.canvasNode && this.canvasNode.parentElement ? this.canvasNode.parentElement.offsetWidth : 0;
@@ -98,8 +95,8 @@ export class Signature extends PureComponent<SignatureProps> {
9895
}
9996
};
10097

101-
private signaturePadOptions(): IOptions {
102-
let options: IOptions = {};
98+
private signaturePadOptions(): Options {
99+
let options: Options = {};
103100
if (this.props.penType === "fountain") {
104101
options = { minWidth: 0.6, maxWidth: 2.6, velocityFilterWeight: 0.6 };
105102
} else if (this.props.penType === "ballpoint") {
@@ -111,7 +108,7 @@ export class Signature extends PureComponent<SignatureProps> {
111108
}
112109

113110
private handleSignEnd = (): void => {
114-
if (this.props.onSignEndAction) {
111+
if (this.props.onSignEndAction && this.signaturePad) {
115112
this.props.onSignEndAction(this.signaturePad.toDataURL());
116113
}
117114
};

packages/customWidgets/signature-web/src/components/SizeContainer.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createElement, CSSProperties, FC, PropsWithChildren } from "react";
22
import classNames from "classnames";
3+
import { useResizeObserver } from "../utils/useResizeObserver";
34

45
export type HeightUnitType = "percentageOfWidth" | "percentageOfParent" | "pixels";
56

@@ -17,6 +18,7 @@ export interface SizeProps extends Dimensions, PropsWithChildren {
1718
classNameInner?: string;
1819
readOnly?: boolean;
1920
style?: CSSProperties;
21+
onResize?: () => void;
2022
}
2123

2224
export const SizeContainer: FC<SizeProps> = ({
@@ -28,12 +30,16 @@ export const SizeContainer: FC<SizeProps> = ({
2830
height,
2931
children,
3032
style,
31-
readOnly = false
33+
readOnly = false,
34+
onResize
3235
}) => {
36+
const ref = useResizeObserver(() => onResize?.());
37+
3338
const styleWidth = widthUnit === "percentage" ? `${width}%` : `${width}px`;
3439
return createElement(
3540
"div",
3641
{
42+
ref,
3743
className: classNames(className, "size-box"),
3844
style: {
3945
position: "relative",

packages/customWidgets/signature-web/src/components/__tests__/SizeContainer.spec.ts

Lines changed: 4 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,7 @@ describe("Grid", () => {
2121
it("renders structure correctly", () => {
2222
const grid = renderGrid(defaultProps);
2323

24-
expect(grid.getElement()).toEqual(
25-
createElement(
26-
"div",
27-
{
28-
className: "widget-signature size-box",
29-
style: {
30-
position: "relative",
31-
width: "500px",
32-
height: "300px"
33-
}
34-
},
35-
createElement("div", {
36-
className: "size-box-inner",
37-
readOnly: defaultProps.readOnly,
38-
disabled: defaultProps.readOnly,
39-
style: {
40-
position: "absolute",
41-
top: "0",
42-
right: "0",
43-
bottom: "0",
44-
left: "0"
45-
}
46-
})
47-
)
48-
);
24+
expect(grid.getElement()).toMatchSnapshot();
4925
});
5026

5127
it("with percentage units renders the structure correctly", () => {
@@ -57,32 +33,7 @@ describe("Grid", () => {
5733
height: 50
5834
});
5935

60-
expect(grid.getElement()).toEqual(
61-
createElement(
62-
"div",
63-
{
64-
className: "widget-signature size-box",
65-
style: {
66-
position: "relative",
67-
width: "80%",
68-
height: "auto",
69-
paddingBottom: "40%"
70-
}
71-
},
72-
createElement("div", {
73-
className: "size-box-inner",
74-
readOnly: defaultProps.readOnly,
75-
disabled: defaultProps.readOnly,
76-
style: {
77-
position: "absolute",
78-
top: "0",
79-
right: "0",
80-
bottom: "0",
81-
left: "0"
82-
}
83-
})
84-
)
85-
);
36+
expect(grid.getElement()).toMatchSnapshot();
8637
});
8738

8839
it("with percentage of parent units renders the structure correctly", () => {
@@ -94,31 +45,7 @@ describe("Grid", () => {
9445
height: 50
9546
});
9647

97-
expect(grid.getElement()).toEqual(
98-
createElement(
99-
"div",
100-
{
101-
className: "widget-signature size-box",
102-
style: {
103-
position: "relative",
104-
width: "80%",
105-
height: "50%"
106-
}
107-
},
108-
createElement("div", {
109-
className: "size-box-inner",
110-
readOnly: defaultProps.readOnly,
111-
disabled: defaultProps.readOnly,
112-
style: {
113-
position: "absolute",
114-
top: "0",
115-
right: "0",
116-
bottom: "0",
117-
left: "0"
118-
}
119-
})
120-
)
121-
);
48+
expect(grid.getElement()).toMatchSnapshot();
12249
});
12350

12451
it("with percentage and pixel units renders the structure correctly", () => {
@@ -130,30 +57,6 @@ describe("Grid", () => {
13057
height: 50
13158
});
13259

133-
expect(grid.getElement()).toEqual(
134-
createElement(
135-
"div",
136-
{
137-
className: "widget-signature size-box",
138-
style: {
139-
position: "relative",
140-
width: "80px",
141-
height: "40px"
142-
}
143-
},
144-
createElement("div", {
145-
className: "size-box-inner",
146-
readOnly: defaultProps.readOnly,
147-
disabled: defaultProps.readOnly,
148-
style: {
149-
position: "absolute",
150-
top: "0",
151-
right: "0",
152-
bottom: "0",
153-
left: "0"
154-
}
155-
})
156-
)
157-
);
60+
expect(grid.getElement()).toMatchSnapshot();
15861
});
15962
});

packages/customWidgets/signature-web/src/components/__tests__/__snapshots__/Signature.spec.ts.snap

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports[`Signature renders the structure correctly 1`] = `
1212
gridCellWidth={50}
1313
height={50}
1414
heightUnit="percentageOfWidth"
15+
onResize={[Function]}
1516
penColor="#000"
1617
penType="fountain"
1718
readOnly={false}
@@ -45,10 +46,5 @@ exports[`Signature renders the structure correctly 1`] = `
4546
<canvas
4647
className="widget-signature-canvas"
4748
/>
48-
<ResizeDetector
49-
handleHeight={true}
50-
handleWidth={true}
51-
onResize={[Function]}
52-
/>
5349
</SizeContainer>
5450
`;

0 commit comments

Comments
 (0)