Skip to content

Commit bee2c22

Browse files
committed
Code cleanup
1 parent b306cb3 commit bee2c22

6 files changed

Lines changed: 12 additions & 22 deletions

File tree

src/components/ContactForm.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,11 @@ import React from 'react';
55

66
export type ContactFormProps = {
77
className?: string;
8-
onSubmit?: React.FormEventHandler<HTMLFormElement>;
98
} & Omit<React.ComponentPropsWithRef<'form'>, 'children'>;
109

11-
export default React.forwardRef(function ContactForm(
12-
{ className, onSubmit = () => {}, ...rest }: ContactFormProps,
13-
ref: React.ForwardedRef<HTMLFormElement>,
14-
) {
10+
export default function ContactForm({ className, ...rest }: ContactFormProps) {
1511
return (
16-
<form
17-
className={classNames('contact-form', className)}
18-
onSubmit={onSubmit}
19-
{...rest}
20-
ref={ref}
21-
>
12+
<form className={classNames('contact-form', className)} {...rest}>
2213
<input
2314
aria-label="Name"
2415
id="contactName"
@@ -45,4 +36,4 @@ export default React.forwardRef(function ContactForm(
4536
<input aria-label="Send" id="contactSubmit" type="submit" value="Send" />
4637
</form>
4738
);
48-
});
39+
}

src/components/Overlay.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import type { ThemeToken, ZIndexToken } from '../types';
99

1010
export type OverlayProps = {
1111
animated?: boolean;
12-
children?: React.ReactNode;
13-
className?: string;
1412
closeOnScrimClick?: boolean;
1513
dialogClassName?: string;
1614
dialogZIndex?: ZIndexToken | number;

src/hooks/useSmoothDamp.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { smoothdamp } from '../utils';
55

66
export function useSmoothDamp(
77
defaultValue: number,
8-
targetValueRef: React.MutableRefObject<number>,
8+
targetValueRef: React.RefObject<number>,
99
smoothTime: number,
1010
maxSpeed: number = Infinity,
1111
): number {
12-
const animationHandle = useRef<number | undefined>();
13-
const previousTimeRef = useRef<number | undefined>();
12+
const animationHandle = useRef<number>(undefined);
13+
const previousTimeRef = useRef<number>(undefined);
1414
const currentValueRef = useRef<number>(defaultValue);
1515
const velocityRef = useRef<number>(0);
1616
const [value, setValue] = useState(defaultValue);
@@ -21,7 +21,7 @@ export function useSmoothDamp(
2121
const deltaTime = time - previousTimeRef.current;
2222
currentValueRef.current = smoothdamp(
2323
currentValueRef.current,
24-
targetValueRef.current,
24+
targetValueRef.current || currentValueRef.current,
2525
velocityRef,
2626
smoothTime / 1000,
2727
maxSpeed,

src/utils/math.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export function smoothdamp(
3030
deltaTime: number,
3131
): number {
3232
smoothTime = Math.max(0.0001, smoothTime);
33+
const vel = currentVelocity.current || 0;
3334
const num = 2 / smoothTime;
3435
const num2 = num * deltaTime;
3536
const num3 = 1 / (1 + num2 + 0.48 * num2 * num2 + 0.235 * num2 * num2 * num2);
@@ -38,8 +39,8 @@ export function smoothdamp(
3839
const num6 = maxSpeed * smoothTime;
3940
num4 = Math.min(Math.max(num4, -num6), num6);
4041
target = current - num4;
41-
const num7 = (currentVelocity.current + num * num4) * deltaTime;
42-
currentVelocity.current = (currentVelocity.current - num * num7) * num3;
42+
const num7 = (vel + num * num4) * deltaTime;
43+
currentVelocity.current = (vel - num * num7) * num3;
4344
let num8 = target + (num4 + num7) * num3;
4445
if (num5 - current > 0 == num8 > num5) {
4546
num8 = num5;

src/utils/scrolling.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function getScrollbarWidth(): number {
1717
: 0;
1818
}
1919

20-
export function getWheelDirection(e: WheelEvent) {
20+
export function getWheelDirection(e: WheelEvent): number {
2121
if ('deltaY' in e) {
2222
return clamp(e.deltaY, -1, 1) * -1;
2323
} else if ('wheelDeltaY' in e) {

src/utils/timing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function debounce(fn: Function, wait: number): Function {
88
};
99
}
1010

11-
export function throttle(fn: Function, wait: number = 300) {
11+
export function throttle(fn: Function, wait: number): Function {
1212
let inThrottle: boolean,
1313
lastFn: ReturnType<typeof setTimeout>,
1414
lastTime: number;

0 commit comments

Comments
 (0)