* refactor: enhance analytics page tab functionality and UI - Introduced state management for selected tabs using useState and useEffect hooks. - Updated tab handling to improve user experience with onValueChange for Tabs component. - Refactored AnalyticsFilterActions to remove unused duration selection. - Added Tooltip to project name in ActiveProjectItem for better visibility. - Minor styling adjustments in Tabs component for improved layout consistency. * refactor: improve tab layout in analytics page by adding w-fit * fix: update styling for ActiveProjectItem component * refactor: simplify analytics page and introduce useAnalyticsTabs hook - Removed unused imports and optimized the analytics page component. - Replaced getAnalyticsTabs with a new custom hook useAnalyticsTabs for better modularity. - Added useAnalyticsTabs hook to manage analytics tab logic. - Created new files for useAnalyticsTabs and analytics tabs in the 'ce' and 'ee' directories. * fix: ensure consistent export in use-analytics-tabs file * style: format code for better readability in AnalyticsPage component * fix: add missing newline at end of file in use-analytics-tabs * chore: remove unused analytics tab components --------- Co-authored-by: sriramveeraghanta <veeraghanta.sriram@gmail.com>
114 lines
3.9 KiB
TypeScript
114 lines
3.9 KiB
TypeScript
import * as React from "react";
|
|
import { Tabs as TabsPrimitive } from "@base-ui-components/react/tabs";
|
|
import { cn } from "../utils/classname";
|
|
|
|
type TabsCompound = React.ForwardRefExoticComponent<
|
|
React.ComponentProps<typeof TabsPrimitive.Root> & React.RefAttributes<React.ElementRef<typeof TabsPrimitive.Root>>
|
|
> & {
|
|
List: React.ForwardRefExoticComponent<
|
|
React.ComponentProps<typeof TabsPrimitive.List> & React.RefAttributes<React.ElementRef<typeof TabsPrimitive.List>>
|
|
>;
|
|
Trigger: React.ForwardRefExoticComponent<
|
|
React.ComponentProps<typeof TabsPrimitive.Tab> & { size?: "sm" | "md" | "lg" } & React.RefAttributes<
|
|
React.ElementRef<typeof TabsPrimitive.Tab>
|
|
>
|
|
>;
|
|
Content: React.ForwardRefExoticComponent<
|
|
React.ComponentProps<typeof TabsPrimitive.Panel> & React.RefAttributes<React.ElementRef<typeof TabsPrimitive.Panel>>
|
|
>;
|
|
Indicator: React.ForwardRefExoticComponent<React.ComponentProps<"div"> & React.RefAttributes<HTMLDivElement>>;
|
|
};
|
|
|
|
const TabsRoot = React.forwardRef(function TabsRoot(
|
|
{ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Root>,
|
|
ref: React.ForwardedRef<React.ElementRef<typeof TabsPrimitive.Root>>
|
|
) {
|
|
return (
|
|
<TabsPrimitive.Root
|
|
data-slot="tabs"
|
|
className={cn("flex flex-col w-full h-full", className)}
|
|
{...props}
|
|
ref={ref}
|
|
/>
|
|
);
|
|
});
|
|
|
|
const TabsList = React.forwardRef(function TabsList(
|
|
{ className, ...props }: React.ComponentProps<typeof TabsPrimitive.List>,
|
|
ref: React.ForwardedRef<React.ElementRef<typeof TabsPrimitive.List>>
|
|
) {
|
|
return (
|
|
<TabsPrimitive.List
|
|
data-slot="tabs-list"
|
|
className={cn(
|
|
"flex w-full items-center justify-between gap-1.5 rounded-md text-sm p-0.5 bg-custom-background-80/60 relative overflow-auto",
|
|
className
|
|
)}
|
|
{...props}
|
|
ref={ref}
|
|
/>
|
|
);
|
|
});
|
|
|
|
const TabsTrigger = React.forwardRef(function TabsTrigger(
|
|
{ className, size = "md", ...props }: React.ComponentProps<typeof TabsPrimitive.Tab> & { size?: "sm" | "md" | "lg" },
|
|
ref: React.ForwardedRef<React.ElementRef<typeof TabsPrimitive.Tab>>
|
|
) {
|
|
return (
|
|
<TabsPrimitive.Tab
|
|
data-slot="tabs-trigger"
|
|
className={cn(
|
|
"flex items-center justify-center p-1 min-w-fit w-full font-medium text-custom-text-100 outline-none focus:outline-none cursor-pointer transition-all duration-200 ease-in-out rounded",
|
|
"data-[selected]:bg-custom-background-100 data-[selected]:text-custom-text-100 data-[selected]:shadow-sm",
|
|
"text-custom-text-400 hover:text-custom-text-300 hover:bg-custom-background-80/60",
|
|
"disabled:text-custom-text-400 disabled:cursor-not-allowed",
|
|
{
|
|
"text-xs": size === "sm",
|
|
"text-sm": size === "md",
|
|
"text-base": size === "lg",
|
|
},
|
|
className
|
|
)}
|
|
{...props}
|
|
ref={ref}
|
|
/>
|
|
);
|
|
});
|
|
|
|
const TabsContent = React.forwardRef(function TabsContent(
|
|
{ className, ...props }: React.ComponentProps<typeof TabsPrimitive.Panel>,
|
|
ref: React.ForwardedRef<React.ElementRef<typeof TabsPrimitive.Panel>>
|
|
) {
|
|
return (
|
|
<TabsPrimitive.Panel
|
|
data-slot="tabs-content"
|
|
className={cn("relative outline-none", className)}
|
|
{...props}
|
|
ref={ref}
|
|
/>
|
|
);
|
|
});
|
|
const TabsIndicator = React.forwardRef(function TabsIndicator(
|
|
{ className, ...props }: React.ComponentProps<"div">,
|
|
ref: React.ForwardedRef<HTMLDivElement>
|
|
) {
|
|
return (
|
|
<div
|
|
className={cn(
|
|
"absolute left-0 top-[50%] z-[-1] h-6 w-[var(--active-tab-width)] translate-x-[var(--active-tab-left)] -translate-y-[50%] rounded-sm bg-custom-background-100 shadow-sm transition-[width,transform] duration-200 ease-in-out",
|
|
className
|
|
)}
|
|
{...props}
|
|
ref={ref}
|
|
/>
|
|
);
|
|
});
|
|
|
|
export const Tabs = Object.assign(TabsRoot, {
|
|
List: TabsList,
|
|
Trigger: TabsTrigger,
|
|
Content: TabsContent,
|
|
Indicator: TabsIndicator,
|
|
}) satisfies TabsCompound;
|
|
|
|
export { TabsList, TabsTrigger, TabsContent, TabsIndicator };
|