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

refactor(ui): migrates away from React.forwardRef #9907

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
9 changes: 5 additions & 4 deletions packages/next/src/views/LivePreview/IFrame/index.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
'use client'
import React, { forwardRef } from 'react'
import React from 'react'

import { useLivePreviewContext } from '../Context/context.js'
import './index.scss'

const baseClass = 'live-preview-iframe'

type Props = {
ref: React.RefObject<HTMLIFrameElement>
setIframeHasLoaded: (value: boolean) => void
url: string
}

export const IFrame = forwardRef<HTMLIFrameElement, Props>((props, ref) => {
const { setIframeHasLoaded, url } = props
export const IFrame: React.FC<Props> = (props) => {
const { ref, setIframeHasLoaded, url } = props

const { zoom } = useLivePreviewContext()

Expand All @@ -30,4 +31,4 @@ export const IFrame = forwardRef<HTMLIFrameElement, Props>((props, ref) => {
title={url}
/>
)
})
}
9 changes: 5 additions & 4 deletions packages/ui/src/elements/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import React, { forwardRef, Fragment, isValidElement } from 'react'
import React, { Fragment, isValidElement } from 'react'

import type { Props } from './types.js'

Expand Down Expand Up @@ -47,7 +47,7 @@ export const ButtonContents = ({ children, icon, showTooltip, tooltip }) => {
)
}

export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((props, ref) => {
export const Button: React.FC<Props> = (props) => {
const {
id,
type = 'button',
Expand All @@ -64,6 +64,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((
newTab,
onClick,
onMouseDown,
ref,
round,
size = 'medium',
SubMenuPopupContent,
Expand Down Expand Up @@ -131,7 +132,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((
<a
{...buttonProps}
href={!disabled ? url : undefined}
ref={ref as React.Ref<HTMLAnchorElement>}
ref={ref as React.RefObject<HTMLAnchorElement>}
>
<ButtonContents icon={icon} showTooltip={showTooltip} tooltip={tooltip}>
{children}
Expand Down Expand Up @@ -195,4 +196,4 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((
}

return buttonElement
})
}
2 changes: 2 additions & 0 deletions packages/ui/src/elements/Button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type secondaryAction = {
label: string
onClick: (event: MouseEvent) => void
}

export type Props = {
'aria-label'?: string
buttonId?: string
Expand All @@ -29,6 +30,7 @@ export type Props = {
* @default false
*/
programmaticSubmit?: boolean
ref?: React.RefObject<HTMLAnchorElement | HTMLButtonElement | null>
round?: boolean
secondaryActions?: secondaryAction | secondaryAction[]
size?: 'large' | 'medium' | 'small'
Expand Down
9 changes: 5 additions & 4 deletions packages/ui/src/elements/EditUpload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { UploadEdits } from 'payload'

import { useModal } from '@faceless-ui/modal'
import React, { forwardRef, useRef, useState } from 'react'
import React, { useRef, useState } from 'react'
import ReactCrop from 'react-image-crop'
import 'react-image-crop/dist/ReactCrop.css'

Expand All @@ -18,11 +18,12 @@ const baseClass = 'edit-upload'
type Props = {
name: string
onChange: (value: string) => void
ref?: React.RefObject<HTMLInputElement>
value: string
}

const Input = forwardRef<HTMLInputElement, Props>((props, ref) => {
const { name, onChange, value } = props
const Input: React.FC<Props> = (props) => {
const { name, onChange, ref, value } = props

return (
<div className={`${baseClass}__input`}>
Expand All @@ -36,7 +37,7 @@ const Input = forwardRef<HTMLInputElement, Props>((props, ref) => {
/>
</div>
)
})
}

type FocalPosition = {
x: number
Expand Down
8 changes: 5 additions & 3 deletions packages/ui/src/elements/Gutter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import React, { forwardRef } from 'react'
import React from 'react'

import './index.scss'

Expand All @@ -9,18 +9,20 @@ export type GutterProps = {
left?: boolean
negativeLeft?: boolean
negativeRight?: boolean
ref?: React.RefObject<HTMLDivElement>
right?: boolean
}

const baseClass = 'gutter'

export const Gutter = forwardRef<HTMLDivElement, GutterProps>((props, ref) => {
export const Gutter: React.FC<GutterProps> = (props) => {
const {
children,
className,
left = true,
negativeLeft = false,
negativeRight = false,
ref,
right = true,
} = props

Expand All @@ -43,6 +45,6 @@ export const Gutter = forwardRef<HTMLDivElement, GutterProps>((props, ref) => {
{children}
</div>
)
})
}

Gutter.displayName = 'Gutter'
8 changes: 5 additions & 3 deletions packages/ui/src/forms/Submit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client'
import React, { forwardRef } from 'react'
import React from 'react'

import type { Props } from '../../elements/Button/types.js'

Expand All @@ -9,15 +9,17 @@ import './index.scss'

const baseClass = 'form-submit'

export const FormSubmit = forwardRef<HTMLButtonElement, Props>((props, ref) => {
export const FormSubmit: React.FC<Props> = (props) => {
const {
type = 'submit',
buttonId: id,
children,
disabled: disabledFromProps,
onClick,
programmaticSubmit,
ref,
} = props

const processing = useFormProcessing()
const initializing = useFormInitializing()
const { disabled, submit } = useForm()
Expand Down Expand Up @@ -46,4 +48,4 @@ export const FormSubmit = forwardRef<HTMLButtonElement, Props>((props, ref) => {
</Button>
</div>
)
})
}
2 changes: 2 additions & 0 deletions packages/ui/src/utilities/getClientConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export const getClientConfig = cache(
if (cachedClientConfig && !global._payload_doNotCacheClientConfig) {
return cachedClientConfig
}

const { config, i18n, importMap } = args

cachedClientConfig = createClientConfig({
config,
i18n,
importMap,
})

global._payload_clientConfig = cachedClientConfig

global._payload_doNotCacheClientConfig = false
Expand Down