doom-design-system 0.4.6 → 0.4.8

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.
Files changed (148) hide show
  1. package/dist/DesignSystemProvider.d.ts +4 -4
  2. package/dist/DesignSystemProvider.js +6 -6
  3. package/dist/components/Accordion/Accordion.js +6 -5
  4. package/dist/components/Accordion/index.d.ts +1 -1
  5. package/dist/components/Accordion/index.js +1 -1
  6. package/dist/components/ActionRow/ActionRow.js +4 -4
  7. package/dist/components/ActionRow/index.d.ts +1 -1
  8. package/dist/components/ActionRow/index.js +1 -1
  9. package/dist/components/Alert/Alert.d.ts +3 -3
  10. package/dist/components/Alert/Alert.js +5 -5
  11. package/dist/components/Alert/index.d.ts +1 -1
  12. package/dist/components/Alert/index.js +1 -1
  13. package/dist/components/Avatar/Avatar.js +3 -3
  14. package/dist/components/Avatar/index.d.ts +1 -1
  15. package/dist/components/Avatar/index.js +1 -1
  16. package/dist/components/Badge/index.d.ts +1 -1
  17. package/dist/components/Badge/index.js +1 -1
  18. package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +2 -2
  19. package/dist/components/Breadcrumbs/Breadcrumbs.js +7 -7
  20. package/dist/components/Breadcrumbs/index.d.ts +1 -1
  21. package/dist/components/Breadcrumbs/index.js +1 -1
  22. package/dist/components/Button/Button.js +1 -1
  23. package/dist/components/Button/index.d.ts +1 -1
  24. package/dist/components/Button/index.js +1 -1
  25. package/dist/components/Card/Card.d.ts +1 -1
  26. package/dist/components/Card/Card.js +4 -4
  27. package/dist/components/Card/index.d.ts +1 -1
  28. package/dist/components/Card/index.js +1 -1
  29. package/dist/components/Chart/Chart.d.ts +3 -0
  30. package/dist/components/Chart/Chart.js +123 -0
  31. package/dist/components/Chart/Chart.module.css +159 -0
  32. package/dist/components/Chart/index.d.ts +1 -0
  33. package/dist/components/Chart/index.js +1 -0
  34. package/dist/components/Chart/renderers.d.ts +23 -0
  35. package/dist/components/Chart/renderers.js +229 -0
  36. package/dist/components/Chart/types.d.ts +63 -0
  37. package/dist/components/Chart/types.js +1 -0
  38. package/dist/components/Checkbox/Checkbox.js +3 -2
  39. package/dist/components/Checkbox/index.d.ts +1 -1
  40. package/dist/components/Checkbox/index.js +1 -1
  41. package/dist/components/Drawer/Drawer.js +9 -6
  42. package/dist/components/Drawer/index.d.ts +1 -1
  43. package/dist/components/Drawer/index.js +1 -1
  44. package/dist/components/Dropdown/Dropdown.d.ts +2 -2
  45. package/dist/components/Dropdown/Dropdown.js +9 -9
  46. package/dist/components/Dropdown/index.d.ts +1 -1
  47. package/dist/components/Dropdown/index.js +1 -1
  48. package/dist/components/FileUpload/FileUpload.js +51 -35
  49. package/dist/components/FileUpload/index.d.ts +1 -1
  50. package/dist/components/Form/Form.d.ts +2 -2
  51. package/dist/components/Form/Form.js +8 -8
  52. package/dist/components/Form/index.d.ts +1 -1
  53. package/dist/components/Form/index.js +1 -1
  54. package/dist/components/Icon/index.d.ts +1 -1
  55. package/dist/components/Icon/index.js +14 -14
  56. package/dist/components/Image/Image.js +33 -23
  57. package/dist/components/Input/Input.js +8 -5
  58. package/dist/components/Input/index.d.ts +1 -1
  59. package/dist/components/Input/index.js +1 -1
  60. package/dist/components/Label/Label.d.ts +1 -1
  61. package/dist/components/Label/Label.js +3 -3
  62. package/dist/components/Label/index.d.ts +1 -1
  63. package/dist/components/Label/index.js +1 -1
  64. package/dist/components/Layout/Layout.js +3 -2
  65. package/dist/components/Layout/index.d.ts +1 -1
  66. package/dist/components/Layout/index.js +1 -1
  67. package/dist/components/Link/Link.js +5 -4
  68. package/dist/components/Link/index.d.ts +1 -1
  69. package/dist/components/Link/index.js +1 -1
  70. package/dist/components/Modal/Modal.js +13 -11
  71. package/dist/components/Modal/index.d.ts +1 -1
  72. package/dist/components/Modal/index.js +1 -1
  73. package/dist/components/Page/Page.d.ts +3 -3
  74. package/dist/components/Page/Page.js +4 -4
  75. package/dist/components/Page/index.d.ts +1 -1
  76. package/dist/components/Page/index.js +1 -1
  77. package/dist/components/Pagination/Pagination.d.ts +1 -1
  78. package/dist/components/Pagination/Pagination.js +17 -15
  79. package/dist/components/Pagination/index.d.ts +1 -1
  80. package/dist/components/Pagination/index.js +1 -1
  81. package/dist/components/Popover/Popover.js +7 -4
  82. package/dist/components/Popover/index.d.ts +1 -1
  83. package/dist/components/Popover/index.js +1 -1
  84. package/dist/components/ProgressBar/ProgressBar.js +3 -3
  85. package/dist/components/ProgressBar/index.d.ts +1 -1
  86. package/dist/components/ProgressBar/index.js +1 -1
  87. package/dist/components/RadioGroup/RadioGroup.d.ts +3 -3
  88. package/dist/components/RadioGroup/RadioGroup.js +12 -11
  89. package/dist/components/RadioGroup/index.d.ts +1 -1
  90. package/dist/components/RadioGroup/index.js +1 -1
  91. package/dist/components/Select/Select.js +9 -9
  92. package/dist/components/Select/index.d.ts +1 -1
  93. package/dist/components/Select/index.js +1 -1
  94. package/dist/components/Sheet/Sheet.js +9 -6
  95. package/dist/components/Sheet/index.d.ts +1 -1
  96. package/dist/components/Sheet/index.js +1 -1
  97. package/dist/components/Skeleton/Skeleton.d.ts +2 -2
  98. package/dist/components/Skeleton/Skeleton.js +5 -5
  99. package/dist/components/Skeleton/index.d.ts +1 -1
  100. package/dist/components/Skeleton/index.js +1 -1
  101. package/dist/components/Slat/Slat.js +5 -5
  102. package/dist/components/Slat/index.d.ts +1 -1
  103. package/dist/components/Slider/Slider.js +7 -5
  104. package/dist/components/Slider/index.d.ts +1 -1
  105. package/dist/components/Slider/index.js +1 -1
  106. package/dist/components/Spinner/Spinner.d.ts +3 -3
  107. package/dist/components/Spinner/Spinner.js +6 -6
  108. package/dist/components/Spinner/index.d.ts +1 -1
  109. package/dist/components/Spinner/index.js +1 -1
  110. package/dist/components/SplitButton/SplitButton.js +4 -4
  111. package/dist/components/SplitButton/index.d.ts +1 -1
  112. package/dist/components/SplitButton/index.js +1 -1
  113. package/dist/components/Switch/Switch.d.ts +1 -1
  114. package/dist/components/Switch/Switch.js +8 -7
  115. package/dist/components/Switch/index.d.ts +1 -1
  116. package/dist/components/Switch/index.js +1 -1
  117. package/dist/components/Table/Table.js +12 -12
  118. package/dist/components/Table/index.d.ts +1 -1
  119. package/dist/components/Table/index.js +1 -1
  120. package/dist/components/Tabs/Tabs.js +11 -8
  121. package/dist/components/Tabs/index.d.ts +1 -1
  122. package/dist/components/Tabs/index.js +1 -1
  123. package/dist/components/Text/Text.d.ts +6 -6
  124. package/dist/components/Text/Text.js +11 -6
  125. package/dist/components/Text/index.d.ts +1 -1
  126. package/dist/components/Text/index.js +1 -1
  127. package/dist/components/Textarea/Textarea.js +4 -3
  128. package/dist/components/Textarea/index.d.ts +1 -1
  129. package/dist/components/Textarea/index.js +1 -1
  130. package/dist/components/Toast/Toast.d.ts +2 -2
  131. package/dist/components/Toast/Toast.js +18 -17
  132. package/dist/components/Toast/index.d.ts +1 -1
  133. package/dist/components/Toast/index.js +1 -1
  134. package/dist/components/Tooltip/Tooltip.d.ts +3 -3
  135. package/dist/components/Tooltip/Tooltip.js +9 -8
  136. package/dist/components/Tooltip/index.d.ts +1 -1
  137. package/dist/components/Tooltip/index.js +1 -1
  138. package/dist/index.d.ts +20 -19
  139. package/dist/index.js +20 -19
  140. package/dist/styles/themes/ThemeProvider.d.ts +3 -3
  141. package/dist/styles/themes/ThemeProvider.js +7 -7
  142. package/dist/styles/themes/definitions.js +1 -1
  143. package/dist/styles/themes/index.d.ts +2 -2
  144. package/dist/styles/themes/index.js +2 -2
  145. package/dist/tsconfig.build.tsbuildinfo +1 -1
  146. package/dist/vitest.setup.d.ts +1 -1
  147. package/dist/vitest.setup.js +1 -1
  148. package/package.json +31 -2
