@@ -13,140 +13,140 @@ export default function TabsPage() {
13
13
"language" : "tsx"
14
14
}
15
15
] }
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 ";
19
19
20
20
interface 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;
26
26
}
27
27
28
28
interface TabsListProps {
29
- children: React.ReactNode;
30
- className?: string;
29
+ children: React.ReactNode;
30
+ className?: string;
31
31
}
32
32
33
33
interface TabsTriggerProps {
34
- value: string;
35
- children: React.ReactNode;
36
- className?: string;
34
+ value: string;
35
+ children: React.ReactNode;
36
+ className?: string;
37
37
}
38
38
39
39
interface TabsContentProps {
40
- value: string;
41
- children: React.ReactNode;
42
- className?: string;
40
+ value: string;
41
+ children: React.ReactNode;
42
+ className?: string;
43
43
}
44
44
45
45
const TabsContext = React.createContext<{
46
- value: string;
47
- onValueChange: (value: string) => void;
46
+ value: string;
47
+ onValueChange: (value: string) => void;
48
48
}>({
49
- value: "",
50
- onValueChange: () => { },
49
+ value: "",
50
+ onValueChange: () => {},
51
51
});
52
52
53
53
const 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
+ );
58
58
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
+ );
66
66
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
+ },
80
80
);
81
81
82
82
const 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
+ },
97
97
);
98
98
99
99
const 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;
104
104
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
+ },
127
127
);
128
128
129
129
const 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;
133
133
134
- if (!isSelected) return null;
134
+ if (!isSelected) return null;
135
135
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
+ },
142
142
);
143
143
144
144
Tabs.displayName = "Tabs";
145
145
TabsList.displayName = "TabsList";
146
146
TabsTrigger.displayName = "TabsTrigger";
147
147
TabsContent.displayName = "TabsContent";
148
148
149
- export { Tabs, TabsList, TabsTrigger, TabsContent };
149
+ export { Tabs, TabsContent, TabsList, TabsTrigger };
150
150
` }
151
151
previewCode = { `import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
152
152
import * as React from "react";
0 commit comments