|
| 1 | +import { Stack } from "expo-router"; |
| 2 | +import { View, Text } from "@native-ui-org/primitives"; |
| 3 | +import { Tabs, TabsList, TabsTrigger, TabsContent } from "@native-ui-org/primitives"; |
| 4 | +import { StyleSheet, Platform, ScrollView } from "react-native"; |
| 5 | +import React from "react"; |
| 6 | + |
| 7 | +export default function TabsPreview() { |
| 8 | + return ( |
| 9 | + <ScrollView style={styles.container}> |
| 10 | + <Stack.Screen options={{ title: "Tabs" }} /> |
| 11 | + |
| 12 | + <View style={styles.content}> |
| 13 | + <View style={styles.section}> |
| 14 | + <Text as="h2" style={styles.sectionTitle}>Tabs Primitive</Text> |
| 15 | + <Text as="p" style={styles.description}> |
| 16 | + Organize content into tabbed sections. On web: classic tabs. On iOS/Android: native dropdown button. |
| 17 | + </Text> |
| 18 | + </View> |
| 19 | + |
| 20 | + {/* Example 1: Normal tabs, no styling */} |
| 21 | + <View style={styles.section}> |
| 22 | + <Text as="h3" style={styles.subTitle}>Example 1: Normal Tabs</Text> |
| 23 | + <Text as="p" style={styles.description}> |
| 24 | + Basic tabs without any custom styling |
| 25 | + </Text> |
| 26 | + |
| 27 | + <Tabs |
| 28 | + defaultValue="tab1" |
| 29 | + style={Platform.OS !== "web" ? styles.nativeTabsButton : undefined} |
| 30 | + backgroundColor={Platform.OS !== "web" ? "#F2F2F7" : undefined} |
| 31 | + borderColor={Platform.OS !== "web" ? "#E5E5EA" : undefined} |
| 32 | + cornerRadius={Platform.OS !== "web" ? 10 : undefined} |
| 33 | + > |
| 34 | + <TabsList> |
| 35 | + <TabsTrigger value="tab1" iosIcon="house.fill" androidIcon="home" icon="🏠">Home</TabsTrigger> |
| 36 | + <TabsTrigger value="tab2" iosIcon="person.fill" androidIcon="person" icon="👤">Profile</TabsTrigger> |
| 37 | + <TabsTrigger value="tab3" iosIcon="gear" androidIcon="settings" icon="⚙️">Settings</TabsTrigger> |
| 38 | + </TabsList> |
| 39 | + |
| 40 | + <TabsContent value="tab1"> |
| 41 | + <View style={styles.tabContent}> |
| 42 | + <Text style={styles.tabTitle}>Home Tab</Text> |
| 43 | + <Text style={styles.tabText}> |
| 44 | + This is the content for the Home tab. You can see that the content is properly displayed with full width. |
| 45 | + </Text> |
| 46 | + </View> |
| 47 | + </TabsContent> |
| 48 | + |
| 49 | + <TabsContent value="tab2"> |
| 50 | + <View style={styles.tabContent}> |
| 51 | + <Text style={styles.tabTitle}>Profile Tab</Text> |
| 52 | + <Text style={styles.tabText}> |
| 53 | + This is the content for the Profile tab. The content should take the full width available. |
| 54 | + </Text> |
| 55 | + </View> |
| 56 | + </TabsContent> |
| 57 | + |
| 58 | + <TabsContent value="tab3"> |
| 59 | + <View style={styles.tabContent}> |
| 60 | + <Text style={styles.tabTitle}>Settings Tab</Text> |
| 61 | + <Text style={styles.tabText}> |
| 62 | + This is the content for the Settings tab. All content should be properly sized and visible. |
| 63 | + </Text> |
| 64 | + </View> |
| 65 | + </TabsContent> |
| 66 | + </Tabs> |
| 67 | + </View> |
| 68 | + |
| 69 | + {/* Example 2: Right aligned button */} |
| 70 | + {Platform.OS !== "web" && ( |
| 71 | + <View style={styles.section}> |
| 72 | + <Text as="h3" style={styles.subTitle}>Example 2: Right Aligned Button</Text> |
| 73 | + <Text as="p" style={styles.description}> |
| 74 | + Button aligned to the right with auto width |
| 75 | + </Text> |
| 76 | + |
| 77 | + <View style={styles.rightAlignedContainer}> |
| 78 | + <Tabs |
| 79 | + defaultValue="option1" |
| 80 | + alignment="right" |
| 81 | + style={styles.nativeTabsButtonAuto} |
| 82 | + backgroundColor="#F2F2F7" |
| 83 | + borderColor="#E5E5EA" |
| 84 | + cornerRadius={10} |
| 85 | + > |
| 86 | + <TabsList> |
| 87 | + <TabsTrigger value="option1" iosIcon="star.fill" androidIcon="star" icon="⭐">Option 1</TabsTrigger> |
| 88 | + <TabsTrigger value="option2" iosIcon="heart.fill" androidIcon="favorite" icon="❤️">Option 2</TabsTrigger> |
| 89 | + <TabsTrigger value="option3" iosIcon="bookmark.fill" androidIcon="bookmark" icon="🔖">Option 3</TabsTrigger> |
| 90 | + </TabsList> |
| 91 | + |
| 92 | + <TabsContent value="option1"> |
| 93 | + <View style={styles.tabContent}> |
| 94 | + <Text style={styles.tabTitle}>Option 1 Selected</Text> |
| 95 | + <Text style={styles.tabText}> |
| 96 | + The button is aligned to the right. The content below should take full width and be properly displayed. |
| 97 | + </Text> |
| 98 | + </View> |
| 99 | + </TabsContent> |
| 100 | + |
| 101 | + <TabsContent value="option2"> |
| 102 | + <View style={styles.tabContent}> |
| 103 | + <Text style={styles.tabTitle}>Option 2 Selected</Text> |
| 104 | + <Text style={styles.tabText}> |
| 105 | + The button is aligned to the right. The content below should take full width and be properly displayed. |
| 106 | + </Text> |
| 107 | + </View> |
| 108 | + </TabsContent> |
| 109 | + |
| 110 | + <TabsContent value="option3"> |
| 111 | + <View style={styles.tabContent}> |
| 112 | + <Text style={styles.tabTitle}>Option 3 Selected</Text> |
| 113 | + <Text style={styles.tabText}> |
| 114 | + The button is aligned to the right. The content below should take full width and be properly displayed. |
| 115 | + </Text> |
| 116 | + </View> |
| 117 | + </TabsContent> |
| 118 | + </Tabs> |
| 119 | + </View> |
| 120 | + </View> |
| 121 | + )} |
| 122 | + |
| 123 | + {/* Example 3: Custom styling */} |
| 124 | + <View style={styles.section}> |
| 125 | + <Text as="h3" style={styles.subTitle}>Example 3: Custom Styled</Text> |
| 126 | + <Text as="p" style={styles.description}> |
| 127 | + Custom colors and styling with blue background |
| 128 | + </Text> |
| 129 | + |
| 130 | + <Tabs |
| 131 | + defaultValue="home" |
| 132 | + backgroundColor={Platform.OS !== "web" ? "#007AFF" : undefined} |
| 133 | + textColor={Platform.OS !== "web" ? "#FFFFFF" : undefined} |
| 134 | + borderColor={Platform.OS !== "web" ? "#0051D5" : undefined} |
| 135 | + cornerRadius={Platform.OS !== "web" ? 20 : undefined} |
| 136 | + showChevron={Platform.OS !== "web" ? true : undefined} |
| 137 | + chevronIcon={Platform.OS !== "web" ? "arrow.down.circle.fill" : undefined} |
| 138 | + style={Platform.OS !== "web" ? styles.nativeTabsButton : undefined} |
| 139 | + > |
| 140 | + <TabsList> |
| 141 | + <TabsTrigger value="home" iosIcon="house.fill" androidIcon="home" icon="🏠">Home</TabsTrigger> |
| 142 | + <TabsTrigger value="search" iosIcon="magnifyingglass" androidIcon="search" icon="🔍">Search</TabsTrigger> |
| 143 | + <TabsTrigger value="profile" iosIcon="person.fill" androidIcon="person" icon="👤">Profile</TabsTrigger> |
| 144 | + </TabsList> |
| 145 | + |
| 146 | + <TabsContent value="home"> |
| 147 | + <View style={styles.tabContent}> |
| 148 | + <Text style={styles.tabTitle}>Home</Text> |
| 149 | + <Text style={styles.tabText}> |
| 150 | + Custom styled button with blue background. The content should be properly displayed with full width. |
| 151 | + </Text> |
| 152 | + </View> |
| 153 | + </TabsContent> |
| 154 | + |
| 155 | + <TabsContent value="search"> |
| 156 | + <View style={styles.tabContent}> |
| 157 | + <Text style={styles.tabTitle}>Search</Text> |
| 158 | + <Text style={styles.tabText}> |
| 159 | + Custom styled button with blue background. The content should be properly displayed with full width. |
| 160 | + </Text> |
| 161 | + </View> |
| 162 | + </TabsContent> |
| 163 | + |
| 164 | + <TabsContent value="profile"> |
| 165 | + <View style={styles.tabContent}> |
| 166 | + <Text style={styles.tabTitle}>Profile</Text> |
| 167 | + <Text style={styles.tabText}> |
| 168 | + Custom styled button with blue background. The content should be properly displayed with full width. |
| 169 | + </Text> |
| 170 | + </View> |
| 171 | + </TabsContent> |
| 172 | + </Tabs> |
| 173 | + </View> |
| 174 | + </View> |
| 175 | + </ScrollView> |
| 176 | + ); |
| 177 | +} |
| 178 | + |
| 179 | +const styles = StyleSheet.create({ |
| 180 | + container: { |
| 181 | + flex: 1, |
| 182 | + backgroundColor: Platform.OS === "web" ? "#fff" : "#f2f2f7", |
| 183 | + }, |
| 184 | + content: { |
| 185 | + ...Platform.select({ |
| 186 | + web: { |
| 187 | + maxWidth: 800, |
| 188 | + marginHorizontal: "auto", |
| 189 | + width: "100%", |
| 190 | + paddingHorizontal: 24, |
| 191 | + paddingVertical: 32, |
| 192 | + }, |
| 193 | + default: { |
| 194 | + padding: 16, |
| 195 | + }, |
| 196 | + }), |
| 197 | + }, |
| 198 | + section: { |
| 199 | + marginBottom: 32, |
| 200 | + }, |
| 201 | + sectionTitle: { |
| 202 | + fontSize: 24, |
| 203 | + fontWeight: "600", |
| 204 | + marginBottom: 8, |
| 205 | + color: "#000", |
| 206 | + }, |
| 207 | + subTitle: { |
| 208 | + fontSize: 18, |
| 209 | + fontWeight: "600", |
| 210 | + marginBottom: 8, |
| 211 | + color: "#000", |
| 212 | + }, |
| 213 | + description: { |
| 214 | + fontSize: 14, |
| 215 | + color: "#666", |
| 216 | + marginBottom: 16, |
| 217 | + lineHeight: 20, |
| 218 | + }, |
| 219 | + tabContent: { |
| 220 | + padding: 16, |
| 221 | + backgroundColor: Platform.OS === "web" ? "#f9fafb" : "#fff", |
| 222 | + borderRadius: 8, |
| 223 | + marginTop: Platform.OS === "web" ? 16 : 0, // TabsContent already has marginTop on native |
| 224 | + }, |
| 225 | + tabTitle: { |
| 226 | + fontSize: 18, |
| 227 | + fontWeight: "600", |
| 228 | + marginBottom: 8, |
| 229 | + color: "#000", |
| 230 | + }, |
| 231 | + tabText: { |
| 232 | + fontSize: 14, |
| 233 | + color: "#666", |
| 234 | + lineHeight: 20, |
| 235 | + }, |
| 236 | + nativeTabsButton: { |
| 237 | + height: 44, |
| 238 | + marginBottom: 16, |
| 239 | + width: "100%", |
| 240 | + }, |
| 241 | + nativeTabsButtonAuto: { |
| 242 | + height: 44, |
| 243 | + marginBottom: 16, |
| 244 | + minWidth: 150, |
| 245 | + }, |
| 246 | + rightAlignedContainer: { |
| 247 | + width: "100%", |
| 248 | + alignItems: "flex-end" as any, |
| 249 | + marginBottom: 16, |
| 250 | + alignSelf: "stretch" as any, |
| 251 | + }, |
| 252 | +}); |
0 commit comments