99from reflex_ui .components .base_ui import PACKAGE_NAME , BaseUIComponent
1010
1111LiteralOrientation = Literal ["horizontal" , "vertical" ]
12+ LiteralTabsSize = Literal ["sm" , "md" , "lg" ]
1213
1314
1415class ClassNames :
1516 """Class names for tabs components."""
1617
1718 ROOT = "flex flex-col gap-2"
18- LIST = "bg-secondary-3 inline-flex gap-1 p-1 items-center justify-start rounded-ui-md relative z-0"
19- TAB = "h-7 px-1.5 rounded-ui-sm justify-center items-center gap-1.5 inline-flex text-sm font-medium text-secondary-11 cursor-pointer z-[1] hover:text-secondary-12 transition-color text-nowrap data-[active]:text-secondary-12 data-[disabled]:cursor-not-allowed data-[disabled]:text-secondary-8"
20- INDICATOR = "absolute top-1/2 left-0 - z-1 h-7 w-(--active-tab-width) - translate-y-1/2 translate- x-(--active-tab-left) rounded-ui-sm bg-secondary-1 shadow-small transition-all duration-200 ease-in-out "
19+ LIST = "bg-secondary-1 inline-flex items-center justify-start relative z-0 shadow-button-outline dark:border dark:border-secondary-4 "
20+ TAB = "justify-center items-center inline-flex font-medium text-secondary-11 cursor-pointer z-[1] hover:text-primary-9 transition-color text-nowrap data-[active]:text-secondary-12 data-[disabled]:cursor-not-allowed data-[disabled]:text-secondary-8 text-sm "
21+ INDICATOR = "absolute left-0 inset-y-0 my-0.5 - z-1 w-(--active-tab-width) translate-x-(--active-tab-left) transition-all duration-200 ease-in-out dark: shadow-[0_1px_0_0_rgba(255,255,255,0.08)_inset] bg-white dark:bg-secondary-3 text-secondary-12 shadow-button-outline "
2122 PANEL = "flex flex-col gap-2"
23+ SIZES = {
24+ "list" : {
25+ "sm" : "p-0.5 rounded-ui-md gap-0.5" ,
26+ "md" : "p-0.5 rounded-ui-md gap-0.5" ,
27+ "lg" : "p-0.5 rounded-ui-md gap-0.5" ,
28+ },
29+ "tab" : {
30+ "sm" : "h-7 px-1.5 rounded-ui-sm gap-1" ,
31+ "md" : "h-8 px-2 rounded-ui-sm gap-1.5" ,
32+ "lg" : "h-9 px-2.5 rounded-ui-sm gap-2" ,
33+ },
34+ "indicator" : {
35+ "sm" : "rounded-ui-sm" ,
36+ "md" : "rounded-ui-sm" ,
37+ "lg" : "rounded-ui-sm" ,
38+ },
39+ }
2240
2341
2442class TabsBaseComponent (BaseUIComponent ):
@@ -75,17 +93,24 @@ class TabsList(TabsBaseComponent):
7593 # Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. Defaults to True.
7694 loop_focus : Var [bool ]
7795
96+ # The size of the tabs list. Defaults to "sm".
97+ size : Var [LiteralTabsSize ]
98+
7899 @classmethod
79100 def create (cls , * children , ** props ) -> BaseUIComponent :
80101 """Create the tabs list component.
81102
82103 Returns:
83104 The component.
84105 """
106+ size = props .pop ("size" , "sm" )
85107 props ["data-slot" ] = "tabs-list"
86- cls .set_class_name (ClassNames .LIST , props )
108+ cls .set_class_name (f" { ClassNames .LIST } { ClassNames . SIZES [ 'list' ][ size ] } " , props )
87109 return super ().create (* children , ** props )
88110
111+ def _exclude_props (self ) -> list [str ]:
112+ return [* super ()._exclude_props (), "size" ]
113+
89114
90115class TabsTab (TabsBaseComponent ):
91116 """An individual interactive tab button that toggles the corresponding panel. Renders a <button> element."""
@@ -104,17 +129,24 @@ class TabsTab(TabsBaseComponent):
104129 # The render prop
105130 render_ : Var [Component ]
106131
132+ # The size of the tab. Defaults to "sm".
133+ size : Var [LiteralTabsSize ]
134+
107135 @classmethod
108136 def create (cls , * children , ** props ) -> BaseUIComponent :
109137 """Create the tabs tab component.
110138
111139 Returns:
112140 The component.
113141 """
142+ size = props .pop ("size" , "sm" )
114143 props ["data-slot" ] = "tabs-tab"
115- cls .set_class_name (ClassNames .TAB , props )
144+ cls .set_class_name (f" { ClassNames .TAB } { ClassNames . SIZES [ 'tab' ][ size ] } " , props )
116145 return super ().create (* children , ** props )
117146
147+ def _exclude_props (self ) -> list [str ]:
148+ return [* super ()._exclude_props (), "size" ]
149+
118150
119151class TabsIndicator (TabsBaseComponent ):
120152 """A visual indicator that can be styled to match the position of the currently active tab. Renders a <span> element."""
@@ -127,17 +159,26 @@ class TabsIndicator(TabsBaseComponent):
127159 # The render prop
128160 render_ : Var [Component ]
129161
162+ # The size of the indicator. Defaults to "sm".
163+ size : Var [LiteralTabsSize ]
164+
130165 @classmethod
131166 def create (cls , * children , ** props ) -> BaseUIComponent :
132167 """Create the tabs indicator component.
133168
134169 Returns:
135170 The component.
136171 """
172+ size = props .pop ("size" , "sm" )
137173 props ["data-slot" ] = "tabs-indicator"
138- cls .set_class_name (ClassNames .INDICATOR , props )
174+ cls .set_class_name (
175+ f"{ ClassNames .INDICATOR } { ClassNames .SIZES ['indicator' ][size ]} " , props
176+ )
139177 return super ().create (* children , ** props )
140178
179+ def _exclude_props (self ) -> list [str ]:
180+ return [* super ()._exclude_props (), "size" ]
181+
141182
142183class TabsPanel (TabsBaseComponent ):
143184 """A panel displayed when the corresponding tab is active. Renders a <div> element."""
0 commit comments