Skip to content

Commit 7b6bbe2

Browse files
committed
feat: improve chart component with new config options
Added new configuration options to the chart component for better customization. This includes theme and color settings, and improved CSS generation.
1 parent 1a43266 commit 7b6bbe2

File tree

5 files changed

+407
-388
lines changed

5 files changed

+407
-388
lines changed

apps/docs/app/examples/charts/_components/chart-area-axes.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77
CardFooter,
88
CardHeader,
99
CardTitle,
10-
} from '@codefast/ui';
11-
import {
1210
type ChartConfig,
1311
ChartContainer,
1412
ChartTooltip,
@@ -29,7 +27,7 @@ const chartData = [
2927
{ month: 'June', desktop: 214, mobile: 140 },
3028
];
3129

32-
const chartConfig = {
30+
const chartConfig: ChartConfig = {
3331
desktop: {
3432
label: 'Desktop',
3533
color: 'hsl(var(--chart-1))',
@@ -38,7 +36,7 @@ const chartConfig = {
3836
label: 'Mobile',
3937
color: 'hsl(var(--chart-2))',
4038
},
41-
} satisfies ChartConfig;
39+
};
4240

4341
export function ChartAreaAxes(): JSX.Element {
4442
return (
@@ -63,7 +61,7 @@ export function ChartAreaAxes(): JSX.Element {
6361
<XAxis
6462
axisLine={false}
6563
dataKey="month"
66-
tickFormatter={(value) => value.slice(0, 3)}
64+
tickFormatter={(value: string) => value.slice(0, 3)}
6765
tickLine={false}
6866
tickMargin={8}
6967
/>

packages/ui/src/components/chart.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const THEMES = {
2727

2828
type Theme = keyof typeof THEMES;
2929

30-
export type ChartConfig = {
30+
type ChartConfig = {
3131
[k in string]: {
3232
icon?: ComponentType;
3333
label?: ReactNode;
@@ -488,7 +488,8 @@ function getConfigLabelKey(
488488
*
489489
* @param theme - The theme to be used (for example, 'light', 'dark').
490490
* @param id - The unique identifier of the chart.
491-
* @param configEntries - A list of configuration entries, each containing a key and a chart configuration.
491+
* @param configEntries - A list of configuration entries, each containing a
492+
* key and a chart configuration.
492493
* @returns The generated CSS as a string.
493494
*/
494495
function generateThemeCSS(
@@ -514,10 +515,12 @@ function generateThemeCSS(
514515
}
515516

516517
/**
517-
* Generates CSS styles for a chart based on the provided configuration and themes.
518+
* Generates CSS styles for a chart based on the provided configuration and
519+
* themes.
518520
*
519521
* @param id - The unique identifier for the chart element.
520-
* @param config - Configuration object for the chart. This includes theme and color settings.
522+
* @param config - Configuration object for the chart. This includes theme and
523+
* color settings.
521524
* @returns A string containing the generated CSS rules.
522525
*/
523526
function generateCSS(id: string, config: ChartConfig): string {
@@ -553,4 +556,5 @@ export {
553556
ChartTooltipContent,
554557
type ChartTooltipContentProps,
555558
type ChartTooltipProps,
559+
type ChartConfig,
556560
};

packages/ui/src/components/data-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
MixerHorizontalIcon,
1313
} from '@radix-ui/react-icons';
1414
import { type HTMLAttributes, type JSX } from 'react';
15+
import type * as ReactTable from '@tanstack/react-table';
1516
import { Button } from '@/components/button';
1617
import {
1718
DropdownMenu,
@@ -31,7 +32,6 @@ import {
3132
} from '@/components/select';
3233
import { cn } from '@/lib/utils';
3334
import { buttonVariants } from '@/styles/button-variants';
34-
import type * as ReactTable from '@tanstack/react-table';
3535

3636
/* -----------------------------------------------------------------------------
3737
* Component: DataTableViewOptions

packages/ui/src/components/form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import {
2121
type GlobalError,
2222
useFormState,
2323
} from 'react-hook-form';
24+
import type * as LabelPrimitive from '@radix-ui/react-label';
2425
import { Label } from '@/components/label';
2526
import { cn } from '@/lib/utils';
26-
import type * as LabelPrimitive from '@radix-ui/react-label';
2727

2828
/* -----------------------------------------------------------------------------
2929
* Component: Form

0 commit comments

Comments
 (0)