@@ -4,6 +4,7 @@ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
44import Layout from '@theme/Layout' ;
55import CodeBlock from '@theme/CodeBlock' ;
66import Heading from '@theme/Heading' ;
7+ import React , { useEffect , useRef } from 'react' ;
78import Tabs from '@theme/Tabs' ;
89import TabItem from '@theme/TabItem' ;
910import { kotlinVersion , mokkeryVersion } from "../versions" ;
@@ -87,11 +88,11 @@ function HomepageHeader() {
8788 < div className = "main-page-description" >
8889 < div style = { { display : "flex" , flexDirection : "row" , alignItems : "center" , gap : "16px" } } >
8990 < Logo width = "100" height = "100" className = "logoTheme" />
90- < Heading as = "h1" className = "hero__title" style = { { letterSpacing : "-2px" , marginTop : "10px" } } >
91+ < Heading as = "h1" className = "hero__title" style = { { letterSpacing : "-2px" , marginTop : "10px" } } >
9192 { siteConfig . title }
9293 </ Heading >
9394 </ div >
94- < p className = "hero__subtitle" style = { { lineHeight : "1.2" , fontSize : '2rem' } } > { siteConfig . tagline } </ p >
95+ < p className = "hero__subtitle" style = { { lineHeight : "1.2" , fontSize : '2rem' } } > { siteConfig . tagline } </ p >
9596 < div style = { {
9697 display : "flex" ,
9798 flexDirection : "row" ,
@@ -125,15 +126,15 @@ function WhyMokkeryTabs() {
125126 < div style = { { height : "2rem" } } />
126127 < h2 style = { { fontWeight : "400" } } > Why Mokkery?</ h2 >
127128 < div style = { { minHeight : "500px" } } >
128- < Tabs >
129- < TabItem value = "simple" label = "🌿 Simple" data-umami-event = "home-tabs" data-umami-event-tab = "simple" >
129+ < TrackedTabs tabEventPrefix = "home-tabs" >
130+ < TabItem value = "simple" label = "🌿 Simple" >
130131 < CodeBlock
131132 language = "kotlin"
132133 showLineNumbers >
133134 { simpleTabBlock }
134135 </ CodeBlock >
135136 </ TabItem >
136- < TabItem value = "setup" label = "⌚ Easy setup" data-umami-event = "home-tabs" data-umami-event-tab = "setup" >
137+ < TabItem value = "setup" label = "⌚ Easy setup" >
137138 < h3 style = { { fontWeight : "400" } } > Just apply Gradle plugin and...</ h3 >
138139 < Tabs
139140 groupId = "kotlinVersion"
@@ -147,22 +148,23 @@ function WhyMokkeryTabs() {
147148 language = "kotlin"
148149 showLineNumbers >
149150 { setupTabBlockK1 }
150- </ CodeBlock >
151+ </ CodeBlock >
151152 </ TabItem >
152153 < TabItem value = "k2" >
153154 < CodeBlock
154155 language = "kotlin"
155156 showLineNumbers >
156157 { setupTabBlockK2 }
157- </ CodeBlock >
158+ </ CodeBlock >
158159 </ TabItem >
159- </ Tabs >
160+ </ Tabs >
160161 < h3 style = { { fontWeight : "400" } } > ...that's it!</ h3 >
161162 < h3 style = { { fontWeight : "400" } } >
162- Please refer to the < Link to = "../docs/Setup" > setup section</ Link > , as additional configuration may be required in some cases!
163+ Please refer to the < Link to = "../docs/Setup" > setup section</ Link > , as additional
164+ configuration may be required in some cases!
163165 </ h3 >
164166 </ TabItem >
165- < TabItem value = "multiplatform" label = "🌍 Multiplatform" data-umami-event = "home-tabs" data-umami-event-tab = "multiplatform" >
167+ < TabItem value = "multiplatform" label = "🌍 Multiplatform" >
166168 < div style = { { fontSize : "1.4rem" , fontWeight : "300" , width : "100%" } } >
167169 < div style = { { height : "1rem" } } />
168170 < ul >
@@ -174,7 +176,7 @@ function WhyMokkeryTabs() {
174176 </ ul >
175177 </ div >
176178 </ TabItem >
177- < TabItem value = "customizable" label = "🖌️ Customizable" data-umami-event = "home-tabs" data-umami-event-tab = "customizable" >
179+ < TabItem value = "customizable" label = "🖌️ Customizable" >
178180 < h3 style = { { fontWeight : "400" } } > Change Mokkery strictness globally...</ h3 >
179181 < CodeBlock
180182 title = "build.gradle.kts"
@@ -190,7 +192,7 @@ function WhyMokkeryTabs() {
190192 { customizableLocallyTabBlock }
191193 </ CodeBlock >
192194 </ TabItem >
193- < TabItem value = "extensible" label = "🧩 Extensible" data-umami-event = "home-tabs" data-umami-event-tab = "extensible" >
195+ < TabItem value = "extensible" label = "🧩 Extensible" >
194196 < h3 style = { { fontWeight : "400" } } > Custom matchers!</ h3 >
195197 < CodeBlock
196198 language = "kotlin"
@@ -204,8 +206,49 @@ function WhyMokkeryTabs() {
204206 { extensilbeAnswersTabBlock }
205207 </ CodeBlock >
206208 </ TabItem >
207- </ Tabs >
209+ </ TrackedTabs >
208210 </ div >
209211 </ div >
210212 )
211213}
214+
215+ const TrackedTabs = ( { groupId, children, tabEventPrefix = 'tab-click' , ...props } ) => {
216+ const tabsRef = useRef ( null ) ;
217+ const labelToValueMap = React . useMemo ( ( ) => {
218+ const map = { } ;
219+ React . Children . forEach ( children , ( child ) => {
220+ if ( React . isValidElement ( child ) ) {
221+ const label = child . props . label ?. trim ( ) ;
222+ const value = child . props . value ?. trim ( ) ;
223+ if ( label && value ) {
224+ map [ label ] = value ;
225+ }
226+ }
227+ } ) ;
228+ return map ;
229+ } , [ children ]
230+ ) ;
231+ useEffect ( ( ) => {
232+ const container = tabsRef . current ;
233+ if ( ! container ) return ;
234+ const handleClick = ( e ) => {
235+ if ( e . target . classList . contains ( 'tabs__item' ) ) {
236+ if ( window . umami !== undefined ) {
237+ let value = labelToValueMap [ e . target . textContent ] ;
238+ window . umami . track ( `${ tabEventPrefix } -${ value } ` ) ;
239+ }
240+ }
241+ } ;
242+
243+ container . addEventListener ( 'click' , handleClick ) ;
244+ return ( ) => container . removeEventListener ( 'click' , handleClick ) ;
245+ } , [ tabEventPrefix ] ) ;
246+
247+ return (
248+ < div ref = { tabsRef } >
249+ < Tabs groupId = { groupId } { ...props } >
250+ { children }
251+ </ Tabs >
252+ </ div >
253+ ) ;
254+ } ;
0 commit comments