Update AGENTS.md. Start fixing old weird errors

This commit is contained in:
2026-03-26 12:05:12 -05:00
parent 0bc04dbf6b
commit d16f4287ce
96 changed files with 18195 additions and 9182 deletions

View File

@@ -8,23 +8,24 @@ import { cn } from '@gib/ui';
// Format: { THEME_NAME: CSS_SELECTOR }
const THEMES = { light: '', dark: '.dark' } as const;
export type ChartConfig = {
[k in string]: {
export type ChartConfig = Record<
string,
{
label?: React.ReactNode;
icon?: React.ComponentType;
} & (
| { color?: string; theme?: never }
| { color?: never; theme: Record<keyof typeof THEMES, string> }
);
};
)
>;
type ChartContextProps = {
interface ChartContextProps {
config: ChartConfig;
};
}
const ChartContext = React.createContext<ChartContextProps | null>(null);
function useChart() {
const useChart = () => {
const context = React.useContext(ChartContext);
if (!context) {
@@ -32,9 +33,9 @@ function useChart() {
}
return context;
}
};
function ChartContainer({
const ChartContainer = ({
id,
className,
children,
@@ -45,7 +46,7 @@ function ChartContainer({
children: React.ComponentProps<
typeof RechartsPrimitive.ResponsiveContainer
>['children'];
}) {
}) => {
const uniqueId = React.useId();
const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`;
@@ -67,7 +68,7 @@ function ChartContainer({
</div>
</ChartContext.Provider>
);
}
};
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
const colorConfig = Object.entries(config).filter(
@@ -104,7 +105,7 @@ ${colorConfig
const ChartTooltip = RechartsPrimitive.Tooltip;
function ChartTooltipContent({
const ChartTooltipContent = ({
active,
payload,
className,
@@ -125,7 +126,7 @@ function ChartTooltipContent({
indicator?: 'line' | 'dot' | 'dashed';
nameKey?: string;
labelKey?: string;
}) {
}) => {
const { config } = useChart();
const tooltipLabel = React.useMemo(() => {
@@ -138,7 +139,7 @@ function ChartTooltipContent({
const itemConfig = getPayloadConfigFromPayload(config, item, key);
const value =
!labelKey && typeof label === 'string'
? config[label as keyof typeof config]?.label || label
? config[label]?.label || label
: itemConfig?.label;
if (labelFormatter) {
@@ -248,11 +249,11 @@ function ChartTooltipContent({
</div>
</div>
);
}
};
const ChartLegend = RechartsPrimitive.Legend;
function ChartLegendContent({
const ChartLegendContent = ({
className,
hideIcon = false,
payload,
@@ -262,7 +263,7 @@ function ChartLegendContent({
Pick<RechartsPrimitive.LegendProps, 'payload' | 'verticalAlign'> & {
hideIcon?: boolean;
nameKey?: string;
}) {
}) => {
const { config } = useChart();
if (!payload?.length) {
@@ -306,13 +307,13 @@ function ChartLegendContent({
})}
</div>
);
}
};
function getPayloadConfigFromPayload(
const getPayloadConfigFromPayload = (
config: ChartConfig,
payload: unknown,
key: string,
) {
) => {
if (typeof payload !== 'object' || payload === null) {
return undefined;
}
@@ -341,10 +342,8 @@ function getPayloadConfigFromPayload(
] as string;
}
return configLabelKey in config
? config[configLabelKey]
: config[key as keyof typeof config];
}
return configLabelKey in config ? config[configLabelKey] : config[key];
};
export {
ChartContainer,