Skip to content

Commit 7a52a44

Browse files
authored
Merge pull request #3619 from clairep94/pr05/Migrate_client_components_final_rebuild
pr05 Typescript Migration #7: migrate client components
2 parents 6266a69 + 52be7e3 commit 7a52a44

37 files changed

+447
-439
lines changed

client/common/ButtonOrLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Link } from 'react-router-dom';
44
/**
55
* Accepts all the props of an HTML <a> or <button> tag.
66
*/
7-
export interface ButtonOrLinkProps {
7+
export interface ButtonOrLinkProps extends React.HTMLAttributes<HTMLElement> {
88
/**
99
* Can be internal or external ('http'- or 'https'-).
1010
*/

client/common/useModalClose.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef, MutableRefObject } from 'react';
1+
import { useEffect, useRef, MutableRefObject, ForwardedRef } from 'react';
22
import { useKeyDownHandlers } from './useKeyDownHandlers';
33

44
/**
@@ -18,12 +18,29 @@ import { useKeyDownHandlers } from './useKeyDownHandlers';
1818
* @param passedRef - Optional ref to the modal element. If not provided, one is created internally.
1919
* @returns A ref to be attached to the modal DOM element
2020
*/
21-
export function useModalClose(
21+
export function useModalClose<T extends HTMLElement = HTMLElement>(
2222
onClose: () => void,
23-
passedRef?: MutableRefObject<HTMLElement | null>
24-
): MutableRefObject<HTMLElement | null> {
25-
const createdRef = useRef<HTMLElement | null>(null);
26-
const modalRef = passedRef ?? createdRef;
23+
passedRef?: MutableRefObject<T | null> | ForwardedRef<T>
24+
): MutableRefObject<T | null> {
25+
const createdRef = useRef<T | null>(null);
26+
27+
// Normalize any ref to a MutableRefObject internally
28+
const modalRef: MutableRefObject<T | null> = (() => {
29+
if (!passedRef) return createdRef;
30+
if (typeof passedRef === 'function') {
31+
// For function refs, write to createdRef and call the function
32+
return {
33+
get current() {
34+
return createdRef.current;
35+
},
36+
set current(value: T | null) {
37+
createdRef.current = value;
38+
passedRef(value);
39+
}
40+
};
41+
}
42+
return passedRef;
43+
})();
2744

2845
useEffect(() => {
2946
modalRef.current?.focus();

client/common/usePrevious.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { useEffect, useRef } from 'react';
55
* @param value - The current value to track.
66
* @returns The previous value before the current render, or undefined if none.
77
*/
8-
export function usePrevious(value: unknown): unknown | undefined {
9-
const ref = useRef<unknown>();
8+
export function usePrevious<T>(value: T): T | undefined {
9+
const ref = useRef<T>();
1010

1111
useEffect(() => {
1212
ref.current = value;

client/components/Dropdown.jsx

Lines changed: 0 additions & 110 deletions
This file was deleted.

client/components/Dropdown/DropdownMenu.jsx

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)