|
1 | 1 | import * as React from 'react'; |
2 | | -import { View, TextInput, Platform } from 'react-native'; |
3 | | - |
4 | | -import { ButtonV1 as Button } from '@fluentui-react-native/button'; |
5 | | -import { Checkbox } from '@fluentui-react-native/experimental-checkbox'; |
6 | | -import type { InteractionEvent } from '@fluentui-react-native/interactive-hooks'; |
7 | | -import type { Theme } from '@fluentui-react-native/theme-types'; |
8 | | -import { useTheme } from '@fluentui-react-native/theme-types'; |
9 | | -import { themedStyleSheet } from '@fluentui-react-native/themed-stylesheet'; |
| 2 | +import { Platform } from 'react-native'; |
10 | 3 |
|
11 | 4 | import { E2ECheckboxV1Test } from './E2ECheckboxV1Test'; |
12 | 5 | import { CHECKBOXV1_TESTPAGE } from '../../../../E2E/src/CheckboxV1/consts'; |
13 | | -import { commonTestStyles as commonStyles, mobileStyles } from '../Common/styles'; |
14 | 6 | import type { TestSection, PlatformStatus } from '../Test'; |
15 | 7 | import { Test } from '../Test'; |
16 | | - |
17 | | -function onChangeUncontrolled(_e: InteractionEvent, isChecked: boolean) { |
18 | | - console.log(isChecked); |
19 | | -} |
20 | | - |
21 | | -const BasicCheckbox: React.FunctionComponent = () => { |
22 | | - return ( |
23 | | - <View> |
24 | | - <Checkbox label="Unchecked checkbox (undefined)" onChange={onChangeUncontrolled} /> |
25 | | - <Checkbox label="Unchecked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked={false} /> |
26 | | - <Checkbox label="Checked checkbox (uncontrolled)" onChange={onChangeUncontrolled} defaultChecked accessibilityLabel="Hello there" /> |
27 | | - <Checkbox label="Disabled checkbox" disabled /> |
28 | | - <Checkbox label="Disabled checked checkbox" defaultChecked disabled /> |
29 | | - <Checkbox label="A required checkbox" required /> |
30 | | - </View> |
31 | | - ); |
32 | | -}; |
33 | | - |
34 | | -const DesktopSpecificCheckbox: React.FunctionComponent = () => { |
35 | | - return ( |
36 | | - <> |
37 | | - <Checkbox label="Checkbox will display a tooltip" tooltip="This is a tooltip" /> |
38 | | - <Checkbox label="A circular checkbox" shape="circular" /> |
39 | | - <Checkbox label="A checkbox with label placed before" labelPosition="before" /> |
40 | | - </> |
41 | | - ); |
42 | | -}; |
43 | | - |
44 | | -const SizeCheckbox: React.FunctionComponent = () => { |
45 | | - return ( |
46 | | - <View> |
47 | | - <Checkbox tooltip="Medium checkbox" size="medium" /> |
48 | | - <Checkbox tooltip="Large checkbox" size="large" /> |
49 | | - <Checkbox label="Medium checkbox" size="medium" /> |
50 | | - <Checkbox label="Large checkbox" size="large" /> |
51 | | - </View> |
52 | | - ); |
53 | | -}; |
54 | | - |
55 | | -const OtherCheckbox: React.FunctionComponent = () => { |
56 | | - const [isChecked, setisChecked] = React.useState(false); |
57 | | - |
58 | | - const setCheckedTrue = React.useCallback(() => { |
59 | | - setisChecked(true); |
60 | | - }, []); |
61 | | - |
62 | | - const setCheckedFalse = React.useCallback(() => { |
63 | | - setisChecked(false); |
64 | | - }, []); |
65 | | - |
66 | | - const memoizedStyles = React.useMemo(() => (Platform.OS === 'android' ? { ...mobileStyles.containerSpacedEvenly, height: 150 } : {}), []); |
67 | | - |
68 | | - return ( |
69 | | - <View style={memoizedStyles}> |
70 | | - <Button onClick={setCheckedTrue} size="small"> |
71 | | - Check controlled checkboxes below |
72 | | - </Button> |
73 | | - <Button onClick={setCheckedFalse} size="small"> |
74 | | - Uncheck controlled checkboxes below |
75 | | - </Button> |
76 | | - |
77 | | - <Checkbox label="This is a controlled Checkbox" checked={isChecked} /> |
78 | | - {Platform.OS !== 'android' && ( |
79 | | - <> |
80 | | - <Checkbox label="Checkbox rendered with labelPosition 'before' (controlled)" labelPosition="before" checked={isChecked} /> |
81 | | - <Checkbox label="A required checkbox with other required text" required="**" /> |
82 | | - </> |
83 | | - )} |
84 | | - </View> |
85 | | - ); |
86 | | -}; |
87 | | - |
88 | | -const CircleColorCheckbox = Checkbox.customize({ |
89 | | - checked: { |
90 | | - checkboxBackgroundColor: 'green', |
91 | | - checkboxBorderColor: 'green', |
92 | | - checkmarkColor: 'white', |
93 | | - }, |
94 | | -}); |
95 | | - |
96 | | -const HoverCheckbox = Checkbox.customize({ |
97 | | - hovered: { |
98 | | - checkmarkOpacity: 1, |
99 | | - }, |
100 | | -}); |
101 | | - |
102 | | -const BigLabelCheckbox = Checkbox.customize({ |
103 | | - label: { |
104 | | - fontSize: 24, |
105 | | - fontWeight: 'bold', |
106 | | - }, |
107 | | -}); |
108 | | - |
109 | | -const ComposedCheckbox = Checkbox.compose({ |
110 | | - slotProps: { |
111 | | - label: { style: { color: 'hotpink' } }, |
112 | | - }, |
113 | | -}); |
114 | | - |
115 | | -const getThemedStyles = themedStyleSheet((t: Theme) => { |
116 | | - return { textbox: { ...commonStyles.textBox, borderColor: t.colors.inputBorder } }; |
117 | | -}); |
118 | | - |
119 | | -const TokenCheckbox: React.FunctionComponent = () => { |
120 | | - const [checkboxColor, setCheckboxColor] = React.useState('blue'); |
121 | | - const [checkmarkColor, setCheckmarkColor] = React.useState('white'); |
122 | | - |
123 | | - const BlueCheckbox = Checkbox.customize({ |
124 | | - checked: { |
125 | | - checkboxBackgroundColor: checkboxColor, |
126 | | - checkboxBorderColor: checkboxColor, |
127 | | - checkmarkColor: checkmarkColor, |
128 | | - }, |
129 | | - }); |
130 | | - |
131 | | - const theme = useTheme(); |
132 | | - const textBoxBorderStyle = getThemedStyles(theme); |
133 | | - |
134 | | - return ( |
135 | | - <View> |
136 | | - {Platform.OS !== 'android' && ( |
137 | | - <> |
138 | | - <HoverCheckbox label="A checkbox with checkmark visible on hover" onChange={onChangeUncontrolled} /> |
139 | | - <CircleColorCheckbox |
140 | | - label="A circular token-customized checkbox" |
141 | | - shape="circular" |
142 | | - onChange={onChangeUncontrolled} |
143 | | - defaultChecked |
144 | | - /> |
145 | | - </> |
146 | | - )} |
147 | | - |
148 | | - <BigLabelCheckbox label="A checkbox with a bold large font label" /> |
149 | | - <ComposedCheckbox label="A checkbox with a hot pink label and no padding" /> |
150 | | - |
151 | | - <BlueCheckbox |
152 | | - label="Token-customized checkbox. Customizable below." |
153 | | - onChange={onChangeUncontrolled} |
154 | | - labelPosition="before" |
155 | | - defaultChecked={false} |
156 | | - /> |
157 | | - <TextInput |
158 | | - accessibilityLabel="Background color" |
159 | | - style={textBoxBorderStyle.textbox} |
160 | | - placeholder="Background color" |
161 | | - blurOnSubmit={true} |
162 | | - onSubmitEditing={(e) => { |
163 | | - setCheckboxColor(e.nativeEvent.text); |
164 | | - }} |
165 | | - /> |
166 | | - |
167 | | - <TextInput |
168 | | - accessibilityLabel="Checkmark color" |
169 | | - style={textBoxBorderStyle.textbox} |
170 | | - placeholder="Checkmark color" |
171 | | - blurOnSubmit={true} |
172 | | - onSubmitEditing={(e) => { |
173 | | - setCheckmarkColor(e.nativeEvent.text); |
174 | | - }} |
175 | | - /> |
176 | | - </View> |
177 | | - ); |
178 | | -}; |
| 8 | +import { BasicCheckbox } from './BasicCheckboxTest'; |
| 9 | +import { DesktopSpecificCheckbox } from './DesktopSpecificCheckboxTest'; |
| 10 | +import { OtherCheckbox } from './OtherCheckboxPropsTest'; |
| 11 | +import { SizeCheckbox } from './SizeCheckboxTest'; |
| 12 | +import { TokenCheckbox } from './TokenCheckboxTest'; |
179 | 13 |
|
180 | 14 | const checkboxSections: TestSection[] = [ |
181 | 15 | { |
|
0 commit comments