Skip to content

Commit 8ccef62

Browse files
committed
feat: add onPointer props.
1 parent d799d01 commit 8ccef62

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

core/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,31 @@ import { type StrokeOptions } from 'perfect-freehand';
4242
export interface SignatureProps extends React.SVGProps<SVGSVGElement> {
4343
prefixCls?: string;
4444
options?: StrokeOptions;
45+
onPointer?: (points: number[][]) => void;
4546
}
4647
export default function Signature(props?: SignatureProps): React.JSX.Element;
4748
```
4849

50+
utils
51+
52+
```ts
53+
import { type StrokeOptions } from 'perfect-freehand';
54+
/**
55+
* Turn the points returned from perfect-freehand into SVG path data.
56+
*/
57+
export declare function getSvgPathFromStroke(stroke: number[][]): string;
58+
export declare const defaultOptions: StrokeOptions;
59+
export declare const getBoundingClientRect: (el: SVGSVGElement | null) => {
60+
offsetX: number;
61+
offsetY: number;
62+
};
63+
export declare const getClinetXY: ({ clientX, clientY }: PointerEvent) => {
64+
clientX: number;
65+
clientY: number;
66+
};
67+
export declare const defaultStyle: React.CSSProperties;
68+
```
69+
4970
### Options
5071

5172
The options object is optional, as are each of its properties.

core/src/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ import React, { useEffect, useRef, forwardRef, useImperativeHandle } from 'react
22
import { getStroke, type StrokeOptions } from 'perfect-freehand';
33
import { getSvgPathFromStroke, getBoundingClientRect, getClinetXY, defaultOptions, defaultStyle } from './utils';
44

5+
export * from './utils';
6+
57
export interface SignatureProps extends React.SVGProps<SVGSVGElement> {
68
prefixCls?: string;
79
options?: StrokeOptions;
10+
onPointer?: (points: number[][]) => void;
811
}
912

1013
let points: number[][] = [];
1114

1215
const Signature = forwardRef<SVGSVGElement, SignatureProps>((props, ref) => {
13-
const { className, prefixCls = 'w-signature', style, options, ...others } = props;
16+
const { className, prefixCls = 'w-signature', style, onPointer, options, ...others } = props;
1417
const cls = [className, prefixCls].filter(Boolean).join(' ');
1518
const $svg = useRef<SVGSVGElement>(null);
1619
const $path = useRef<SVGPathElement>();
@@ -40,6 +43,7 @@ const Signature = forwardRef<SVGSVGElement, SignatureProps>((props, ref) => {
4043
};
4144

4245
const handlePointerUp = () => {
46+
onPointer && onPointer(points);
4347
points = [];
4448
$path.current = undefined;
4549
};

0 commit comments

Comments
 (0)