The Open Standard for Generative UI
Charts Forder structure and code re factor
i-subhamb903dd2c3fb2
diff --git a/frontend-sdk/packages/react-ui/package.json b/frontend-sdk/packages/react-ui/package.jsonindex eac16428b..3866aadda 100644--- a/frontend-sdk/packages/react-ui/package.json+++ b/frontend-sdk/packages/react-ui/package.json@@ -49,6 +49,7 @@"@radix-ui/react-radio-group": "^1.2.2","@radix-ui/react-select": "^2.1.5","@radix-ui/react-slider": "^1.2.2",+ "@radix-ui/react-switch": "^1.1.2","@radix-ui/react-tabs": "^1.1.2","@storybook/addon-styling-webpack": "^1.0.1","clsx": "^2.1.1",diff --git a/frontend-sdk/packages/react-ui/src/components/Button/button.scss b/frontend-sdk/packages/react-ui/src/components/Button/button.scssindex 9c3c06cf2..cd0a4a86d 100644--- a/frontend-sdk/packages/react-ui/src/components/Button/button.scss+++ b/frontend-sdk/packages/react-ui/src/components/Button/button.scss@@ -12,6 +12,10 @@display: flex;gap: map.get(cssUtils.$spacing, "2xs");align-items: center;+ & svg {+ height: 1rem;+ width: 1rem;+ }// Primary variant&-primary {diff --git a/frontend-sdk/packages/react-ui/src/components/Charts/Charts.tsx b/frontend-sdk/packages/react-ui/src/components/Charts/Charts.tsxindex e8d71b4ad..781e5eddf 100644--- a/frontend-sdk/packages/react-ui/src/components/Charts/Charts.tsx+++ b/frontend-sdk/packages/react-ui/src/components/Charts/Charts.tsx@@ -1,15 +1,8 @@-import clsx from 'clsx'-import { uniqueId } from 'lodash-es'-import {- ComponentProps,- createContext,- forwardRef,- useContext,- useId,- useMemo,-} from 'react'-import * as RechartsPrimitive from 'recharts'-import './Charts.scss'+import clsx from "clsx";+import { uniqueId } from "lodash-es";+import { ComponentProps, createContext, forwardRef, useContext, useId, useMemo } from "react";+import * as RechartsPrimitive from "recharts";+import "./Charts.scss";/*** @module Charts@@ -21,42 +14,42 @@ import './Charts.scss'* @constant* @type {Record<'light' | 'dark', string>}*/-const THEMES = { light: '', dark: '.dark' } as const+const THEMES = { light: "", dark: ".dark" } as const;/*** Configuration type for chart elements*/export type ChartConfig = {[k in string]: {- label?: React.ReactNode- icon?: React.ComponentType+ label?: React.ReactNode;+ icon?: React.ComponentType;} & (| { color?: string; theme?: never }| { color?: never; theme: Record<keyof typeof THEMES, string> }- )-}+ );+};/*** Context props for chart configuration*/type ChartContextProps = {- config: ChartConfig-}+ config: ChartConfig;+};-const ChartContext = createContext<ChartContextProps | null>(null)+const ChartContext = createContext<ChartContextProps | null>(null);/*** Hook to access chart context* @throws Error if used outside of ChartContainer*/function useChart() {- const context = useContext(ChartContext)+ const context = useContext(ChartContext);if (!context) {- throw new Error('useChart must be used within a <ChartContainer />')+ throw new Error("useChart must be used within a <ChartContainer />");}- return context+ return context;}/**@@ -64,44 +57,38 @@ function useChart() {*/const ChartContainer = forwardRef<HTMLDivElement,- ComponentProps<'div'> & {- config: ChartConfig- children: React.ComponentProps<- typeof RechartsPrimitive.ResponsiveContainer- >['children']+ ComponentProps<"div"> & {+ config: ChartConfig;+ children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];}>(({ id, className, children, config, ...props }, ref) => {- const uniqueId = useId()- const chartId = `chart-${id || uniqueId.replace(/:/g, '')}`+ const uniqueId = useId();+ const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;return (<ChartContext.Provider value={{ config }}><divdata-chart={chartId}ref={ref}- className={clsx('crayon-chart-container', className)}+ className={clsx("crayon-chart-container", className)}{...props}><ChartStyle id={chartId} config={config} />- <RechartsPrimitive.ResponsiveContainer>- {children}- </RechartsPrimitive.ResponsiveContainer>+ <RechartsPrimitive.ResponsiveContainer>{children}</RechartsPrimitive.ResponsiveContainer></div></ChartContext.Provider>- )-})-ChartContainer.displayName = 'Chart'+ );+});+ChartContainer.displayName = "Chart";/*** Component that generates theme-specific styles for chart elements*/const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {- const colorConfig = Object.entries(config).filter(- ([_, config]) => config.theme || config.color,- )+ const colorConfig = Object.entries(config).filter(([_, config]) => config.theme || config.color);if (!colorConfig.length) {- return null+ return null;}return (@@ -113,26 +100,24 @@ const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {${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+ const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] || itemConfig.color;+ return color ? ` --color-${key}: ${color};` : null;}).filter(Boolean)- .join('\n')}+ .join("\n")}}`,)- .join('\n'),+ .join("\n"),}}/>- )-}+ );+};/*** Re-exported Tooltip component from Recharts*/-const ChartTooltip = RechartsPrimitive.Tooltip+const ChartTooltip = RechartsPrimitive.Tooltip;/*** Custom tooltip content component with enhanced styling and formatting@@ -140,13 +125,13 @@ const ChartTooltip = RechartsPrimitive.Tooltipconst ChartTooltipContent = forwardRef<HTMLDivElement,React.ComponentProps<typeof RechartsPrimitive.Tooltip> &- React.ComponentProps<'div'> & {- hideLabel?: boolean- hideIndicator?: boolean- indicator?: 'line' | 'dot' | 'dashed'- nameKey?: string- labelKey?: string- showPercentage?: boolean+ React.ComponentProps<"div"> & {+ hideLabel?: boolean;+ hideIndicator?: boolean;+ indicator?: "line" | "dot" | "dashed";+ nameKey?: string;+ labelKey?: string;+ showPercentage?: boolean;}>((@@ -154,7 +139,7 @@ const ChartTooltipContent = forwardRef<active,payload,className,- indicator = 'dot',+ indicator = "dot",hideLabel = false,hideIndicator = false,label,@@ -168,67 +153,56 @@ const ChartTooltipContent = forwardRef<},ref,) => {- const { config } = useChart()+ const { config } = useChart();const tooltipLabel = useMemo(() => {if (hideLabel || !payload?.length) {- return null+ return null;}- const [item] = payload- const key = `${labelKey ?? item?.dataKey ?? item?.name ?? 'value'}`- const itemConfig = getPayloadConfigFromPayload(config, item, key)+ const [item] = payload;+ const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;+ const itemConfig = getPayloadConfigFromPayload(config, item, key);const value =- !labelKey && typeof label === 'string'- ? config[label]?.label || label- : itemConfig?.label+ !labelKey && typeof label === "string" ? config[label]?.label || label : itemConfig?.label;if (labelFormatter) {return (- <div className={clsx('crayon-chart-tooltip-label', labelClassName)}>+ <div className={clsx("crayon-chart-tooltip-label-heavy", labelClassName)}>{labelFormatter(value, payload)}</div>- )+ );}if (!value) {- return null+ return null;}- return (- <div className={clsx('crayon-chart-tooltip-label', labelClassName)}>- {value}- </div>- )- }, [- label,- labelFormatter,- payload,- hideLabel,- labelClassName,- config,- labelKey,- ])+ return <div className={clsx("crayon-chart-tooltip-label", labelClassName)}>{value}</div>;+ }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);if (!active || !payload?.length) {- return null+ return null;}- const nestLabel = payload.length === 1 && indicator !== 'dot'+ const nestLabel = payload.length === 1 && indicator !== "dot";return (- <div ref={ref} className={clsx('crayon-chart-tooltip', className)}>+ <div ref={ref} className={clsx("crayon-chart-tooltip", className)}>{!nestLabel && tooltipLabel}<div className="crayon-chart-tooltip-content">{payload.map((item, index) => {- const key = `${nameKey ?? item.name ?? item.dataKey ?? 'value'}`- const itemConfig = getPayloadConfigFromPayload(config, item, key)- const indicatorColor = (color ?? item.payload.fill) || item.color+ const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;+ const itemConfig = getPayloadConfigFromPayload(config, item, key);+ const indicatorColor = (color ?? item.payload.fill) || item.color;return (<divkey={item.dataKey}- className="crayon-chart-tooltip-content-item"+ className={clsx(+ "crayon-chart-tooltip-content-item",+ indicator === "dot" && "crayon-chart-tooltip-content-item--dot",+ )}>{formatter && item?.value !== undefined && item.name ? (formatter(item.value, item.name, item, index, item.payload)@@ -240,13 +214,13 @@ const ChartTooltipContent = forwardRef<!hideIndicator && (<divclassName={clsx(- 'crayon-chart-tooltip-content-indicator',+ "crayon-chart-tooltip-content-indicator",`crayon-chart-tooltip-content-indicator--${indicator}`,)}style={{- '--color-bg': indicatorColor,- '--color-border': indicatorColor,+ "--color-bg": indicatorColor,+ "--color-border": indicatorColor,} as React.CSSProperties}/>@@ -254,10 +228,10 @@ const ChartTooltipContent = forwardRef<)}<divclassName={clsx(- 'crayon-chart-tooltip-content-value-wrapper',+ "crayon-chart-tooltip-content-value-wrapper",nestLabel- ? 'crayon-chart-tooltip-content-value-wrapper--nested'- : 'crayon-chart-tooltip-content-value-wrapper--standard',+ ? "crayon-chart-tooltip-content-value-wrapper--nested"+ : "crayon-chart-tooltip-content-value-wrapper--standard",)}><div className="crayon-chart-tooltip-content-label">@@ -267,136 +241,112 @@ const ChartTooltipContent = forwardRef<{item.value !== undefined && (<spanclassName={clsx(- 'crayon-chart-tooltip-content-value',- showPercentage && 'percentage',+ "crayon-chart-tooltip-content-value",+ showPercentage && "percentage",)}>{item.value.toLocaleString()}- {showPercentage ? '%' : ''}+ {showPercentage ? "%" : ""}</span>)}</div></>)}</div>- )+ );})}</div></div>- )+ );},-)-ChartTooltipContent.displayName = 'ChartTooltip'+);+ChartTooltipContent.displayName = "ChartTooltip";/*** Re-exported Legend component from Recharts*/-const ChartLegend = RechartsPrimitive.Legend+const ChartLegend = RechartsPrimitive.Legend;/*** Custom legend content component with enhanced styling*/const ChartLegendContent = forwardRef<HTMLDivElement,- React.ComponentProps<'div'> &- Pick<RechartsPrimitive.LegendProps, 'payload' | 'verticalAlign'> & {- hideIcon?: boolean- nameKey?: string- }->(- (- { className, hideIcon = false, payload, verticalAlign = 'bottom', nameKey },- ref,- ) => {- const { config } = useChart()-- const payloadWithKeys = useMemo(- () =>- payload?.map((item) => ({- ...item,- uniqueKey: uniqueId(- `chart-legend-${item.dataKey || item.value || ''}-`,- ),- })),- [payload],- )-- if (!payload?.length) {- return null+ React.ComponentProps<"div"> &+ Pick<RechartsPrimitive.LegendProps, "payload" | "verticalAlign"> & {+ hideIcon?: boolean;+ nameKey?: string;}+>(({ className, hideIcon = false, payload, verticalAlign = "bottom", nameKey }, ref) => {+ const { config } = useChart();++ const payloadWithKeys = useMemo(+ () =>+ payload?.map((item) => ({+ ...item,+ uniqueKey: uniqueId(`chart-legend-${item.dataKey || item.value || ""}-`),+ })),+ [payload],+ );++ if (!payload?.length) {+ return null;+ }- return (- <div- ref={ref}- className={clsx(- 'crayon-chart-legend',- `crayon-chart-legend--${verticalAlign}`,- className,- )}- >- {payloadWithKeys?.map((item) => {- const key = `${nameKey || item.dataKey || 'value'}`- const itemConfig = getPayloadConfigFromPayload(config, item, key)-- return (- <div key={item.uniqueKey} className="crayon-chart-legend-item">- {itemConfig?.icon && !hideIcon ? (- <itemConfig.icon />- ) : (- <div- className="crayon-chart-legend-item-indicator"- style={{ backgroundColor: item.color }}- />- )}- <span className="crayon-chart-legend-item-label">- {itemConfig?.label}- </span>- </div>- )- })}- </div>- )- },-)-ChartLegendContent.displayName = 'ChartLegend'+ return (+ <div+ ref={ref}+ className={clsx("crayon-chart-legend", `crayon-chart-legend--${verticalAlign}`, className)}+ >+ {payloadWithKeys?.map((item) => {+ const key = `${nameKey || item.dataKey || "value"}`;+ const itemConfig = getPayloadConfigFromPayload(config, item, key);++ return (+ <div key={item.uniqueKey} className="crayon-chart-legend-item">+ {itemConfig?.icon && !hideIcon ? (+ <itemConfig.icon />+ ) : (+ <div+ className="crayon-chart-legend-item-indicator"+ style={{ backgroundColor: item.color }}+ />+ )}+ <span className="crayon-chart-legend-item-label">{itemConfig?.label}</span>+ </div>+ );+ })}+ </div>+ );+});+ChartLegendContent.displayName = "ChartLegend";/*** Helper function to extract configuration for a chart element from a payload*/-function getPayloadConfigFromPayload(- config: ChartConfig,- payload: unknown,- key: string,-) {- if (typeof payload !== 'object' || payload === null) {- return undefined+function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {+ if (typeof payload !== "object" || payload === null) {+ return undefined;}const payloadPayload =- 'payload' in payload &&- typeof payload.payload === 'object' &&- payload.payload !== null+ "payload" in payload && typeof payload.payload === "object" && payload.payload !== null? payload.payload- : undefined+ : undefined;- let configLabelKey: string = key+ let configLabelKey: string = key;- if (- key in payload &&- typeof payload[key as keyof typeof payload] === 'string'- ) {- configLabelKey = payload[key as keyof typeof payload] as string+ if (key in payload && typeof payload[key as keyof typeof payload] === "string") {+ configLabelKey = payload[key as keyof typeof payload] as string;} else if (payloadPayload &&key in payloadPayload &&- typeof payloadPayload[key as keyof typeof payloadPayload] === 'string'+ typeof payloadPayload[key as keyof typeof payloadPayload] === "string") {- configLabelKey = payloadPayload[- key as keyof typeof payloadPayload- ] as string+ configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;}- return configLabelKey in config ? config[configLabelKey] : config[key]+ return configLabelKey in config ? config[configLabelKey] : config[key];}export {@@ -406,4 +356,4 @@ export {ChartStyle,ChartTooltip,ChartTooltipContent,-}\ No newline at end of file+};diff --git a/frontend-sdk/packages/react-ui/src/components/Charts/cartesianGrid.tsx b/frontend-sdk/packages/react-ui/src/components/Charts/cartesianGrid.tsxnew file mode 100644index 000000000..4f26689b3--- /dev/null+++ b/frontend-sdk/packages/react-ui/src/components/Charts/cartesianGrid.tsx@@ -0,0 +1,15 @@+import { CartesianGrid } from "recharts";++export const cartesianGrid = () => (+ <CartesianGrid+ vertical={false}+ fillOpacity={1}+ strokeOpacity={1}+ strokeWidth={2}+ strokeDasharray="6"+ strokeLinecap="round"+ strokeLinejoin="round"+ stroke="currentColor"+ className="crayon-chart-cartesian-grid"+ />+);diff --git a/frontend-sdk/packages/react-ui/src/components/Charts/charts.scss b/frontend-sdk/packages/react-ui/src/components/Charts/charts.scssindex 0c81ae6c0..e60ee8310 100644--- a/frontend-sdk/packages/react-ui/src/components/Charts/charts.scss+++ b/frontend-sdk/packages/react-ui/src/components/Charts/charts.scss@@ -1,23 +1,26 @@+@use "sass:map";+@use "../../cssUtils" as cssUtils;+.crayon-chart {// Container styles&-container {display: flex;aspect-ratio: 16 / 9;justify-content: center;- font-size: 0.75rem;+ font-size: 12px;+ line-height: 16px;- // Recharts overrides// Text and fills.recharts-cartesian-axis-tick text {- fill: var(--t-comp-primary);+ fill: map.get(cssUtils.$colors, "text", "primary");}.recharts-radial-bar-background-sector {- fill: var(--t-comp-background);+ fill: map.get(cssUtils.$colors, "fills", "background");}.recharts-rectangle.recharts-tooltip-cursor {- fill: var(--t-comp-background);+ fill: map.get(cssUtils.$colors, "fills", "background");}// Strokes and borders@@ -25,7 +28,7 @@.recharts-curve.recharts-tooltip-cursor,.recharts-polar-grid[stroke="#ccc"],.recharts-reference-line[stroke="#ccc"] {- stroke: var(--t-comp-default);+ stroke: map.get(cssUtils.$colors, "strokes", "default");}// Transparency settings@@ -46,56 +49,66 @@&-tooltip {display: grid;align-items: start;- min-width: 8rem;- gap: var(--t-comp-spacing-xs);- padding: var(--t-comp-spacing-xs);- color: var(--t-comp-primary);- font-family: var(--t-comp-typography-label-family);- font-size: var(--t-comp-typography-label-size);- font-weight: var(--t-comp-typography-label-weight);- border-radius: var(--t-comp-clickables-radius);- border: 1px solid var(--t-comp-default);- background-color: var(--t-comp-container);- box-shadow: var(--t-comp-shadow-small);+ min-width: 128px;+ gap: map.get(cssUtils.$spacing, "xs");+ padding: map.get(cssUtils.$spacing, "xs");+ color: map.get(cssUtils.$colors, "text", "primary");+ @include cssUtils.typography(label, default);+ border-radius: map.get(cssUtils.$radius, "s");+ border: 1px solid map.get(cssUtils.$colors, "strokes", "default");+ background-color: map.get(cssUtils.$colors, "fills", "container");+ box-shadow: map.get(cssUtils.$shadow, "small");&-label {- color: var(--t-comp-primary);- font-family: var(--t-comp-typography-label-family);- font-size: var(--t-comp-typography-label-size);- font-weight: var(--t-comp-typography-label-weight);+ @include cssUtils.typography(label, default);+ }++ &-label-heavy {+ @include cssUtils.typography(label, heavy);}&-content {display: grid;- gap: 0.375rem;+ align-items: start;+ min-width: 128px;+ gap: map.get(cssUtils.$spacing, "xs");+ padding: map.get(cssUtils.$spacing, "xs");+ color: map.get(cssUtils.$colors, "text", "primary");+ @include cssUtils.typography(label, default);+ border-radius: map.get(cssUtils.$radius, "s");+ border: 1px solid map.get(cssUtils.$colors, "strokes", "default");+ background-color: map.get(cssUtils.$colors, "fills", "container");+ box-shadow: map.get(cssUtils.$shadow, "small");&-item {display: flex;width: 100%;flex-wrap: wrap;- gap: 0.5rem;- align-items: center;+ gap: map.get(cssUtils.$spacing, "xs");+ align-items: stretch;+ &--dot {+ align-items: center;+ }svg {- height: 0.625rem;- width: 0.625rem;- color: var(--t-comp-primary);+ height: 10px;+ width: 10px;+ color: map.get(cssUtils.$colors, "text", "primary");}}-- &-indicator {+ & &-indicator {flex-shrink: 0;- border-radius: 2px;+ border-radius: map.get(cssUtils.$radius, "3xs");&--dot {- height: 0.625rem;- width: 0.625rem;+ height: 10px;+ width: 10px;background-color: var(--color-bg);border-color: var(--color-border);}&--line {- width: 0.25rem;+ width: 4px;height: 100%;background-color: var(--color-bg);border-color: var(--color-border);@@ -108,7 +121,7 @@}&--nested-dashed {- margin: 0.125rem 0;+ margin: map.get(cssUtils.$spacing, "3xs") 0;}}@@ -129,22 +142,18 @@&-label {display: grid;- gap: 0.375rem;- color: var(--t-comp-primary);- font-family: var(--t-comp-typography-label-family);- font-size: var(--t-comp-typography-label-size);- font-weight: var(--t-comp-typography-label-weight);+ gap: map.get(cssUtils.$spacing, "xs");+ color: map.get(cssUtils.$colors, "text", "primary");+ @include cssUtils.typography(label, default);}&-value {font-variant-numeric: tabular-nums;- color: var(--t-comp-primary);- font-family: var(--t-comp-typography-label-family);- font-size: var(--t-comp-typography-label-size);- font-weight: var(--t-comp-typography-label-weight);+ color: map.get(cssUtils.$colors, "text", "primary");+ @include cssUtils.typography(label, default);&--percentage {- padding-left: 0.5rem;+ padding-left: map.get(cssUtils.$spacing, "s");}}}@@ -155,45 +164,47 @@display: flex;align-items: center;justify-content: center;- gap: 1rem;+ gap: 16px;&--top {- padding-bottom: 0.75rem;+ padding-bottom: map.get(cssUtils.$spacing, "s");}&--bottom {- padding-top: 0.75rem;+ padding-top: map.get(cssUtils.$spacing, "m");}&-item {display: flex;align-items: center;- gap: 0.375rem;+ gap: map.get(cssUtils.$spacing, "xs");svg {- height: 0.75rem;- width: 0.75rem;- color: var(--t-comp-primary);+ height: map.get(cssUtils.$spacing, "m");+ width: map.get(cssUtils.$spacing, "m");+ color: map.get(cssUtils.$colors, "text", "primary");}&-indicator {- height: 0.5rem;- width: 0.5rem;+ height: map.get(cssUtils.$spacing, "s");+ width: map.get(cssUtils.$spacing, "s");flex-shrink: 0;- border-radius: 2px;+ border-radius: map.get(cssUtils.$radius, "3xs");background-color: var(--color-bg);}&-label {- font-family: var(--t-comp-typography-label-heavy-family);- font-size: var(--t-comp-typography-label-heavy-size);- font-weight: var(--t-comp-typography-label-heavy-weight);- max-width: 4rem;+ @include cssUtils.typography(label, heavy);+ max-width: 64px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;- color: var(--t-comp-primary);+ color: map.get(cssUtils.$colors, "text", "primary");}}}-}\ No newline at end of file+}++.crayon-chart-cartesian-grid {+ stroke: map.get(cssUtils.$colors, "strokes", "default");+}diff --git a/frontend-sdk/packages/react-ui/src/components/Charts/index.ts b/frontend-sdk/packages/react-ui/src/components/Charts/index.tsnew file mode 100644index 000000000..e69de29bbdiff --git a/frontend-sdk/packages/react-ui/src/components/Charts/stories/charts.stories.tsx b/frontend-sdk/packages/react-ui/src/components/Charts/stories/charts.stories.tsxnew file mode 100644index 000000000..051019434--- /dev/null+++ b/frontend-sdk/packages/react-ui/src/components/Charts/stories/charts.stories.tsx@@ -0,0 +1,90 @@+import type { Meta, StoryObj } from "@storybook/react";+import { Download, TrendingUp } from "lucide-react";+import { Bar, BarChart, XAxis } from "recharts";+import "../charts.scss";++import { Button } from "../../Button";+import { Card } from "../../Card";+import { Footer } from "../../Footer/Footer";+import { Header } from "../../Header";+import { IconButton } from "../../IconButton";+import { ChartConfig, ChartContainer, ChartTooltip, ChartTooltipContent } from "../Charts";+import { cartesianGrid } from "../cartesianGrid";++const chartData = [+ { month: "January", desktop: 186, mobile: 80 },+ { month: "February", desktop: 305, mobile: 200 },+ { month: "March", desktop: 237, mobile: 120 },+ { month: "April", desktop: 73, mobile: 190 },+ { month: "May", desktop: 209, mobile: 130 },+ { month: "June", desktop: 214, mobile: 140 },+];++const chartConfig = {+ desktop: {+ label: "Desktop",+ color: "red",+ },+ mobile: {+ label: "Mobile",+ color: "green",+ },+} satisfies ChartConfig;++const BarChartComponent = () => {+ return (+ <Card style={{ width: "500px" }}>+ <Header+ actions={[+ <IconButton variant="tertiary" key="download-btn" size="small" icon={<TrendingUp />} />,+ ]}+ title="Bar Chart - Multiple"+ subtitle="January - June 2024"+ />+ <>+ <ChartContainer config={chartConfig}>+ <BarChart accessibilityLayer data={chartData}>+ {cartesianGrid()}+ <XAxis+ dataKey="month"+ tickLine={false}+ tickMargin={10}+ axisLine={false}+ tickFormatter={(value) => value.slice(0, 3)}+ />+ <ChartTooltip cursor={false} content={<ChartTooltipContent />} />+ <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />+ <Bar dataKey="mobile" fill="var(--color-mobile)" radius={4} />+ </BarChart>+ </ChartContainer>+ </>+ <Footer>+ <Button iconRight={<Download />}>Download</Button>+ </Footer>+ </Card>+ );+};++const meta = {+ title: "Components/Charts/BarChart",+ component: BarChartComponent,+ parameters: {+ layout: "centered",+ },+ tags: ["autodocs"],+} satisfies Meta<typeof BarChartComponent>;++export default meta;+type Story = StoryObj<typeof meta>;++export const Default: Story = {};++export const CustomData: Story = {+ args: {+ data: [+ { month: "July", desktop: 250, mobile: 150 },+ { month: "August", desktop: 320, mobile: 180 },+ { month: "September", desktop: 280, mobile: 160 },+ ],+ },+};diff --git a/frontend-sdk/packages/react-ui/src/components/Charts/utils/PalletUtils.ts b/frontend-sdk/packages/react-ui/src/components/Charts/utils/PalletUtils.tsnew file mode 100644index 000000000..e8898f962--- /dev/null+++ b/frontend-sdk/packages/react-ui/src/components/Charts/utils/PalletUtils.ts@@ -0,0 +1,158 @@+import invariant from "tiny-invariant";++export type ColorPalette = {+ name: string;+ // colors are used to display the palette+ colors: string[];+};++type PaletteMap = Record<string, ColorPalette>;++const colorPalettes: PaletteMap = {+ ocean: {+ name: "Ocean",+ colors: [+ "#0D47A1",+ "#1565C0",+ "#1976D2",+ "#1E88E5",+ "#2196F3",+ "#42A5F5",+ "#64B5F6",+ "#90CAF9",+ "#BBDEFB",+ "#E3F2FD",+ "#EFF8FF",+ ],+ },+ orchid: {+ name: "Orchid",+ colors: [+ "#3A365B",+ "#482E77",+ "#552594",+ "#631DB0",+ "#7014CC",+ "#883BD5",+ "#A062DD",+ "#B88AE6",+ "#CFB1EE",+ "#E7D8F7",+ "#F7EFFF",+ ],+ },+ emerald: {+ name: "Emerald",+ colors: [+ "#10451D",+ "#155D27",+ "#1A7431",+ "#208B3A",+ "#25A244",+ "#2DC653",+ "#4AD66D",+ "#6EDE8A",+ "#92E6A7",+ "#B7EFC5",+ "#DCFFE5",+ ],+ },+ spectrum: {+ name: "Spectrum",+ colors: [+ "#2171BC",+ "#2681D7",+ "#72A4EB",+ "#A0C0F7",+ "#C2D4F7",+ "#EADDE8",+ "#EEB3B1",+ "#E99492",+ "#E17475",+ "#D75259",+ "#CB253E",+ ],+ },+ sunset: {+ name: "Sunset",+ colors: [+ "#0D0887",+ "#42049E",+ "#6A00A8",+ "#900DA4",+ "#B12A90",+ "#CC4678",+ "#E16462",+ "#F1844B",+ "#FCA636",+ "#FCCE25",+ "#FFE06E",+ ],+ },+ vivid: {+ name: "Vivid",+ colors: [+ "#FF595E",+ "#FF924C",+ "#FFCA3A",+ "#C5CA30",+ "#8AC926",+ "#36949D",+ "#1982C4",+ "#4267AC",+ "#565AA0",+ "#6A4C93",+ "#63438F",+ ],+ },+};++export type PaletteKey = keyof typeof colorPalettes;++export const getPalette = (key: PaletteKey): ColorPalette => {+ const palette = colorPalettes[key];+ invariant(palette, `Palette ${key} not found`);+ return palette;+};++export const getAllPalettes = (): ColorPalette[] => {+ return Object.values(colorPalettes);+};++export const getPaletteKeys = (): PaletteKey[] => {+ return Object.keys(colorPalettes) as PaletteKey[];+};++export const getPaletteKey = (palette: ColorPalette): PaletteKey => {+ return Object.keys(colorPalettes).find((key) => colorPalettes[key] === palette) as PaletteKey;+};++export const getPaletteMap = (): PaletteMap => {+ return colorPalettes;+};++export const getDistributedColors = (palette: ColorPalette, dataLength: number): string[] => {+ const colors = palette.colors;+ const midIndex = Math.floor(colors.length / 2);++ if (dataLength === 1) {+ // For single item, return the middle color+ return [colors[midIndex]!];+ }++ if (dataLength === 2) {+ // For two items, return colors equally spaced around the middle+ return [colors[midIndex - 1]!, colors[midIndex + 1]!];+ }++ // For 3 or more items, distribute colors evenly around the middle+ const result: string[] = [];+ const offset = Math.floor((dataLength - 1) / 2);++ for (let i = 0; i < dataLength; i++) {+ const index = midIndex + (i - offset);+ result.push(colors[index] ?? colors[midIndex]!); // Fallback to middle color if index out of bounds+ }++ return result;+};diff --git a/frontend-sdk/packages/react-ui/src/components/Shell/mobileHeader.scss b/frontend-sdk/packages/react-ui/src/components/Shell/mobileHeader.scssindex f102582f2..b401af0ae 100644--- a/frontend-sdk/packages/react-ui/src/components/Shell/mobileHeader.scss+++ b/frontend-sdk/packages/react-ui/src/components/Shell/mobileHeader.scss@@ -1,7 +1,6 @@@use "sass:map";@use "../../cssUtils" as cssUtils;-.crayon-shell-mobile-header {display: none;@@ -12,14 +11,13 @@padding: map.get(cssUtils.$spacing, "m") map.get(cssUtils.$spacing, "l");background-color: map.get(cssUtils.$colors, fills, container);}-}.crayon-shell-mobile-header-logo-container {display: flex;align-items: center;gap: map.get(cssUtils.$spacing, "m");- @include cssUtils.typography(title, medium)+ @include cssUtils.typography(title, medium);}.crayon-shell-mobile-header-logo {diff --git a/frontend-sdk/packages/react-ui/src/components/Shell/shell.scss b/frontend-sdk/packages/react-ui/src/components/Shell/shell.scssindex bbd7e99d4..5cd0d83cc 100644--- a/frontend-sdk/packages/react-ui/src/components/Shell/shell.scss+++ b/frontend-sdk/packages/react-ui/src/components/Shell/shell.scss@@ -20,7 +20,7 @@}&.crayon-shell-container--mobile {- padding: 0+ padding: 0;}}diff --git a/frontend-sdk/packages/react-ui/src/components/Shell/sidebar.scss b/frontend-sdk/packages/react-ui/src/components/Shell/sidebar.scssindex 07d8d1a81..928e34d3a 100644--- a/frontend-sdk/packages/react-ui/src/components/Shell/sidebar.scss+++ b/frontend-sdk/packages/react-ui/src/components/Shell/sidebar.scss@@ -8,7 +8,7 @@ $sidebar-mobile-padding: map.get(cssUtils.$spacing, "l");.crayon-shell-sidebar-container {//todo: fills elevated container- background: rgba(255, 255, 255, 0.60);+ background: rgba(255, 255, 255, 0.6);height: 100%;width: $sidebar-width;border-radius: 12px;@@ -84,7 +84,6 @@ $sidebar-mobile-padding: map.get(cssUtils.$spacing, "l");}.crayon-shell-sidebar-header__toggle-button {-.crayon-shell-container--mobile & {display: none;}@@ -98,7 +97,7 @@ $sidebar-mobile-padding: map.get(cssUtils.$spacing, "l");height: 100%;background-color: map.get(cssUtils.$colors, fills, overlay);transition: opacity 0.3s ease-in-out;-+&--collapsed {opacity: 0;pointer-events: none;diff --git a/frontend-sdk/packages/react-ui/src/components/Shell/threadlist.scss b/frontend-sdk/packages/react-ui/src/components/Shell/threadlist.scssindex efcf05b6b..bdb816a38 100644--- a/frontend-sdk/packages/react-ui/src/components/Shell/threadlist.scss+++ b/frontend-sdk/packages/react-ui/src/components/Shell/threadlist.scss@@ -29,4 +29,4 @@background-color: map.get(cssUtils.$colors, "fills", "sunk");border-color: map.get(cssUtils.$colors, "stokes", "default");}-}\ No newline at end of file+}diff --git a/frontend-sdk/packages/react-ui/src/index.ts b/frontend-sdk/packages/react-ui/src/index.tsindex 8b1378917..e69de29bb 100644--- a/frontend-sdk/packages/react-ui/src/index.ts+++ b/frontend-sdk/packages/react-ui/src/index.ts@@ -1 +0,0 @@-