diff --git a/src/components/editor/RigEditor.tsx b/src/components/editor/RigEditor.tsx index ea4be70..726ab2b 100644 --- a/src/components/editor/RigEditor.tsx +++ b/src/components/editor/RigEditor.tsx @@ -1,4 +1,4 @@ -import { lazy, Suspense, useId, useState } from "react"; +import { lazy, Suspense, useId, useState, type ReactNode } from "react"; import { useTranslation } from "react-i18next"; import { AlertTriangle, ChevronsUpDown } from "lucide-react"; import clsx from "clsx"; @@ -230,7 +230,7 @@ export function RigEditor() { // before it, so cascading option lists, dynamic labels and hidden-when // predicates line up. const previousValues: string[] = []; - const renderedParts: React.ReactNode[] = []; + const renderedParts: ReactNode[] = []; composite.parts.forEach((part, index) => { const stored = partValues[index] ?? ""; if (!part.hiddenWhen?.(previousValues)) { diff --git a/src/components/ui/Button.tsx b/src/components/ui/Button.tsx index fc922fd..30cd0dd 100644 --- a/src/components/ui/Button.tsx +++ b/src/components/ui/Button.tsx @@ -1,4 +1,4 @@ -import { forwardRef, type ButtonHTMLAttributes } from "react"; +import type { ComponentProps } from "react"; import { Slot } from "radix-ui"; import clsx from "clsx"; import { Spinner } from "@components/icons/animated"; @@ -6,7 +6,8 @@ import { Spinner } from "@components/icons/animated"; export type ButtonVariant = "primary" | "brand" | "secondary" | "outline" | "ghost" | "danger"; export type ButtonSize = "sm" | "md" | "lg" | "icon" | "icon-sm"; -export interface ButtonProps extends ButtonHTMLAttributes { +/** `ref` is an ordinary prop in React 19 — it comes with `ComponentProps<"button">`. */ +export interface ButtonProps extends ComponentProps<"button"> { variant?: ButtonVariant; size?: ButtonSize; /** Shows a spinner, disables the button and keeps its width. */ @@ -42,43 +43,37 @@ export const buttonClasses = (variant: ButtonVariant = "primary", size: ButtonSi SIZES[size], ); -export const Button = forwardRef( - ( - { - variant = "primary", - size = "md", - loading = false, - asChild = false, - className, - children, - disabled, - type, - ...props - }, - ref, - ) => { - if (asChild) { - return ( - - {children} - - ); - } +export function Button({ + variant = "primary", + size = "md", + loading = false, + asChild = false, + className, + children, + disabled, + type, + ref, + ...props +}: ButtonProps) { + if (asChild) { return ( - + ); - }, -); - -Button.displayName = "Button"; + } + return ( + + ); +} diff --git a/src/components/ui/IconButton.tsx b/src/components/ui/IconButton.tsx index 4228a0d..5a6150e 100644 --- a/src/components/ui/IconButton.tsx +++ b/src/components/ui/IconButton.tsx @@ -1,29 +1,35 @@ -import { forwardRef } from "react"; +import type { ReactNode } from "react"; import { Button, type ButtonProps } from "./Button"; import { Tooltip } from "./Tooltip"; interface IconButtonProps extends Omit { /** Accessible name AND tooltip text — an icon-only control needs both. */ label: string; - children: React.ReactNode; + children: ReactNode; size?: "icon" | "icon-sm"; /** Hide the hover tooltip (the name stays for screen readers). */ noTooltip?: boolean; tooltipSide?: "top" | "right" | "bottom" | "left"; } -/** A square, icon-only button that cannot be rendered without a name. */ -export const IconButton = forwardRef( - ( - { label, children, variant = "ghost", size = "icon", noTooltip, tooltipSide, ...props }, - ref, - ) => ( +/** + * A square, icon-only button that cannot be rendered without a name. A `ref` + * reaches the button through `props`. + */ +export function IconButton({ + label, + children, + variant = "ghost", + size = "icon", + noTooltip, + tooltipSide, + ...props +}: IconButtonProps) { + return ( - - ), -); - -IconButton.displayName = "IconButton"; + ); +} diff --git a/src/components/ui/Input.tsx b/src/components/ui/Input.tsx index c116bb7..a63eff3 100644 --- a/src/components/ui/Input.tsx +++ b/src/components/ui/Input.tsx @@ -1,8 +1,8 @@ -import { forwardRef, type InputHTMLAttributes, type ReactNode } from "react"; +import type { ComponentProps, ReactNode } from "react"; import clsx from "clsx"; import { Field, controlClasses } from "./Field"; -interface InputProps extends InputHTMLAttributes { +interface InputProps extends ComponentProps<"input"> { label?: string; error?: boolean; /** Inline error message shown below the input (also forces the red border). */ @@ -15,35 +15,42 @@ interface InputProps extends InputHTMLAttributes { leading?: ReactNode; } -export const Input = forwardRef( - ({ label, error, errorText, helpText, labelExtra, leading, className, id, ...props }, ref) => { - const isError = Boolean(error) || Boolean(errorText); - return ( - - {(control) => ( -
- {leading && ( - - {leading} - +export function Input({ + label, + error, + errorText, + helpText, + labelExtra, + leading, + className, + id, + ref, + ...props +}: InputProps) { + const isError = Boolean(error) || Boolean(errorText); + return ( + + {(control) => ( +
+ {leading && ( + + {leading} + + )} + -
- )} -
- ); - }, -); - -Input.displayName = "Input"; + {...props} + /> +
+ )} +
+ ); +} diff --git a/src/components/ui/Select.tsx b/src/components/ui/Select.tsx index bb21489..01b8052 100644 --- a/src/components/ui/Select.tsx +++ b/src/components/ui/Select.tsx @@ -1,4 +1,4 @@ -import { forwardRef, type SelectHTMLAttributes } from "react"; +import type { ComponentProps } from "react"; import { ChevronsUpDown } from "lucide-react"; import clsx from "clsx"; import { Field, controlClasses } from "./Field"; @@ -8,7 +8,7 @@ interface SelectOption { label: string; } -interface SelectProps extends Omit, "onChange"> { +interface SelectProps extends Omit, "onChange"> { label?: string; options: readonly SelectOption[]; onChange: (value: string) => void; @@ -21,8 +21,19 @@ interface SelectProps extends Omit, "onC * Android and iOS, type-ahead, and full keyboard support for free — and it * now matches the other controls' height (it used to be ~6px shorter). */ -export const Select = forwardRef( - ({ label, options, value, onChange, helpText, errorText, className, id, ...props }, ref) => ( +export function Select({ + label, + options, + value, + onChange, + helpText, + errorText, + className, + id, + ref, + ...props +}: SelectProps) { + return ( {(control) => ( // `className` sizes the control box (e.g. max-w-40), so the chevron @@ -52,7 +63,5 @@ export const Select = forwardRef( )} - ), -); - -Select.displayName = "Select"; + ); +} diff --git a/src/components/ui/Textarea.tsx b/src/components/ui/Textarea.tsx index 7006ae8..2e508d3 100644 --- a/src/components/ui/Textarea.tsx +++ b/src/components/ui/Textarea.tsx @@ -1,8 +1,8 @@ -import { forwardRef, type ReactNode, type TextareaHTMLAttributes } from "react"; +import type { ComponentProps, ReactNode } from "react"; import clsx from "clsx"; import { Field, controlClasses } from "./Field"; -interface TextareaProps extends TextareaHTMLAttributes { +interface TextareaProps extends ComponentProps<"textarea"> { label?: string; error?: boolean; errorText?: string; @@ -10,27 +10,33 @@ interface TextareaProps extends TextareaHTMLAttributes { labelExtra?: ReactNode; } -export const Textarea = forwardRef( - ({ label, error, errorText, helpText, labelExtra, className, id, ...props }, ref) => { - const isError = Boolean(error) || Boolean(errorText); - return ( - - {(control) => ( -