-
Notifications
You must be signed in to change notification settings - Fork 1
/
LabelCard.jsx
106 lines (95 loc) · 2.42 KB
/
LabelCard.jsx
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
import Paper from '@material-ui/core/Paper';
import TextField from '@material-ui/core/TextField';
import ColorPickerSystem from './ColorPickerSystem';
const useStyles = makeStyles((theme) => ({
root: {
display: 'flex',
flexWrap: 'wrap',
'& > *': {
margin: theme.spacing(1),
width: theme.spacing(16),
height: theme.spacing(16),
},
},
paper: {
padding: theme.spacing(2),
margin: '2rem',
textAlign: 'center',
color: theme.palette.text.secondary,
},
form: {
display: 'flex',
flexWrap: 'wrap',
},
}));
const LabelCard = (props) => {
const {
label: { id, name, description, color },
setLabels,
} = props;
const classes = useStyles();
const getNewValueFunc = (prop) => {
const getNewValueFuncLookupTable = {
name: (e) => e.target.value,
color: (e) => e.hex,
description: (e) => e.target.value,
};
return getNewValueFuncLookupTable[prop];
};
const handleUpdateLabelProps = (prop, e) => {
const getNewValue = getNewValueFunc(prop);
const newValue = getNewValue(e) || '';
setLabels((oldLabels) =>
oldLabels.map((label) => {
if (label.id === id) {
return {
...label,
[prop]: newValue,
};
}
return label;
})
);
};
const handleUpdateName = (e) => {
handleUpdateLabelProps('name', e);
};
const handleUpdateColor = (e) => {
handleUpdateLabelProps('color', e);
};
const handleUpdateDescription = (e) => {
handleUpdateLabelProps('description', e);
};
return (
<Paper className={classes.paper} elevaton={0}>
<Grid container spacing={3}>
<Grid item xs={9}>
<TextField
label="Name"
value={name}
required
fullWidth
variant="standard"
onChange={handleUpdateName}
/>
</Grid>
<Grid item xs={3}>
<ColorPickerSystem color={color} handleUpdateColor={handleUpdateColor} />
</Grid>
<Grid item xs={12}>
<TextField
label="Description"
value={description}
fullWidth
variant="standard"
onChange={handleUpdateDescription}
/>
</Grid>
</Grid>
</Paper>
);
};
export default LabelCard;