@@ -33,135 +33,136 @@ interface TabsNavbarItemProps<T> {
3333
3434export const TabsNavbarItem : FC < TabsNavbarItemProps < any > & RefAttributes < HTMLElement > >
3535 = forwardRef < HTMLElement , TabsNavbarItemProps < any > > (
36- < T , > ( props : TabsNavbarItemProps < T > , ref : ForwardedRef < HTMLElement >
37- ) => {
38- const [ openDropdown , setOpenDropdown ] = useState ( false )
39- const { width : screenWidth } : WindowSize = useWindowSize ( )
40- const isMobile = useMemo ( ( ) => screenWidth < 745 , [ screenWidth ] )
36+ < T , > ( props : TabsNavbarItemProps < T > , ref : ForwardedRef < HTMLElement > ,
37+ ) => {
38+ const [ openDropdown , setOpenDropdown ] = useState ( false )
39+ const { width : screenWidth } : WindowSize = useWindowSize ( )
40+ const isMobile = useMemo ( ( ) => screenWidth < 745 , [ screenWidth ] )
4141
42- const tabContent : ReactNode = (
43- < >
44- < span className = { classNames ( styles [ 'tab-label' ] , 'tab-label' ) } >
45- { props . tab . title }
46- </ span >
47- { props . tab . badges ?. map ( badge => (
48- < span
49- className = { classNames ( styles [ 'tab-badge' ] , badge . type ) }
50- key = { badge . type }
51- >
52- { badge . count }
42+ const tabContent : ReactNode = (
43+ < >
44+ < span className = { classNames ( styles [ 'tab-label' ] , 'tab-label' ) } >
45+ { props . tab . title }
5346 </ span >
54- ) ) }
55- </ >
56- )
47+ { props . tab . badges ?. map ( badge => (
48+ < span
49+ className = { classNames ( styles [ 'tab-badge' ] , badge . type ) }
50+ key = { badge . type }
51+ >
52+ { badge . count }
53+ </ span >
54+ ) ) }
55+ </ >
56+ )
57+
58+ if ( props . tab . url ) {
59+ return (
60+ < a
61+ ref = { ref as ForwardedRef < HTMLAnchorElement > }
62+ className = { classNames (
63+ styles [ 'tab-item' ] ,
64+ {
65+ [ styles . isNotExtraMenu ] : ! props . isExtraMenu ,
66+ } ,
67+ props . className ,
68+ ) }
69+ key = { props . tab . id as string }
70+ href = { props . tab . url }
71+ rel = 'noopener noreferrer'
72+ target = '_blank'
73+ >
74+ { tabContent }
75+ </ a >
76+ )
77+ }
78+
79+ if ( props . tab . children ) {
80+ return props . menuIsVisible || ! props . isExtraMenu || ! isMobile ? (
81+ < DropdownMenu
82+ open = { openDropdown }
83+ setOpen = { setOpenDropdown }
84+ key = { props . tab . id as string }
85+ placement = 'bottom-end'
86+ shouldIgnoreWhenClickMenu
87+ classNames = { {
88+ trigger : styles . blockMenuTrigger ,
89+ } }
90+ triggerUI = { (
91+ < div
92+ ref = { ref as ForwardedRef < HTMLDivElement > }
93+ className = { classNames (
94+ styles [ 'tab-item' ] ,
95+ {
96+ [ styles . isNotExtraMenu ] : ! props . isExtraMenu ,
97+ } ,
98+ props . activeTabId === props . tab . id && 'active' ,
99+ props . className ,
100+ ) }
101+ key = { props . tab . id as string }
102+ onClick = { function onClick (
103+ event : MouseEvent < HTMLDivElement > ,
104+ ) {
105+ if ( ! isMobile || props . isExtraMenu ) {
106+ event . stopPropagation ( )
107+ event . preventDefault ( )
108+ setOpenDropdown ( preValue => ! preValue )
109+ }
110+ } }
111+ >
112+ { tabContent }
113+ { ( props . isExtraMenu || ! isMobile ) && (
114+ < IconOutline . ChevronDownIcon
115+ className = { styles . dropdownIcon }
116+ />
117+ ) }
118+ </ div >
119+ ) }
120+ >
121+ < ul >
122+ { props . tab . children . map ( item => (
123+ < li key = { item . title } >
124+ < div
125+ role = 'button'
126+ tabIndex = { 0 }
127+ onClick = { function onClick ( ) {
128+ setOpenDropdown ( false )
129+ if ( item . id ) {
130+ props . handleActivateChildTab (
131+ props . tab . id ,
132+ item . id ,
133+ ) ( )
134+ }
135+ } }
136+ >
137+ { item . title }
138+ </ div >
139+ </ li >
140+ ) ) }
141+ </ ul >
142+ </ DropdownMenu >
143+ ) : (
144+ < > </ >
145+ )
146+ }
57147
58- if ( props . tab . url ) {
59148 return (
60- < a
61- ref = { ref as ForwardedRef < HTMLAnchorElement > }
149+ < div
150+ ref = { ref as ForwardedRef < HTMLDivElement > }
62151 className = { classNames (
63152 styles [ 'tab-item' ] ,
64153 {
65154 [ styles . isNotExtraMenu ] : ! props . isExtraMenu ,
66155 } ,
156+ props . activeTabId === props . tab . id && 'active' ,
67157 props . className ,
68158 ) }
69159 key = { props . tab . id as string }
70- href = { props . tab . url }
71- rel = 'noopener noreferrer'
72- target = '_blank'
160+ onClick = { props . handleActivateTab ( props . tab . id ) }
73161 >
74162 { tabContent }
75- </ a >
163+ </ div >
76164 )
77- }
78-
79- if ( props . tab . children ) {
80- return props . menuIsVisible || ! props . isExtraMenu || ! isMobile ? (
81- < DropdownMenu
82- open = { openDropdown }
83- setOpen = { setOpenDropdown }
84- key = { props . tab . id as string }
85- placement = 'bottom-end'
86- shouldIgnoreWhenClickMenu
87- classNames = { {
88- trigger : styles . blockMenuTrigger ,
89- } }
90- triggerUI = { (
91- < div
92- ref = { ref as ForwardedRef < HTMLDivElement > }
93- className = { classNames (
94- styles [ 'tab-item' ] ,
95- {
96- [ styles . isNotExtraMenu ] : ! props . isExtraMenu ,
97- } ,
98- props . activeTabId === props . tab . id && 'active' ,
99- props . className ,
100- ) }
101- key = { props . tab . id as string }
102- onClick = { function onClick (
103- event : MouseEvent < HTMLDivElement > ,
104- ) {
105- if ( ! isMobile || props . isExtraMenu ) {
106- event . stopPropagation ( )
107- event . preventDefault ( )
108- setOpenDropdown ( preValue => ! preValue )
109- }
110- } }
111- >
112- { tabContent }
113- { ( props . isExtraMenu || ! isMobile ) && (
114- < IconOutline . ChevronDownIcon
115- className = { styles . dropdownIcon }
116- />
117- ) }
118- </ div >
119- ) }
120- >
121- < ul >
122- { props . tab . children . map ( item => (
123- < li key = { item . title } >
124- < div
125- role = 'button'
126- tabIndex = { 0 }
127- onClick = { function onClick ( ) {
128- setOpenDropdown ( false )
129- if ( item . id ) {
130- props . handleActivateChildTab (
131- props . tab . id ,
132- item . id ,
133- ) ( )
134- }
135- } }
136- >
137- { item . title }
138- </ div >
139- </ li >
140- ) ) }
141- </ ul >
142- </ DropdownMenu >
143- ) : (
144- < > </ >
145- )
146- }
147-
148- return (
149- < div
150- ref = { ref as ForwardedRef < HTMLDivElement > }
151- className = { classNames (
152- styles [ 'tab-item' ] ,
153- {
154- [ styles . isNotExtraMenu ] : ! props . isExtraMenu ,
155- } ,
156- props . activeTabId === props . tab . id && 'active' ,
157- props . className ,
158- ) }
159- key = { props . tab . id as string }
160- onClick = { props . handleActivateTab ( props . tab . id ) }
161- >
162- { tabContent }
163- </ div >
164- )
165- } )
165+ } ,
166+ )
166167
167168export default TabsNavbarItem
0 commit comments