@wavv/ui 2.2.2-alpha.6 → 2.2.2-alpha.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.
- package/build/components/BarChart.d.ts +1 -1
- package/build/components/BarChart.js +9 -5
- package/build/components/ChartHelpers.d.ts +6 -2
- package/build/components/ChartHelpers.js +8 -1
- package/build/components/LineChart.d.ts +1 -1
- package/build/components/LineChart.js +8 -4
- package/build/index.d.ts +1 -0
- package/build/index.js +2 -1
- package/build/utils/formatNumber.d.ts +8 -0
- package/build/utils/formatNumber.js +32 -0
- package/package.json +14 -15
|
@@ -25,7 +25,7 @@ type Props = {
|
|
|
25
25
|
/** The width of the Y axis */
|
|
26
26
|
yAxisWidth?: number;
|
|
27
27
|
} & ChartProps;
|
|
28
|
-
declare const BarChart: ({ data, legend, keys, stacked, barGap, barCategoryGap, barSize, maxBarSize, vertical, hideYLabels, hideXLabels, diagonalXLabels, maxXLabelLength, xAxisHeight, yAxisWidth, axisColor, tooltipLegendPostfix, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
declare const BarChart: ({ data, legend, keys, stacked, barGap, barCategoryGap, barSize, maxBarSize, vertical, hideYLabels, hideXLabels, diagonalXLabels, maxXLabelLength, xAxisHeight, yAxisWidth, axisColor, tooltipLegendPostfix, initialDimension, width, height, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
29
29
|
export declare const DiagonalAxisTick: ({ x, y, payload, maxXLabelLength, axisColor, }: {
|
|
30
30
|
x: number;
|
|
31
31
|
y: number;
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useTheme } from "@emotion/react";
|
|
3
3
|
import styled from "@emotion/styled";
|
|
4
|
-
import millify from "millify";
|
|
5
4
|
import { Bar, BarChart, CartesianGrid, Legend, ResponsiveContainer, XAxis, YAxis } from "recharts";
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { formatNumber } from "../utils/formatNumber.js";
|
|
6
|
+
import { ChartContainer, ChartStyles, LegendContent, Tooltip, getInitialDimension } from "./ChartHelpers.js";
|
|
7
|
+
const BarChart_BarChart = ({ data, legend, keys, stacked, barGap, barCategoryGap, barSize = 16, maxBarSize, vertical = false, hideYLabels, hideXLabels, diagonalXLabels, maxXLabelLength = 10, xAxisHeight = 22, yAxisWidth = 45, axisColor, tooltipLegendPostfix, initialDimension, width, height, ...rest })=>{
|
|
8
8
|
const { scale2 } = useTheme();
|
|
9
9
|
const xAxisTick = diagonalXLabels ? (args)=>DiagonalAxisTick({
|
|
10
10
|
...args,
|
|
11
11
|
maxXLabelLength,
|
|
12
12
|
axisColor
|
|
13
13
|
}) : {};
|
|
14
|
+
const initial = getInitialDimension(initialDimension, width, height);
|
|
14
15
|
return /*#__PURE__*/ jsxs(ChartContainer, {
|
|
16
|
+
width: width,
|
|
17
|
+
height: height,
|
|
15
18
|
...rest,
|
|
16
19
|
children: [
|
|
17
20
|
/*#__PURE__*/ jsx(ChartStyles, {}),
|
|
18
21
|
/*#__PURE__*/ jsx(ResponsiveContainer, {
|
|
19
22
|
width: "100%",
|
|
20
23
|
height: "100%",
|
|
24
|
+
initialDimension: initial,
|
|
21
25
|
children: /*#__PURE__*/ jsxs(BarChart, {
|
|
22
26
|
margin: {
|
|
23
27
|
top: 0,
|
|
@@ -41,7 +45,7 @@ const BarChart_BarChart = ({ data, legend, keys, stacked, barGap, barCategoryGap
|
|
|
41
45
|
/*#__PURE__*/ jsx(XAxis, {
|
|
42
46
|
stroke: axisColor || scale2,
|
|
43
47
|
tickMargin: 4,
|
|
44
|
-
tickFormatter: (value)=>vertical ?
|
|
48
|
+
tickFormatter: (value)=>vertical ? formatNumber(value) : value,
|
|
45
49
|
tick: hideXLabels ? false : xAxisTick,
|
|
46
50
|
height: hideXLabels ? 12 : xAxisHeight,
|
|
47
51
|
interval: diagonalXLabels ? 0 : void 0,
|
|
@@ -51,7 +55,7 @@ const BarChart_BarChart = ({ data, legend, keys, stacked, barGap, barCategoryGap
|
|
|
51
55
|
/*#__PURE__*/ jsx(YAxis, {
|
|
52
56
|
stroke: axisColor || scale2,
|
|
53
57
|
tickMargin: 4,
|
|
54
|
-
tickFormatter: (value)=>vertical ? value :
|
|
58
|
+
tickFormatter: (value)=>vertical ? value : formatNumber(value),
|
|
55
59
|
tick: hideYLabels ? false : {},
|
|
56
60
|
width: hideYLabels ? 5 : yAxisWidth,
|
|
57
61
|
dataKey: vertical ? 'name' : void 0,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LegendPayload, type TooltipContentProps } from 'recharts';
|
|
1
|
+
import { type LegendPayload, type TooltipContentProps, type ResponsiveContainerProps } from 'recharts';
|
|
2
2
|
import type { Attributes } from './typeDefs/elementTypes';
|
|
3
3
|
import type { Margin, MaxWidthHeight, WidthHeight } from './types';
|
|
4
4
|
type ChartData = {
|
|
@@ -23,7 +23,11 @@ export type ChartProps = {
|
|
|
23
23
|
axisColor?: string;
|
|
24
24
|
/** The postfix to display after the legend value in the tooltip */
|
|
25
25
|
tooltipLegendPostfix?: React.ReactNode;
|
|
26
|
-
} & Margin & WidthHeight & MaxWidthHeight & ElAttributes;
|
|
26
|
+
} & Pick<ResponsiveContainerProps, 'initialDimension'> & Margin & WidthHeight & MaxWidthHeight & ElAttributes;
|
|
27
|
+
type InitialDimension = ResponsiveContainerProps['initialDimension'];
|
|
28
|
+
type Width = WidthHeight['width'];
|
|
29
|
+
type Height = WidthHeight['height'];
|
|
30
|
+
export declare const getInitialDimension: (initialDimension: InitialDimension, width: Width, height: Height) => InitialDimension;
|
|
27
31
|
export declare const ChartStyles: () => import("react/jsx-runtime").JSX.Element;
|
|
28
32
|
export declare const ChartContainer: import("@emotion/styled").StyledComponent<{
|
|
29
33
|
theme?: import("@emotion/react").Theme;
|
|
@@ -5,6 +5,13 @@ import { Tooltip } from "recharts";
|
|
|
5
5
|
import { numberWithCommas } from "../utils/index.js";
|
|
6
6
|
import Dot from "./Dot.js";
|
|
7
7
|
import { marginProps } from "./helpers/styledProps.js";
|
|
8
|
+
const getInitialDimension = (initialDimension, width, height)=>{
|
|
9
|
+
if (initialDimension) return initialDimension;
|
|
10
|
+
if ('number' == typeof width && 'number' == typeof height) return {
|
|
11
|
+
width,
|
|
12
|
+
height
|
|
13
|
+
};
|
|
14
|
+
};
|
|
8
15
|
const ChartStyles = ()=>/*#__PURE__*/ jsx(Global, {
|
|
9
16
|
styles: {
|
|
10
17
|
'.recharts-cartesian-grid-vertical line:first-of-type': {
|
|
@@ -118,4 +125,4 @@ const TooltipLabel = styled.div(({ theme })=>({
|
|
|
118
125
|
color: theme.tooltip.color.subtext,
|
|
119
126
|
marginBottom: 4
|
|
120
127
|
}));
|
|
121
|
-
export { ChartContainer, ChartStyles, LegendContent, ChartHelpers_Tooltip as Tooltip, TooltipContent };
|
|
128
|
+
export { ChartContainer, ChartStyles, LegendContent, ChartHelpers_Tooltip as Tooltip, TooltipContent, getInitialDimension };
|
|
@@ -2,5 +2,5 @@ import { type ChartProps } from './ChartHelpers';
|
|
|
2
2
|
type Props = {
|
|
3
3
|
enableLegendToggle?: boolean;
|
|
4
4
|
} & ChartProps;
|
|
5
|
-
declare const LineChart: ({ data, legend, keys, enableLegendToggle, axisColor, tooltipLegendPostfix, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
5
|
+
declare const LineChart: ({ data, legend, keys, enableLegendToggle, axisColor, tooltipLegendPostfix, initialDimension, width, height, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
export default LineChart;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useTheme } from "@emotion/react";
|
|
3
|
-
import millify from "millify";
|
|
4
3
|
import { useState } from "react";
|
|
5
4
|
import { CartesianGrid, Legend, Line, LineChart, ResponsiveContainer, XAxis, YAxis } from "recharts";
|
|
6
|
-
import {
|
|
7
|
-
|
|
5
|
+
import { formatNumber } from "../utils/formatNumber.js";
|
|
6
|
+
import { ChartContainer, ChartStyles, LegendContent, Tooltip, getInitialDimension } from "./ChartHelpers.js";
|
|
7
|
+
const LineChart_LineChart = ({ data, legend, keys, enableLegendToggle, axisColor, tooltipLegendPostfix, initialDimension, width, height, ...rest })=>{
|
|
8
8
|
const [lines, setLines] = useState(keys);
|
|
9
9
|
const { scale2 } = useTheme();
|
|
10
10
|
const handleLineToggle = (item)=>{
|
|
@@ -19,13 +19,17 @@ const LineChart_LineChart = ({ data, legend, keys, enableLegendToggle, axisColor
|
|
|
19
19
|
setLines((prevLines)=>toggleLines(prevLines));
|
|
20
20
|
};
|
|
21
21
|
const toggleData = enableLegendToggle && keys.length > 1 ? handleLineToggle : void 0;
|
|
22
|
+
const initial = getInitialDimension(initialDimension, width, height);
|
|
22
23
|
return /*#__PURE__*/ jsxs(ChartContainer, {
|
|
24
|
+
width: width,
|
|
25
|
+
height: height,
|
|
23
26
|
...rest,
|
|
24
27
|
children: [
|
|
25
28
|
/*#__PURE__*/ jsx(ChartStyles, {}),
|
|
26
29
|
/*#__PURE__*/ jsx(ResponsiveContainer, {
|
|
27
30
|
width: "100%",
|
|
28
31
|
height: "100%",
|
|
32
|
+
initialDimension: initial,
|
|
29
33
|
children: /*#__PURE__*/ jsxs(LineChart, {
|
|
30
34
|
margin: {
|
|
31
35
|
top: 8,
|
|
@@ -48,7 +52,7 @@ const LineChart_LineChart = ({ data, legend, keys, enableLegendToggle, axisColor
|
|
|
48
52
|
/*#__PURE__*/ jsx(YAxis, {
|
|
49
53
|
stroke: axisColor || scale2,
|
|
50
54
|
tickMargin: 4,
|
|
51
|
-
tickFormatter: (value)=>
|
|
55
|
+
tickFormatter: (value)=>formatNumber(value)
|
|
52
56
|
}),
|
|
53
57
|
Tooltip({
|
|
54
58
|
legendPostfix: tooltipLegendPostfix
|
package/build/index.d.ts
CHANGED
|
@@ -85,5 +85,6 @@ export { default as useCopy } from './hooks/useCopy';
|
|
|
85
85
|
export { marginProps, paddingProps, positionProps, widthHeightProps } from './components/helpers/styledProps';
|
|
86
86
|
export { default as copyToClipboard } from './utils/copyToClipboard';
|
|
87
87
|
export { default as formatDate } from './utils/formatDate';
|
|
88
|
+
export { default as formatNumber } from './utils/formatNumber';
|
|
88
89
|
export { default as numberWithCommas } from './utils/numberWithCommas';
|
|
89
90
|
export { createEditorContent, editorContentToText } from './components/Editor';
|
package/build/index.js
CHANGED
|
@@ -75,5 +75,6 @@ import useCopy from "./hooks/useCopy.js";
|
|
|
75
75
|
import { marginProps, paddingProps, positionProps, widthHeightProps } from "./components/helpers/styledProps.js";
|
|
76
76
|
import copyToClipboard from "./utils/copyToClipboard.js";
|
|
77
77
|
import formatDate from "./utils/formatDate.js";
|
|
78
|
+
import formatNumber from "./utils/formatNumber.js";
|
|
78
79
|
import numberWithCommas from "./utils/numberWithCommas.js";
|
|
79
|
-
export { Accordion, Audio, BarChart, Button, Calendar, Checkbox, Code, ComboBox, CommandMenu, DatePicker, DateRangePicker, DateRangeSelect, DocTable, Dot, DraftEditor, Dropdown, DropdownMenu, DropdownSelect, Editor, Ellipsis, Form, Grid, Icon, ImageViewer, InlineCode, InlineInput, InputHelpers as InputUtils, Label, LineChart, Menu, Message, MessageHr, Modal, MultiSelect, NumberInput, Pagination, PhoneInput, PieChart, Popover, PortalScope, Progress, Radio, RangeCalendar, ResetStyles, ScrollbarStyles, SearchInput, Select, Slider, Spinner, Table, Tabs, Tag, TextArea, TextInput, TimeInput, ToastStyles, Toggle, ToggleButton, ToggleButtonGroup, Tooltip, TransferList, Tree, UnstyledButton, colors, copyToClipboard, createEditorContent, darkScale, editorContentToText, formatDate, lightScale, marginProps, numberWithCommas, paddingProps, positionProps, theme, themeClasses, themeOptions, useConfirm, useCopy, useElementObserver, useEventListener, useOnClickOutside, usePrevious, useSelectAll, useWindowSize, widthHeightProps };
|
|
80
|
+
export { Accordion, Audio, BarChart, Button, Calendar, Checkbox, Code, ComboBox, CommandMenu, DatePicker, DateRangePicker, DateRangeSelect, DocTable, Dot, DraftEditor, Dropdown, DropdownMenu, DropdownSelect, Editor, Ellipsis, Form, Grid, Icon, ImageViewer, InlineCode, InlineInput, InputHelpers as InputUtils, Label, LineChart, Menu, Message, MessageHr, Modal, MultiSelect, NumberInput, Pagination, PhoneInput, PieChart, Popover, PortalScope, Progress, Radio, RangeCalendar, ResetStyles, ScrollbarStyles, SearchInput, Select, Slider, Spinner, Table, Tabs, Tag, TextArea, TextInput, TimeInput, ToastStyles, Toggle, ToggleButton, ToggleButtonGroup, Tooltip, TransferList, Tree, UnstyledButton, colors, copyToClipboard, createEditorContent, darkScale, editorContentToText, formatDate, formatNumber, lightScale, marginProps, numberWithCommas, paddingProps, positionProps, theme, themeClasses, themeOptions, useConfirm, useCopy, useElementObserver, useEventListener, useOnClickOutside, usePrevious, useSelectAll, useWindowSize, widthHeightProps };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a number with thousand separators and unit suffixes (K, M, B, T)
|
|
3
|
+
* @param value - The number to format
|
|
4
|
+
* @param decimals - Number of decimal places (default: 1)
|
|
5
|
+
* @returns Formatted number string (e.g., "1.2K", "500M")
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatNumber: (value: number, decimals?: number) => string;
|
|
8
|
+
export default formatNumber;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const formatNumber_formatNumber = (value, decimals = 1)=>{
|
|
2
|
+
if (0 === value) return '0';
|
|
3
|
+
if (!Number.isFinite(value)) return String(value);
|
|
4
|
+
const absValue = Math.abs(value);
|
|
5
|
+
const sign = value < 0 ? '-' : '';
|
|
6
|
+
const units = [
|
|
7
|
+
{
|
|
8
|
+
threshold: 1e12,
|
|
9
|
+
suffix: 'T'
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
threshold: 1e9,
|
|
13
|
+
suffix: 'B'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
threshold: 1e6,
|
|
17
|
+
suffix: 'M'
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
threshold: 1e3,
|
|
21
|
+
suffix: 'K'
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
for (const unit of units)if (absValue >= unit.threshold) {
|
|
25
|
+
const formatted = (absValue / unit.threshold).toFixed(decimals);
|
|
26
|
+
const trimmed = formatted.replace(/\.?0+$/, '');
|
|
27
|
+
return `${sign}${trimmed}${unit.suffix}`;
|
|
28
|
+
}
|
|
29
|
+
return String(value);
|
|
30
|
+
};
|
|
31
|
+
const formatNumber = formatNumber_formatNumber;
|
|
32
|
+
export { formatNumber as default, formatNumber_formatNumber as formatNumber };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wavv/ui",
|
|
3
|
-
"version": "2.2.2-alpha.
|
|
3
|
+
"version": "2.2.2-alpha.8",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -31,23 +31,22 @@
|
|
|
31
31
|
"@emotion/styled": "^11.14.1",
|
|
32
32
|
"@internationalized/date": "3.10.0",
|
|
33
33
|
"@react-hook/resize-observer": "^2.0.2",
|
|
34
|
-
"@tiptap/core": "^3.
|
|
35
|
-
"@tiptap/extension-character-count": "^3.
|
|
36
|
-
"@tiptap/extension-highlight": "^3.
|
|
37
|
-
"@tiptap/extension-placeholder": "^3.
|
|
38
|
-
"@tiptap/extension-task-item": "^3.
|
|
39
|
-
"@tiptap/extension-task-list": "^3.
|
|
40
|
-
"@tiptap/markdown": "^3.
|
|
41
|
-
"@tiptap/pm": "^3.
|
|
42
|
-
"@tiptap/react": "^3.
|
|
43
|
-
"@tiptap/starter-kit": "^3.
|
|
34
|
+
"@tiptap/core": "^3.9.1",
|
|
35
|
+
"@tiptap/extension-character-count": "^3.9.1",
|
|
36
|
+
"@tiptap/extension-highlight": "^3.9.1",
|
|
37
|
+
"@tiptap/extension-placeholder": "^3.9.1",
|
|
38
|
+
"@tiptap/extension-task-item": "^3.9.1",
|
|
39
|
+
"@tiptap/extension-task-list": "^3.9.1",
|
|
40
|
+
"@tiptap/markdown": "^3.9.1",
|
|
41
|
+
"@tiptap/pm": "^3.9.1",
|
|
42
|
+
"@tiptap/react": "^3.9.1",
|
|
43
|
+
"@tiptap/starter-kit": "^3.9.1",
|
|
44
44
|
"cmdk": "^1.1.1",
|
|
45
45
|
"date-fns": "^4.1.0",
|
|
46
46
|
"draft-js": "^0.11.7",
|
|
47
47
|
"es-toolkit": "^1.41.0",
|
|
48
48
|
"libphonenumber-js": "^1.12.25",
|
|
49
49
|
"lucide-react": "^0.548.0",
|
|
50
|
-
"millify": "^6.1.0",
|
|
51
50
|
"polished": "^4.1.4",
|
|
52
51
|
"prism-react-renderer": "^2.4.1",
|
|
53
52
|
"react-aria": "3.44.0",
|
|
@@ -62,7 +61,7 @@
|
|
|
62
61
|
"@babel/core": "^7.28.5",
|
|
63
62
|
"@babel/preset-env": "^7.28.5",
|
|
64
63
|
"@babel/preset-typescript": "^7.28.5",
|
|
65
|
-
"@biomejs/biome": "2.3.
|
|
64
|
+
"@biomejs/biome": "2.3.2",
|
|
66
65
|
"@chromatic-com/storybook": "^4.1.1",
|
|
67
66
|
"@emotion/babel-plugin": "^11.13.5",
|
|
68
67
|
"@emotion/react": "^11.14.0",
|
|
@@ -87,7 +86,7 @@
|
|
|
87
86
|
"@types/draft-js": "^0.11.18",
|
|
88
87
|
"@types/jest": "^30.0.0",
|
|
89
88
|
"@types/ncp": "^2.0.8",
|
|
90
|
-
"@types/node": "^24.9.
|
|
89
|
+
"@types/node": "^24.9.2",
|
|
91
90
|
"@types/prompts": "^2.4.9",
|
|
92
91
|
"@types/randomcolor": "^0.5.9",
|
|
93
92
|
"@types/react": "^19.2.2",
|
|
@@ -99,7 +98,7 @@
|
|
|
99
98
|
"change-case": "^5.4.4",
|
|
100
99
|
"chromatic": "^13.3.2",
|
|
101
100
|
"jest": "^30.2.0",
|
|
102
|
-
"lefthook": "^2.0.
|
|
101
|
+
"lefthook": "^2.0.2",
|
|
103
102
|
"ncp": "^2.0.0",
|
|
104
103
|
"path": "^0.12.7",
|
|
105
104
|
"phone": "^3.1.67",
|