@ammarkhalidfarooq/dashboard-package 0.6.23 → 0.6.24

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.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import React, { Suspense, lazy, useState, useRef, useEffect, useMemo } from 'react';
2
2
  import { Box, Button, Menu, MenuItem, Grid, Card, CardContent, Typography, IconButton, ThemeProvider, CircularProgress, Avatar, LinearProgress, Stack, TableContainer, Table, TableHead, TableRow, TableCell, TableBody, Skeleton } from '@mui/material';
3
- import { MoreHoriz, TrendingUp, MoreVert, Check, InfoOutlined, Settings, Adjust, PaidOutlined, PeopleAltOutlined, FavoriteOutlined, PersonOutlined, IndeterminateCheckBoxOutlined, SearchOutlined, HighlightOff, NearMe, Email, NotInterested } from '@mui/icons-material';
3
+ import { MoreHoriz, TrendingDown, TrendingUp, MoreVert, Check, InfoOutlined, Settings, Adjust, PaidOutlined, PeopleAltOutlined, FavoriteOutlined, PersonOutlined, IndeterminateCheckBoxOutlined, SearchOutlined, HighlightOff, NearMe, Email, NotInterested } from '@mui/icons-material';
4
4
  import { createTheme, useTheme } from '@mui/material/styles';
5
5
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
6
  import Grid$1 from '@mui/material/Grid';
@@ -559,6 +559,51 @@ var RevenueChart = function RevenueChart(_ref) {
559
559
  }, "".concat(id, "-").concat(type, "-").concat(chartSeries.length));
560
560
  };
561
561
 
562
+ var TREND_UP_COLOR = "#22C55E";
563
+ var TREND_DOWN_COLOR = "#EF4444";
564
+ function getTrendDirection(valueOrText) {
565
+ var text = String(valueOrText !== null && valueOrText !== void 0 ? valueOrText : "").trim();
566
+ if (text.includes("▼")) return "down";
567
+ if (text.includes("▲")) return "up";
568
+ var match = text.match(/-?\d+(\.\d+)?/);
569
+ if (!match) return "neutral";
570
+ var n = Number(match[0]);
571
+ if (n < 0) return "down";
572
+ if (n > 0) return "up";
573
+ return "neutral";
574
+ }
575
+ function getTrendColor(valueOrText) {
576
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
577
+ _ref$up = _ref.up,
578
+ up = _ref$up === void 0 ? TREND_UP_COLOR : _ref$up,
579
+ _ref$down = _ref.down,
580
+ down = _ref$down === void 0 ? TREND_DOWN_COLOR : _ref$down,
581
+ _ref$neutral = _ref.neutral,
582
+ neutral = _ref$neutral === void 0 ? up : _ref$neutral;
583
+ var direction = getTrendDirection(valueOrText);
584
+ if (direction === "down") return down;
585
+ if (direction === "up") return up;
586
+ return neutral;
587
+ }
588
+ function getTrendArrow(valueOrText) {
589
+ var direction = getTrendDirection(valueOrText);
590
+ if (direction === "down") return "▼";
591
+ if (direction === "up") return "▲";
592
+ return "";
593
+ }
594
+ function formatNumber(num) {
595
+ if (num >= 1000000000) {
596
+ return (num / 1000000000).toFixed(1).replace(/\.0$/, "") + "B";
597
+ }
598
+ if (num >= 1000000) {
599
+ return (num / 1000000).toFixed(1).replace(/\.0$/, "") + "M";
600
+ }
601
+ if (num >= 1000) {
602
+ return (num / 1000).toFixed(1).replace(/\.0$/, "") + "K";
603
+ }
604
+ return (num !== null && num !== void 0 ? num : 0).toString();
605
+ }
606
+
562
607
  var RenderChartCard = function RenderChartCard(_ref) {
563
608
  var item = _ref.item,
564
609
  index = _ref.index,
@@ -581,6 +626,13 @@ var RenderChartCard = function RenderChartCard(_ref) {
581
626
  _ref$contentSx = _ref.contentSx,
582
627
  contentSx = _ref$contentSx === void 0 ? {} : _ref$contentSx;
583
628
  var daysLabel = "".concat(numberOfDays, " day").concat(numberOfDays === 1 ? "" : "s");
629
+ var trendText = item.trend || "18%";
630
+ var trendColor = getTrendColor(trendText, {
631
+ up: "#054835ff",
632
+ down: "#EF4444"
633
+ });
634
+ var trendArrow = getTrendArrow(trendText);
635
+ var trendBadgeBg = trendColor === "#EF4444" ? "#fee2e2" : "#8df3be9a";
584
636
  return /*#__PURE__*/jsx(Grid, {
585
637
  item: true,
586
638
  xs: 12,
@@ -651,17 +703,17 @@ var RenderChartCard = function RenderChartCard(_ref) {
651
703
  display: "flex",
652
704
  alignItems: "center",
653
705
  gap: 0.5,
654
- bgcolor: "#8df3be9a",
655
- color: "#054835ff",
706
+ bgcolor: trendBadgeBg,
707
+ color: trendColor,
656
708
  px: 1,
657
709
  py: 0.5,
658
710
  borderRadius: "100px",
659
711
  fontSize: "12px",
660
712
  fontWeight: 600
661
713
  },
662
- children: [/*#__PURE__*/jsx("span", {
663
- children: "\u25B2"
664
- }), item.trend || "18% vs last month"]
714
+ children: [trendArrow && /*#__PURE__*/jsx("span", {
715
+ children: trendArrow
716
+ }), trendText === "18%" && !item.trend ? "18% vs last month" : trendText]
665
717
  })]
666
718
  })]
