import { useTheme } from "@fiftyone/components"; import React, { forwardRef } from "react"; import styled from "styled-components"; const StyledInputContainer = styled.div` font-size: 14px; border-bottom: 1px ${({ theme }) => theme.brand} solid; position: relative; margin: 0.5rem 0; `; const StyledInput = styled.input` background-color: transparent; border: none; color: ${({ theme }) => theme.font}; height: 2rem; font-size: 14px; border: none; align-items: center; font-weight: bold; width: 100%; &:focus { border: none; outline: none; font-weight: bold; } &::placeholder { color: ${({ theme }) => theme.fontDark}; font-weight: bold; } `; interface InputProps { color?: string; placeholder?: string; validator?: (value: string) => boolean; setter: (value: string) => void; value: string; onEnter?: () => void; disabled?: boolean; onFocus?: () => void; onBlur?: () => void; onKeyDown?: (event: React.KeyboardEvent) => void; } const Input = React.memo( forwardRef( ( { color = null, placeholder, validator = () => true, setter, value, disabled = false, onEnter, onFocus, onBlur, onKeyDown, }: InputProps, ref ) => { const theme = useTheme(); color = color ?? theme.brand; return ( ) => { if (validator(e.currentTarget.value)) { setter(e.currentTarget.value); } }} onKeyPress={(e: React.KeyboardEvent) => { e.key === "Enter" && onEnter && onEnter(); }} onKeyDown={(e: React.KeyboardEvent) => { e.key === "Escape" && e.currentTarget.blur(); onKeyDown && onKeyDown(e); }} style={disabled ? { color: theme.fontDark } : {}} disabled={disabled} onFocus={(e: React.FocusEvent) => { onFocus && onFocus(); }} onBlur={onBlur} /> ); } ) ); export default Input;