@kaio-xyz/design-system 1.1.83 → 1.1.85

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/dist/index.cjs.js CHANGED
@@ -692,6 +692,13 @@ var dateFormatOptions = {
692
692
  month: "2-digit",
693
693
  day: "2-digit"
694
694
  };
695
+ function commaSeparateNumber(val, digits) {
696
+ if (digits === void 0) { digits = 2; }
697
+ var numberFormatOptions = {
698
+ minimumFractionDigits: digits,
699
+ };
700
+ return Number(val).toLocaleString("en-US", numberFormatOptions);
701
+ }
695
702
  function getClientLocale() {
696
703
  var _a;
697
704
  if (!(typeof window !== "undefined"))
@@ -716,6 +723,39 @@ function formatDate(value, locale, format) {
716
723
  var date = value instanceof Date ? value : new Date(value);
717
724
  return date.toLocaleString(locale, format);
718
725
  }
726
+ function formatLargeNumber(input, decimalPlaces) {
727
+ if (decimalPlaces === void 0) { decimalPlaces = 2; }
728
+ try {
729
+ if (!input)
730
+ return input;
731
+ var number = Number(input);
732
+ if (isNaN(number)) {
733
+ return input;
734
+ }
735
+ // Determine the suffix and reduce the number accordingly
736
+ var suffix = "";
737
+ if (number >= 1e9) {
738
+ suffix = "B";
739
+ number /= 1e9;
740
+ }
741
+ else if (number >= 1e6) {
742
+ suffix = "M";
743
+ number /= 1e6;
744
+ // If the number is above 10,000, round to the nearest thousand
745
+ }
746
+ else if (number >= 1e4) {
747
+ suffix = "K";
748
+ number /= 1e3;
749
+ }
750
+ // Round the number to decimal places and add comma separation
751
+ return suffix
752
+ ? "".concat(commaSeparateNumber(number, 2)).concat(suffix)
753
+ : commaSeparateNumber(number, decimalPlaces);
754
+ }
755
+ catch (_a) {
756
+ return input;
757
+ }
758
+ }
719
759
  var formatNumber = function (amount, digits) {
720
760
  if (digits === void 0) { digits = 2; }
721
761
  return Number(amount).toLocaleString("en-US", {
@@ -783,26 +823,28 @@ var InvestmentGraph = function (_a) {
783
823
  case Timeframes.year: return filterByPeriod(12);
784
824
  }
785
825
  }, [timeFrame, filterByPeriod]);
826
+ var monthTicks = React.useMemo(function () {
827
+ if (!dataBasedOnPeriod || dataBasedOnPeriod.length === 0)
828
+ return [];
829
+ var seenMonths = [];
830
+ return dataBasedOnPeriod.reduce(function (ticks, point) {
831
+ var month = new Date(point.date).getMonth();
832
+ if (seenMonths.indexOf(month) === -1) {
833
+ seenMonths.push(month);
834
+ return __spreadArray(__spreadArray([], ticks, true), [point.date], false);
835
+ }
836
+ return ticks;
837
+ }, []);
838
+ }, [dataBasedOnPeriod]);
786
839
  var formatXAxis = function (timestamp) {
787
840
  var date = new Date(timestamp);
788
- var monthlyDates = dataBasedOnPeriod === null || dataBasedOnPeriod === void 0 ? void 0 : dataBasedOnPeriod.reduce(function (acc, curr) {
789
- var month = new Date(curr.date).getMonth();
790
- if (!acc[month])
791
- acc[month] = [];
792
- acc[month].push(curr.date);
793
- return acc;
794
- }, {});
795
- var month = date.getMonth();
796
- var isFirstInMonth = (monthlyDates === null || monthlyDates === void 0 ? void 0 : monthlyDates[month]) && monthlyDates[month][0] === timestamp;
797
- return isFirstInMonth
798
- ? ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][month]
799
- : "";
841
+ return ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date.getMonth()];
800
842
  };
801
843
  return (jsxRuntime.jsxs(Stack, { className: style$6.root, space: "m", children: [jsxRuntime.jsxs(Stack, { space: "none", children: [header && (jsxRuntime.jsx("div", { className: style$6.paddedWrapper, children: header })), jsxRuntime.jsx(Stack, { position: "horizontal-space", children: jsxRuntime.jsx("div", { className: clsx(style$6.timeframeSelector, style$6.paddedWrapper), children: periodOptions.map(function (p) {
802
844
  return jsxRuntime.jsx("button", { tabIndex: 0, onKeyDown: function (e) { return (isEnter(e) ? setTimeFrame(p) : null); }, className: style$6.timeFrameValue, "data-active": (timeFrame === null || timeFrame === void 0 ? void 0 : timeFrame.value) === p.value ? "true" : "false", onClick: function () { return setTimeFrame(p); }, children: p.label }, p.value);
803
845
  }) }) })] }), jsxRuntime.jsx(recharts.ResponsiveContainer, { width: "100%", height: "100%", minHeight: 500, children: jsxRuntime.jsxs(recharts.AreaChart, { width: 500, height: 300, data: dataBasedOnPeriod, children: [jsxRuntime.jsx("defs", { children: jsxRuntime.jsx("linearGradient", { id: "splitColor", x1: "0", y1: "0", x2: "0", y2: "1", children: hasPositiveAndNegativeValues
804
846
  ? (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("stop", { offset: off, stopColor: "var(--semantic-success)", stopOpacity: 1 }), jsxRuntime.jsx("stop", { offset: off, stopColor: "var(--semantic-error)", stopOpacity: 1 })] }))
805
- : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("stop", { offset: "5%", stopColor: "var(--primary-30)", stopOpacity: 0.8 }), jsxRuntime.jsx("stop", { offset: "95%", stopColor: "var(--neutral-90)", stopOpacity: 0 })] })) }) }), jsxRuntime.jsx(recharts.XAxis, { dataKey: "date", strokeWidth: 0, style: { fill: "var(--neutral-45)" }, tickFormatter: formatXAxis }), jsxRuntime.jsx(recharts.YAxis, { dataKey: "value", strokeWidth: 0, axisLine: false, tickLine: false, scale: "auto", domain: hasNegativeValues && hasPositiveValues ? ["auto", "auto"] : [dataMin, dataMax], tickCount: 6, tick: false, width: 10 }), jsxRuntime.jsx(recharts.Tooltip, { contentStyle: {
847
+ : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("stop", { offset: "5%", stopColor: "var(--primary-30)", stopOpacity: 0.8 }), jsxRuntime.jsx("stop", { offset: "95%", stopColor: "var(--neutral-90)", stopOpacity: 0 })] })) }) }), jsxRuntime.jsx(recharts.XAxis, { dataKey: "date", strokeWidth: 0, style: { fill: "var(--neutral-45)" }, tickFormatter: formatXAxis, ticks: monthTicks }), jsxRuntime.jsx(recharts.YAxis, { dataKey: "value", strokeWidth: 0, axisLine: false, tickLine: false, scale: "auto", domain: hasNegativeValues && hasPositiveValues ? ["auto", "auto"] : [dataMin, dataMax], tickCount: 6, tickFormatter: function (value) { return String(formatLargeNumber(value)); }, style: { fontSize: "var(--font-size-10-px)" } }), jsxRuntime.jsx(recharts.Tooltip, { contentStyle: {
806
848
  backgroundColor: "var(--neutral-90)",
807
849
  color: "var(--neutral-45)",
808
850
  borderRadius: "var(--radius-8-px)",