import { createContext, forwardRef, useContext, type ComponentPropsWithoutRef } from "react"; import { inputGroupAffixVariants, inputGroupVariants } from "./input-group.variants"; import { cn } from "../lib/cn"; import type { VariantProps } from "../lib/cva"; import type { FieldStateProps } from "../lib/contracts"; import { createDataAttributes, createSlot } from "../lib/contracts"; import { useFieldContext } from "./field"; type InputGroupContextValue = { disabled: boolean; invalid: boolean; readOnly: boolean; required: boolean; size: Exclude["size"], null | undefined>; }; const InputGroupContext = createContext(null); export function useInputGroupContext() { return useContext(InputGroupContext); } export type InputGroupProps = ComponentPropsWithoutRef<"div"> & FieldStateProps & VariantProps; export const InputGroup = forwardRef(function InputGroup( { className, disabled, invalid, readOnly, required, size = "md", ...props }, ref ) { const field = useFieldContext(); const resolvedDisabled = disabled ?? field?.disabled ?? false; const resolvedInvalid = invalid ?? field?.invalid ?? false; const resolvedReadOnly = readOnly ?? field?.readOnly ?? false; const resolvedRequired = required ?? field?.required ?? false; const resolvedSize = size ?? "md"; return (
); }); export type InputGroupPrefixProps = ComponentPropsWithoutRef<"div">; export const InputGroupPrefix = forwardRef( function InputGroupPrefix({ className, ...props }, ref) { return (
); } ); export type InputGroupSuffixProps = ComponentPropsWithoutRef<"div">; export const InputGroupSuffix = forwardRef( function InputGroupSuffix({ className, ...props }, ref) { return (
); } );