Unify workspace dropdowns; Update layouts (#458)

Unified Account and Workspace drop-downs; Layout updates, now header lives within the PageBody component; Sidebars now use floating variant
This commit is contained in:
Giancarlo Buomprisco
2026-03-11 14:45:42 +08:00
committed by GitHub
parent ca585e09be
commit 4bc8448a1d
530 changed files with 14398 additions and 11198 deletions

View File

@@ -3,27 +3,64 @@
import * as React from 'react';
import * as RechartsPrimitive from 'recharts';
import type { LegendPayload } from 'recharts/types/component/DefaultLegendContent';
import {
NameType,
Payload,
ValueType,
} from 'recharts/types/component/DefaultTooltipContent';
import type { Props as LegendProps } from 'recharts/types/component/Legend';
import { TooltipContentProps } from 'recharts/types/component/Tooltip';
import { cn } from '../lib/utils';
import { cn } from '@kit/ui/utils';
// Format: { THEME_NAME: CSS_SELECTOR }
const THEMES = { light: '', dark: '.dark' } as const;
export type ChartConfig = Record<
string,
{
export type ChartConfig = {
[k in string]: {
label?: React.ReactNode;
icon?: React.ComponentType;
} & (
| { color?: string; theme?: never }
| { color?: never; theme: Record<keyof typeof THEMES, string> }
)
>;
);
};
type ChartContextProps = {
config: ChartConfig;
};
export type CustomTooltipProps = TooltipContentProps<ValueType, NameType> & {
className?: string;
hideLabel?: boolean;
hideIndicator?: boolean;
indicator?: 'line' | 'dot' | 'dashed';
nameKey?: string;
labelKey?: string;
labelFormatter?: (
label: TooltipContentProps<number, string>['label'],
payload: TooltipContentProps<number, string>['payload'],
) => React.ReactNode;
formatter?: (
value: number | string,
name: string,
item: Payload<number | string, string>,
index: number,
payload: ReadonlyArray<Payload<number | string, string>>,
) => React.ReactNode;
labelClassName?: string;
color?: string;
};
export type ChartLegendContentProps = {
className?: string;
hideIcon?: boolean;
verticalAlign?: LegendProps['verticalAlign'];
payload?: LegendPayload[];
nameKey?: string;
};
const ChartContext = React.createContext<ChartContextProps | null>(null);
function useChart() {
@@ -36,20 +73,25 @@ function useChart() {
return context;
}
const ChartContainer: React.FC<
React.ComponentProps<'div'> & {
config: ChartConfig;
children: React.ComponentProps<
typeof RechartsPrimitive.ResponsiveContainer
>['children'];
}
> = ({ id, className, children, config, ...props }) => {
function ChartContainer({
id,
className,
children,
config,
...props
}: React.ComponentProps<'div'> & {
config: ChartConfig;
children: React.ComponentProps<
typeof RechartsPrimitive.ResponsiveContainer
>['children'];
}) {
const uniqueId = React.useId();
const chartId = `chart-${id ?? uniqueId.replace(/:/g, '')}`;
const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`;
return (
<ChartContext.Provider value={{ config }}>
<div
data-slot="chart"
data-chart={chartId}
className={cn(
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
@@ -64,12 +106,11 @@ const ChartContainer: React.FC<
</div>
</ChartContext.Provider>
);
};
ChartContainer.displayName = 'Chart';
}
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter(
([_, config]) => config.theme ?? config.color,
([, config]) => config.theme || config.color,
);
if (!colorConfig.length) {
@@ -82,17 +123,17 @@ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
__html: Object.entries(THEMES)
.map(
([theme, prefix]) => `
${prefix} [data-chart=${id}] {
${colorConfig
.map(([key, itemConfig]) => {
const color =
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ??
itemConfig.color;
return color ? ` --color-${key}: ${color};` : null;
})
.join('\n')}
}
`,
${prefix} [data-chart=${id}] {
${colorConfig
.map(([key, itemConfig]) => {
const color =
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
itemConfig.color;
return color ? ` --color-${key}: ${color};` : null;
})
.join('\n')}
}
`,
)
.join('\n'),
}}
@@ -102,46 +143,39 @@ ${colorConfig
const ChartTooltip = RechartsPrimitive.Tooltip;
const ChartTooltipContent: React.FC<
React.ComponentPropsWithRef<typeof RechartsPrimitive.Tooltip> &
React.ComponentPropsWithRef<'div'> & {
hideLabel?: boolean;
hideIndicator?: boolean;
indicator?: 'line' | 'dot' | 'dashed';
nameKey?: string;
labelKey?: string;
}
> = ({
ref,
function ChartTooltipContent({
active,
payload,
label,
className,
indicator = 'dot',
hideLabel = false,
hideIndicator = false,
label,
labelFormatter,
labelClassName,
formatter,
labelClassName,
color,
nameKey,
labelKey,
}) => {
}: CustomTooltipProps) {
const { config } = useChart();
const tooltipLabel = React.useMemo(() => {
if (hideLabel ?? !payload?.length) {
if (hideLabel || !payload?.length) {
return null;
}
const [item] = payload;
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`;
const key = `${labelKey || item?.dataKey || item?.name || 'value'}`;
const itemConfig = getPayloadConfigFromPayload(config, item, key);
const value = (() => {
const v =
!labelKey && typeof label === 'string'
? (config[label as keyof typeof config]?.label ?? label)
: itemConfig?.label;
const value =
!labelKey && typeof label === 'string'
? (config[label]?.label ?? label)
: itemConfig?.label;
return typeof v === 'string' || typeof v === 'number' ? v : undefined;
})();
if (labelFormatter) {
return (
@@ -174,7 +208,6 @@ const ChartTooltipContent: React.FC<
return (
<div
ref={ref}
className={cn(
'border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl',
className,
@@ -183,9 +216,9 @@ const ChartTooltipContent: React.FC<
{!nestLabel ? tooltipLabel : null}
<div className="grid gap-1.5">
{payload.map((item, index) => {
const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`;
const key = `${nameKey || item.name || item.dataKey || 'value'}`;
const itemConfig = getPayloadConfigFromPayload(config, item, key);
const indicatorColor = color ?? item.payload.fill ?? item.color;
const indicatorColor = color || item.payload.fill || item.color;
return (
<div
@@ -232,7 +265,7 @@ const ChartTooltipContent: React.FC<
<div className="grid gap-1.5">
{nestLabel ? tooltipLabel : null}
<span className="text-muted-foreground">
{itemConfig?.label ?? item.name}
{itemConfig?.label || item.name}
</span>
</div>
{item.value && (
@@ -249,26 +282,17 @@ const ChartTooltipContent: React.FC<
</div>
</div>
);
};
ChartTooltipContent.displayName = 'ChartTooltip';
}
const ChartLegend = RechartsPrimitive.Legend;
const ChartLegendContent: React.FC<
React.ComponentPropsWithRef<'div'> &
Pick<RechartsPrimitive.LegendProps, 'payload' | 'verticalAlign'> & {
hideIcon?: boolean;
nameKey?: string;
}
> = ({
function ChartLegendContent({
className,
hideIcon = false,
payload,
verticalAlign = 'bottom',
nameKey,
ref,
}) => {
}: ChartLegendContentProps) {
const { config } = useChart();
if (!payload?.length) {
@@ -277,7 +301,6 @@ const ChartLegendContent: React.FC<
return (
<div
ref={ref}
className={cn(
'flex items-center justify-center gap-4',
verticalAlign === 'top' ? 'pb-3' : 'pt-3',
@@ -285,7 +308,7 @@ const ChartLegendContent: React.FC<
)}
>
{payload.map((item) => {
const key = `${nameKey ?? item.dataKey ?? 'value'}`;
const key = `${nameKey || item.dataKey || 'value'}`;
const itemConfig = getPayloadConfigFromPayload(config, item, key);
return (
@@ -311,8 +334,7 @@ const ChartLegendContent: React.FC<
})}
</div>
);
};
ChartLegendContent.displayName = 'ChartLegend';
}
// Helper to extract item config from a payload.
function getPayloadConfigFromPayload(
@@ -320,7 +342,7 @@ function getPayloadConfigFromPayload(
payload: unknown,
key: string,
) {
if (typeof payload !== 'object' || !payload) {
if (typeof payload !== 'object' || payload === null) {
return undefined;
}
@@ -348,7 +370,9 @@ function getPayloadConfigFromPayload(
] as string;
}
return configLabelKey in config ? config[configLabelKey] : config[key];
return configLabelKey in config
? config[configLabelKey]
: config[key as keyof typeof config];
}
export {