-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): removes all instances of React.forwardRef (#10334)
Similar to #10331. Since React 19, refs can now be passed directly through props without the need for `React.forwardRef`. This greatly simplifies components types and overall syntax.
- Loading branch information
1 parent
47e8158
commit 1f4790a
Showing
16 changed files
with
209 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,48 @@ | ||
/* eslint-disable jsx-a11y/heading-has-content */ | ||
import { cn } from 'src/utilities/cn' | ||
import * as React from 'react' | ||
|
||
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>( | ||
({ className, ...props }, ref) => ( | ||
<div | ||
className={cn('rounded-lg border bg-card text-card-foreground shadow-sm', className)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
), | ||
const Card: React.FC< | ||
{ ref?: React.Ref<HTMLDivElement> } & React.HTMLAttributes<HTMLDivElement> | ||
> = ({ className, ref, ...props }) => ( | ||
<div | ||
className={cn('rounded-lg border bg-card text-card-foreground shadow-sm', className)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
) | ||
Card.displayName = 'Card' | ||
|
||
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>( | ||
({ className, ...props }, ref) => ( | ||
<div className={cn('flex flex-col space-y-1.5 p-6', className)} ref={ref} {...props} /> | ||
), | ||
const CardHeader: React.FC< | ||
{ ref?: React.Ref<HTMLDivElement> } & React.HTMLAttributes<HTMLDivElement> | ||
> = ({ className, ref, ...props }) => ( | ||
<div className={cn('flex flex-col space-y-1.5 p-6', className)} ref={ref} {...props} /> | ||
) | ||
CardHeader.displayName = 'CardHeader' | ||
|
||
const CardTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>( | ||
({ className, ...props }, ref) => ( | ||
<h3 | ||
className={cn('text-2xl font-semibold leading-none tracking-tight', className)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
), | ||
const CardTitle: React.FC< | ||
{ ref?: React.Ref<HTMLHeadingElement> } & React.HTMLAttributes<HTMLHeadingElement> | ||
> = ({ className, ref, ...props }) => ( | ||
<h3 | ||
className={cn('text-2xl font-semibold leading-none tracking-tight', className)} | ||
ref={ref} | ||
{...props} | ||
/> | ||
) | ||
CardTitle.displayName = 'CardTitle' | ||
|
||
const CardDescription = React.forwardRef< | ||
HTMLParagraphElement, | ||
React.HTMLAttributes<HTMLParagraphElement> | ||
>(({ className, ...props }, ref) => ( | ||
const CardDescription: React.FC< | ||
{ ref?: React.Ref<HTMLParagraphElement> } & React.HTMLAttributes<HTMLParagraphElement> | ||
> = ({ className, ref, ...props }) => ( | ||
<p className={cn('text-sm text-muted-foreground', className)} ref={ref} {...props} /> | ||
)) | ||
CardDescription.displayName = 'CardDescription' | ||
) | ||
|
||
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>( | ||
({ className, ...props }, ref) => ( | ||
<div className={cn('p-6 pt-0', className)} ref={ref} {...props} /> | ||
), | ||
const CardContent: React.FC< | ||
{ ref?: React.Ref<HTMLDivElement> } & React.HTMLAttributes<HTMLDivElement> | ||
> = ({ className, ref, ...props }) => ( | ||
<div className={cn('p-6 pt-0', className)} ref={ref} {...props} /> | ||
) | ||
CardContent.displayName = 'CardContent' | ||
|
||
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>( | ||
({ className, ...props }, ref) => ( | ||
<div className={cn('flex items-center p-6 pt-0', className)} ref={ref} {...props} /> | ||
), | ||
const CardFooter: React.FC< | ||
{ ref?: React.Ref<HTMLDivElement> } & React.HTMLAttributes<HTMLDivElement> | ||
> = ({ className, ref, ...props }) => ( | ||
<div className={cn('flex items-center p-6 pt-0', className)} ref={ref} {...props} /> | ||
) | ||
CardFooter.displayName = 'CardFooter' | ||
|
||
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import { cn } from 'src/utilities/cn' | ||
import * as React from 'react' | ||
|
||
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {} | ||
|
||
const Input = React.forwardRef<HTMLInputElement, InputProps>( | ||
({ type, className, ...props }, ref) => { | ||
return ( | ||
<input | ||
className={cn( | ||
'flex h-10 w-full rounded border border-border bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', | ||
className, | ||
)} | ||
ref={ref} | ||
type={type} | ||
{...props} | ||
/> | ||
) | ||
}, | ||
) | ||
Input.displayName = 'Input' | ||
const Input: React.FC< | ||
{ | ||
ref?: React.Ref<HTMLInputElement> | ||
} & React.InputHTMLAttributes<HTMLInputElement> | ||
> = ({ type, className, ref, ...props }) => { | ||
return ( | ||
<input | ||
className={cn( | ||
'flex h-10 w-full rounded border border-border bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', | ||
className, | ||
)} | ||
ref={ref} | ||
type={type} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
export { Input } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.