Skip to content

Commit 12b4e95

Browse files
committed
Solve ui react/typescript performance issues
1 parent 6182f19 commit 12b4e95

8 files changed

Lines changed: 349 additions & 432 deletions

File tree

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,13 @@
5353
"devDependencies": {
5454
"@biomejs/biome": "2.4.5",
5555
"typescript": "5.9.3"
56+
},
57+
"pnpm": {
58+
"overrides": {
59+
"react": "19.2.4",
60+
"react-dom": "19.2.4",
61+
"@types/react": "19.2.14",
62+
"@types/react-dom": "19.2.3"
63+
}
5664
}
5765
}

packages/config/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"noErrorTruncation": true,
3+
"noErrorTruncation": false,
44
"target": "esnext",
55
"module": "esnext",
66
"moduleResolution": "bundler",

packages/ui/src/atoms/Button/Button.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { type VariantProps, cva } from "cva"
2-
import type { ComponentPropsWithRef, ElementType, PropsWithChildren, ReactNode } from "react"
2+
import type { ElementType, HTMLAttributes, PropsWithChildren, ReactNode, Ref } from "react"
33
import { cn } from "../../utils"
44

5-
// Add variants, colors, or sizes in the arrays below
6-
// to add them to the component
75
export const BUTTON_VARIANTS = ["solid", "outline", "text", "unstyled"] as const
86
export const BUTTON_COLORS = ["light", "dark", "brand", "blue", "red"] as const
97
export const BUTTON_SIZES = ["sm", "md", "lg"] as const
@@ -12,21 +10,23 @@ export type ButtonVariant = (typeof BUTTON_VARIANTS)[number]
1210
export type ButtonColor = (typeof BUTTON_COLORS)[number]
1311
export type ButtonSize = (typeof BUTTON_SIZES)[number]
1412

15-
export type ButtonProps<E extends ElementType = "button"> = VariantProps<typeof button> &
16-
PropsWithChildren & {
17-
/**
18-
* The HTML element to render the button as
19-
*
20-
* Defaults to an HTML <button> element, but can be used with the Link
21-
* component from 'next/link' to create a link that looks like a button
22-
*/
23-
element?: E
13+
export type ButtonProps = VariantProps<typeof button> &
14+
PropsWithChildren &
15+
Omit<HTMLAttributes<HTMLElement>, "color"> & {
16+
element?: ElementType
2417
className?: string
2518
icon?: ReactNode
2619
iconRight?: ReactNode
27-
} & ComponentPropsWithRef<E>
20+
ref?: Ref<HTMLElement>
21+
href?: string
22+
type?: "button" | "submit" | "reset"
23+
disabled?: boolean
24+
target?: string
25+
rel?: string
26+
prefetch?: boolean
27+
}
2828

