'use client'
import { Input as GuiInput } from '@hanzo/gui';
import React from 'react';
// gui's Input — a real `` on web, a real TextInput on native (soft
// keyboard, `returnKeyType`, autofill, IME) — wearing the Lux size/variant
// scale. `size` stays the Lux scale and never reaches the primitive, whose
// `size` is a gui SizeToken.
//
// Everything the element itself can express is a prop. The two states that only
// a selector reaches — `::placeholder`, and `:read-only`, neither of which is a
// style of the input so much as of something inside or about it — are one CSS
// rule in tokens.css, keyed off `.lux-control`.
type InputSize = 'xs' | 'sm' | 'md' | 'lg' | '2xl';
type InputVariant = 'outline' | 'filled' | 'unstyled';
export interface InputProps extends Omit, 'size'> {
readonly size?: InputSize;
readonly variant?: InputVariant;
/**
* React-Native convention: called with the text value on every change. The gui
* Input raises it natively; on web we bridge it off `onChange`, so callers
* using EITHER API get updates on either platform.
*/
readonly onChangeText?: (text: string) => void;
}
export const SIZE: Record> = {
xs: { height: 24, paddingHorizontal: 8, fontSize: '$1', borderRadius: 4 },
sm: { height: 32, paddingHorizontal: 12, fontSize: '$3', borderRadius: 6 },
md: { height: 40, paddingHorizontal: 16, fontSize: '$5', borderRadius: 6 },
lg: { height: 48, paddingHorizontal: 16, fontSize: '$6', borderRadius: 8 },
'2xl': { height: 56, paddingHorizontal: 16, fontSize: '$7', borderRadius: 8 },
};
export const VARIANT: Record> = {
outline: { borderWidth: 1, borderStyle: 'solid' },
filled: { borderWidth: 0, backgroundColor: 'var(--color-input-filled-bg)' },
unstyled: { borderWidth: 0, backgroundColor: 'transparent', padding: 0, height: 'auto' },
};
/** The frame every text control shares. */
export const CONTROL = {
width: '100%',
outlineWidth: 0,
backgroundColor: 'var(--color-input-bg)',
color: 'var(--color-input-fg)',
borderColor: 'var(--color-input-border)',
hoverStyle: { borderColor: 'var(--color-input-border-hover)' },
focusStyle: { borderColor: 'var(--color-input-border-focus)' },
disabledStyle: { opacity: 0.4, cursor: 'not-allowed' },
} as const;
export const Input = React.forwardRef(
({ size = 'md', variant = 'outline', className, onChange, onChangeText, ...rest }, ref) => {
const handleChange = React.useCallback(
(event: React.ChangeEvent): void => {
onChange?.(event);
onChangeText?.(event.target.value);
},
[ onChange, onChangeText ],
);
return (
);
},
);
Input.displayName = 'Input';