Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MUI: Compat with React 19 types #619

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/local-ui-lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
export const bounceAnim: string;
export const Button: React.ComponentType<
JSX.IntrinsicElements['button'] & {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/base/components/modal/UseModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function UseModal() {
}

interface ModalProps {
children: React.ReactElement;
children: React.ReactElement<any>;
closeAfterTransition?: boolean;
container?: Element | (() => Element | null) | null;
disableAutoFocus?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions docs/data/base/components/popper/PlacementPopper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import { Popper, PopperPlacementType } from '@mui/base/Popper';

import type { JSX } from "react";

function Radio({ value, ...props }: JSX.IntrinsicElements['input']) {
return (
<span>
Expand Down
2 changes: 2 additions & 0 deletions docs/data/base/components/popup/Placement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from '@mui/base/Unstable_Popup';
import { styled, css, Theme } from '@mui/system';

import type { JSX } from "react";

function Radio({ value, ...props }: JSX.IntrinsicElements['input']) {
return (
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';

import type { JSX } from "react";

const Select = React.forwardRef(function Select<
TValue extends {},
Multiple extends boolean,
Expand Down
2 changes: 2 additions & 0 deletions docs/data/base/components/select/UnstyledSelectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Option as BaseOption, optionClasses } from '@mui/base/Option';
import { styled } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';

import type { JSX } from "react";

export default function UnstyledSelectForm() {
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function PopupWithTrigger(props: PopupProps) {
);
}

function MaterialUITransitionAdapter(props: { children: React.ReactElement }) {
function MaterialUITransitionAdapter(props: { children: React.ReactElement<any> }) {
const { requestedEnter, onExited } = useTransitionStateManager();
const { children } = props;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { MenuItem as BaseMenuItem, menuItemClasses } from '@mui/base/MenuItem';
import { styled, alpha } from '@mui/system';
import UnfoldMoreRoundedIcon from '@mui/icons-material/UnfoldMoreRounded';

import type { JSX } from "react";

export default function KeyboardNavigation() {
return (
<Container>
Expand Down
2 changes: 2 additions & 0 deletions docs/data/joy/components/autocomplete/AutocompleteHint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from 'react';
import Autocomplete from '@mui/joy/Autocomplete';
import { Typography, styled } from '@mui/joy';

import type { JSX } from "react";

const StyledDiv = styled('div')({
flex: 1, // stretch to fill the root slot
minWidth: 0, // won't push end decorator out of the autocomplete
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/input/DebouncedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type DebounceProps = {
function DebounceInput(props: InputProps & DebounceProps) {
const { handleDebounce, debounceTimeout, ...rest } = props;

const timerRef = React.useRef<ReturnType<typeof setTimeout>>();
const timerRef = React.useRef<ReturnType<typeof setTimeout>>(undefined);

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
clearTimeout(timerRef.current);
Expand Down
2 changes: 2 additions & 0 deletions docs/data/joy/components/input/FloatingLabelInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { styled } from '@mui/joy/styles';
import Input from '@mui/joy/Input';
import CheckCircleOutlined from '@mui/icons-material/CheckCircleOutlined';

import type { JSX } from "react";

const StyledInput = styled('input')({
border: 'none', // remove the native input border
minWidth: 0, // remove the native input width
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/menu/MenuIconSideNavExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import MenuButton from '@mui/joy/MenuButton';
// https://popper.js.org/docs/v2/modifiers/offset/
interface MenuButtonProps extends React.HTMLAttributes<HTMLButtonElement> {
children: React.ReactNode;
menu: React.ReactElement;
menu: React.ReactElement<any>;
open: boolean;
onOpen: (
event?:
Expand Down
2 changes: 2 additions & 0 deletions docs/data/joy/components/menu/MenuToolbarExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import Dropdown, { DropdownProps } from '@mui/joy/Dropdown';
import MenuButton from '@mui/joy/MenuButton';
import { Theme } from '@mui/joy';

import type { JSX } from "react";

type MenuBarButtonProps = Pick<DropdownProps, 'children' | 'open'> & {
onOpen: DropdownProps['onOpenChange'];
onKeyDown: React.KeyboardEventHandler;
Expand Down
2 changes: 1 addition & 1 deletion docs/data/joy/components/snackbar/SnackbarHideDuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function SnackbarHideDuration() {
const [open, setOpen] = React.useState(false);
const [duration, setDuration] = React.useState<undefined | number>();
const [left, setLeft] = React.useState<undefined | number>();
const timer = React.useRef<undefined | number>();
const timer = React.useRef<undefined | number>(undefined);
const countdown = () => {
timer.current = window.setInterval(() => {
setLeft((prev) => (prev === undefined ? prev : Math.max(0, prev - 100)));
Expand Down
2 changes: 2 additions & 0 deletions docs/data/joy/components/textarea/FloatingLabelTextarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { TextareaAutosize } from '@mui/base/TextareaAutosize';
import { styled } from '@mui/joy/styles';
import Textarea from '@mui/joy/Textarea';

import type { JSX } from "react";

const StyledTextarea = styled(TextareaAutosize)({
resize: 'none',
border: 'none', // remove the native textarea border
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import MenuItem from '@mui/joy/MenuItem';
import { ListActionTypes } from '@mui/base/useList';

export default function Menu(props: {
control: React.ReactElement;
control: React.ReactElement<any>;
id: string;
menus: Array<{ label: string } & { [k: string]: any }>;
}) {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/app-bar/ElevateAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface Props {
* You won't need it on your project.
*/
window?: () => Window;
children: React.ReactElement;
children: React.ReactElement<any>;
}

function ElevationScroll(props: Props) {
Expand Down
2 changes: 1 addition & 1 deletion docs/data/material/components/modal/SpringModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Typography from '@mui/material/Typography';
import { useSpring, animated } from '@react-spring/web';

interface FadeProps {
children: React.ReactElement;
children: React.ReactElement<any>;
in?: boolean;
onClick?: any;
onEnter?: (node: HTMLElement, isAppearing: boolean) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SaveIcon from '@mui/icons-material/Save';
export default function CircularIntegration() {
const [loading, setLoading] = React.useState(false);
const [success, setSuccess] = React.useState(false);
const timer = React.useRef<ReturnType<typeof setTimeout>>();
const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);

const buttonSx = {
...(success && {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Typography from '@mui/material/Typography';
export default function DelayingAppearance() {
const [loading, setLoading] = React.useState(false);
const [query, setQuery] = React.useState('idle');
const timerRef = React.useRef<ReturnType<typeof setTimeout>>();
const timerRef = React.useRef<ReturnType<typeof setTimeout>>(undefined);

React.useEffect(
() => () => {
Expand Down
2 changes: 2 additions & 0 deletions docs/src/components/header/HeaderNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import ROUTES from 'docs/src/route';
import { Link } from '@mui/docs/Link';
import MuiProductSelector from 'docs/src/modules/components/MuiProductSelector';

import type { JSX } from "react";

const Navigation = styled('nav')(({ theme }) => [
{
'& > div': {
Expand Down
2 changes: 2 additions & 0 deletions docs/src/components/home/StoreTemplatesBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import LaunchRounded from '@mui/icons-material/LaunchRounded';
import Slide from 'docs/src/components/animation/Slide';
import FadeDelay from 'docs/src/components/animation/FadeDelay';

import type { JSX } from "react";

const ratio = 900 / 494;

// 'transparent' is interpreted as transparent black in Safari
Expand Down
2 changes: 2 additions & 0 deletions docs/src/components/icon/IconImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { useTheme, styled, Theme } from '@mui/material/styles';
import Box from '@mui/material/Box';
import { SxProps } from '@mui/system';

import type { JSX } from "react";

export type IconImageProps = {
name:
| 'product-core'
Expand Down
2 changes: 2 additions & 0 deletions docs/src/components/markdown/MarkdownElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
styled,
} from '@mui/material/styles';

import type { JSX } from "react";

const Root = styled('div')(({ theme }) => ({
...theme.typography.caption,
color: (theme.vars || theme).palette.text.primary,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Box from '@mui/material/Box';
import { Input } from '@mui/base/Input';
import { styled, GlobalStyles } from '@mui/system';

import type { JSX } from "react";

const fieldStyles = `
--TextInput-height: 64px;
--TextInput-paddingTop: 2rem;
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/typography/SectionHeadline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface SectionHeadlineProps {
*/
inverted?: boolean;
overline?: React.ReactNode;
title: string | React.ReactElement;
title: string | React.ReactElement<any>;
}

export default function SectionHeadline(props: SectionHeadlineProps) {
Expand Down
22 changes: 13 additions & 9 deletions docs/src/modules/components/JoyThemeBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ function filterGlobalVariantTokens(palette: Partial<PaletteVariant>, variant: Va
return tokens;
}

type StateReducer<T> = (state: T, action: Partial<T>) => T;
type State = { hover: boolean; active: boolean; disabled: boolean };

function GlobalVariantForm({
color,
Expand All @@ -1001,13 +1001,17 @@ function GlobalVariantForm({
onRemove: (token: string) => void;
}) {
const [selectedVariant, setSelectedVariant] = React.useState<VariantProp>('solid');
const [states, setStates] = React.useReducer<
StateReducer<{ hover: boolean; active: boolean; disabled: boolean }>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One less utility type 👍🏻

>((prevState, action) => ({ ...prevState, ...action }), {
hover: false,
active: false,
disabled: false,
});
const [states, setStates] = React.useReducer(
(prevState, action: Partial<State>) => ({
...prevState,
...action,
}),
{
hover: false,
active: false,
disabled: false,
},
);
const themeDefaultValue = filterGlobalVariantTokens(themeDefaultValueProp, selectedVariant);
const value = filterGlobalVariantTokens(valueProp, selectedVariant);
const mergedValue = { ...themeDefaultValue, ...value };
Expand Down Expand Up @@ -1273,7 +1277,7 @@ function getAvailableTokens(colorSchemes: any, colorMode: 'light' | 'dark') {
return tokens;
}

function TemplatesDialog({ children, data }: { children: React.ReactElement; data: any }) {
function TemplatesDialog({ children, data }: { children: React.ReactElement<any>; data: any }) {
const [open, setOpen] = React.useState(false);
const { map: templateMap } = sourceJoyTemplates();
const renderItem = (name: string, item: TemplateData) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/utils/useClipboardCopy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clipboardCopy from 'clipboard-copy';

export default function useClipboardCopy() {
const [isCopied, setIsCopied] = React.useState(false);
const timeout = React.useRef<ReturnType<typeof setTimeout>>();
const timeout = React.useRef<ReturnType<typeof setTimeout>>(undefined);
const mounted = React.useRef(false);

React.useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions docs/src/pages/premium-themes/onepirate/modules/withRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { ThemeProvider } from '@mui/material/styles';
import CssBaseline from '@mui/material/CssBaseline';
import theme from './theme';

import type { JSX } from "react";

export default function withRoot<P extends JSX.IntrinsicAttributes>(
Component: React.ComponentType<P>,
) {
Expand Down
50 changes: 26 additions & 24 deletions docs/types/docs.d.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
declare module 'docs/src/modules/components/HighlightedCode' {
import * as React from 'react';
import { StyledComponentProps } from '@mui/material/styles';
import * as React from 'react';
import { StyledComponentProps } from '@mui/material/styles';

type ClassKey = 'root';
export interface Props extends StyledComponentProps<ClassKey> {
className?: string;
/**
* plain string
*/
code: string;
copyButtonHidden?: boolean;
copyButtonProps?: JSX.IntrinsicElements['button'];
/**
* short identifier of the code language
* see @mui/internal-markdown/prism for possible languages
*/
language: string;
/**
* The component used for the root node.
* @default MarkdownElement
*/
component?: React.ElementType;
sx?: object;
}
export default function HighlightedCode(props: Props): React.ReactElement;
import type { JSX } from "react";

type ClassKey = 'root';
export interface Props extends StyledComponentProps<ClassKey> {
className?: string;
/**
* plain string
*/
code: string;
copyButtonHidden?: boolean;
copyButtonProps?: JSX.IntrinsicElements['button'];
/**
* short identifier of the code language
* see @mui/internal-markdown/prism for possible languages
*/
language: string;
/**
* The component used for the root node.
* @default MarkdownElement
*/
component?: React.ElementType;
sx?: object;
}
export default function HighlightedCode(props: Props): React.ReactElement;
}

declare module 'react-imask';
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@
"@definitelytyped/typescript-versions": "^0.1.1",
"@definitelytyped/utils": "^0.1.5",
"@types/node": "^18.19.22",
"@types/react": "^18.2.55",
"@types/react-dom": "18.2.19",
"@types/react": "npm:@eps1lon/react-19-types",
"@types/react-dom": "npm:@eps1lon/react-dom-19-types",
"@types/react-is": "npm:@eps1lon/react-is-19-types",
"cross-fetch": "^4.0.0"
},
"nyc": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
type Props = {
foo?: boolean;
bar?: true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
type Props = {
foo: boolean;
bar: true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as React from 'react';

import type { JSX } from "react";

export interface Props {
value: unknown;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
interface Props {
/**
* The type of the button relevant to its `<form>`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
export function Foo(props: {
element: Element;
optional?: Element;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from "react";
type Type = 'one' | 'two' | 'three'

interface ParentProps<T extends Type> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as React from 'react';

import type { JSX } from "react";

export default function Modal(props: React.HTMLAttributes<HTMLDivElement>): JSX.Element;
Loading