diff --git a/package.json b/package.json index 7cf0b63..98f4266 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,8 @@ }, "devDependencies": { "@opencast/eslint-config-ts-react": "^0.3.0", - "@types/react": "^18.2.13", - "@types/react-dom": "^18.2.19", + "@types/react": "^19.1.8", + "@types/react-dom": "^19.1.6", "eslint": "^9.20.1", "typescript": "^5.1.3 <5.8.4" }, @@ -28,9 +28,9 @@ "@emotion/react": "^11.11.4", "@floating-ui/react": "^0.27.5", "focus-trap-react": "^10.2.3 || ^11.0.3", - "react": "^18.2.0", - "react-dom": "^18.2.0", + "react": "^19.1.0", + "react-dom": "^19.1.0", "react-icons": "^5.5.0", - "react-merge-refs": "^2.0.2" + "react-merge-refs": "^3.0.2" } } diff --git a/src/button.tsx b/src/button.tsx index 912baed..5d705a7 100644 --- a/src/button.tsx +++ b/src/button.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { JSX } from "react"; import { Interpolation, Theme } from "@emotion/react"; import { AppkitConfig, focusStyle, match, useAppkitConfig, useColorScheme } from "."; diff --git a/src/card.tsx b/src/card.tsx index 8294356..39837ee 100644 --- a/src/card.tsx +++ b/src/card.tsx @@ -1,5 +1,6 @@ import { LuTriangleAlert, LuInfo } from "react-icons/lu"; import { match, useAppkitConfig } from "."; +import { JSX } from "react"; type Props = JSX.IntrinsicElements["div"] & { diff --git a/src/confirmationModal.tsx b/src/confirmationModal.tsx index 5b41cb3..ba397de 100644 --- a/src/confirmationModal.tsx +++ b/src/confirmationModal.tsx @@ -6,6 +6,7 @@ import { useState, useRef, useImperativeHandle, + JSX, } from "react"; import { ModalProps, ModalHandle, Modal, Spinner, Button, boxError } from "."; import { currentRef } from "./util"; diff --git a/src/errorBox.tsx b/src/errorBox.tsx index 57d8568..d1358c0 100644 --- a/src/errorBox.tsx +++ b/src/errorBox.tsx @@ -1,4 +1,4 @@ -import { ReactNode } from "react"; +import { JSX, ReactNode } from "react"; import { Card } from "."; diff --git a/src/floating.tsx b/src/floating.tsx index df97040..c1841e6 100644 --- a/src/floating.tsx +++ b/src/floating.tsx @@ -18,7 +18,7 @@ import { useListNavigation, useRole, } from "@floating-ui/react"; -import React, { ReactNode, ReactElement, useRef, useState, useImperativeHandle } from "react"; +import React, { ReactNode, ReactElement, useRef, useState, useImperativeHandle, HTMLAttributes } from "react"; import { mergeRefs } from "react-merge-refs"; import { bug, unreachable } from "./err"; @@ -47,8 +47,8 @@ type Context = { }; }; refs: Pick & { - arrowRef: React.MutableRefObject; - listRef: React.MutableRefObject>; + arrowRef: React.RefObject; + listRef: React.RefObject>; }; getReferenceProps: ReturnType["getReferenceProps"]; getFloatingProps: ReturnType["getFloatingProps"]; @@ -259,7 +259,7 @@ export const FloatingContainer = React.forwardRef ====================================================================== export type FloatingTriggerProps = { - children: ReactElement; + children: ReactElement> }; /** @@ -273,9 +273,9 @@ export type FloatingTriggerProps = { export const FloatingTrigger: React.FC = ({ children }) => { const context = useFloatingContext(); - return React.cloneElement(children, { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return React.cloneElement(children, { "data-floating-state": context.open ? "open" : "closed", - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument ...context.getReferenceProps({ ref: context.refs.setReference, onClick: () => context.open && context.setOpen?.(false), @@ -437,7 +437,7 @@ export const Floating = React.forwardRef( // ===== Convenience Components ================================================================== export type WithTooltipProps = { - children: ReactElement; + children: FloatingTriggerProps["children"] tooltip: ReactNode; tooltipCss?: CSSObject; } & Partial>; diff --git a/src/header.tsx b/src/header.tsx index 4f24fe4..f201a8d 100644 --- a/src/header.tsx +++ b/src/header.tsx @@ -1,10 +1,11 @@ -import { ReactElement, ReactNode, forwardRef, useRef } from "react"; +import { JSX, ReactNode, forwardRef, useRef } from "react"; import { CSSObject, jsx } from "@emotion/react"; import { FiArrowLeft, FiCheck } from "react-icons/fi"; import { useAppkitConfig, Floating, FloatingContainer, FloatingContainerProps, FloatingHandle, FloatingTrigger, ProtoButton, focusStyle, useColorScheme, match, useFloatingItemProps, + FloatingTriggerProps, } from "."; @@ -14,7 +15,7 @@ export type WithHeaderMenuProps = { menu: Omit, /** Overrides for the floating container */ floatingContainer?: Partial, - children: ReactElement; + children: FloatingTriggerProps["children"] }; /** @@ -205,7 +206,13 @@ export const HeaderMenuItem = forwardRef( }} {...!wrapper && { className, - ref: r => typeof ref === "function" ? ref(r) : (ref ? ref.current = r : {}), + ref: r => { + if (typeof ref === "function") { + ref(r); + } else if (ref && "current" in ref) { + ref.current = r; + } + }, }} > {jsx(wrapperElem.type, { diff --git a/src/modal.tsx b/src/modal.tsx index 9572dce..a3f81e1 100644 --- a/src/modal.tsx +++ b/src/modal.tsx @@ -7,7 +7,7 @@ import { } from "react"; import ReactDOM from "react-dom"; import { LuX } from "react-icons/lu"; -import FocusTrap from "focus-trap-react"; +import { FocusTrap } from "focus-trap-react"; import { useAppkitConfig, ProtoButton, focusStyle, useColorScheme, } from "."; diff --git a/src/spinner.tsx b/src/spinner.tsx index fcd4fc0..f85a2a9 100644 --- a/src/spinner.tsx +++ b/src/spinner.tsx @@ -1,5 +1,5 @@ import { keyframes } from "@emotion/react"; -import React from "react"; +import React, { JSX } from "react"; type Props = JSX.IntrinsicElements["svg"] & { size?: number | string; diff --git a/src/util.tsx b/src/util.tsx index 2c937da..f832722 100644 --- a/src/util.tsx +++ b/src/util.tsx @@ -1,4 +1,4 @@ -import { MutableRefObject, useEffect } from "react"; +import { RefObject, useEffect } from "react"; import { bug } from "./err"; /** @@ -131,7 +131,7 @@ export const screenWidthAbove = (w: number) => `@media not all and (max-width: $ /** Helper to react to clicks outside of the DOM element referred to by `ref`. */ export const useOnOutsideClick = ( - ref: MutableRefObject, + ref: RefObject, callback: () => void, ): void => { useEffect(() => { @@ -153,6 +153,6 @@ export const useOnOutsideClick = ( * This is mainly for accessing refs in event handlers for elements * that are guaranteed to be alive as long as the ref itself. */ -export const currentRef = (ref: React.RefObject): T => ( +export const currentRef = (ref: React.RefObject): T => ( ref.current ?? bug("ref unexpectedly unbound") );