Add tests on top of ui/buttons, ui/links and ui/inputs (#342)

This commit is contained in:
Charles Bochet
2023-06-21 03:47:00 +02:00
committed by GitHub
parent e2eb40c1ea
commit e2d8c3a2ec
14 changed files with 284 additions and 61 deletions

View File

@ -2,8 +2,9 @@ import { ChangeEvent, useState } from 'react';
import styled from '@emotion/styled';
type OwnProps = {
initialValue: string;
onChange: (text: string) => void;
value: string;
onChange?: (text: string) => void;
placeholder?: string;
fullWidth?: boolean;
};
@ -29,20 +30,23 @@ const StyledInput = styled.input<{ fullWidth: boolean }>`
`;
export function TextInput({
initialValue,
value,
onChange,
placeholder,
fullWidth,
}: OwnProps): JSX.Element {
const [value, setValue] = useState(initialValue);
const [internalValue, setInternalValue] = useState(value);
return (
<StyledInput
fullWidth={fullWidth ?? false}
value={value}
placeholder="Email"
value={internalValue}
placeholder={placeholder}
onChange={(event: ChangeEvent<HTMLInputElement>) => {
setValue(event.target.value);
onChange(event.target.value);
setInternalValue(event.target.value);
if (onChange) {
onChange(event.target.value);
}
}}
/>
);