-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSubGoalFields.tsx
More file actions
47 lines (40 loc) · 1.52 KB
/
SubGoalFields.tsx
File metadata and controls
47 lines (40 loc) · 1.52 KB
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
import * as styles from '../UpperTodo.css';
import { ORDER_LABELS } from '../constants';
import { DEFAULT_PLACEHOLDER } from '@/common/component/TextField/mandalart/constants';
import { MandalartTextField } from '@/common/component/TextField/mandalart';
interface SubGoalFieldsProps {
values: string[];
onChange: (values: string[]) => void;
idPositions?: { id: number; position: number }[];
onEnter?: (index: number, value: string, coreGoalId?: number) => void;
}
const SubGoalFields = ({ values, onChange, idPositions, onEnter }: SubGoalFieldsProps) => {
const updatedValues = (index: number, newValue: string) =>
values.map((v, i) => (i === index ? newValue : v));
const handleChange = (index: number, newValue: string) => {
const newValues = updatedValues(index, newValue);
onChange(newValues);
};
const getHandleFieldCommit =
(index: number, coreGoalId?: number) => (value: string, reason: 'enter' | 'blur') => {
if (reason === 'enter' && onEnter) {
onEnter(index, value, coreGoalId);
}
};
return (
<div className={styles.textFieldColumn}>
{values.map((value, index) => (
<MandalartTextField
key={index}
variant="subGoal"
value={value}
onChange={(val) => handleChange(index, val)}
onCommit={getHandleFieldCommit(index, idPositions?.[index]?.id)}
placeholder={`${ORDER_LABELS[index]} ${DEFAULT_PLACEHOLDER.subGoal}`}
maxLength={30}
/>
))}
</div>
);
};
export default SubGoalFields;