-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathMultipleAnswersField.tsx
More file actions
95 lines (86 loc) · 3.01 KB
/
MultipleAnswersField.tsx
File metadata and controls
95 lines (86 loc) · 3.01 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
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
import React, { useCallback, useMemo, useState } from 'react';
import { StyleSheet, Switch, Text, View } from 'react-native';
import Animated, { LinearTransition } from 'react-native-reanimated';
import { MultipleVotesSettings } from './MultipleVotesSettings';
import { useTheme, useTranslationContext } from '../../../contexts';
import { useMessageComposer } from '../../../contexts/messageInputContext/hooks/useMessageComposer';
import { primitives } from '../../../theme';
export const MultipleAnswersField = () => {
const [allowMultipleVotes, setAllowMultipleVotes] = useState<boolean>(false);
const { t } = useTranslationContext();
const messageComposer = useMessageComposer();
const { pollComposer } = messageComposer;
const { updateFields } = pollComposer;
const {
theme: {
poll: {
createContent: { multipleAnswers },
},
},
} = useTheme();
const styles = useStyles();
const onEnforceUniqueVoteHandler = useCallback(
async (value: boolean) => {
setAllowMultipleVotes(value);
await updateFields({ enforce_unique_vote: !value });
},
[updateFields],
);
return (
<Animated.View
layout={LinearTransition.duration(200)}
style={[styles.multipleAnswersWrapper, multipleAnswers.wrapper]}
>
<View style={[styles.optionCard, multipleAnswers.optionCard]}>
<View style={[styles.optionCardContent, multipleAnswers.optionCardContent]}>
<Text style={[styles.title, multipleAnswers.title]}>{t('Multiple votes')}</Text>
<Text style={[styles.description, multipleAnswers.description]}>
{t('Select more than one option')}
</Text>
</View>
<Switch
onValueChange={onEnforceUniqueVoteHandler}
value={allowMultipleVotes}
style={[styles.optionCardSwitch, multipleAnswers.optionCardSwitch]}
/>
</View>
{allowMultipleVotes ? <MultipleVotesSettings /> : null}
</Animated.View>
);
};
const useStyles = () => {
const {
theme: { semantics },
} = useTheme();
return useMemo(() => {
return StyleSheet.create({
multipleAnswersWrapper: {
backgroundColor: semantics.inputOptionCardBg,
padding: primitives.spacingMd,
borderRadius: primitives.radiusLg,
gap: primitives.spacingMd,
},
title: {
color: semantics.textPrimary,
fontSize: primitives.typographyFontSizeMd,
fontWeight: primitives.typographyFontWeightSemiBold,
lineHeight: primitives.typographyLineHeightNormal,
},
description: {
color: semantics.textTertiary,
fontSize: primitives.typographyFontSizeSm,
fontWeight: primitives.typographyFontWeightRegular,
lineHeight: primitives.typographyLineHeightNormal,
},
optionCardContent: {
gap: primitives.spacingXxs,
},
optionCard: {
alignItems: 'center',
justifyContent: 'space-between',
flexDirection: 'row',
},
optionCardSwitch: { width: 64 },
});
}, [semantics]);
};