diff --git a/packages/ui-button/src/index.tsx b/packages/ui-button/src/index.tsx index 742b433..e3d57df 100644 --- a/packages/ui-button/src/index.tsx +++ b/packages/ui-button/src/index.tsx @@ -1,7 +1,6 @@ -import { forwardRef } from "react" import type { ArgsFunction } from "@halvaradop/ts-utility-types" import { cva, type VariantProps } from "class-variance-authority" -import { merge, Slot, SlotProps } from "@halvaradop/ui-core" +import { merge, Slot, type SlotProps } from "@halvaradop/ui-core" export type ButtonProps = SlotProps<"button"> & VariantProps @@ -41,13 +40,13 @@ export const buttonVariants = cva("flex items-center justify-center font-semibol * The Button component is a versatile and customizable button element. * It supports various variants, sizes, and additional props to enhance its appearance and functionality. */ -export const Button = forwardRef>(({ className, variant, size, fullWidth, fullRounded, asChild, children, ...props }, ref) => { +export const Button = ({ className, variant, size, fullWidth, fullRounded, asChild, children, ref, ...props }: ButtonProps) => { const SlotComponent = asChild ? Slot : "button" return ( {children} ) -}) +} Button.displayName = "Button" diff --git a/packages/ui-core/src/slot.ts b/packages/ui-core/src/slot.ts index 8668538..6063eef 100644 --- a/packages/ui-core/src/slot.ts +++ b/packages/ui-core/src/slot.ts @@ -11,9 +11,17 @@ export const Slot = ({ children, ...props }: { children: React.ReactNode }) => { return null } -export type SlotWithAsChild< +/** + * @internal + */ +type SlotWithAsChild< Component extends keyof React.JSX.IntrinsicElements | React.JSXElementConstructor, -> = ({ asChild?: false } & ComponentProps) | { asChild: true; children: ReactNode } + Element extends HTMLElement, +> = + | ({ asChild?: false } & ComponentProps) + | { asChild: true; children: ReactNode; ref: React.Ref | undefined } -export type SlotProps> = - SlotWithAsChild & { className?: string } +export type SlotProps< + Component extends keyof React.JSX.IntrinsicElements | React.JSXElementConstructor, + Element extends HTMLElement = never, +> = SlotWithAsChild & { className?: string } diff --git a/packages/ui-dialog/src/index.tsx b/packages/ui-dialog/src/index.tsx index 05910ff..690aab8 100644 --- a/packages/ui-dialog/src/index.tsx +++ b/packages/ui-dialog/src/index.tsx @@ -1,8 +1,9 @@ -import { ComponentProps, forwardRef } from "react" -import { cva } from "class-variance-authority" +import type { ComponentProps } from "react" +import type { ArgsFunction } from "@halvaradop/ts-utility-types" +import { cva, type VariantProps } from "class-variance-authority" import { merge } from "@halvaradop/ui-core" -export type DialogProps = ComponentProps<"dialog"> +export type DialogProps = ComponentProps<"dialog"> & VariantProps export const innerDialogVariants = cva("flex items-center justify-center", { variants: { @@ -26,10 +27,10 @@ export const innerDialogVariants = cva("flex items-center justify-center", { const classNameDialog = "w-full min-h-screen max-w-none max-h-none items-center justify-center relative inset-0 bg-transparent backdrop:bg-slate-500/50 open:flex" -export const Modal = forwardRef(({ className, children, ...props }, ref) => { +export const Modal = ({ className, children, ref, ...props }: DialogProps) => { return ( {children} ) -}) +} diff --git a/packages/ui-form/src/index.tsx b/packages/ui-form/src/index.tsx index 76de41a..61df5ca 100644 --- a/packages/ui-form/src/index.tsx +++ b/packages/ui-form/src/index.tsx @@ -1,4 +1,4 @@ -import { ComponentProps, forwardRef } from "react" +import type { ComponentProps } from "react" import type { ArgsFunction } from "@halvaradop/ts-utility-types" import { cva, type VariantProps } from "class-variance-authority" import { merge } from "@halvaradop/ui-core" @@ -26,10 +26,10 @@ export const formVariants = cva("mx-auto flex items-center flex-col relative", { }, }) -export const Form = forwardRef>(({ className, variant, size, children, ...props }, ref) => { +export const Form = ({ className, variant, size, children, ref, ...props }: FormProps) => { return (
{children}
) -}) +} diff --git a/packages/ui-input/src/index.tsx b/packages/ui-input/src/index.tsx index 0ab8acd..bd3f582 100644 --- a/packages/ui-input/src/index.tsx +++ b/packages/ui-input/src/index.tsx @@ -1,4 +1,4 @@ -import { forwardRef, ComponentProps } from "react" +import type { ComponentProps } from "react" import type { ArgsFunction } from "@halvaradop/ts-utility-types" import { cva, type VariantProps } from "class-variance-authority" import { merge } from "@halvaradop/ui-core" @@ -36,6 +36,6 @@ export const inputVariants = cva("text-slate-600 border focus-within:outline-non }, }) -export const Input = forwardRef>(({ className, variant, size, fullWidth, fullRounded, type, ...props }, ref) => { +export const Input = ({ className, variant, size, fullWidth, fullRounded, type, ref, ...props }: InputProps) => { return -}) +} diff --git a/packages/ui-label/src/index.tsx b/packages/ui-label/src/index.tsx index cadb2c4..57844d6 100644 --- a/packages/ui-label/src/index.tsx +++ b/packages/ui-label/src/index.tsx @@ -1,6 +1,6 @@ import type { ArgsFunction } from "@halvaradop/ts-utility-types" import { cva, type VariantProps } from "class-variance-authority" -import { merge, Slot, SlotProps, SlotWithAsChild } from "@halvaradop/ui-core" +import { merge, Slot, type SlotProps } from "@halvaradop/ui-core" export type LabelProps = SlotProps<"label"> & VariantProps @@ -23,10 +23,10 @@ export const labelVariants = cva("font-medium relative leading-none", { }, }) -export const Label = ({ className, variant, size, children, asChild, ...props }: LabelProps) => { +export const Label = ({ className, variant, size, children, asChild, ref, ...props }: LabelProps) => { const SlotComponent = asChild ? Slot : "label" return ( - + {children} )