@cmdniels/uikit 1.1.7 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -113,13 +113,13 @@ export default function MyComponent() {
113
113
 
114
114
  ## Available Components
115
115
 
116
- - **Layout**: Accordion, Card, Item, Separator, Table
116
+ - **Layout**: Accordion, AspectRatio, Card, Item, ScrollArea, Separator, Sheet, Sidebar, Table
117
117
  - **Forms**: Button, ButtonGroup, Checkbox, Input, InputGroup, Label, Select, Switch, Textarea, Toggle
118
- - **Data Entry**: Calendar, Combobox, DatePicker, Field, FileDropzone
119
- - **Feedback**: Alert, AlertDialog, Error, Skeleton, Toaster (Sonner)
118
+ - **Data Entry**: Calendar, Combobox, CopyInput, DatePicker, Field, FileDropzone, LinkInput
119
+ - **Feedback**: Alert, AlertDialog, Error, Skeleton, Spinner, Toaster (Sonner)
120
120
  - **Navigation**: ContextMenu, DropdownMenu
121
121
  - **Overlay**: Popover, Tooltip
122
- - **Utilities**: AspectRatio, Badge, Sortable
122
+ - **Utilities**: Badge, Chart, Sortable
123
123
  - **Typography**: Complete set of typography components
124
124
 
125
125
  ## Development
@@ -16,5 +16,5 @@ import Spinner from "../../components/spinner/Spinner";
16
16
  import { buttonVariants } from "./buttonVariants";
17
17
  export default function Button(_a) {
18
18
  var { className, children, variant = "default", size = "default", loading = false, disabled } = _a, props = __rest(_a, ["className", "children", "variant", "size", "loading", "disabled"]);
19
- return (_jsxs(ButtonPrimitive, Object.assign({ "data-slot": "button", className: cn(buttonVariants({ variant, size, className }), loading && "relative"), disabled: disabled !== null && disabled !== void 0 ? disabled : loading }, props, { children: [loading && _jsx(Spinner, { className: "absolute inset-0 m-auto" }), _jsx("span", { className: cn("contents", loading && "invisible"), children: children })] })));
19
+ return (_jsxs(ButtonPrimitive, Object.assign({ "data-slot": "button", className: cn(buttonVariants({ variant, size, className }), loading && "relative"), disabled: loading || disabled }, props, { children: [loading && _jsx(Spinner, { className: "absolute inset-0 m-auto" }), _jsx("span", { className: cn("contents", loading && "invisible"), children: children })] })));
20
20
  }
@@ -0,0 +1,7 @@
1
+ import { type ComponentProps } from "react";
2
+ import { ResponsiveContainer as RechartsResponsiveContainer } from "recharts";
3
+ import { type ChartConfig } from "./ChartContext";
4
+ export default function ChartContainer({ id, className, children, config, ...props }: ComponentProps<"div"> & {
5
+ config: ChartConfig;
6
+ children: ComponentProps<typeof RechartsResponsiveContainer>["children"];
7
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useId } from "react";
15
+ import { ResponsiveContainer as RechartsResponsiveContainer } from "recharts";
16
+ import cn from "../../cn";
17
+ import { ChartContext } from "./ChartContext";
18
+ import ChartStyle from "./ChartStyle";
19
+ export default function ChartContainer(_a) {
20
+ var { id, className, children, config } = _a, props = __rest(_a, ["id", "className", "children", "config"]);
21
+ const uniqueId = useId();
22
+ const chartId = `chart-${id !== null && id !== void 0 ? id : uniqueId.replace(/:/g, "")}`;
23
+ return (_jsx(ChartContext.Provider, { value: { config }, children: _jsxs("div", Object.assign({ "data-slot": "chart", "data-chart": chartId, className: cn("flex aspect-video justify-center text-xs [&_.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-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-none [&_.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-sector]:outline-none [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-none [&_g]:focus:outline-none", className) }, props, { children: [_jsx(ChartStyle, { id: chartId, config: config }), _jsx(RechartsResponsiveContainer, { children: children })] })) }));
24
+ }
@@ -0,0 +1,16 @@
1
+ import { type ComponentType, type ReactNode } from "react";
2
+ export type ChartConfig = {
3
+ [k in string]: {
4
+ label?: ReactNode;
5
+ icon?: ComponentType;
6
+ } & ({
7
+ color?: string;
8
+ theme?: never;
9
+ } | {
10
+ color?: never;
11
+ theme: Record<"light" | "dark", string>;
12
+ });
13
+ };
14
+ export declare const ChartContext: import("react").Context<{
15
+ config: ChartConfig;
16
+ } | null>;
@@ -0,0 +1,2 @@
1
+ import { createContext } from "react";
2
+ export const ChartContext = createContext(null);
@@ -0,0 +1,3 @@
1
+ import { type ComponentProps } from "react";
2
+ import { Legend as RechartsLegend } from "recharts";
3
+ export default function ChartLegend(props: ComponentProps<typeof RechartsLegend>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Legend as RechartsLegend } from "recharts";
3
+ export default function ChartLegend(props) {
4
+ return _jsx(RechartsLegend, Object.assign({}, props));
5
+ }
@@ -0,0 +1,9 @@
1
+ import type { LegendPayload } from "recharts/types/component/DefaultLegendContent";
2
+ import type { Props as LegendProps } from "recharts/types/component/Legend";
3
+ export default function ChartLegendContent({ className, hideIcon, payload, verticalAlign, nameKey, }: {
4
+ className?: string;
5
+ hideIcon?: boolean;
6
+ verticalAlign?: LegendProps["verticalAlign"];
7
+ payload?: readonly LegendPayload[];
8
+ nameKey?: string;
9
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,19 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import cn from "../../cn";
4
+ import getPayloadConfigFromPayload from "./getPayloadConfigFromPayload";
5
+ import useChart from "./useChart";
6
+ export default function ChartLegendContent({ className, hideIcon = false, payload, verticalAlign = "bottom", nameKey, }) {
7
+ const { config } = useChart();
8
+ if (!(payload === null || payload === void 0 ? void 0 : payload.length)) {
9
+ return null;
10
+ }
11
+ return (_jsx("div", { className: cn("flex items-center justify-center gap-4", verticalAlign === "top" ? "pb-3" : "pt-3", className), children: payload.map((item) => {
12
+ var _a;
13
+ const key = `${(_a = nameKey !== null && nameKey !== void 0 ? nameKey : item.dataKey) !== null && _a !== void 0 ? _a : "value"}`;
14
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
15
+ return (_jsxs("div", { className: cn("flex items-center gap-1.5 [&>svg]:size-3 [&>svg]:text-muted-foreground"), children: [(itemConfig === null || itemConfig === void 0 ? void 0 : itemConfig.icon) && !hideIcon ? (_jsx(itemConfig.icon, {})) : (_jsx("div", { className: "size-2 shrink-0 rounded-[2px]", style: {
16
+ backgroundColor: item.color,
17
+ } })), itemConfig === null || itemConfig === void 0 ? void 0 : itemConfig.label] }, item.value));
18
+ }) }));
19
+ }
@@ -0,0 +1,5 @@
1
+ import { type ChartConfig } from "./ChartContext";
2
+ export default function ChartStyle({ id, config }: {
3
+ id: string;
4
+ config: ChartConfig;
5
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ const THEMES = { light: "", dark: ".dark" }; // Format: { THEME_NAME: CSS_SELECTOR }
3
+ export default function ChartStyle({ id, config }) {
4
+ const colorConfig = Object.entries(config).filter(([, _config]) => { var _a; return (_a = _config.theme) !== null && _a !== void 0 ? _a : _config.color; });
5
+ if (!colorConfig.length) {
6
+ return null;
7
+ }
8
+ return (_jsx("style", { dangerouslySetInnerHTML: {
9
+ __html: Object.entries(THEMES)
10
+ .map(([theme, prefix]) => `
11
+ ${prefix} [data-chart=${id}] {
12
+ ${colorConfig
13
+ .map(([key, itemConfig]) => {
14
+ var _a, _b;
15
+ const color = (_b = (_a = itemConfig.theme) === null || _a === void 0 ? void 0 : _a[theme]) !== null && _b !== void 0 ? _b : itemConfig.color;
16
+ return color ? ` --color-${key}: ${color};` : null;
17
+ })
18
+ .join("\n")}
19
+ }
20
+ `)
21
+ .join("\n"),
22
+ } }));
23
+ }
@@ -0,0 +1,3 @@
1
+ import { type ComponentProps } from "react";
2
+ import { Tooltip as RechartsTooltip } from "recharts";
3
+ export default function ChartTooltip({ ...props }: ComponentProps<typeof RechartsTooltip>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,17 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { Tooltip as RechartsTooltip } from "recharts";
14
+ export default function ChartTooltip(_a) {
15
+ var props = __rest(_a, []);
16
+ return _jsx(RechartsTooltip, Object.assign({}, props));
17
+ }
@@ -0,0 +1,15 @@
1
+ import { type ReactNode } from "react";
2
+ import type { NameType, Payload, ValueType } from "recharts/types/component/DefaultTooltipContent";
3
+ import type { TooltipContentProps } from "recharts/types/component/Tooltip";
4
+ export default function ChartTooltipContent({ active, payload, label, className, indicator, hideLabel, hideIndicator, labelFormatter, formatter, labelClassName, color, nameKey, labelKey, }: TooltipContentProps<ValueType, NameType> & {
5
+ className?: string;
6
+ hideLabel?: boolean;
7
+ hideIndicator?: boolean;
8
+ indicator?: "line" | "dot" | "dashed";
9
+ nameKey?: string;
10
+ labelKey?: string;
11
+ labelFormatter?: (label: TooltipContentProps<number, string>["label"], payload: TooltipContentProps<number, string>["payload"]) => ReactNode;
12
+ formatter?: (value: number | string, name: string, item: Payload<number | string, string>, index: number, payload: ReadonlyArray<Payload<number | string, string>>) => ReactNode;
13
+ labelClassName?: string;
14
+ color?: string;
15
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,49 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { useMemo } from "react";
4
+ import cn from "../../cn";
5
+ import getPayloadConfigFromPayload from "./getPayloadConfigFromPayload";
6
+ import useChart from "./useChart";
7
+ export default function ChartTooltipContent({ active, payload, label, className, indicator = "dot", hideLabel = false, hideIndicator = false, labelFormatter, formatter, labelClassName, color, nameKey, labelKey, }) {
8
+ const { config } = useChart();
9
+ const tooltipLabel = useMemo(() => {
10
+ var _a, _b;
11
+ if (hideLabel || !(payload === null || payload === void 0 ? void 0 : payload.length)) {
12
+ return null;
13
+ }
14
+ const [item] = payload;
15
+ const key = `${(_b = (_a = labelKey !== null && labelKey !== void 0 ? labelKey : item === null || item === void 0 ? void 0 : item.dataKey) !== null && _a !== void 0 ? _a : item === null || item === void 0 ? void 0 : item.name) !== null && _b !== void 0 ? _b : "value"}`;
16
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
17
+ const value = (() => {
18
+ var _a, _b;
19
+ const v = !labelKey && typeof label === "string" ? ((_b = (_a = config[label]) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : label) : itemConfig === null || itemConfig === void 0 ? void 0 : itemConfig.label;
20
+ return typeof v === "string" || typeof v === "number" ? v : undefined;
21
+ })();
22
+ if (labelFormatter) {
23
+ return _jsx("div", { className: cn("font-medium", labelClassName), children: labelFormatter(value, payload) });
24
+ }
25
+ if (!value) {
26
+ return null;
27
+ }
28
+ return _jsx("div", { className: cn("font-medium", labelClassName), children: value });
29
+ }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
30
+ if (!active || !(payload === null || payload === void 0 ? void 0 : payload.length)) {
31
+ return null;
32
+ }
33
+ const nestLabel = payload.length === 1 && indicator !== "dot";
34
+ return (_jsxs("div", { className: cn("grid min-w-32 items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl", className), children: [!nestLabel ? tooltipLabel : null, _jsx("div", { className: "grid gap-1.5", children: payload.map((item, index) => {
35
+ var _a, _b, _c, _d;
36
+ const key = `${(_b = (_a = nameKey !== null && nameKey !== void 0 ? nameKey : item.name) !== null && _a !== void 0 ? _a : item.dataKey) !== null && _b !== void 0 ? _b : "value"}`;
37
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
38
+ const indicatorColor = (_c = color !== null && color !== void 0 ? color : item.payload.fill) !== null && _c !== void 0 ? _c : item.color;
39
+ return (_jsx("div", { className: cn("flex w-full flex-wrap items-stretch gap-2 [&>svg]:size-2.5 [&>svg]:text-muted-foreground", indicator === "dot" && "items-center"), children: formatter && (item === null || item === void 0 ? void 0 : item.value) !== undefined && item.name ? (formatter(item.value, item.name, item, index, item.payload)) : (_jsxs(_Fragment, { children: [(itemConfig === null || itemConfig === void 0 ? void 0 : itemConfig.icon) ? (_jsx(itemConfig.icon, {})) : (!hideIndicator && (_jsx("div", { className: cn("shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)", {
40
+ "size-2.5 ": indicator === "dot",
41
+ "w-1": indicator === "line",
42
+ "w-0 border-[1.5px] border-dashed bg-transparent": indicator === "dashed",
43
+ "my-0.5": nestLabel && indicator === "dashed",
44
+ }), style: {
45
+ "--color-bg": indicatorColor,
46
+ "--color-border": indicatorColor,
47
+ } }))), _jsxs("div", { className: cn("flex flex-1 justify-between leading-none", nestLabel ? "items-end" : "items-center"), children: [_jsxs("div", { className: "grid gap-1.5", children: [nestLabel ? tooltipLabel : null, _jsx("span", { className: "text-muted-foreground", children: (_d = itemConfig === null || itemConfig === void 0 ? void 0 : itemConfig.label) !== null && _d !== void 0 ? _d : item.name })] }), item.value && (_jsx("span", { className: "font-mono font-medium text-foreground tabular-nums", children: item.value.toLocaleString() }))] })] })) }, item.dataKey));
48
+ }) })] }));
49
+ }
@@ -0,0 +1,11 @@
1
+ import { type ChartConfig } from "./ChartContext";
2
+ export default function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string): ({
3
+ label?: import("react").ReactNode;
4
+ icon?: import("react").ComponentType;
5
+ } & ({
6
+ color?: string;
7
+ theme?: never;
8
+ } | {
9
+ color?: never;
10
+ theme: Record<"light" | "dark", string>;
11
+ })) | undefined;
@@ -0,0 +1,18 @@
1
+ export default function getPayloadConfigFromPayload(config, payload, key) {
2
+ if (typeof payload !== "object" || payload === null) {
3
+ return undefined;
4
+ }
5
+ const payloadPayload = "payload" in payload && typeof payload.payload === "object" && payload.payload !== null
6
+ ? payload.payload
7
+ : undefined;
8
+ let configLabelKey = key;
9
+ if (key in payload && typeof payload[key] === "string") {
10
+ configLabelKey = payload[key];
11
+ }
12
+ else if (payloadPayload &&
13
+ key in payloadPayload &&
14
+ typeof payloadPayload[key] === "string") {
15
+ configLabelKey = payloadPayload[key];
16
+ }
17
+ return configLabelKey in config ? config[configLabelKey] : config[key];
18
+ }
@@ -0,0 +1,3 @@
1
+ export default function useChart(): {
2
+ config: import("./ChartContext").ChartConfig;
3
+ };
@@ -0,0 +1,9 @@
1
+ import { useContext } from "react";
2
+ import { ChartContext } from "./ChartContext";
3
+ export default function useChart() {
4
+ const context = useContext(ChartContext);
5
+ if (!context) {
6
+ throw new Error("useChart must be used within a <ChartContainer />");
7
+ }
8
+ return context;
9
+ }
package/out/index.d.ts CHANGED
@@ -33,6 +33,13 @@ export { default as CardDescription } from "./components/card/CardDescription";
33
33
  export { default as CardFooter } from "./components/card/CardFooter";
34
34
  export { default as CardHeader } from "./components/card/CardHeader";
35
35
  export { default as CardTitle } from "./components/card/CardTitle";
36
+ export type { ChartConfig } from "./components/chart/ChartContext";
37
+ export { default as ChartContainer } from "./components/chart/ChartContainer";
38
+ export { default as ChartLegend } from "./components/chart/ChartLegend";
39
+ export { default as ChartLegendContent } from "./components/chart/ChartLegendContent";
40
+ export { default as ChartStyle } from "./components/chart/ChartStyle";
41
+ export { default as ChartTooltip } from "./components/chart/ChartTooltip";
42
+ export { default as ChartTooltipContent } from "./components/chart/ChartTooltipContent";
36
43
  export { default as Checkbox } from "./components/checkbox/Checkbox";
37
44
  export { default as Combobox } from "./components/combobox/Combobox";
38
45
  export { default as ComboboxChip } from "./components/combobox/ComboboxChip";
package/out/index.js CHANGED
@@ -42,6 +42,12 @@ export { default as CardDescription } from "./components/card/CardDescription";
42
42
  export { default as CardFooter } from "./components/card/CardFooter";
43
43
  export { default as CardHeader } from "./components/card/CardHeader";
44
44
  export { default as CardTitle } from "./components/card/CardTitle";
45
+ export { default as ChartContainer } from "./components/chart/ChartContainer";
46
+ export { default as ChartLegend } from "./components/chart/ChartLegend";
47
+ export { default as ChartLegendContent } from "./components/chart/ChartLegendContent";
48
+ export { default as ChartStyle } from "./components/chart/ChartStyle";
49
+ export { default as ChartTooltip } from "./components/chart/ChartTooltip";
50
+ export { default as ChartTooltipContent } from "./components/chart/ChartTooltipContent";
45
51
  // Checkbox
46
52
  export { default as Checkbox } from "./components/checkbox/Checkbox";
47
53
  // Combobox
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmdniels/uikit",
3
- "version": "1.1.7",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,6 +30,7 @@
30
30
  "sideEffects": false,
31
31
  "peerDependencies": {
32
32
  "@clerk/themes": "^2.4.46",
33
+ "recharts": "^3.6.0",
33
34
  "next": "^14.0.0 || ^15.0.0 || ^16.0.0",
34
35
  "react": "^18.0.0 || ^19.0.0",
35
36
  "react-dom": "^18.0.0 || ^19.0.0"