@ttoss/react-dashboard 0.2.0 → 0.2.2

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
@@ -442,6 +442,56 @@ type DashboardCardType =
442
442
  type CardVariant = 'default' | 'dark' | 'light-green';
443
443
  ```
444
444
 
445
+ ### TrendIndicator
446
+
447
+ Trend indicator that displays a percentage change with visual indicators.
448
+
449
+ ```tsx
450
+ type TrendIndicator = {
451
+ value: number;
452
+ status?: 'positive' | 'negative' | 'neutral';
453
+ type?: 'higher' | 'lower';
454
+ };
455
+ ```
456
+
457
+ **Behavior:**
458
+
459
+ - **Positive status**: Displays an up arrow icon and the percentage value (e.g., "10.5% vs. período anterior")
460
+ - **Negative status**: Displays a down arrow icon and the percentage value (e.g., "5.2% vs. período anterior")
461
+ - **Neutral status**: Displays no arrow icon, only the percentage value (e.g., "0.0% vs. período anterior")
462
+ - The value is always formatted to 1 decimal place followed by "%"
463
+ - Note: Positive values do not include a "+" sign prefix
464
+
465
+ **Example:**
466
+
467
+ ```tsx
468
+ trend={{
469
+ value: 15.5,
470
+ status: 'positive',
471
+ type: 'higher', // Optional: indicates if higher/lower is good
472
+ }}
473
+ ```
474
+
475
+ ### StatusIndicator
476
+
477
+ Status indicator that displays text with an optional icon.
478
+
479
+ ```tsx
480
+ type StatusIndicator = {
481
+ text: string;
482
+ icon?: string;
483
+ };
484
+ ```
485
+
486
+ **Example:**
487
+
488
+ ```tsx
489
+ status={{
490
+ text: 'Active',
491
+ icon: 'mdi:check-circle',
492
+ }}
493
+ ```
494
+
445
495
  ## Complete Example
446
496
 
447
497
  ```tsx
package/dist/esm/index.js CHANGED
@@ -45,7 +45,7 @@ var CardWrapper = /* @__PURE__ */__name(({
45
45
  return "feedback.text.positive.default";
46
46
  case "default":
47
47
  default:
48
- return "display.text.primary.default";
48
+ return "input.background.muted.disabled";
49
49
  }
50
50
  }, "getTitleColor");
51
51
  return /* @__PURE__ */React.createElement(Flex, {
@@ -65,8 +65,9 @@ var CardWrapper = /* @__PURE__ */__name(({
65
65
  gap: "2"
66
66
  }
67
67
  }, /* @__PURE__ */React.createElement(Text, {
68
- variant: "h5",
69
68
  sx: {
69
+ fontSize: "sm",
70
+ fontWeight: "bold",
70
71
  color: getTitleColor(),
71
72
  flex: 1,
72
73
  minWidth: 0
@@ -130,19 +131,28 @@ var getValueColor = /* @__PURE__ */__name((color, variant) => {
130
131
  }
131
132
  return "display.text.primary.default";
132
133
  }, "getValueColor");
133
- var getTrendColor = /* @__PURE__ */__name(status => {
134
- if (status === "positive") {
135
- return "feedback.text.positive.default";
134
+ var getTrendColor = /* @__PURE__ */__name(trend => {
135
+ const colors = {
136
+ positive: "feedback.text.positive.default",
137
+ negative: "feedback.text.negative.default",
138
+ neutral: "display.text.primary.default"
139
+ };
140
+ if (!trend) {
141
+ return colors.neutral;
136
142
  }
137
- if (status === "negative") {
138
- return "feedback.text.negative.default";
143
+ const isGoodTrend = trend.type === "higher" && trend.status === "positive" || trend.type === "lower" && trend.status === "negative";
144
+ if (isGoodTrend) {
145
+ return colors.positive;
139
146
  }
140
- return "display.text.primary.default";
147
+ const isBadTrend = trend.type === "higher" && trend.status === "negative" || trend.type === "lower" && trend.status === "positive";
148
+ if (isBadTrend) {
149
+ return colors.negative;
150
+ }
151
+ return colors.neutral;
141
152
  }, "getTrendColor");
142
153
  var BigNumber = /* @__PURE__ */__name(props => {
143
154
  const total = props.data.meta?.total ?? props.data.api?.total ?? void 0;
144
155
  const formattedValue = formatNumber(total, props.numberType, props.numberDecimalPlaces);
145
- const displayValue = props.numberType === "number" && props.title.toLowerCase().includes("roas") ? `${formattedValue}x` : formattedValue;
146
156
  const valueColor = getValueColor(props.color, props.variant);
147
157
  const variant = props.variant || "default";
148
158
  return /* @__PURE__ */React.createElement(CardWrapper, {
@@ -161,14 +171,14 @@ var BigNumber = /* @__PURE__ */__name(props => {
161
171
  fontWeight: "bold",
162
172
  lineHeight: "1.2"
163
173
  }
164
- }, displayValue), props.trend && /* @__PURE__ */React.createElement(Flex2, {
174
+ }, formattedValue), props.trend && /* @__PURE__ */React.createElement(Flex2, {
165
175
  sx: {
166
176
  alignItems: "center",
167
177
  gap: "1"
168
178
  }
169
179
  }, /* @__PURE__ */React.createElement(Box2, {
170
180
  sx: {
171
- color: getTrendColor(props.trend.status),
181
+ color: getTrendColor(props.trend),
172
182
  display: "flex",
173
183
  alignItems: "center"
174
184
  }
@@ -178,13 +188,13 @@ var BigNumber = /* @__PURE__ */__name(props => {
178
188
  }) : props.trend.status === "negative" ? /* @__PURE__ */React.createElement(Icon, {
179
189
  icon: "mdi:arrow-down",
180
190
  width: 16
181
- }) : null), ["positive", "negative"].includes(props.trend?.status || "") && /* @__PURE__ */React.createElement(Text2, {
191
+ }) : null), /* @__PURE__ */React.createElement(Text2, {
182
192
  sx: {
183
- color: getTrendColor(props.trend.status),
193
+ color: getTrendColor(props.trend),
184
194
  fontSize: "sm",
185
195
  fontWeight: "medium"
186
196
  }
187
- }, props.trend.status === "positive" ? "+" : "", props.trend.value.toFixed(1), "%", " ", props.trend ? "vs. per\xEDodo anterior" : "")), props.additionalInfo && /* @__PURE__ */React.createElement(Text2, {
197
+ }, props.trend.value.toFixed(1), "%", " ", props.trend ? "vs. per\xEDodo anterior" : "")), props.additionalInfo && /* @__PURE__ */React.createElement(Text2, {
188
198
  sx: {
189
199
  color: getValueColor(props.color, props.variant),
190
200
  fontSize: "sm",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/react-dashboard",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "ttoss dashboard module for React apps.",
5
5
  "license": "MIT",
6
6
  "author": "ttoss",
@@ -28,9 +28,9 @@
28
28
  "react-grid-layout": "^1.5.2",
29
29
  "@ttoss/components": "^2.12.4",
30
30
  "@ttoss/forms": "^0.38.0",
31
- "@ttoss/react-i18n": "^2.0.25",
32
31
  "@ttoss/react-icons": "^0.5.6",
33
- "@ttoss/ui": "^6.5.0"
32
+ "@ttoss/ui": "^6.5.0",
33
+ "@ttoss/react-i18n": "^2.0.25"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": ">=16.8.0"