From a2282f544250b2d41851f1eea9b2a2501c8e8549 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Wed, 30 Mar 2022 22:57:06 -0700 Subject: [PATCH] Extract out Tabs component --- web/components/layout/tabs.tsx | 43 ++++++++++++++++++++++++++++++++++ web/pages/analytics.tsx | 40 +------------------------------ 2 files changed, 44 insertions(+), 39 deletions(-) create mode 100644 web/components/layout/tabs.tsx diff --git a/web/components/layout/tabs.tsx b/web/components/layout/tabs.tsx new file mode 100644 index 00000000..88f27c78 --- /dev/null +++ b/web/components/layout/tabs.tsx @@ -0,0 +1,43 @@ +import clsx from 'clsx' +import { useState } from 'react' + +type Tab = { + title: string + tabIcon?: JSX.Element + content: JSX.Element +} + +export function Tabs(props: { tabs: Tab[]; defaultIndex?: number }) { + const { tabs, defaultIndex } = props + const [activeIndex, setActiveIndex] = useState(defaultIndex ?? 0) + const activeTab = tabs[activeIndex] + + return ( +
+ + +
{activeTab.content}
+
+ ) +} diff --git a/web/pages/analytics.tsx b/web/pages/analytics.tsx index f7aac21b..7344c11b 100644 --- a/web/pages/analytics.tsx +++ b/web/pages/analytics.tsx @@ -9,6 +9,7 @@ import { } from '../components/analytics/charts' import { Col } from '../components/layout/col' import { Spacer } from '../components/layout/spacer' +import { Tabs } from '../components/layout/tabs' import { Page } from '../components/page' import { Title } from '../components/title' import { fromPropz, usePropz } from '../hooks/use-propz' @@ -250,45 +251,6 @@ export function CustomAnalytics(props: { ) } -type Tab = { - title: string - content: JSX.Element -} - -function Tabs(props: { tabs: Tab[]; defaultIndex: number }) { - const { tabs, defaultIndex } = props - const [activeTab, setActiveTab] = useState(tabs[defaultIndex]) - - return ( -
- - -
{activeTab.content}
-
- ) -} - export function FirebaseAnalytics() { // Edit dashboard at https://datastudio.google.com/u/0/reporting/faeaf3a4-c8da-4275-b157-98dad017d305/page/Gg3/edit