|
1 | 1 | import React from 'react';
|
2 |
| -import { View, StyleSheet } from 'react-native'; |
| 2 | +import { View } from 'react-native'; |
3 | 3 |
|
| 4 | +import { ButtonV1 as Button } from '@fluentui-react-native/button'; |
4 | 5 | import { Divider } from '@fluentui-react-native/divider';
|
| 6 | +import { Menu, MenuTrigger, MenuList, MenuItem, MenuPopover } from '@fluentui-react-native/menu'; |
5 | 7 | import { TabList, Tab } from '@fluentui-react-native/tablist';
|
6 | 8 | import { TextV1 as Text } from '@fluentui-react-native/text';
|
7 | 9 |
|
| 10 | +import { svgProps, fontProps } from '../Common/iconExamples'; |
| 11 | +import { stackStyle } from '../Common/styles'; |
8 | 12 | import type { PlatformStatus, TestSection } from '../Test';
|
9 | 13 | import { Test } from '../Test';
|
10 | 14 |
|
11 |
| -const Header = Text.customize({ variant: 'subheaderStandard' }); |
| 15 | +const SubHeader = Text.customize({ variant: 'subheaderStandard' }); |
| 16 | +const Header = Text.customize({ variant: 'headerStandard' }); |
12 | 17 | const Line = Divider.customize({ paddingVertical: 4 });
|
13 | 18 | const PaddedTabList = TabList.customize({
|
14 | 19 | paddingVertical: 4,
|
15 | 20 | });
|
16 | 21 |
|
17 |
| -const styles = StyleSheet.create({ |
18 |
| - container: { |
19 |
| - paddingVertical: 8, |
20 |
| - }, |
21 |
| -}); |
22 |
| - |
23 |
| -const TabListSizeTest: React.FunctionComponent = () => { |
| 22 | +const TabListDefaultTest: React.FunctionComponent = () => { |
| 23 | + const [key, setKey] = React.useState('tab1'); |
24 | 24 | return (
|
25 |
| - <View style={styles.container}> |
26 |
| - <Header>Small</Header> |
27 |
| - <PaddedTabList size="small"> |
28 |
| - <Tab tabKey="hello">Tab 1</Tab> |
29 |
| - <Tab tabKey="world">Tab 2</Tab> |
30 |
| - </PaddedTabList> |
| 25 | + <View style={stackStyle}> |
| 26 | + <Header>Uncontrolled Component</Header> |
31 | 27 | <Line />
|
32 |
| - <Header>Medium (default)</Header> |
33 |
| - <PaddedTabList size="medium"> |
34 |
| - <Tab tabKey="hello">Tab 1</Tab> |
35 |
| - <Tab tabKey="world">Tab 2</Tab> |
| 28 | + <PaddedTabList defaultSelectedKey={'tab1'}> |
| 29 | + <Tab tabKey="tab1">Tab 1</Tab> |
| 30 | + <Tab tabKey="tab2">Tab 2</Tab> |
| 31 | + <Tab tabKey="tab3">Tab 3</Tab> |
36 | 32 | </PaddedTabList>
|
| 33 | + <Header>Controlled Component</Header> |
37 | 34 | <Line />
|
38 |
| - <Header>Large</Header> |
39 |
| - <PaddedTabList size="large"> |
40 |
| - <Tab tabKey="hello">Tab 1</Tab> |
41 |
| - <Tab tabKey="world">Tab 2</Tab> |
| 35 | + <Text>Selected Key: {key}</Text> |
| 36 | + <PaddedTabList |
| 37 | + selectedKey={key} |
| 38 | + onTabSelect={(val) => { |
| 39 | + console.log('New key:', val); |
| 40 | + setKey(val); |
| 41 | + }} |
| 42 | + > |
| 43 | + <Tab tabKey="tab1">Tab 1</Tab> |
| 44 | + <Tab tabKey="tab2">Tab 2</Tab> |
| 45 | + <Tab tabKey="tab3">Tab 3</Tab> |
42 | 46 | </PaddedTabList>
|
43 | 47 | </View>
|
44 | 48 | );
|
45 | 49 | };
|
46 | 50 |
|
47 |
| -const TabListVerticalTest: React.FunctionComponent = () => { |
| 51 | +const TabListDisabledTest: React.FunctionComponent = () => { |
48 | 52 | return (
|
49 |
| - <TabList vertical> |
50 |
| - <Tab tabKey="hello">Tab 1</Tab> |
51 |
| - <Tab tabKey="world">Tab 2</Tab> |
52 |
| - </TabList> |
| 53 | + <View style={stackStyle}> |
| 54 | + <PaddedTabList defaultSelectedKey="tab2"> |
| 55 | + <Tab disabled tabKey="tab1"> |
| 56 | + Tab 1 |
| 57 | + </Tab> |
| 58 | + <Tab tabKey="tab2">Tab 2</Tab> |
| 59 | + <Tab disabled tabKey="tab3"> |
| 60 | + Tab 3 |
| 61 | + </Tab> |
| 62 | + <Tab tabKey="tab4">Tab 4</Tab> |
| 63 | + </PaddedTabList> |
| 64 | + <PaddedTabList disabled> |
| 65 | + <Tab tabKey="tab1">Tab 1</Tab> |
| 66 | + <Tab tabKey="tab2">Tab 2</Tab> |
| 67 | + <Tab tabKey="tab3">Tab 3</Tab> |
| 68 | + </PaddedTabList> |
| 69 | + </View> |
53 | 70 | );
|
54 | 71 | };
|
55 | 72 |
|
56 |
| -const TabListAppearanceTest: React.FunctionComponent = () => { |
| 73 | +const TabListVariantsTest: React.FunctionComponent = () => { |
57 | 74 | return (
|
58 |
| - <View style={styles.container}> |
59 |
| - <Header>Transparent Appearance</Header> |
60 |
| - <PaddedTabList appearance="transparent"> |
61 |
| - <Tab tabKey="hello">Tab 1</Tab> |
62 |
| - <Tab tabKey="world">Tab 2</Tab> |
| 75 | + <View style={stackStyle}> |
| 76 | + <Header>Size Variants</Header> |
| 77 | + <Line /> |
| 78 | + <SubHeader>Small</SubHeader> |
| 79 | + <PaddedTabList defaultSelectedKey="sm1" size="small"> |
| 80 | + <Tab tabKey="sm1">Small Tab 1</Tab> |
| 81 | + <Tab tabKey="sm2">Small Tab 2</Tab> |
| 82 | + <Tab tabKey="sm3">Small Tab 3</Tab> |
| 83 | + </PaddedTabList> |
| 84 | + <SubHeader>Medium (default)</SubHeader> |
| 85 | + <PaddedTabList defaultSelectedKey="m1" size="medium"> |
| 86 | + <Tab tabKey="m1">Medium Tab 1</Tab> |
| 87 | + <Tab tabKey="m2">Medium Tab 2</Tab> |
| 88 | + <Tab tabKey="m3">Medium Tab 3</Tab> |
| 89 | + </PaddedTabList> |
| 90 | + <SubHeader>Large</SubHeader> |
| 91 | + <PaddedTabList defaultSelectedKey="lg1" size="large"> |
| 92 | + <Tab tabKey="lg1">Large Tab 1</Tab> |
| 93 | + <Tab tabKey="lg2">Large Tab 2</Tab> |
| 94 | + <Tab tabKey="lg3">Large Tab 3</Tab> |
63 | 95 | </PaddedTabList>
|
64 |
| - <Header>Subtle Appearance</Header> |
65 |
| - <PaddedTabList appearance="subtle"> |
66 |
| - <Tab tabKey="hello">Tab 1</Tab> |
67 |
| - <Tab tabKey="world">Tab 2</Tab> |
| 96 | + <Header>Appearance</Header> |
| 97 | + <Line /> |
| 98 | + <SubHeader>Transparent Appearance</SubHeader> |
| 99 | + <PaddedTabList defaultSelectedKey="tab1" appearance="transparent"> |
| 100 | + <Tab tabKey="tab1">Tab 1</Tab> |
| 101 | + <Tab tabKey="tab2">Tab 2</Tab> |
| 102 | + <Tab tabKey="tab3">Tab 3</Tab> |
| 103 | + </PaddedTabList> |
| 104 | + <SubHeader>Subtle Appearance</SubHeader> |
| 105 | + <PaddedTabList defaultSelectedKey="tab1" appearance="subtle"> |
| 106 | + <Tab tabKey="tab1">Tab 1</Tab> |
| 107 | + <Tab tabKey="tab2">Tab 2</Tab> |
| 108 | + <Tab tabKey="tab3">Tab 3</Tab> |
| 109 | + </PaddedTabList> |
| 110 | + <Header>Vertical Orientation</Header> |
| 111 | + <Line /> |
| 112 | + <PaddedTabList defaultSelectedKey="tab1" vertical> |
| 113 | + <Tab tabKey="tab1">Tab 1</Tab> |
| 114 | + <Tab tabKey="tab2">Tab 2</Tab> |
| 115 | + <Tab tabKey="tab3">Tab 3</Tab> |
68 | 116 | </PaddedTabList>
|
69 | 117 | </View>
|
70 | 118 | );
|
71 | 119 | };
|
72 | 120 |
|
73 |
| -const TabListDisabledTest: React.FunctionComponent = () => { |
| 121 | +const TabListIconTest: React.FunctionComponent = () => { |
74 | 122 | return (
|
75 |
| - <View> |
76 |
| - <PaddedTabList> |
77 |
| - <Tab disabled tabKey="hello"> |
78 |
| - Tab 1 |
| 123 | + <View style={stackStyle}> |
| 124 | + <TabList defaultSelectedKey="fontIcon"> |
| 125 | + <Tab icon={{ fontSource: fontProps }} tabKey="fontIcon"> |
| 126 | + Font Icon |
79 | 127 | </Tab>
|
80 |
| - <Tab tabKey="world">Tab 2</Tab> |
81 |
| - </PaddedTabList> |
82 |
| - <PaddedTabList disabled> |
83 |
| - <Tab tabKey="hello">Tab 1</Tab> |
84 |
| - <Tab tabKey="world">Tab 2</Tab> |
85 |
| - </PaddedTabList> |
| 128 | + <Tab icon={{ fontSource: fontProps }} tabKey="fontIconOnly" /> |
| 129 | + <Tab icon={{ svgSource: svgProps }} tabKey="svgIcon"> |
| 130 | + SVG Icon |
| 131 | + </Tab> |
| 132 | + <Tab icon={{ svgSource: svgProps }} tabKey="svgIconOnly" /> |
| 133 | + </TabList> |
86 | 134 | </View>
|
87 | 135 | );
|
88 | 136 | };
|
89 | 137 |
|
90 |
| -const TabListIconTest: React.FunctionComponent = () => { |
91 |
| - const iconProp = { |
92 |
| - fontSource: { |
93 |
| - fontFamily: 'Arial', |
94 |
| - codepoint: 0x2663, |
95 |
| - }, |
96 |
| - }; |
| 138 | +const TabListViewTest: React.FunctionComponent = () => { |
| 139 | + const [key, setKey] = React.useState('a'); |
| 140 | + const views = React.useMemo( |
| 141 | + () => ({ |
| 142 | + a: ( |
| 143 | + <View> |
| 144 | + <SubHeader>This is View 1</SubHeader> |
| 145 | + <Text variant="body1">Here is some text.</Text> |
| 146 | + </View> |
| 147 | + ), |
| 148 | + b: ( |
| 149 | + <View> |
| 150 | + <SubHeader>This is View 2</SubHeader> |
| 151 | + <Button>Button 1</Button> |
| 152 | + </View> |
| 153 | + ), |
| 154 | + c: ( |
| 155 | + <View> |
| 156 | + <SubHeader>This is View 3</SubHeader> |
| 157 | + <Menu> |
| 158 | + <MenuTrigger> |
| 159 | + <Button>Menu</Button> |
| 160 | + </MenuTrigger> |
| 161 | + <MenuPopover> |
| 162 | + <MenuList> |
| 163 | + <MenuItem>Item 1</MenuItem> |
| 164 | + <MenuItem>Item 2</MenuItem> |
| 165 | + <MenuItem>Item 3</MenuItem> |
| 166 | + </MenuList> |
| 167 | + </MenuPopover> |
| 168 | + </Menu> |
| 169 | + </View> |
| 170 | + ), |
| 171 | + }), |
| 172 | + [], |
| 173 | + ); |
97 | 174 | return (
|
98 |
| - <TabList> |
99 |
| - <Tab icon={iconProp} tabKey="withIcon"> |
100 |
| - Tab Item |
101 |
| - </Tab> |
102 |
| - <Tab icon={iconProp} tabKey="iconOnly" /> |
103 |
| - </TabList> |
| 175 | + <View style={stackStyle}> |
| 176 | + <TabList selectedKey={key} onTabSelect={setKey}> |
| 177 | + <Tab tabKey="a">View 1</Tab> |
| 178 | + <Tab tabKey="b">View 2</Tab> |
| 179 | + <Tab tabKey="c">View 3</Tab> |
| 180 | + </TabList> |
| 181 | + {views[key]} |
| 182 | + </View> |
104 | 183 | );
|
105 | 184 | };
|
106 | 185 |
|
107 | 186 | const sections: TestSection[] = [
|
108 | 187 | {
|
109 |
| - name: 'Size', |
110 |
| - component: TabListSizeTest, |
111 |
| - }, |
112 |
| - { |
113 |
| - name: 'Vertical', |
114 |
| - component: TabListVerticalTest, |
115 |
| - }, |
116 |
| - { |
117 |
| - name: 'Appearance', |
118 |
| - component: TabListAppearanceTest, |
| 188 | + name: 'TabList Controlled vs Uncontrolled', |
| 189 | + component: TabListDefaultTest, |
119 | 190 | },
|
120 | 191 | {
|
121 | 192 | name: 'Disabled',
|
122 | 193 | component: TabListDisabledTest,
|
123 | 194 | },
|
| 195 | + { |
| 196 | + name: 'Variants', |
| 197 | + component: TabListVariantsTest, |
| 198 | + }, |
124 | 199 | {
|
125 | 200 | name: 'Icon',
|
126 | 201 | component: TabListIconTest,
|
127 | 202 | },
|
| 203 | + { |
| 204 | + name: 'Rendering Content Separately', |
| 205 | + component: TabListViewTest, |
| 206 | + }, |
128 | 207 | ];
|
129 | 208 |
|
130 | 209 | export const TabListTest: React.FunctionComponent = () => {
|
|
0 commit comments