Skip to content

Commit

Permalink
feat!: upgrade to react 19 (#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsladerman authored Jan 4, 2025
1 parent ff257cf commit 44d3c60
Show file tree
Hide file tree
Showing 115 changed files with 3,199 additions and 3,321 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@
"@testing-library/jest-dom": "5.17.0",
"@types/chroma-js": "2.4.3",
"@types/lodash-es": "4.17.12",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@types/react-transition-group": "4.4.10",
"@types/react": "19.0.2",
"@types/react-dom": "19.0.2",
"@types/react-transition-group": "4.4.12",
"@typescript-eslint/eslint-plugin": "6.14.0",
"@typescript-eslint/parser": "6.14.0",
"@vitejs/plugin-react": "4.3.2",
Expand Down Expand Up @@ -125,8 +125,8 @@
"lint-staged": "15.2.0",
"npm-run-all": "4.1.5",
"prettier": "3.0.3",
"react": "18.3.1",
"react-dom": "18.3.1",
"react": "19.0.0",
"react-dom": "19.0.0",
"react-transition-group": "4.4.5",
"rimraf": "5.0.5",
"storybook": "8.3.5",
Expand All @@ -141,8 +141,8 @@
"@emotion/styled": ">=11.11.0",
"honorable": ">=1.0.0-beta.17",
"honorable-theme-default": ">=1.0.0-beta.5",
"react": ">=18.3.1",
"react-dom": ">=18.3.1",
"react": ">=19.0.0",
"react-dom": ">=19.0.0",
"react-transition-group": ">=4.4.5",
"styled-components": ">=6.1.13"
},
Expand Down
14 changes: 10 additions & 4 deletions src/ThemeDecorator.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { type ComponentType, useEffect } from 'react'
import { type ComponentType, type FC, useEffect } from 'react'
import {
CssBaseline,
Div,
ThemeProvider as HonorableThemeProvider,
type ThemeProviderProps,
} from 'honorable'
import { ThemeProvider as StyledThemeProvider } from 'styled-components'

Expand All @@ -16,6 +17,11 @@ import {
} from './theme'
import StyledCss from './GlobalStyle'

// workarounds for broken type from honorable
const TypedHonorableThemeProvider =
HonorableThemeProvider as FC<ThemeProviderProps>
const TypedCssBaseline = CssBaseline as any

