-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathChoiceOptionCreator.js
More file actions
70 lines (66 loc) · 1.77 KB
/
ChoiceOptionCreator.js
File metadata and controls
70 lines (66 loc) · 1.77 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { useWatch } from 'react-hook-form';
import ImageChoices from './ImageChoices';
import TextBasedChoices from './TextBasedChoices';
export default function ChoiceOptionCreator({
setValue = () => {},
error = [],
register,
fieldName,
control,
clearErrors,
voteType,
} = {}) {
const tabOption = useWatch({ control, name: 'tabOption' });
// tabOption value is saved on form
const setTab = (option) => (e) => {
e.preventDefault();
e.stopPropagation();
setValue('tabOption', option);
};
if (voteType === 'ranked-choice' || voteType === 'basic') {
setTab('text-based');
}
return (
<>
{voteType === 'single-choice' ? (
<div className="tabs choice-option is-toggle mt-2 mb-4">
<ul>
<li>
<button
className={`button left ${
tabOption === 'text-based' ? 'is-black' : 'outlined'
}`}
onClick={setTab('text-based')}
>
<span>Text-based</span>
</button>
</li>
<li>
<button
className={`button right ${
tabOption === 'visual' ? 'is-black' : 'outlined'
}`}
onClick={setTab('visual')}
>
<span>Visual</span>
</button>
</li>
</ul>
</div>
) : null}
{tabOption === 'text-based' && (
<TextBasedChoices
error={error}
register={register}
fieldName={fieldName}
control={control}
clearErrors={clearErrors}
voteType={voteType}
/>
)}
{tabOption === 'visual' && (
<ImageChoices control={control} error={error} />
)}
</>
);
}