-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathCheckboxV1Test.tsx
More file actions
233 lines (204 loc) · 6.97 KB
/
CheckboxV1Test.tsx
File metadata and controls
233 lines (204 loc) · 6.97 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import * as React from 'react';
import { View, TextInput, Platform } from 'react-native';
import { ButtonV1 as Button } from '@fluentui-react-native/button';
import { Checkbox } from '@fluentui-react-native/experimental-checkbox';
import type { InteractionEvent } from '@fluentui-react-native/interactive-hooks';
import type { Theme } from '@fluentui-react-native/theme-types';
import { useTheme } from '@fluentui-react-native/theme-types';
import { themedStyleSheet } from '@fluentui-react-native/themed-stylesheet';
import { E2ECheckboxV1Test } from './E2ECheckboxV1Test';
import { CHECKBOXV1_TESTPAGE } from '../../../../E2E/src/CheckboxV1/consts';
import { commonTestStyles as commonStyles, mobileStyles } from '../Common/styles';
import type { TestSection, PlatformStatus } from '../Test';
import { Test } from '../Test';
function onChangeUncontrolled(_e: InteractionEvent, isChecked: boolean) {
console.log(isChecked);
}
const BasicCheckbox: React.FunctionComponent = () => {
return (
<View>
<Checkbox label="Unchecked checkbox (undefined) aidasdijk ahsdihsaidhas jasdhasid" onChange={onChangeUncontrolled} />
<Checkbox label="Unchecked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked={false} />
<Checkbox label="Checked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked accessibilityLabel="Hello there" />
<Checkbox label="Disabled checkbox" disabled />
<Checkbox label="Disabled checked checkbox" defaultChecked disabled />
<Checkbox label="A required checkbox" required />
</View>
);
};
const DesktopSpecificCheckbox: React.FunctionComponent = () => {
return (
<>
<Checkbox label="Checkbox will display a tooltip" tooltip="This is a tooltip" />
<Checkbox label="A circular checkbox" shape="circular" />
<Checkbox label="A checkbox with label placed before" labelPosition="before" />
</>
);
};
const SizeCheckbox: React.FunctionComponent = () => {
return (
<View>
<Checkbox tooltip="Medium checkbox" size="medium" />
<Checkbox tooltip="Large checkbox" size="large" />
<Checkbox label="Medium checkbox" size="medium" />
<Checkbox label="Large checkbox" size="large" />
</View>
);
};
const OtherCheckbox: React.FunctionComponent = () => {
const [isChecked, setisChecked] = React.useState(false);
const setCheckedTrue = React.useCallback(() => {
setisChecked(true);
}, []);
const setCheckedFalse = React.useCallback(() => {
setisChecked(false);
}, []);
const memoizedStyles = React.useMemo(() => (Platform.OS === 'android' ? { ...mobileStyles.containerSpacedEvenly, height: 150 } : {}), []);
return (
<View style={memoizedStyles}>
<Button onClick={setCheckedTrue} size="small">
Check controlled checkboxes below
</Button>
<Button onClick={setCheckedFalse} size="small">
Uncheck controlled checkboxes below
</Button>
<Checkbox label="This is a controlled Checkbox" checked={isChecked} />
{Platform.OS !== 'android' && (
<>
<Checkbox label="Checkbox rendered with labelPosition 'before' (controlled)" labelPosition="before" checked={isChecked} />
<Checkbox label="A required checkbox with other required text" required="**" />
</>
)}
</View>
);
};
const CircleColorCheckbox = Checkbox.customize({
checked: {
checkboxBackgroundColor: 'green',
checkboxBorderColor: 'green',
checkmarkColor: 'white',
},
});
const HoverCheckbox = Checkbox.customize({
hovered: {
checkmarkOpacity: 1,
},
});
const BigLabelCheckbox = Checkbox.customize({
label: {
fontSize: 24,
fontWeight: 'bold',
},
});
const ComposedCheckbox = Checkbox.compose({
slotProps: {
label: { style: { color: 'hotpink' } },
},
});
const getThemedStyles = themedStyleSheet((t: Theme) => {
return { textbox: { ...commonStyles.textBox, borderColor: t.colors.inputBorder } };
});
const TokenCheckbox: React.FunctionComponent = () => {
const [checkboxColor, setCheckboxColor] = React.useState('blue');
const [checkmarkColor, setCheckmarkColor] = React.useState('white');
const BlueCheckbox = Checkbox.customize({
checked: {
checkboxBackgroundColor: checkboxColor,
checkboxBorderColor: checkboxColor,
checkmarkColor: checkmarkColor,
},
});
const theme = useTheme();
const textBoxBorderStyle = getThemedStyles(theme);
return (
<View>
{Platform.OS !== 'android' && (
<>
<HoverCheckbox label="A checkbox with checkmark visible on hover" onChange={onChangeUncontrolled} />
<CircleColorCheckbox
label="A circular token-customized checkbox"
shape="circular"
onChange={onChangeUncontrolled}
defaultChecked
/>
</>
)}
<BigLabelCheckbox label="A checkbox with a bold large font label" />
<ComposedCheckbox label="A checkbox with a hot pink label and no padding" />
<BlueCheckbox
label="Token-customized checkbox. Customizable below."
onChange={onChangeUncontrolled}
labelPosition="before"
defaultChecked={false}
/>
<TextInput
accessibilityLabel="Background color"
style={textBoxBorderStyle.textbox}
placeholder="Background color"
blurOnSubmit={true}
onSubmitEditing={(e) => {
setCheckboxColor(e.nativeEvent.text);
}}
/>
<TextInput
accessibilityLabel="Checkmark color"
style={textBoxBorderStyle.textbox}
placeholder="Checkmark color"
blurOnSubmit={true}
onSubmitEditing={(e) => {
setCheckmarkColor(e.nativeEvent.text);
}}
/>
</View>
);
};
const checkboxSections: TestSection[] = [
{
name: 'Basic Checkboxes',
testID: CHECKBOXV1_TESTPAGE,
component: BasicCheckbox,
},
Platform.select({
android: null,
default: {
name: 'Size Checkboxes',
component: SizeCheckbox,
},
}),
Platform.select({
android: null,
default: {
name: 'Desktop Specific Checkboxes',
component: DesktopSpecificCheckbox,
},
}),
{
name: 'Other Implementations',
component: OtherCheckbox,
},
Platform.select({
android: null,
default: {
name: 'Token Customized Checkboxes',
component: TokenCheckbox,
},
}),
];
const e2eSections: TestSection[] = [
{
name: 'E2E Testing for CheckboxV1',
component: E2ECheckboxV1Test,
},
];
export const CheckboxV1Test: React.FunctionComponent = () => {
const status: PlatformStatus = {
win32Status: 'Production',
uwpStatus: 'N/A',
iosStatus: 'N/A',
macosStatus: 'Experimental',
androidStatus: 'Experimental',
};
const description =
'Checkboxes give people a way to select one or more items from a group, or switch between two mutually exclusive options (checked or unchecked, on or off).';
return <Test name="CheckboxV1 Test" description={description} sections={checkboxSections} status={status} e2eSections={e2eSections} />;
};