667
719
  }) : /*#__PURE__*/jsxs(Box, {
@@ -1184,12 +1236,13 @@ var MetricCard$1 = function MetricCard(_ref) {
1184
1236
  avatarSx = _ref$avatarSx === void 0 ? {} : _ref$avatarSx;
1185
1237
  var captionText = String(caption !== null && caption !== void 0 ? caption : "");
1186
1238
  var isPercentCaption = captionText.includes("%");
1187
- var firstNumberMatch = captionText.match(/-?\d+(\.\d+)?/);
1188
- var trendValue = firstNumberMatch ? Number(firstNumberMatch[0]) : null;
1189
- var isNegativeTrend = isPercentCaption && trendValue !== null && trendValue < 0;
1190
- var isPositiveTrend = isPercentCaption && trendValue !== null && trendValue > 0;
1191
- var trendPrefix = isNegativeTrend ? "▼ " : isPositiveTrend ? "" : "";
1192
- var captionColor = captionText.includes("failed") ? "#4F46E5" : error || isNegativeTrend ? "#ef4444" : "#0B8F61";
1239
+ var trendDirection = isPercentCaption ? getTrendDirection(captionText) : "neutral";
1240
+ var hasTrendArrow = captionText.includes("▼") || captionText.includes("▲");
1241
+ var trendPrefix = hasTrendArrow || !isPercentCaption ? "" : trendDirection === "down" ? "▼ " : trendDirection === "up" ? "▲ " : "";
1242
+ var captionColor = captionText.includes("failed") ? "#4F46E5" : error ? "#ef4444" : isPercentCaption ? getTrendColor(captionText, {
1243
+ up: "#0B8F61",
1244
+ down: "#ef4444"
1245
+ }) : "#0B8F61";
1193
1246
  return /*#__PURE__*/jsxs(Box, {
1194
1247
  sx: _objectSpread2({
1195
1248
  bgcolor: "#fff",
@@ -1245,19 +1298,6 @@ var MetricCard$1 = function MetricCard(_ref) {
1245
1298
  });
1246
1299
  };
1247
1300
 
1248
- function formatNumber(num) {
1249
- if (num >= 1000000000) {
1250
- return (num / 1000000000).toFixed(1).replace(/\.0$/, "") + "B";
1251
- }
1252
- if (num >= 1000000) {
1253
- return (num / 1000000).toFixed(1).replace(/\.0$/, "") + "M";
1254
- }
1255
- if (num >= 1000) {
1256
- return (num / 1000).toFixed(1).replace(/\.0$/, "") + "K";
1257
- }
1258
- return (num !== null && num !== void 0 ? num : 0).toString();
1259
- }
1260
-
1261
1301
  var PURPLE = "#6363E6";
1262
1302
  var REPORT_COLORS = {
1263
1303
  purple: PURPLE};
@@ -3724,6 +3764,8 @@ var DonorMixCard = function DonorMixCard(_ref) {
3724
3764
  compact = _ref$compact === void 0 ? false : _ref$compact,
3725
3765
  _ref$sx = _ref.sx,
3726
3766
  sx = _ref$sx === void 0 ? {} : _ref$sx;
3767
+ var trendColor = getTrendColor(bottomSummaryTrend);
3768
+ var trendArrow = getTrendArrow(bottomSummaryTrend);
3727
3769
  var chartOptions = {
3728
3770
  chart: {
3729
3771
  type: "donut"
@@ -3895,12 +3937,12 @@ var DonorMixCard = function DonorMixCard(_ref) {
3895
3937
  display: "flex",
3896
3938
  alignItems: "center",
3897
3939
  gap: 0.5,
3898
- color: "#22C55E",
3940
+ color: trendColor,
3899
3941
  fontSize: "12px",
3900
3942
  fontWeight: 600
3901
3943
  },
3902
- children: [/*#__PURE__*/jsx("span", {
3903
- children: "\u25B2"
3944
+ children: [trendArrow && /*#__PURE__*/jsx("span", {
3945
+ children: trendArrow
3904
3946
  }), bottomSummaryTrend]
3905
3947
  })]
3906
3948
  })]
@@ -4115,8 +4157,7 @@ var MetricSparklineCard = function MetricSparklineCard(_ref) {
4115
4157
  subtitle = _ref.subtitle,
4116
4158
  value = _ref.value,
4117
4159
  trend = _ref.trend,
4118
- _ref$trendColor = _ref.trendColor,
4119
- trendColor = _ref$trendColor === void 0 ? "#22C55E" : _ref$trendColor,
4160
+ trendColor = _ref.trendColor,
4120
4161
  _ref$chartData = _ref.chartData,
4121
4162
  chartData = _ref$chartData === void 0 ? [] : _ref$chartData,
4122
4163
  _ref$chartColor = _ref.chartColor,
@@ -4128,6 +4169,8 @@ var MetricSparklineCard = function MetricSparklineCard(_ref) {
4128
4169
  bottomSection = _ref$bottomSection === void 0 ? false : _ref$bottomSection,
4129
4170
  _ref$compact = _ref.compact,
4130
4171
  compact = _ref$compact === void 0 ? false : _ref$compact;
4172
+ var resolvedTrendColor = trendColor !== null && trendColor !== void 0 ? trendColor : getTrendColor(trend);
4173
+
4131
4174
  // Extract values for chart series
4132
4175
  var series = [{
4133
4176
  name: title,
@@ -4248,7 +4291,7 @@ var MetricSparklineCard = function MetricSparklineCard(_ref) {
4248
4291
  sx: {
4249
4292
  fontSize: "11px",
4250
4293
  fontWeight: 700,
4251
- color: trendColor,
4294
+ color: resolvedTrendColor,
4252
4295
  mt: 0.2
4253
4296
  },
4254
4297
  children: trend
@@ -4322,19 +4365,39 @@ var MetricSparklineCard = function MetricSparklineCard(_ref) {
4322
4365
  });
4323
4366
  };
4324
4367
 
4325
- var MetricDonutCard = function MetricDonutCard(_ref) {
4326
- var title = _ref.title,
4327
- subtitle = _ref.subtitle,
4328
- acceptanceRate = _ref.acceptanceRate,
4329
- acceptanceVal = _ref.acceptanceVal,
4330
- acceptanceTrend = _ref.acceptanceTrend,
4331
- raisedVal = _ref.raisedVal,
4332
- raisedTrend = _ref.raisedTrend,
4333
- _ref$chartColors = _ref.chartColors,
4334
- chartColors = _ref$chartColors === void 0 ? ["rgb(99, 99, 230)", "#88bfd290"] : _ref$chartColors,
4335
- sx = _ref.sx,
4336
- _ref$compact = _ref.compact,
4337
- compact = _ref$compact === void 0 ? false : _ref$compact;
4368
+ var TrendValue = function TrendValue(_ref) {
4369
+ var trend = _ref.trend;
4370
+ var direction = getTrendDirection(trend);
4371
+ var color = getTrendColor(trend);
4372
+ var Icon = direction === "down" ? TrendingDown : TrendingUp;
4373
+ return /*#__PURE__*/jsxs(Typography, {
4374
+ sx: {
4375
+ fontSize: "10px",
4376
+ fontWeight: 700,
4377
+ color: color,
4378
+ display: "flex",
4379
+ alignItems: "center"
4380
+ },
4381
+ children: [/*#__PURE__*/jsx(Icon, {
4382
+ sx: {
4383
+ fontSize: "12px"
4384
+ }
4385
+ }), " ", trend]
4386
+ });
4387
+ };
4388
+ var MetricDonutCard = function MetricDonutCard(_ref2) {
4389
+ var title = _ref2.title,
4390
+ subtitle = _ref2.subtitle,
4391
+ acceptanceRate = _ref2.acceptanceRate,
4392
+ acceptanceVal = _ref2.acceptanceVal,
4393
+ acceptanceTrend = _ref2.acceptanceTrend,
4394
+ raisedVal = _ref2.raisedVal,
4395
+ raisedTrend = _ref2.raisedTrend,
4396
+ _ref2$chartColors = _ref2.chartColors,
4397
+ chartColors = _ref2$chartColors === void 0 ? ["rgb(99, 99, 230)", "#88bfd290"] : _ref2$chartColors,
4398
+ sx = _ref2.sx,
4399
+ _ref2$compact = _ref2.compact,
4400
+ compact = _ref2$compact === void 0 ? false : _ref2$compact;
4338
4401
  var chartOptions = {
4339
4402
  chart: {
4340
4403
  type: "radialBar",
@@ -4475,19 +4538,8 @@ var MetricDonutCard = function MetricDonutCard(_ref) {
4475
4538
  color: "#000"
4476
4539
  },
4477
4540
  children: acceptanceVal
4478
- }), /*#__PURE__*/jsxs(Typography, {
4479
- sx: {
4480
- fontSize: "10px",
4481
- fontWeight: 700,
4482
- color: "#22C55E",
4483
- display: "flex",
4484
- alignItems: "center"
4485
- },
4486
- children: [/*#__PURE__*/jsx(TrendingUp, {
4487
- sx: {
4488
- fontSize: "12px"
4489
- }
4490
- }), " ", acceptanceTrend]
4541
+ }), /*#__PURE__*/jsx(TrendValue, {
4542
+ trend: acceptanceTrend
4491
4543
  })]
4492
4544
  })]
4493
4545
  }), /*#__PURE__*/jsxs(Box, {
@@ -4530,19 +4582,8 @@ var MetricDonutCard = function MetricDonutCard(_ref) {
4530
4582
  color: "#000"
4531
4583
  },
4532
4584
  children: raisedVal
4533
- }), /*#__PURE__*/jsxs(Typography, {
4534
- sx: {
4535
- fontSize: "10px",
4536
- fontWeight: 700,
4537
- color: "#22C55E",
4538
- display: "flex",
4539
- alignItems: "center"
4540
- },
4541
- children: [/*#__PURE__*/jsx(TrendingUp, {
4542
- sx: {
4543
- fontSize: "12px"
4544
- }
4545
- }), " ", raisedTrend]
4585
+ }), /*#__PURE__*/jsx(TrendValue, {
4586
+ trend: raisedTrend
4546
4587
  })]
4547
4588
  })]
