"use client"; /* * Documentation: * Text Input — https://app.subframe.com/f023064a5ca0/library?component=Text+Input_be48ca43-f8e7-4c0e-8870-d219ea11abfe */ import React from "react"; import { FeatherEye } from "@subframe/core"; import { FeatherEyeOff } from "@subframe/core"; import { FeatherLock } from "@subframe/core"; import { FeatherPlus } from "@subframe/core"; import { FeatherSearch } from "@subframe/core"; import * as SubframeCore from "@subframe/core"; import * as SubframeUtils from "../../utils"; // @subframe/sync-disable -- local fix: Context, ueber den der PasswordEyeButton (im Root) die Sichtbarkeit // des Passworts steuert. Davids Komponente hatte den Eye-Button rein dekorativ (kein Toggle). const TextInputContext = React.createContext<{ showPassword: boolean; togglePassword: () => void; }>({ showPassword: false, togglePassword: () => {} }); export interface InputProps extends Omit< React.InputHTMLAttributes, "type" | "placeholder" | "value" > { type?: "text" | "password" | "email" | "number" | "tel" | "url" | "search"; placeholder?: React.ReactNode; variant?: "regular" | "small" | "extra-small"; value?: React.ReactNode; onChange?: (event: React.ChangeEvent) => void; className?: string; } const Input = React.forwardRef(function Input( { type = "text", placeholder, variant = "regular", value, className, ...otherProps }: InputProps, ref ) { // @subframe/sync-disable -- local fix: Password-Reveal via Context; boxShadow:none entfernt den geerbten // nativen Fokus-Ring (der Fokus-Glow gehoert ans Feld, nicht an den Input -> kein Doppelrahmen). const { showPassword } = React.useContext(TextInputContext); const nativeType = type === "password" && showPassword ? "text" : type === "search" ? "search" : type === "url" ? "url" : type === "tel" ? "tel" : type === "number" ? "number" : type === "email" ? "email" : type === "password" ? "password" : "text"; return ( ); }); export interface PasswordEyeButtonProps extends React.HTMLAttributes { showPassword?: boolean; className?: string; } const PasswordEyeButton = React.forwardRef< HTMLDivElement, PasswordEyeButtonProps >(function PasswordEyeButton( { showPassword = false, className, ...otherProps }: PasswordEyeButtonProps, ref ) { return (
{showPassword ? ( ) : ( )}
); }); export interface TextInputRootProps extends React.LabelHTMLAttributes { disabled?: boolean; error?: boolean; variant?: "outline" | "filled"; size?: "small" | "medium" | "large"; fillContainer?: boolean; borderless?: boolean; noPadding?: boolean; showLabel?: boolean; label?: React.ReactNode; helpText?: React.ReactNode; icon?: React.ReactNode; iconRight?: React.ReactNode; type?: "text" | "password" | "email" | "number" | "tel" | "url" | "search"; children?: React.ReactNode; className?: string; } const TextInputRoot = React.forwardRef( function TextInputRoot( { disabled = false, error = false, variant = "outline", size = "medium", fillContainer = false, borderless = false, noPadding = false, showLabel = false, label, helpText, icon = null, iconRight = null, type = "text", children, className, ...otherProps }: TextInputRootProps, ref ) { // @subframe/sync-disable -- local fix: Password-Sichtbarkeits-State; der Eye-Button toggelt, der Input liest via Context. const [showPassword, setShowPassword] = React.useState(false); return ( setShowPassword((v) => !v) }}> ); } ); export const TextInput = Object.assign(TextInputRoot, { Input, PasswordEyeButton, });