@@ -13,140 +13,140 @@ export default function TabsPage() {
1313 "language" : "tsx"
1414 }
1515] }
16- componentCode = { `import * as React from "react ";
17- import { View, Text, Pressable, Platform } from "react-native ";
18- import { cn } from "@/lib/utils ";
16+ componentCode = { `import { cn } from "@/lib/utils ";
17+ import * as React from "react";
18+ import { Platform, Pressable, Text, View } from "react-native ";
1919
2020interface TabsProps {
21- defaultValue?: string;
22- value?: string;
23- onValueChange?: (value: string) => void;
24- children: React.ReactNode;
25- className?: string;
21+ defaultValue?: string;
22+ value?: string;
23+ onValueChange?: (value: string) => void;
24+ children: React.ReactNode;
25+ className?: string;
2626}
2727
2828interface TabsListProps {
29- children: React.ReactNode;
30- className?: string;
29+ children: React.ReactNode;
30+ className?: string;
3131}
3232
3333interface TabsTriggerProps {
34- value: string;
35- children: React.ReactNode;
36- className?: string;
34+ value: string;
35+ children: React.ReactNode;
36+ className?: string;
3737}
3838
3939interface TabsContentProps {
40- value: string;
41- children: React.ReactNode;
42- className?: string;
40+ value: string;
41+ children: React.ReactNode;
42+ className?: string;
4343}
4444
4545const TabsContext = React.createContext<{
46- value: string;
47- onValueChange: (value: string) => void;
46+ value: string;
47+ onValueChange: (value: string) => void;
4848}>({
49- value: "",
50- onValueChange: () => { },
49+ value: "",
50+ onValueChange: () => {},
5151});
5252
5353const Tabs = React.forwardRef<View, TabsProps>(
54- ({ defaultValue, value, onValueChange, children, className }, ref) => {
55- const [selectedValue, setSelectedValue] = React.useState(
56- value || defaultValue || ""
57- );
54+ ({ defaultValue, value, onValueChange, children, className }, ref) => {
55+ const [selectedValue, setSelectedValue] = React.useState(
56+ value || defaultValue || "",
57+ );
5858
59- const handleValueChange = React.useCallback(
60- (newValue: string) => {
61- setSelectedValue(newValue);
62- onValueChange?.(newValue);
63- },
64- [onValueChange]
65- );
59+ const handleValueChange = React.useCallback(
60+ (newValue: string) => {
61+ setSelectedValue(newValue);
62+ onValueChange?.(newValue);
63+ },
64+ [onValueChange],
65+ );
6666
67- return (
68- <TabsContext.Provider
69- value={{
70- value: selectedValue,
71- onValueChange: handleValueChange,
72- }}
73- >
74- <View ref={ref} className={cn("w-full", className)}>
75- {children}
76- </View>
77- </TabsContext.Provider>
78- );
79- }
67+ return (
68+ <TabsContext.Provider
69+ value={{
70+ value: selectedValue,
71+ onValueChange: handleValueChange,
72+ }}
73+ >
74+ <View ref={ref} className={cn("flex-1 w-full", className)}>
75+ {children}
76+ </View>
77+ </TabsContext.Provider>
78+ );
79+ },
8080);
8181
8282const TabsList = React.forwardRef<View, TabsListProps>(
83- ({ children, className }, ref) => {
84- return (
85- <View
86- ref={ref}
87- className={cn(
88- "flex-row items-center justify-center rounded-xl bg-muted p-1",
89- Platform.OS === "ios" ? "h-12" : "h-14",
90- className
91- )}
92- >
93- {children}
94- </View>
95- );
96- }
83+ ({ children, className }, ref) => {
84+ return (
85+ <View
86+ ref={ref}
87+ className={cn(
88+ "flex-row items-center justify-center rounded-xl bg-muted p-1",
89+ Platform.OS === "ios" ? "h-12" : "h-14",
90+ className,
91+ )}
92+ >
93+ {children}
94+ </View>
95+ );
96+ },
9797);
9898
9999const TabsTrigger = React.forwardRef<View, TabsTriggerProps>(
100- ({ value, children, className }, ref) => {
101- const { value: selectedValue, onValueChange } =
102- React.useContext(TabsContext);
103- const isSelected = selectedValue === value;
100+ ({ value, children, className }, ref) => {
101+ const { value: selectedValue, onValueChange } =
102+ React.useContext(TabsContext);
103+ const isSelected = selectedValue === value;
104104
105- return (
106- <Pressable
107- ref={ref}
108- onPress={() => onValueChange(value)}
109- className={cn(
110- "flex-1 items-center justify-center rounded-lg px-4 py-2",
111- Platform.OS === "ios" ? "h-10" : "h-12",
112- isSelected ? "bg-background" : "bg-transparent",
113- className
114- )}
115- >
116- <Text
117- className={cn(
118- "text-base font-medium",
119- isSelected ? "text-foreground" : "text-muted-foreground"
120- )}
121- >
122- {children}
123- </Text>
124- </Pressable>
125- );
126- }
105+ return (
106+ <Pressable
107+ ref={ref}
108+ onPress={() => onValueChange(value)}
109+ className={cn(
110+ "flex-1 items-center justify-center rounded-lg px-4 py-2",
111+ Platform.OS === "ios" ? "h-10" : "h-12",
112+ isSelected ? "bg-background" : "bg-transparent",
113+ className,
114+ )}
115+ >
116+ <Text
117+ className={cn(
118+ "text-base font-medium",
119+ isSelected ? "text-foreground" : "text-muted-foreground",
120+ )}
121+ >
122+ {children}
123+ </Text>
124+ </Pressable>
125+ );
126+ },
127127);
128128
129129const TabsContent = React.forwardRef<View, TabsContentProps>(
130- ({ value, children, className }, ref) => {
131- const { value: selectedValue } = React.useContext(TabsContext);
132- const isSelected = selectedValue === value;
130+ ({ value, children, className }, ref) => {
131+ const { value: selectedValue } = React.useContext(TabsContext);
132+ const isSelected = selectedValue === value;
133133
134- if (!isSelected) return null;
134+ if (!isSelected) return null;
135135
136- return (
137- <View ref={ref} className={cn("mt-4", className)}>
138- {children}
139- </View>
140- );
141- }
136+ return (
137+ <View ref={ref} className={cn("flex-1 mt-4", className)}>
138+ {children}
139+ </View>
140+ );
141+ },
142142);
143143
144144Tabs.displayName = "Tabs";
145145TabsList.displayName = "TabsList";
146146TabsTrigger.displayName = "TabsTrigger";
147147TabsContent.displayName = "TabsContent";
148148
149- export { Tabs, TabsList, TabsTrigger, TabsContent };
149+ export { Tabs, TabsContent, TabsList, TabsTrigger };
150150` }
151151 previewCode = { `import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
152152import * as React from "react";
0 commit comments