/******************************************************************************** * Copyright (c) 2020 TypeFox and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0. * * SPDX-License-Identifier: EPL-2.0 ********************************************************************************/ import { ChangeEvent, FunctionComponent, KeyboardEvent, useContext, useState } from 'react'; import { Paper, IconButton, InputBase } from '@mui/material'; import SearchIcon from '@mui/icons-material/Search'; import { MainContext } from '../../context'; interface InputProps { onSubmit?: (inputValue: string) => void; onChange: (inputValue: string) => void; value?: string; hideIconButton?: boolean; error?: boolean; autoFocus?: boolean; placeholder?: string; } export const StyledInput: FunctionComponent = props => { const [inputValue, setInputValue] = useState(props.value || ''); const { pageSettings } = useContext(MainContext); const onChangeInputValue = (ev: ChangeEvent) => { const inputValue = ev.target.value; props.onChange(inputValue); setInputValue(inputValue); }; const onSubmit = () => { if (props.onSubmit) { props.onSubmit(inputValue); } }; const searchIconColor = pageSettings?.themeType === 'dark' ? '#111111' : '#ffffff'; return { if (e.key === 'Enter' && props.onSubmit) { props.onSubmit(inputValue); } }} /> { props.hideIconButton ? '' : } ; };