Skip to content

Commit b04b39b

Browse files
committed
Make Draggable generic over the value type.
Selection is the only user of Draggable. In this use, TypeScript will now infer the type PreviewSelection for the type argument.
1 parent 1faf2e3 commit b04b39b

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/components/shared/Draggable.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,17 @@
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

55
import * as React from 'react';
6-
import type { Milliseconds } from 'firefox-profiler/types';
76

8-
export type OnMove = (
9-
originalValue: {
10-
readonly selectionEnd: Milliseconds;
11-
readonly selectionStart: Milliseconds;
12-
},
7+
export type OnMove<T> = (
8+
originalValue: T,
139
dx: number,
1410
dy: number,
1511
isModifying: boolean
1612
) => void;
1713

18-
type Props = {
19-
value: {
20-
readonly selectionStart: Milliseconds;
21-
readonly selectionEnd: Milliseconds;
22-
};
23-
onMove: OnMove;
14+
type Props<T> = {
15+
value: T;
16+
onMove: OnMove<T>;
2417
className: string;
2518
children?: React.ReactNode;
2619
};
@@ -37,7 +30,7 @@ type State = {
3730
* x and y deltas compared to the mouse position at mousedown.
3831
* During the drag, the additional className 'dragging' is set on the element.
3932
*/
40-
export class Draggable extends React.PureComponent<Props, State> {
33+
export class Draggable<T> extends React.PureComponent<Props<T>, State> {
4134
_container: HTMLDivElement | null = null;
4235
_handlers: {
4336
mouseMoveHandler: (param: MouseEvent) => void;

0 commit comments

Comments
 (0)