import { ChangeEvent, ComponentType, CSSProperties, forwardRef, KeyboardEvent, } from "react"; import { attributes } from "../utils/attributes"; import { classnames } from "../utils/classnames"; import "./input.css"; import { SimpleText } from "../SimpleText/SimpleText"; export interface InputCustomStyleCSS extends CSSProperties { "--codex-input-background"?: string; "--codex-color"?: string; "--codex-border-radius"?: string; "--codex-input-border"?: string; "--codex-color-primary"?: string; "--codex-input-background-disabled"?: string; } type Props = { label?: string; id: string; /** * OnChange event triggered every time the input value changed. */ onChange?: (e: ChangeEvent) => void | Promise; onFocus?: () => void | Promise; onBlur?: () => unknown | Promise; onClick?: (() => void) | undefined; onMouseEnter?: () => void; onMouseLeave?: () => void; onKeyUp?: (e: KeyboardEvent) => void; placeholder?: string; value?: string; /** * Apply custom css variables. * --codex-input-background * --codex-color * --codex-border-radius * --codex-input-border * --codex-color-primary * --codex-input-background-disabled */ style?: InputCustomStyleCSS; /** * Helper text to add indication about your input. */ helper?: string; disabled?: boolean; /** * Add an icon on the left. */ Icon?: ComponentType; className?: string; /** * Default is text */ type?: string; step?: string; }; export const Input = forwardRef( ( { id, label, helper, disabled, value, onBlur, onFocus, placeholder, onChange, onMouseEnter, onMouseLeave, onClick, onKeyUp, className, style, Icon, step, type = "text", }, ref ) => { return ( <> {label && ( )}
{Icon && (
)}
{helper && (
{helper}
)} ); } );