Skip to content

The Open Standard for Generative UI

823 B
Raw Blame
import clsx from "clsx";
import React, { forwardRef } from "react";
import { useFormControlContext } from "../context";

export interface HintProps extends React.ComponentPropsWithoutRef<"div"> {
  children: React.ReactNode;
  className?: string;
  style?: React.CSSProperties;
  hasError?: boolean;
}

const Hint = forwardRef<HTMLDivElement, HintProps>(
  ({ children, className, style, hasError, ...props }, ref) => {
    const ctx = useFormControlContext();
    const resolvedHasError = hasError ?? ctx?.hasError ?? false;
    return (
      <div
        ref={ref}
        className={clsx("openui-hint", className, {
          "openui-hint-error": resolvedHasError,
        })}
        style={style}
        {...props}
      >
        {children}
      </div>
    );
  },
);

Hint.displayName = "Hint";

export { Hint };