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

feat: react 19 codemod #654

Open
wants to merge 2 commits into
base: v4.0.0
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions packages/icons/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PixivIcon, Props } from './PixivIcon'

Check failure on line 1 in packages/icons/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

'Props' is defined but never used
import { __SERVER__ } from './ssr'
export { PixivIcon, type KnownIconType, type Props } from './PixivIcon'
export { KNOWN_ICON_FILES } from './charcoalIconFiles'
Expand All @@ -8,11 +8,13 @@
interface Window {
PixivIcon: typeof PixivIcon
}
}

declare module 'react' {
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace JSX {
namespace JSX {
interface IntrinsicElements {
'pixiv-icon': Props
'pixiv-icon': import('./PixivIcon').Props
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions packages/react-sandbox/src/components/TextEllipsis/helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
// https://github.com/fernandopasik/react-children-utilities/blob/971d8a0324e6183734d8d1af9a65dbad18ab3d00/src/lib/onlyText.ts

import {
Children,
isValidElement,
ReactElement,
ReactNode,
ReactText,
} from 'react'
import { Children, isValidElement, ReactElement, ReactNode } from 'react'

const hasChildren = (
element: ReactNode
Expand All @@ -16,7 +10,7 @@ const hasChildren = (

export const childToString = (
// eslint-disable-next-line @typescript-eslint/ban-types
child?: ReactText | boolean | {} | null
child?: number | string | boolean | {} | null
): string => {
if (
typeof child === 'undefined' ||
Expand Down
10 changes: 5 additions & 5 deletions packages/react-sandbox/src/foundation/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function measure(ref: Element | null): ElementSize | undefined {
}

export function useElementSize(
ref: React.RefObject<Element>,
ref: React.RefObject<Element | null>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
deps: any[] = []
) {
Expand Down Expand Up @@ -174,21 +174,21 @@ export function useElementSize(
*/
export function useDebounceAnimationState<T>(defaultValue: T) {
const [state, setState] = useState(defaultValue)
const timer = useRef<ReturnType<typeof requestAnimationFrame>>()
const timer = useRef<ReturnType<typeof requestAnimationFrame> | null>(null)
// typescript bug? (any when omitting type annotation)
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
const setDebounceState = useCallback((value: T, force: boolean = false) => {
if (force) {
setState(value)
return
}
if (timer.current !== undefined) {
if (timer.current !== null) {
return
}
timer.current = requestAnimationFrame(() => {
setState(value)
if (timer.current !== undefined) {
timer.current = undefined
if (timer.current !== null) {
timer.current = null
}
})
}, [])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import './index.css'

import { ForwardedRef, forwardRef, ReactNode, useMemo } from 'react'
import {
ForwardedRef,
forwardRef,
useMemo,
type ReactNode,
type JSX,
} from 'react'
import { useClassNames } from '../../../_lib/useClassNames'

export type CustomJSXElement =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { RefObject, createContext } from 'react'
import { DropdownMenuItemProps } from '../DropdownMenuItem'

type MenuListContextType = {
root?: RefObject<HTMLUListElement>
root?: RefObject<HTMLUListElement | null>
value?: string
propsArray?: DropdownMenuItemProps[]
setValue: (v: string) => void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export type PopoverProps = {
isOpen: boolean
onClose: () => void
children: ReactNode
triggerRef: RefObject<Element>
popoverRef?: RefObject<HTMLDivElement>
triggerRef: RefObject<Element | null>
popoverRef?: RefObject<HTMLDivElement | null>
}

const _empty = () => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { usePreventScroll } from '../DropdownSelector/Popover/usePreventScroll'
export function useCharcoalModalOverlay(
props: AriaModalOverlayProps,
state: { isOpen: boolean; onClose: () => void },
ref: React.RefObject<HTMLElement>
ref: React.RefObject<HTMLElement | null>
): ModalOverlayAria {
const { overlayProps, underlayProps } = useOverlay(
{
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/components/TextField/useFocusWithClick.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useEffect } from 'react'
import * as React from 'react'

export function useFocusWithClick(
containerRef: React.RefObject<HTMLDivElement>,
inputRef: React.RefObject<HTMLInputElement | HTMLTextAreaElement>
containerRef: React.RefObject<HTMLDivElement | null>,
inputRef: React.RefObject<HTMLInputElement | HTMLTextAreaElement | null>
) {
useEffect(() => {
const el = containerRef.current
Expand Down
2 changes: 2 additions & 0 deletions packages/styled/src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import styled, { ThemeProvider } from 'styled-components'
import { Example } from './addThemeUtils.story'
import { MyTheme, myTheme } from './storyHelper'

import type { JSX } from 'react'

function render(children: JSX.Element) {
return renderer
.create(<ThemeProvider theme={myTheme(light)}>{children}</ThemeProvider>)
Expand Down
Loading