chart
gmhlab/chartFreeComponent
gmhlab publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/gmhlab/monorepo/main/packages/ui/public/r/chart.jsonSource
1"use client"23import * as React from "react"4import * as RechartsPrimitive from "recharts"56import { cn } from "@/lib/utils"78// Format: { THEME_NAME: CSS_SELECTOR }9const THEMES = { light: "", dark: ".dark" } as const1011export type ChartConfig = {12 [k in string]: {13 label?: React.ReactNode14 icon?: React.ComponentType15 } & (16 | { color?: string; theme?: never }17 | { color?: never; theme: Record<keyof typeof THEMES, string> }18 )19}2021type ChartContextProps = {22 config: ChartConfig23}2425const ChartContext = React.createContext<ChartContextProps | null>(null)2627function useChart() {28 const context = React.useContext(ChartContext)2930 if (!context) {31 throw new Error("useChart must be used within a <ChartContainer />")32 }3334 return context35}3637function ChartContainer({38 id,39 className,40 children,41 config,42 ...props43}: React.ComponentProps<"div"> & {44 config: ChartConfig45 children: React.ComponentProps<46 typeof RechartsPrimitive.ResponsiveContainer47 >["children"]48}) {49 const uniqueId = React.useId()50 const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`5152 return (53 <ChartContext.Provider value={{ config }}>54 <div55 data-slot="chart"56 data-chart={chartId}57 className={cn(58 "[&_.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",59 className60 )}61 {...props}62 >63 <ChartStyle id={chartId} config={config} />64 <RechartsPrimitive.ResponsiveContainer>65 {children}66 </RechartsPrimitive.ResponsiveContainer>67 </div>68 </ChartContext.Provider>69 )70}7172const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {73 const colorConfig = Object.entries(config).filter(74 ([, config]) => config.theme || config.color75 )7677 if (!colorConfig.length) {78 return null79 }8081 return (82 <style83 dangerouslySetInnerHTML={{84// … truncated
What it pulls in
npm packages
Files it writes
More from gmhlab
All 64 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | gmhlab | Components | Free | 2 deps | |
| alertalert | gmhlab | Components | Free | 1 dep | |
| alert-dialogalert-dialog | gmhlab | Components | Free | 1 dep | |
| aspect-ratioaspect-ratio | gmhlab | Components | Free | 1 dep | |
| avataravatar | gmhlab | Components | Free | 1 dep | |
| badgebadge | gmhlab | Components | Free | 2 deps | |
| breadcrumbbreadcrumb | gmhlab | Components | Free | 2 deps | |
| buttonbutton | gmhlab | Components | Free | 2 deps |
