import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive"; import { Field, useFieldContext } from "@seed-design/react-field"; import type * as React from "react"; import { forwardRef } from "react"; import { createSlotRecipeContext } from "../../utils/createSlotRecipeContext"; import { createWithStateProps } from "../../utils/createWithStateProps"; import { field, type FieldVariantProps } from "@seed-design/css/recipes/field"; import { fieldLabel, type FieldLabelVariantProps } from "@seed-design/css/recipes/field-label"; import { InternalIcon } from "../private/Icon"; import clsx from "clsx"; const { withProvider, withContext, useClassNames } = createSlotRecipeContext(field); const { withContext: withLabelContext, withProvider: withLabelProvider, useClassNames: useLabelClassNames, } = createSlotRecipeContext(fieldLabel); const withStateProps = createWithStateProps([useFieldContext]); //////////////////////////////////////////////////////////////////////////////////// export interface FieldRootProps extends FieldVariantProps, Field.RootProps {} export const FieldRoot = withProvider(Field.Root, "root"); //////////////////////////////////////////////////////////////////////////////////// export interface FieldHeaderProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldHeader = withContext( withStateProps(Primitive.div), "header", ); export interface FieldLabelProps extends FieldLabelVariantProps, Field.LabelProps {} export const FieldLabel = withLabelProvider(Field.Label, "root"); export interface FieldIndicatorTextProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldIndicatorText = withLabelContext( withStateProps(Primitive.span), "indicatorText", ); export interface FieldRequiredIndicatorProps extends React.SVGProps {} export const FieldRequiredIndicator = forwardRef( ({ className, ...props }, ref) => { const { indicatorIcon } = useLabelClassNames(); return ( } ref={ref} {...props} /> ); }, ); //////////////////////////////////////////////////////////////////////////////////// export interface FieldFooterProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldFooter = withContext( withStateProps(Primitive.div), "footer", ); export interface FieldDescriptionProps extends Field.DescriptionProps {} export const FieldDescription = withContext( Field.Description, "description", ); export interface FieldErrorMessageProps extends Field.ErrorMessageProps {} export const FieldErrorMessage = withContext( Field.ErrorMessage, "errorMessage", ); //////////////////////////////////////////////////////////////////////////////////// export interface FieldCharacterCountProps extends PrimitiveProps, React.HTMLAttributes { /** * The current number of characters/graphemes */ current: number; /** * The maximum allowed characters/graphemes */ max: number; } export const FieldCharacterCount = forwardRef( ({ current, max, className, ...otherProps }, ref) => { const classNames = useClassNames(); const { stateProps } = useFieldContext(); return ( max ? { "data-exceeded": true } : {})} className={classNames.characterCount} {...stateProps} > {current} /{max} ); }, );