@@ -1,7 +1,7 @@
1
- import React from 'react';
2
- import './styles/globals.scss';
3
- import { ThemeKey } from './styles/themes';
4
- export declare function DesignSystemProvider({ children, initialTheme, withBody, className, fontClassName }: {
1
+ import "./styles/globals.scss";
2
+ import React from "react";
3
+ import { ThemeKey } from "./styles/themes";
4
+ export declare function DesignSystemProvider({ children, initialTheme, withBody, className, fontClassName, }: {
5
5
  children: React.ReactNode;
6
6
  initialTheme?: ThemeKey;
7
7
  withBody?: boolean;
@@ -1,12 +1,12 @@
1
- 'use client';
1
+ "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import './styles/globals.css';
4
- import { ThemeProvider } from './styles/themes/index.js';
5
- export function DesignSystemProvider({ children, initialTheme = 'default', withBody = false, className = '', fontClassName = '' }) {
3
+ import "./styles/globals.css";
4
+ import { ThemeProvider } from "./styles/themes/index.js";
5
+ export function DesignSystemProvider({ children, initialTheme = "default", withBody = false, className = "", fontClassName = "", }) {
6
6
  const content = (_jsx(ThemeProvider, { initialTheme: initialTheme, children: children }));
7
7
  const combinedClassName = `${fontClassName} ${className}`.trim();
8
8
  if (withBody) {
9
- return (_jsx("body", { className: combinedClassName, children: content }));
9
+ return _jsx("body", { className: combinedClassName, children: content });
10
10
  }
11
- return (_jsx("div", { className: combinedClassName, style: { display: 'contents' }, children: content }));
11
+ return (_jsx("div", { className: combinedClassName, style: { display: "contents" }, children: content }));
12
12
  }
@@ -2,23 +2,24 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import clsx from "clsx";
4
4
  import { ChevronDown } from "lucide-react";
5
- import { Stack } from "../Layout/Layout.js";
5
+ import React, { useState } from "react";
6
6
  import { Button } from "../Button/Button.js";
7
+ import { Stack } from "../Layout/Layout.js";
7
8
  import { Text } from "../Text/Text.js";
8
9
  import styles from "./Accordion.module.css";
9
- import React, { useState } from "react";
10
10
  const AccordionContext = React.createContext(null);
11
11
  export function AccordionItem({ value, trigger, children, className, }) {
12
12
  const context = React.useContext(AccordionContext);
13
- if (!context)
13
+ if (!context) {
14
14
  throw new Error("AccordionItem must be used within Accordion");
15
+ }
15
16
  const reactId = React.useId();
16
17
  const triggerId = `accordion-trigger-${reactId}`;
17
18
  const contentId = `accordion-content-${reactId}`;
18
19
  const isOpen = Array.isArray(context.value)
19
20
  ? context.value.includes(value)
20
21
  : context.value === value;
21
- return (_jsxs("div", { className: clsx(styles.item, isOpen && styles.isOpen, className), children: [_jsx(Text, { variant: "h3", className: styles.header, children: _jsxs(Button, { id: triggerId, variant: "ghost", className: styles.trigger, onClick: () => context.onToggle(value), "aria-expanded": isOpen, "aria-controls": contentId, children: [trigger, _jsx(ChevronDown, { size: 20, strokeWidth: 2.5, className: styles.icon })] }) }), _jsx("div", { id: contentId, className: styles.contentWrapper, "aria-hidden": !isOpen, role: "region", "aria-labelledby": triggerId, children: _jsx("div", { className: styles.contentBody, children: children }) })] }));
22
+ return (_jsxs("div", { className: clsx(styles.item, isOpen && styles.isOpen, className), children: [_jsx(Text, { className: styles.header, variant: "h3", children: _jsxs(Button, { "aria-controls": contentId, "aria-expanded": isOpen, className: styles.trigger, id: triggerId, variant: "ghost", onClick: () => context.onToggle(value), children: [trigger, _jsx(ChevronDown, { className: styles.icon, size: 20, strokeWidth: 2.5 })] }) }), _jsx("div", { "aria-hidden": !isOpen, "aria-labelledby": triggerId, className: styles.contentWrapper, id: contentId, role: "region", children: _jsx("div", { className: styles.contentBody, children: children }) })] }));
22
23
  }
23
24
  export function Accordion({ type = "single", children, defaultValue, value: controlledValue, onValueChange, className, }) {
24
25
  const [internalValue, setInternalValue] = useState(defaultValue || (type === "multiple" ? [] : ""));
@@ -40,5 +41,5 @@ export function Accordion({ type = "single", children, defaultValue, value: cont
40
41
  }
41
42
  onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue);
42
43
  };
43
- return (_jsx(AccordionContext.Provider, { value: { value: currentValue, onToggle: handleToggle, type }, children: _jsx(Stack, { gap: 0, className: clsx(styles.root, className), children: children }) }));
44
+ return (_jsx(AccordionContext.Provider, { value: { value: currentValue, onToggle: handleToggle, type }, children: _jsx(Stack, { className: clsx(styles.root, className), gap: 0, children: children }) }));
44
45
  }
@@ -1 +1 @@
1
- export { Accordion, AccordionItem } from './Accordion';
1
+ export { Accordion, AccordionItem } from "./Accordion";
@@ -1 +1 @@
1
- export { Accordion, AccordionItem } from './Accordion.js';
1
+ export { Accordion, AccordionItem } from "./Accordion.js";
@@ -11,12 +11,12 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { Text } from "../Text/Text.js";
15
- import { Flex } from "../Layout/Layout.js";
16
- import { ChevronRight } from "lucide-react";
17
14
  import clsx from "clsx";
15
+ import { ChevronRight } from "lucide-react";
16
+ import { Flex } from "../Layout/Layout.js";
17
+ import { Text } from "../Text/Text.js";
18
18
  import styles from "./ActionRow.module.css";
19
19
  export function ActionRow(_a) {
20
20
  var { icon, title, description, onClick, className } = _a, props = __rest(_a, ["icon", "title", "description", "onClick", "className"]);
21
- return (_jsxs(Flex, Object.assign({ align: "center", gap: 6, onClick: onClick, className: clsx(styles.actionRow, className) }, props, { children: [_jsx("div", { className: styles.iconWrapper, children: icon }), _jsxs(Flex, { direction: "column", gap: 1, style: { flex: 1 }, children: [_jsx(Text, { variant: "h6", weight: "bold", children: title }), description && (_jsx(Text, { color: "muted", variant: "small", children: description }))] }), _jsx(ChevronRight, { size: 20, strokeWidth: 2.5, style: { color: "var(--muted-foreground)" } })] })));
21
+ return (_jsxs(Flex, Object.assign({ align: "center", className: clsx(styles.actionRow, className), gap: 6, onClick: onClick }, props, { children: [_jsx("div", { className: styles.iconWrapper, children: icon }), _jsxs(Flex, { direction: "column", gap: 1, style: { flex: 1 }, children: [_jsx(Text, { variant: "h6", weight: "bold", children: title }), description && (_jsx(Text, { color: "muted", variant: "small", children: description }))] }), _jsx(ChevronRight, { size: 20, strokeWidth: 2.5, style: { color: "var(--muted-foreground)" } })] })));
22
22
  }
@@ -1 +1 @@
1
- export * from './ActionRow';
1
+ export * from "./ActionRow";
@@ -1 +1 @@
1
- export * from './ActionRow.js';
1
+ export * from "./ActionRow.js";
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- export type AlertVariant = 'info' | 'success' | 'warning' | 'error';
1
+ import React from "react";
2
+ export type AlertVariant = "info" | "success" | "warning" | "error";
3
3
  interface AlertProps {
4
4
  variant?: AlertVariant;
5
5
  title: string;
@@ -7,5 +7,5 @@ interface AlertProps {
7
7
  icon?: React.ReactNode;
8
8
  className?: string;
9
9
  }
10
- export declare function Alert({ variant, title, description, icon, className }: AlertProps): import("react/jsx-runtime").JSX.Element;
10
+ export declare function Alert({ variant, title, description, icon, className, }: AlertProps): import("react/jsx-runtime").JSX.Element;
11
11
  export {};
@@ -1,15 +1,15 @@
1
- 'use client';
1
+ "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import clsx from 'clsx';
4
- import { AlertCircle, CheckCircle, Info, XCircle } from 'lucide-react';
5
- import styles from './Alert.module.css';
3
+ import clsx from "clsx";
4
+ import { AlertCircle, CheckCircle, Info, XCircle } from "lucide-react";
5
+ import styles from "./Alert.module.css";
6
6
  const icons = {
7
7
  info: Info,
8
8
  success: CheckCircle,
9
9
  warning: AlertCircle,
10
10
  error: XCircle,
11
11
  };
12
- export function Alert({ variant = 'info', title, description, icon, className }) {
12
+ export function Alert({ variant = "info", title, description, icon, className, }) {
13
13
  const IconComponent = icons[variant];
14
14
  return (_jsxs("div", { className: clsx(styles.alert, styles[variant], className), role: "alert", children: [_jsx("div", { className: clsx(styles.iconWrapper, styles[variant]), children: icon || _jsx(IconComponent, { size: 20, strokeWidth: 2.5 }) }), _jsxs("div", { className: styles.content, children: [_jsx("h5", { className: styles.title, children: title }), description && _jsx("p", { className: styles.description, children: description })] })] }));
15
15
  }
@@ -1 +1 @@
1
- export { Alert, type AlertVariant } from './Alert';
1
+ export { Alert, type AlertVariant } from "./Alert";
@@ -1 +1 @@
1
- export { Alert } from './Alert.js';
1
+ export { Alert } from "./Alert.js";
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useState } from "react";
4
3
  import clsx from "clsx";
5
- import styles from "./Avatar.module.css";
4
+ import { useState } from "react";
6
5
  import { Image } from "../Image/Image.js";
6
+ import styles from "./Avatar.module.css";
7
7
  export function Avatar({ src, alt = "Avatar", fallback, size = "md", shape = "square", className, }) {
8
8
  const [hasError, setHasError] = useState(false);
9
- return (_jsx("div", { className: clsx(styles.avatar, styles[size], styles[shape], className), children: src && !hasError ? (_jsx(Image, { src: src, alt: alt, className: styles.image, onError: () => setHasError(true), fit: "cover", rounded: false })) : (_jsx("span", { className: clsx(styles.fallback, styles[size]), children: typeof fallback === "string" ? fallback.slice(0, 2) : fallback })) }));
9
+ return (_jsx("div", { className: clsx(styles.avatar, styles[size], styles[shape], className), children: src && !hasError ? (_jsx(Image, { alt: alt, className: styles.image, fit: "cover", rounded: false, src: src, onError: () => setHasError(true) })) : (_jsx("span", { className: clsx(styles.fallback, styles[size]), children: typeof fallback === "string" ? fallback.slice(0, 2) : fallback })) }));
10
10
  }
@@ -1 +1 @@
1
- export { Avatar, type AvatarSize, type AvatarShape } from './Avatar';
1
+ export { Avatar, type AvatarShape, type AvatarSize } from "./Avatar";
@@ -1 +1 @@
1
- export { Avatar } from './Avatar.js';
1
+ export { Avatar } from "./Avatar.js";
@@ -1 +1 @@
1
- export * from './Badge';
1
+ export * from "./Badge";
@@ -1 +1 @@
1
- export * from './Badge.js';
1
+ export * from "./Badge.js";
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  interface BreadcrumbsProps {
3
3
  children: React.ReactNode;
4
4
  className?: string;
@@ -9,5 +9,5 @@ interface BreadcrumbItemProps {
9
9
  isCurrent?: boolean;
10
10
  children: React.ReactNode;
11
11
  }
12
- export declare function BreadcrumbItem({ href, isCurrent, children }: BreadcrumbItemProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function BreadcrumbItem({ href, isCurrent, children, }: BreadcrumbItemProps): import("react/jsx-runtime").JSX.Element;
13
13
  export {};
@@ -1,14 +1,14 @@
1
- 'use client';
1
+ "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import clsx from 'clsx';
4
- import { Link } from '../Link/Link.js';
5
- import styles from './Breadcrumbs.module.css';
3
+ import clsx from "clsx";
4
+ import { Link } from "../Link/Link.js";
5
+ import styles from "./Breadcrumbs.module.css";
6
6
  export function Breadcrumbs({ children, className }) {
7
7
  return (_jsx("nav", { "aria-label": "breadcrumb", className: clsx(styles.nav, className), children: _jsx("ol", { className: styles.list, children: children }) }));
8
8
  }
9
- export function BreadcrumbItem({ href, isCurrent, children }) {
9
+ export function BreadcrumbItem({ href, isCurrent, children, }) {
10
10
  if (isCurrent) {
11
- return (_jsx("li", { className: styles.li, "aria-current": "page", children: _jsx("span", { className: styles.currentPage, children: children }) }));
11
+ return (_jsx("li", { "aria-current": "page", className: styles.li, children: _jsx("span", { className: styles.currentPage, children: children }) }));
12
12
  }
13
- return (_jsx("li", { className: styles.li, children: href ? (_jsx(Link, { href: href, variant: "default", style: { fontSize: 'inherit' }, children: children })) : (_jsx("span", { children: children })) }));
13
+ return (_jsx("li", { className: styles.li, children: href ? (_jsx(Link, { href: href, style: { fontSize: "inherit" }, variant: "default", children: children })) : (_jsx("span", { children: children })) }));
14
14
  }
@@ -1 +1 @@
1
- export { Breadcrumbs, BreadcrumbItem } from './Breadcrumbs';
1
+ export { BreadcrumbItem, Breadcrumbs } from "./Breadcrumbs";
@@ -1 +1 @@
1
- export { Breadcrumbs, BreadcrumbItem } from './Breadcrumbs.js';
1
+ export { BreadcrumbItem, Breadcrumbs } from "./Breadcrumbs.js";
@@ -17,5 +17,5 @@ import styles from "./Button.module.css";
17
17
  export function Button(_a) {
18
18
  var { children, variant = "primary", size = "md", loading = false, className, disabled } = _a, props = __rest(_a, ["children", "variant", "size", "loading", "className", "disabled"]);
19
19
  const buttonClass = clsx(styles.button, styles[variant], styles[size], loading && styles.loading, className);
20
- return (_jsxs("button", Object.assign({ className: buttonClass, disabled: disabled || loading }, props, { children: [loading && _jsx(Spinner, { size: "sm", className: styles.spinnerIcon }), children] })));
20
+ return (_jsxs("button", Object.assign({ className: buttonClass, disabled: disabled || loading }, props, { children: [loading && _jsx(Spinner, { className: styles.spinnerIcon, size: "sm" }), children] })));
21
21
  }
@@ -1 +1 @@
1
- export * from './Button';
1
+ export * from "./Button";
@@ -1 +1 @@
1
- export * from './Button.js';
1
+ export * from "./Button.js";
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
3
3
  children: React.ReactNode;
4
4
  as?: React.ElementType;
@@ -1,4 +1,4 @@
1
- 'use client';
1
+ "use client";
2
2
  var __rest = (this && this.__rest) || function (s, e) {
3
3
  var t = {};
4
4
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -11,9 +11,9 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import clsx from 'clsx';
15
- import styles from './Card.module.css';
14
+ import clsx from "clsx";
15
+ import styles from "./Card.module.css";
16
16
  export function Card(_a) {
17
- var { children, className, as: Component = 'div' } = _a, props = __rest(_a, ["children", "className", "as"]);
17
+ var { children, className, as: Component = "div" } = _a, props = __rest(_a, ["children", "className", "as"]);
18
18
  return (_jsx(Component, Object.assign({ className: clsx(styles.card, className) }, props, { children: children })));
19
19
  }
@@ -1 +1 @@
1
- export * from './Card';
1
+ export * from "./Card";
@@ -1 +1 @@
1
- export * from './Card.js';
1
+ export * from "./Card.js";
@@ -0,0 +1,3 @@
1
+ import { ChartProps } from "./types";
2
+ export type { ChartConfig, ChartProps, DrawContext } from "./types";
3
+ export declare function Chart<T>({ data, type, variant, x, y, d3Config, className, style, renderTooltip, flat, title, render, }: ChartProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,123 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import clsx from "clsx";
4
+ import { pointer, select } from "d3-selection";
5
+ import React, { useEffect, useMemo, useRef, useState } from "react";
6
+ import { Card } from "../Card/Card.js";
7
+ import { Stack } from "../Layout/Layout.js";
8
+ import { Text } from "../Text/Text.js";
9
+ import styles from "./Chart.module.css";
10
+ import { createScales, drawAxes, drawBars, drawGrid, drawLineArea, setupGradient, } from "./renderers.js";
11
+ export function Chart({ data, type = "line", variant = "default", x, y, d3Config, className, style, renderTooltip, flat, title, render, }) {
12
+ const svgRef = useRef(null);
13
+ const containerRef = useRef(null);
14
+ const gradientId = React.useId().replace(/:/g, "");
15
+ const [hoverState, setHoverState] = useState(null);
16
+ const config = useMemo(() => (Object.assign({ margin: {
17
+ top: 20,
18
+ right: 20,
19
+ bottom: (d3Config === null || d3Config === void 0 ? void 0 : d3Config.xAxisLabel) ? 60 : 50,
20
+ left: (d3Config === null || d3Config === void 0 ? void 0 : d3Config.yAxisLabel) ? 65 : 55,
21
+ }, curve: undefined, showAxes: true, grid: false, withGradient: type === "area", showDots: false }, d3Config)), [d3Config, type]);
22
+ const wrapperRef = useRef(null);
23
+ const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
24
+ useEffect(() => {
25
+ if (!wrapperRef.current)
26
+ return;
27
+ const resizeObserver = new ResizeObserver((entries) => {
28
+ const entry = entries[0];
29
+ if (entry) {
30
+ setDimensions({
31
+ width: entry.contentRect.width,
32
+ height: entry.contentRect.height,
33
+ });
34
+ }
35
+ });
36
+ resizeObserver.observe(wrapperRef.current);
37
+ return () => resizeObserver.disconnect();
38
+ }, []);
39
+ useEffect(() => {
40
+ if (!svgRef.current ||
41
+ !data.length ||
42
+ dimensions.width === 0 ||
43
+ dimensions.height === 0) {
44
+ return;
45
+ }
46
+ const { width, height } = dimensions;
47
+ const { margin } = config;
48
+ if (width <= 0 || height <= 0)
49
+ return;
50
+ const svg = select(svgRef.current);
51
+ svg.selectAll("*").remove();
52
+ const g = svg
53
+ .attr("width", width)
54
+ .attr("height", height)
55
+ .append("g")
56
+ .attr("transform", `translate(${margin.left},${margin.top})`);
57
+ if (config.withGradient) {
58
+ setupGradient(svg, gradientId);
59
+ }
60
+ const { xScale, yScale, innerWidth, innerHeight } = createScales(data, width, height, margin, x, y, type);
61
+ if (innerWidth <= 0 || innerHeight <= 0)
62
+ return;
63
+ if (config.grid) {
64
+ drawGrid(g, yScale, innerWidth, styles.grid);
65
+ }
66
+ if (config.showAxes) {
67
+ drawAxes(g, xScale, yScale, innerWidth, innerHeight, margin, config, styles);
68
+ }
69
+ const showTooltip = (event, data) => {
70
+ // Use pointer relative to the full SVG or the group?
71
+ // If we use d3.pointer(event, g.node()), we get coords relative to g (inside margin).
72
+ // hoverState requires coords relative to the .responsiveWrapper (div).
73
+ // .responsiveWrapper contains SVG.
74
+ // g is translate(margin.left, margin.top).
75
+ // So px + margin.left is correct relative to wrapper.
76
+ // pointer(event, g.node()) returns [x_in_g, y_in_g].
77
+ const [px, py] = select(svgRef.current).select("g").empty()
78
+ ? [0, 0]
79
+ : pointer(event, g.node());
80
+ setHoverState({
81
+ x: px + margin.left + 20,
82
+ y: py + margin.top, // margin.top is added because py is relative to g
83
+ data,
84
+ });
85
+ };
86
+ const hideTooltip = () => setHoverState(null);
87
+ const ctx = {
88
+ g,
89
+ data,
90
+ xScale,
91
+ yScale,
92
+ x,
93
+ y,
94
+ innerWidth,
95
+ innerHeight,
96
+ margin,
97
+ config,
98
+ styles,
99
+ gradientId,
100
+ setHoverState,
101
+ showTooltip,
102
+ hideTooltip,
103
+ type,
104
+ };
105
+ if (render) {
106
+ render(ctx);
107
+ }
108
+ else if (type === "bar") {
109
+ drawBars(ctx);
110
+ }
111
+ else {
112
+ drawLineArea(ctx);
113
+ }
114
+ }, [data, config, type, gradientId, dimensions, render]);
115
+ return (_jsx("div", { ref: containerRef, className: clsx(styles.chartContainer, variant === "solid" && styles.solid, flat && styles.flat, className), style: Object.assign({ minHeight: config.height || 400, minWidth: config.width || "100%" }, style), children: _jsxs(Stack, { gap: 4, style: { flex: 1, minHeight: 0 }, children: [title && (_jsx("div", { children: typeof title === "string" ? (_jsx(Text, { style: { margin: 0 }, variant: "h5", children: title })) : (title) })), _jsxs("div", { ref: wrapperRef, className: styles.responsiveWrapper, children: [_jsx("svg", { ref: svgRef, className: styles.chart, style: { display: "block", width: "100%", height: "100%" } }), hoverState && (_jsx("div", { className: styles.tooltipWrapper, style: {
116
+ transform: `translate(${hoverState.x}px, ${hoverState.y}px) translateY(-50%)`,
117
+ }, children: renderTooltip ? (renderTooltip(hoverState.data)) : (_jsxs(Card, { className: styles.tooltipCard, children: [_jsx("div", { style: { marginBottom: 4 }, children: _jsx(Text, { style: {
118
+ color: "var(--text-secondary)",
119
+ textTransform: "uppercase",
120
+ fontSize: "10px",
121
+ letterSpacing: "0.5px",
122
+ }, variant: "h6", children: x(hoverState.data) }) }), _jsx("div", { children: _jsx(Text, { style: { margin: 0 }, variant: "h4", children: y(hoverState.data) }) })] })) }))] })] }) }));
123
+ }
@@ -0,0 +1,159 @@
1
+ .chart {
2
+ width: 100%;
3
+ height: 100%;
4
+ position: relative;
5
+ overflow: visible;
6
+ }
7
+ .chart :global .domain {
8
+ stroke: var(--card-border);
9
+ stroke-width: var(--border-width);
10
+ }
11
+ .chart :global .domain.hideDomain {
12
+ stroke: none;
13
+ }
14
+ .chart :global .tick line {
15
+ stroke: var(--card-border);
16
+ stroke-width: var(--border-width);
17
+ opacity: 1;
18
+ }
19
+ .chart :global .tick text {
20
+ fill: var(--card-border);
21
+ font-size: 11px;
22
+ font-weight: 700;
23
+ text-transform: uppercase;
24
+ }
25
+
26
+ .grid :global(.tick) line {
27
+ stroke: var(--muted, #ddd);
28
+ stroke-opacity: 0.5;
29
+ }
30
+ .grid path {
31
+ display: none;
32
+ }
33
+
34
+ .path {
35
+ fill: none;
36
+ stroke: var(--primary);
37
+ stroke-width: calc(var(--border-width) * 1.5);
38
+ stroke-linecap: round;
39
+ stroke-linejoin: round;
40
+ }
41
+
42
+ .area {
43
+ fill: var(--primary);
44
+ stroke: none;
45
+ }
46
+
47
+ .bar {
48
+ fill: var(--primary);
49
+ stroke: var(--card-border);
50
+ stroke-width: var(--border-width);
51
+ stroke-linejoin: round;
52
+ transition: opacity 0.2s;
53
+ }
54
+ .bar:hover {
55
+ fill: var(--primary-hover);
56
+ opacity: 0.8;
57
+ }
58
+
59
+ .cursorLine {
60
+ stroke: var(--muted-foreground);
61
+ stroke-width: 2px;
62
+ stroke-dasharray: 4 4;
63
+ opacity: 0;
64
+ pointer-events: none;
65
+ }
66
+
67
+ .cursorPoint {
68
+ fill: var(--primary);
69
+ stroke: var(--border-strong, #000);
70
+ stroke-width: var(--border-width);
71
+ pointer-events: none;
72
+ }
73
+
74
+ .dot {
75
+ fill: var(--primary);
76
+ stroke: var(--border-strong);
77
+ stroke-width: var(--border-width);
78
+ transition: r 0.2s;
79
+ z-index: var(--z-overlay);
80
+ }
81
+ .dot:hover {
82
+ r: 8;
83
+ stroke-width: calc(var(--border-width) * 1.5);
84
+ }
85
+
86
+ .chartContainer {
87
+ position: relative;
88
+ background-color: var(--card-bg);
89
+ border: var(--border-width) solid var(--card-border);
90
+ border-radius: var(--radius);
91
+ box-shadow: var(--shadow-hard);
92
+ padding: 1rem;
93
+ overflow: visible;
94
+ display: flex;
95
+ flex-direction: column;
96
+ }
97
+ .chartContainer.flat {
98
+ box-shadow: none;
99
+ }
100
+ .chartContainer.solid {
101
+ --solid-bg: var(--primary);
102
+ --solid-fg: var(--primary-foreground);
103
+ background-color: var(--solid-bg);
104
+ color: var(--solid-fg);
105
+ border-color: var(--border-strong);
106
+ --text-primary: var(--solid-fg);
107
+ --muted-foreground: color-mix(in srgb, var(--solid-fg) 70%, transparent);
108
+ --muted: color-mix(in srgb, var(--solid-fg) 20%, transparent);
109
+ --background: var(--solid-bg);
110
+ --foreground: var(--solid-fg);
111
+ }
112
+ .chartContainer.solid > * {
113
+ --primary: var(--solid-fg);
114
+ --primary-hover: color-mix(in srgb, var(--solid-fg) 80%, transparent);
115
+ }
116
+ .chartContainer.solid :global(.tick) text {
117
+ fill: var(--solid-fg);
118
+ }
119
+ .chartContainer.solid :global(.domain),
120
+ .chartContainer.solid :global(.tick) line {
121
+ stroke: var(--solid-fg);
122
+ }
123
+ .chartContainer.solid .tooltipCard {
124
+ background-color: var(--solid-bg);
125
+ border-color: var(--solid-fg);
126
+ }
127
+
128
+ .responsiveWrapper {
129
+ width: 100%;
130
+ flex: 1;
131
+ height: auto;
132
+ min-height: 0;
133
+ position: relative;
134
+ overflow: visible;
135
+ }
136
+
137
+ .tooltipWrapper {
138
+ position: absolute;
139
+ top: 0;
140
+ left: 0;
141
+ pointer-events: none;
142
+ z-index: 20;
143
+ transform: translate(-50%, -120%);
144
+ transition: transform 0.1s ease-out;
145
+ }
146
+
147
+ .tooltipCard {
148
+ padding: 8px 12px;
149
+ font-size: 12px;
150
+ white-space: nowrap;
151
+ }
152
+
153
+ .axisLabel {
154
+ fill: var(--foreground);
155
+ font-size: 11px;
156
+ font-weight: 700;
157
+ text-transform: uppercase;
158
+ text-anchor: middle;
159
+ }
@@ -0,0 +1 @@
1
+ export * from "./Chart";
@@ -0,0 +1 @@
1
+ export * from "./Chart.js";
@@ -0,0 +1,23 @@
1
+ import * as d3Scale from "d3-scale";
2
+ import { ChartConfig, D3Selection, DrawContext, SVGSelection } from "./types";
3
+ export declare function createScales<T>(data: T[], width: number, height: number, margin: {
4
+ top: number;
5
+ right: number;
6
+ bottom: number;
7
+ left: number;
8
+ }, x: (d: T) => any, y: (d: T) => number, type?: "line" | "area" | "bar"): {
9
+ xScale: any;
10
+ yScale: d3Scale.ScaleLinear<number, number, never>;
11
+ innerWidth: number;
12
+ innerHeight: number;
13
+ };
14
+ export declare function setupGradient(svg: SVGSelection, gradientId: string): void;
15
+ export declare function drawGrid(g: D3Selection, yScale: any, innerWidth: number, className: string): void;
16
+ export declare function drawAxes(g: D3Selection, xScale: any, yScale: any, innerWidth: number, innerHeight: number, margin: {
17
+ top: number;
18
+ right: number;
19
+ bottom: number;
20
+ left: number;
21
+ }, config: ChartConfig, styles: Record<string, string>): void;
22
+ export declare function drawLineArea<T>({ g, data, xScale, yScale, x, y, innerWidth, innerHeight, config, styles, gradientId, setHoverState, margin, type, }: DrawContext<T>): void;
23
+ export declare function drawBars<T>({ g, data, xScale, yScale, x, y, innerHeight, styles, setHoverState, margin, }: DrawContext<T>): void;