Chart
tailark-base-ui/chartFreeComponent
Tailark Base UI Chart component
See it running
Open the demo on Tailark Base UI
tailark.com/blocks/chartInstall it
npx shadcn@latest add https://tailark.com/r/chart.jsonSource
1'use client'23import * as React from 'react'4import type { ComponentType, ReactNode, CSSProperties } from 'react'5import * as RechartsPrimitive from 'recharts'67import { cn } from '@/lib/utils'89// Format: { THEME_NAME: CSS_SELECTOR }10const THEMES = { light: '', dark: '.dark' } as const1112export type ChartConfig = {13 [k in string]: {14 label?: ReactNode15 icon?: ComponentType16 } & ({ color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> })17}1819type ChartContextProps = {20 config: ChartConfig21}2223const ChartContext = React.createContext<ChartContextProps | null>(null)2425function useChart() {26 const context = React.useContext(ChartContext)2728 if (!context) {29 throw new Error('useChart must be used within a <ChartContainer />')30 }3132 return context33}3435function ChartContainer({36 id,37 className,38 children,39 config,40 ...props41}: React.ComponentProps<'div'> & {42 config: ChartConfig43 children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>['children']44}) {45 const uniqueId = React.useId()46 const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`4748 return (49 <ChartContext.Provider value={{ config }}>50 <div51 data-slot="chart"52 data-chart={chartId}53 className={cn(54 "[&_.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 [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-surface]:outline-hidden flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-sector[stroke='#fff']]:stroke-transparent",55 className56 )}57 {...props}>58 <ChartStyle59 id={chartId}60 config={config}61 />62 <RechartsPrimitive.ResponsiveContainer>{children}</RechartsPrimitive.ResponsiveContainer>63 </div>64 </ChartContext.Provider>65 )66}6768const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {69// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from Tailark Base UI
All 468 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | Tailark Base UI | Components | Free | 1 dep | |
| Actionnable Illustrationactionnable | Tailark Base UI | Components | Paid | no deps | |
| Comment Illustrationadd-comment | Tailark Base UI | Components | Paid | no deps | |
| Agent Illustrationagent-feedback | Tailark Base UI | Components | Paid | no deps | |
| Agent Illustrationagent-task-planning | Tailark Base UI | Components | Paid | no deps | |
| Agent Illustrationagent-tasks | Tailark Base UI | Components | Paid | no deps | |
| Agent Illustrationagent-workflow | Tailark Base UI | Components | Paid | no deps | |
| Ai Illustrationai-1 | Tailark Base UI | Components | Paid | no deps |
