import { Primitive, type PrimitiveProps } from "@seed-design/react-primitive"; import { FieldButton, useFieldButtonContext } from "@seed-design/react-field-button"; import * as React from "react"; import { forwardRef } from "react"; import { createSlotRecipeContext } from "../../utils/createSlotRecipeContext"; import { createWithStateProps } from "../../utils/createWithStateProps"; import { splitMultipleVariantsProps } from "../../utils/splitMultipleVariantsProps"; import { field, type FieldVariantProps } from "@seed-design/css/recipes/field"; import { fieldLabel, type FieldLabelVariantProps } from "@seed-design/css/recipes/field-label"; import { InternalIcon, type InternalIconProps } from "../private/Icon"; import { inputButton, type InputButtonVariantProps } from "@seed-design/css/recipes/input-button"; import clsx from "clsx"; const { ClassNamesProvider: FieldClassNamesProvider, withContext: withFieldContext } = createSlotRecipeContext(field); const { withProvider, withContext, useClassNames, PropsProvider: InputButtonPropsProvider, } = createSlotRecipeContext(inputButton); const { withProvider: withLabelProvider, withContext: withLabelContext, useClassNames: useLabelClassNames, } = createSlotRecipeContext(fieldLabel); const withStateProps = createWithStateProps([useFieldButtonContext]); //////////////////////////////////////////////////////////////////////////////////// export interface FieldButtonRootProps extends FieldVariantProps, InputButtonVariantProps, FieldButton.RootProps {} export const FieldButtonRoot = forwardRef( ({ className, ...props }, ref) => { const [{ field: fieldVariantProps, inputButton: inputButtonVariantProps }, otherProps] = splitMultipleVariantsProps(props, { field, inputButton }); const fieldClassNames = field(fieldVariantProps); return ( ); }, ); FieldButtonRoot.displayName = "FieldButtonRoot"; //////////////////////////////////////////////////////////////////////////////////// export interface FieldButtonHeaderProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldButtonHeader = withFieldContext( withStateProps(Primitive.div), "header", ); export interface FieldButtonLabelProps extends PrimitiveProps, FieldLabelVariantProps, React.HTMLAttributes {} export const FieldButtonLabel = withLabelProvider( withStateProps(Primitive.div), "root", ); export interface FieldButtonIndicatorTextProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldButtonIndicatorText = withLabelContext< HTMLSpanElement, FieldButtonIndicatorTextProps >(withStateProps(Primitive.span), "indicatorText"); export interface FieldButtonRequiredIndicatorProps extends React.SVGProps {} export const FieldButtonRequiredIndicator = React.forwardRef< SVGSVGElement, FieldButtonRequiredIndicatorProps >(({ className, ...props }, ref) => { const { indicatorIcon } = useLabelClassNames(); return ( } ref={ref} {...props} /> ); }); FieldButtonRequiredIndicator.displayName = "FieldButtonRequiredIndicator"; //////////////////////////////////////////////////////////////////////////////////// export interface FieldButtonPrefixIconProps extends InternalIconProps {} export const FieldButtonPrefixIcon = withContext( withStateProps(InternalIcon), "prefixIcon", ); export interface FieldButtonPrefixTextProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldButtonPrefixText = React.forwardRef( ({ className, ...props }, ref) => { const { stateProps } = useFieldButtonContext(); const { prefixText } = useClassNames(); return ( ); }, ); FieldButtonPrefixText.displayName = "FieldButtonPrefixText"; export interface FieldButtonSuffixIconProps extends InternalIconProps {} export const FieldButtonSuffixIcon = withContext( withStateProps(InternalIcon), "suffixIcon", ); export interface FieldButtonSuffixTextProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldButtonSuffixText = React.forwardRef( ({ className, ...props }, ref) => { const { stateProps } = useFieldButtonContext(); const { suffixText } = useClassNames(); return ( ); }, ); FieldButtonSuffixText.displayName = "FieldButtonSuffixText"; //////////////////////////////////////////////////////////////////////////////////// export interface FieldButtonFooterProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldButtonFooter = withFieldContext( withStateProps(Primitive.div), "footer", ); export interface FieldButtonDescriptionProps extends FieldButton.DescriptionProps {} export const FieldButtonDescription = withFieldContext< HTMLSpanElement, FieldButtonDescriptionProps >(FieldButton.Description, "description"); export interface FieldButtonErrorMessageProps extends FieldButton.ErrorMessageProps {} export const FieldButtonErrorMessage = withFieldContext< HTMLSpanElement, FieldButtonErrorMessageProps >(FieldButton.ErrorMessage, "errorMessage"); //////////////////////////////////////////////////////////////////////////////////// export interface FieldButtonHiddenInputProps extends FieldButton.HiddenInputProps {} export const FieldButtonHiddenInput = FieldButton.HiddenInput; export interface FieldButtonButtonProps extends FieldButton.ButtonProps {} export const FieldButtonButton = withContext( FieldButton.Button, "button", ); export interface FieldButtonControlProps extends InputButtonVariantProps, PrimitiveProps, React.HTMLAttributes {} export const FieldButtonControl = withProvider( withStateProps(Primitive.div), "root", ); export interface FieldButtonClearButtonProps extends FieldButton.ClearButtonProps {} export const FieldButtonClearButton = withContext( FieldButton.ClearButton, "clearButton", ); export interface FieldButtonValueProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldButtonValue = React.forwardRef( ({ className, ...props }, ref) => { const { stateProps } = useFieldButtonContext(); const { value } = useClassNames(); return ( ); }, ); FieldButtonValue.displayName = "FieldButtonValue"; export interface FieldButtonPlaceholderProps extends PrimitiveProps, React.HTMLAttributes {} export const FieldButtonPlaceholder = React.forwardRef( ({ className, ...props }, ref) => { const { stateProps } = useFieldButtonContext(); const { placeholder } = useClassNames(); return ( ); }, ); FieldButtonPlaceholder.displayName = "FieldButtonPlaceholder";