29-
export function Button<E extends ElementType = "button">({
29+
export function Button({
3030
element,
3131
children,
3232
variant,
@@ -37,7 +37,7 @@ export function Button<E extends ElementType = "button">({
3737
className,
3838
ref,
3939
...props
40-
}: ButtonProps<E>) {
40+
}: ButtonProps) {
4141
const Component = element ?? "button"
4242
const classes = cn(button({ variant, size, color }), "inline-flex items-center justify-center gap-1", className)
4343
return (
@@ -89,7 +89,6 @@ export const button = cva(
8989
color: "light",
9090
variant: "solid",
9191
className: [
92-
// Not using `enabled:` to make it easier to override
9392
"bg-gray-200 hover:bg-gray-100 disabled:hover:bg-gray-200",
9493
"dark:bg-stone-700 dark:hover:bg-stone-600 dark:disabled:hover:bg-stone-700",
9594
].join(" "),

packages/ui/src/atoms/Input/TextInput.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ export type TextInputProps = ComponentPropsWithRef<"input"> & {
1111
className?: string
1212
}
1313

14-
export const TextInput: FC<TextInputProps> = ({ label, description, error, ref, className, ...props }) => {
14+
export const TextInput: FC<TextInputProps> = ({
15+
label,
16+
description,
17+
error,
18+
ref,
19+
className,
20+
size: _htmlSize,
21+
...props
22+
}) => {
1523
const hasError = Boolean(error)
1624
const hasTextError = typeof error === "string"
1725

packages/ui/src/atoms/Typography/Link.tsx

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,20 @@
11
import { type VariantProps, cva } from "cva"
22
import NextLink from "next/link"
3-
import type { ComponentPropsWithoutRef, ElementType, PropsWithChildren } from "react"
3+
import type { ComponentPropsWithoutRef, PropsWithChildren } from "react"
44
import { cn } from "../../utils"
55

6-
export type LinkProps<E extends ElementType = typeof NextLink> = VariantProps<typeof link> &
7-
PropsWithChildren & {
8-
/**
9-
* The HTML element or React component to render this element as.
10-
*
11-
* Defaults to Next.js Link component.
12-
*/
13-
element?: E
6+
export type LinkProps = VariantProps<typeof link> &
7+
PropsWithChildren &
8+
ComponentPropsWithoutRef<typeof NextLink> & {
149
className?: string
15-
href: ComponentPropsWithoutRef<E>["href"]
16-
} & ComponentPropsWithoutRef<E>
10+
}
1711

18-
export function Link<E extends ElementType = typeof NextLink>({
19-
children,
20-
element,
21-
className,
22-
href,
23-
size,
24-
...props
25-
}: LinkProps<E>) {
26-
const Component = element ?? NextLink
12+
export function Link({ children, className, href, size, ...props }: LinkProps) {
2713
const classes = cn(link({ size }), className)
2814
return (
29-
<Component className={classes} {...props} href={href}>
15+
<NextLink className={classes} {...props} href={href}>
3016
{children}
31-
</Component>
17+
</NextLink>
3218
)
3319
}
3420

packages/ui/src/atoms/Typography/Text.tsx

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,24 @@
11
import { type VariantProps, cva } from "cva"
2-
import type { ComponentPropsWithRef, ElementType, PropsWithChildren } from "react"
2+
import type { ElementType, HTMLAttributes, PropsWithChildren, Ref } from "react"
33
import { cn } from "../../utils"
44

5-
export type TextProps<E extends ElementType = "p"> = VariantProps<typeof text> &
6-
PropsWithChildren & {
7-
/**
8-
* The HTML element or React component to render this element as.
9-
*
10-
* Defaults to HTML <p> element.
11-
*/
12-
element?: E
5+
export type TextProps = VariantProps<typeof text> &
6+
PropsWithChildren &
7+
HTMLAttributes<HTMLElement> & {
8+
element?: ElementType
139
className?: string
14-
} & ComponentPropsWithRef<E>
10+
ref?: Ref<any>
11+
htmlFor?: string
12+
type?: string
13+
placeholder?: string
14+
value?: unknown
15+
name?: string
16+
required?: boolean
17+
disabled?: boolean
18+
checked?: boolean
19+
}
1520

16-
export function Text<E extends ElementType = "p">({
17-
children,
18-
element,
19-
className,
20-
size,
21-
truncate,
22-
ref,
23-
...props
24-
}: TextProps<E>) {
21+
export function Text({ children, element, className, size, truncate, ref, ...props }: TextProps) {
2522
const Component = element ?? "p"
2623
const classes = cn(text({ size, truncate }), className)
2724
return (

packages/ui/src/atoms/Typography/Title.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
import { type VariantProps, cva } from "cva"
2-
import type { ComponentPropsWithoutRef, ElementType, PropsWithChildren } from "react"
2+
import type { HTMLAttributes, PropsWithChildren } from "react"
33
import { cn } from "../../utils"
44

5-
export type TitleProps<E extends ElementType = "h2"> = VariantProps<typeof title> &
6-
PropsWithChildren & {
7-
/**
8-
* The HTML element or React component to render this element as.
9-
*
10-
* Defaults to HTML <h2> element.
11-
*/
12-
element?: E
5+
type TitleElement = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p"
6+
7+
export type TitleProps = VariantProps<typeof title> &
8+
PropsWithChildren &
9+
HTMLAttributes<HTMLHeadingElement> & {
10+
element?: TitleElement
1311
className?: string
14-
} & ComponentPropsWithoutRef<E>
12+
}
1513

16-
export function Title<E extends ElementType = "h2">({ children, element, className, size, ...props }: TitleProps<E>) {
14+
export function Title({ children, element, className, size, ...props }: TitleProps) {
1715
const Component = element ?? "h2"
1816
const classes = cn(title({ size }), className)
1917
return (

0 commit comments

Comments
 (0)