Commit d87420d 1 parent 7c84339 commit d87420d Copy full SHA for d87420d
File tree 2 files changed +45
-3
lines changed
2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,35 @@ export const Default = () => {
30
30
)
31
31
}
32
32
33
+ export const Children = ( ) => {
34
+ return (
35
+ < Tabs defaultValue = "leaderboard" >
36
+ < Tabs . TabList >
37
+ < Tabs . Tab key = "leaderboard" value = "leaderboard" >
38
+ < div className = "italic" > Leaderboard</ div >
39
+ </ Tabs . Tab >
40
+ < Tabs . Tab key = "create" value = "create" >
41
+ < div className = "font-bold" > Child Content</ div >
42
+ </ Tabs . Tab >
43
+ </ Tabs . TabList >
44
+ < Tabs . TabContent
45
+ key = "leaderboard"
46
+ value = "leaderboard"
47
+ className = { { root : 'md:px-4' } }
48
+ >
49
+ Course Tab
50
+ </ Tabs . TabContent >
51
+ < Tabs . TabContent
52
+ key = "create"
53
+ value = "create"
54
+ className = { { root : 'md:px-4' } }
55
+ >
56
+ Create Tab
57
+ </ Tabs . TabContent >
58
+ </ Tabs >
59
+ )
60
+ }
61
+
33
62
export const Controlled = ( ) => {
34
63
const [ selectedTab , setSelectedTab ] = useState ( 'leaderboard' )
35
64
return (
Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ interface TabProps {
10
10
}
11
11
key ?: string
12
12
value : string
13
- label : string
13
+ label ?: string
14
+ children ?: React . ReactNode
14
15
disabled ?: boolean
15
16
className ?: {
16
17
override ?: string
@@ -20,6 +21,16 @@ interface TabProps {
20
21
}
21
22
}
22
23
24
+ interface TabPropsWithLabel extends TabProps {
25
+ label : string
26
+ children ?: never
27
+ }
28
+
29
+ interface TabPropsWithChildren extends TabProps {
30
+ label ?: never
31
+ children : React . ReactNode
32
+ }
33
+
23
34
/**
24
35
* This function returns a pre-styled Tab trigger component to be used inside a Tabs.Tablist.
25
36
* The value of this tab is required for both the internally and externally controlled state.
@@ -29,6 +40,7 @@ interface TabProps {
29
40
* @param key - The key of the tab.
30
41
* @param value - The value of the tab. This is required for the internal and external state.
31
42
* @param label - The label of the tab.
43
+ * @param children - A child component of the tab header, which can optionally replace the label
32
44
* @param disabled - The optional disabled property allows you to disable the tab.
33
45
* @param className - The optional className object allows you to override the default styling.
34
46
* @returns Tab trigger component
@@ -39,9 +51,10 @@ export function Tab({
39
51
key,
40
52
value,
41
53
label,
54
+ children,
42
55
disabled,
43
56
className,
44
- } : TabProps ) {
57
+ } : TabPropsWithLabel | TabPropsWithChildren ) {
45
58
return (
46
59
< TabsPrimitive . Trigger
47
60
id = { id }
@@ -64,7 +77,7 @@ export function Tab({
64
77
className ?. label
65
78
) }
66
79
>
67
- { label }
80
+ { label ?? children }
68
81
</ span >
69
82
</ TabsPrimitive . Trigger >
70
83
)
You can’t perform that action at this time.
0 commit comments