blob: 700b08a257cd0efd8e2121bb3315c4ea1075416d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import React from "react";
import styled from "styled-components";
const Container = styled.div`
page-break-inside: avoid;
`;
const Input = styled.input<{ hasError: boolean }>`
padding: 4px;
width: 8rem;
box-shadow: ${({ hasError }) => (hasError ? "0 0 2px red" : "none")};
`;
const Label = styled.label`
font-weight: bold;
min-width: 14rem;
display: inline-block;
`;
interface Props extends React.HTMLAttributes<HTMLElement> {
name: string;
error?: string;
label: string;
value: string;
onValueChange?: (name: string, value: string) => void;
}
const Text: React.FC<Props> = (props) => {
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (props.onValueChange) {
props.onValueChange(e.target.name, e.target.value);
}
};
const pp = { ...props };
delete pp.onValueChange;
return (
<Container>
<Label>
{props.label}
<br />
<Input
type="text"
hasError={props.error !== undefined}
onChange={onChange}
{...pp}
/>
</Label>
</Container>
);
};
export default Text;
|