function ThemeDecorator(Story: ComponentType, context: any) {
const colorMode = useThemeColorMode()

Expand All @@ -28,15 +34,15 @@ function ThemeDecorator(Story: ComponentType, context: any) {
const styledTheme = colorMode === 'light' ? styledThemeLight : styledThemeDark

return (
<HonorableThemeProvider theme={honorableTheme}>
<TypedHonorableThemeProvider theme={honorableTheme}>
<StyledThemeProvider theme={styledTheme}>
<CssBaseline />
<TypedCssBaseline />
<StyledCss />
<Div padding="xlarge">
<Story />
</Div>
</StyledThemeProvider>
</HonorableThemeProvider>
</TypedHonorableThemeProvider>
)
}

Expand Down
65 changes: 25 additions & 40 deletions src/components/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {
type ComponentProps,
type ReactElement,
type ReactNode,
type Ref,
forwardRef,
useId,
} from 'react'

Expand All @@ -22,21 +20,17 @@ import Card from './Card'
export type AccordionProps = ComponentProps<typeof RadixAccordion.Root> &
ComponentProps<typeof Card>

function AccordionRef(
{
children,
...props
}: {
children?:
| ReactElement<typeof AccordionItem>
| ReactElement<typeof AccordionItem>[]
collapsible?: boolean
} & AccordionProps,
ref: Ref<HTMLDivElement>
) {
function Accordion({
children,
...props
}: {
children?:
| ReactElement<typeof AccordionItem>
| ReactElement<typeof AccordionItem>[]
collapsible?: boolean
} & AccordionProps) {
return (
<RadixAccordion.Root
ref={ref}
asChild
collapsible={props.collapsible ?? true}
{...props}
Expand All @@ -46,34 +40,28 @@ function AccordionRef(
)
}

function AccordionItemRef(
{
value,
padding = 'relaxed',
paddingArea = 'all',
caret = 'right',
trigger,
children,
...props
}: {
value?: string
padding?: 'none' | 'compact' | 'relaxed'
paddingArea?: 'trigger-only' | 'all'
caret?: 'none' | 'left' | 'right'
trigger: ReactNode
children: ReactNode
} & Omit<ComponentProps<typeof RadixAccordion.Item>, 'value'>,
ref: Ref<HTMLDivElement>
) {
function AccordionItem({
value,
padding = 'relaxed',
paddingArea = 'all',
caret = 'right',
trigger,
children,
...props
}: {
value?: string
padding?: 'none' | 'compact' | 'relaxed'
paddingArea?: 'trigger-only' | 'all'
caret?: 'none' | 'left' | 'right'
trigger: ReactNode
children: ReactNode
} & Omit<ComponentProps<typeof RadixAccordion.Item>, 'value'>) {
const theme = useTheme()
const paddingSize = getPaddingSize(theme, padding)
// if value is not provided, use a random persisted id
const defaultValue = useId()

return (
<ItemSC
// @ts-ignore, this is the sorta thing React 19 will be nice for
ref={ref}
value={value ?? defaultValue}
{...props}
>
Expand Down Expand Up @@ -208,8 +196,5 @@ const ContentSC = styled(RadixAccordion.Content)`
}
`

const Accordion = forwardRef(AccordionRef)
const AccordionItem = forwardRef(AccordionItemRef)

export default Accordion
export { AccordionItem }
42 changes: 15 additions & 27 deletions src/components/AppIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
type ComponentProps,
type ReactElement,
type Ref,
cloneElement,
forwardRef,
} from 'react'
import { type ComponentProps, type ReactElement, cloneElement } from 'react'
import { last } from 'lodash-es'

import styled, { type DefaultTheme, useTheme } from 'styled-components'
Expand Down Expand Up @@ -36,7 +30,7 @@ type AppIconProps = {
hue?: AppIconHue
clickable?: boolean
url?: string
icon?: ReactElement
icon?: ReactElement<any>
alt?: string
name?: string
initials?: string
Expand Down Expand Up @@ -151,22 +145,19 @@ const ImgSC = styled.img<{
objectFit: 'cover',
}))

function AppIconRef(
{
size = 'medium',
spacing = 'padding',
hue,
clickable = false,
url,
icon = null,
alt,
name,
initials,
onClose,
...props
}: AppIconProps & ComponentProps<typeof AppIconSC>,
ref: Ref<any>
) {
function AppIcon({
size = 'medium',
spacing = 'padding',
hue,
clickable = false,
url,
icon = null,
alt,
name,
initials,
onClose,
...props
}: AppIconProps & ComponentProps<typeof AppIconSC>) {
const theme = useTheme()
const parentFillLevel = useFillLevel()

Expand Down Expand Up @@ -198,7 +189,6 @@ function AppIconRef(
>
{url ? (
<ImgSC
ref={ref}
src={url}
alt={alt}
$iconWidth={iconWidth}
Expand All @@ -214,7 +204,5 @@ function AppIconRef(
)
}

const AppIcon = forwardRef(AppIconRef)

export default AppIcon
export type { AppIconProps }
1 change: 1 addition & 0 deletions src/components/AppList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components'
import {
type Dispatch,
type JSX,
type ReactNode,
createRef,
useCallback,
Expand Down
28 changes: 11 additions & 17 deletions src/components/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Div, Flex, type FlexProps, Span, type SpanProps } from 'honorable'
import { type ReactNode, type Ref, forwardRef } from 'react'
import { type ReactNode } from 'react'
import styled from 'styled-components'

import { type ColorKey, type SeverityExt, sanitizeSeverity } from '../types'
Expand Down Expand Up @@ -114,19 +114,16 @@ const CloseButton = styled(IconFrame)(({ theme }) => ({
marginLeft: theme.spacing.medium,
}))

function BannerRef(
{
heading,
action,
actionProps,
children,
severity = 'success',
fullWidth = false,
onClose,
...props
}: BannerProps,
ref: Ref<any>
) {
function Banner({
heading,
action,
actionProps,
children,
severity = 'success',
fullWidth = false,
onClose,
...props
}: BannerProps) {
const finalSeverity = sanitizeSeverity(severity, {
allowList: BANNER_SEVERITIES,
default: DEFAULT_SEVERITY,
Expand All @@ -138,7 +135,6 @@ function BannerRef(

const content = (
<BannerOuter
ref={ref}
$borderColorKey={borderColorKey}
$fullWidth={fullWidth}
as={Flex}
Expand Down Expand Up @@ -177,6 +173,4 @@ function BannerRef(
return <FillLevelProvider value={3}>{content}</FillLevelProvider>
}

const Banner = forwardRef(BannerRef)

export default Banner
Loading

0 comments on commit 44d3c60

Please sign in to comment.