4548
4589
  })]
@@ -6370,15 +6411,15 @@ var OverallDetailsGrid = function OverallDetailsGrid(_ref) {
6370
6411
  subtitle: "Acceptance & raised",
6371
6412
  acceptanceRate: (downsellData === null || downsellData === void 0 ? void 0 : downsellData.acceptanceRate) || 0,
6372
6413
  acceptanceVal: "".concat(formatNumber((downsellData === null || downsellData === void 0 ? void 0 : downsellData.acceptanceRate) || 0), "%"),
6373
- acceptanceTrend: "".concat(formatNumber((downsellData === null || downsellData === void 0 ? void 0 : downsellData.acceptanceGrowth) || 0), "%"),
6414
+ acceptanceTrend: "".concat((downsellData === null || downsellData === void 0 ? void 0 : downsellData.acceptanceGrowth) >= 0 ? "▲" : "▼", " ").concat(Math.abs((downsellData === null || downsellData === void 0 ? void 0 : downsellData.acceptanceGrowth) || 0).toFixed(1), "%"),
6374
6415
  raisedVal: "$".concat(formatNumber((downsellData === null || downsellData === void 0 ? void 0 : downsellData.raised) || 0)),
6375
- raisedTrend: "".concat(formatNumber((downsellData === null || downsellData === void 0 ? void 0 : downsellData.raisedGrowth) || 0), "%"),
6416
+ raisedTrend: "".concat((downsellData === null || downsellData === void 0 ? void 0 : downsellData.raisedGrowth) >= 0 ? "▲" : "▼", " ").concat(Math.abs((downsellData === null || downsellData === void 0 ? void 0 : downsellData.raisedGrowth) || 0).toFixed(1), "%"),
6376
6417
  sx: CARD_SX
6377
6418
  }), /*#__PURE__*/jsx(MetricSparklineCard, {
6378
6419
  title: "Referrals",
6379
6420
  subtitle: "Revenue trend \xB7 last ".concat(daysLabel),
6380
6421
  value: "$".concat(formatNumber((referralData === null || referralData === void 0 ? void 0 : referralData.totalRevenue) || 0)),
6381
- trend: "\u25B2 ".concat((referralData === null || referralData === void 0 ? void 0 : referralData.growthPercentage) || 0, "% vs previous period"),
6422
+ trend: "".concat((referralData === null || referralData === void 0 ? void 0 : referralData.growthPercentage) >= 0 ? "▲" : "▼", " ").concat(Math.abs((referralData === null || referralData === void 0 ? void 0 : referralData.growthPercentage) || 0).toFixed(1), "% vs previous period"),
6382
6423
  chartData: (referralData === null || referralData === void 0 || (_referralData$chartDa = referralData.chartData) === null || _referralData$chartDa === void 0 ? void 0 : _referralData$chartDa.map(function (item) {
6383
6424
  return {
6384
6425
  label: item.date,
@@ -17886,6 +17927,12 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
17886
17927
  }
17887
17928
  return series;
17888
17929
  }, [trendData, trendSeries, series]);
17930
+ var trendColor = getTrendColor(trend, {
17931
+ up: "#10b981",
17932
+ down: "#EF4444"
17933
+ });
17934
+ var trendArrow = getTrendArrow(trend);
17935
+ var trendBadgeBg = trendColor === "#EF4444" ? "#fee2e2" : "#ebfcf4";
17889
17936
  var chartOptions = {
17890
17937
  chart: {
17891
17938
  type: "area",
@@ -18045,8 +18092,8 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
18045
18092
  children: value
18046
18093
  }), /*#__PURE__*/jsxs(Box, {
18047
18094
  sx: {
18048
- bgcolor: "#ebfcf4",
18049
- color: "#10b981",
18095
+ bgcolor: trendBadgeBg,
18096
+ color: trendColor,
18050
18097
  px: 1,
18051
18098
  py: 0.4,
18052
18099
  borderRadius: "100px",
@@ -18056,11 +18103,11 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
18056
18103
  alignItems: "center",
18057
18104
  gap: 0.3
18058
18105
  },
18059
- children: [/*#__PURE__*/jsx("span", {
18106
+ children: [trendArrow && /*#__PURE__*/jsx("span", {
18060
18107
  style: {
18061
18108
  fontSize: "10px"
18062
18109
  },
18063
- children: "\u25B2"
18110
+ children: trendArrow
18064
18111
  }), " ", trend]
18065
18112
  })]
18066
18113
  }), /*#__PURE__*/jsx(Box, {