-
Notifications
You must be signed in to change notification settings - Fork 985
feat(StatCard): new component for statistics #5758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4
Are you sure you want to change the base?
Conversation
5f5e9c0 to
fee5332
Compare
If OK to share my feedback, I have something like this in my app (more of a dynamic Dashboard) and I am using ref #978 (comment) |
|
It looks like a really great component! (I hope it gets adopted!)
|
Thanks for the feedback! I understand what you mean, but Iβd like to keep things as consistent as possible with NuxtUIβs standards (avoiding external libraries as dependencies). |
Thanks for the feedback! I'm glad you like the component. The trendDirection is now automatically inferred from the trend value: |
commit: |
da414d6 to
a24ff45
Compare
benjamincanac
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the StatGroup component really necessary? We could use PageGrid to do this. Maybe it would make sense to call this component PageStat for consistency? π€
Yeah, I agree β I donβt think itβs strictly necessary, at least for now. The original idea was to have a wrapper component that could group different kinds of elements (not just StatCard), for example if in the future we decide to introduce charts or other stats-related components. That said, Iβm fine with simplifying this. Iβll remove it and push the changes. |
a24ff45 to
e559050
Compare
|
@benjamincanac cleaned and rebase branch. I don't understand why deploy fail. It seems not related to my changes. |
β¦customizable props and themes; includes documentation, examples, and tests
β¦out of stat cards; includes examples, documentation, and tests
β¦pdate documentation; add override option for explicit trend direction
β¦ adjust documentation for prop visibility
β¦te related documentation; enhance styling for zero line visibility
β¦ documentation, and tests; clean up theme and snapshot files
e559050 to
2f2b118
Compare
Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
| </slot> | ||
| </div> | ||
|
|
||
| <div v-if="(value !== undefined && value !== null) || (current !== undefined && current !== null && value === undefined) || !!slots.value" data-slot="value" :class="ui.value({ class: props.ui?.value })"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <div v-if="(value !== undefined && value !== null) || (current !== undefined && current !== null && value === undefined) || !!slots.value" data-slot="value" :class="ui.value({ class: props.ui?.value })"> | |
| <div v-if="(value !== undefined && value !== null) || (current !== undefined && current !== null && (value === undefined || value === null)) || !!slots.value" data-slot="value" :class="ui.value({ class: props.ui?.value })"> |
The value display condition inconsistently checks only for undefined in the fallback case, but the display expression checks for both undefined and null. This causes the value div to not render if value={null} and current exists, even though content should be displayed.
View Details
Analysis
StatCard value display condition inconsistently checks for undefined only in fallback case
What fails: StatCard component fails to render the value div when value={null} and current exists. The v-if condition on line 251 checks only value === undefined instead of handling both undefined and null like the display expression does.
How to reproduce:
<StatCard :value="null" :current="50" :max="100" />Result: The value div does not render, even though the display expression would correctly show 50 as fallback.
Expected: The value div should render with the fallback value of 50 because when value={null}, it should fall back to current, just like when value={undefined}.
Inconsistency: Lines 145, 154, and 160 use the pattern === undefined || === null for null/undefined checks throughout the component, but the second condition of the v-if on line 251 only checks value === undefined.
π Linked issue
β Type of change
π Description
Summary
This PR integrates the
StatCardcomponent with optional progress bar and sparkline chart functionality, consolidating multiple stat components into a single, flexible component.StatCarddisplays key metrics with an icon, title, value, and optional trend indicator. The trend direction is automatically calculated from the trend value (negative = down/red, positive = up/green) but can be explicitly overridden when needed. It can optionally display a progress bar (viacurrentandmaxprops) or a sparkline chart (viadataprop), making it suitable for dashboard use cases.Customization Options
The component is customizable through:
outline,solid,soft,subtle,ghost,nakedfor different visual stylesxs,sm,md,lg,xlfor different card dimensionsprimary,success,warning,error,info, etc.) for icons and accentsicon,title,value,trend,trendDirection,current,max,showLabel,data,strokeWidth,showArea,heighticon,title,value,label,progress,sparkline,trend, anddefaultfor full customizationuiprop or global theme configurationKey Features
PageCardfor visual consistencyPersonal Note
This PR is part of an effort to create a comprehensive suite of components for displaying charts and statistics in dashboards. The goal is to provide a unified, flexible API that covers common dashboard use cases while maintaining consistency and ease of use.
Implementation Note
The sparkline charts are generated using native SVG (no external dependencies) to keep the bundle size minimal and ensure fast rendering. The SVG paths are calculated client-side based on the provided data array.
Feedback Requested
I'd love to get your feedback on:
TODO
stat-card.pngimages indocs/public/components/light/anddocs/public/components/dark/with actual screenshots showing the component with progress bars and sparklinesπ Checklist