@stackshift-ui/stats-card 1.1.0 → 6.0.3

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/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@stackshift-ui/stats-card",
3
3
  "description": "",
4
- "version": "1.1.0",
4
+ "version": "6.0.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
10
10
  "files": [
11
- "dist/**"
11
+ "dist/**",
12
+ "src"
12
13
  ],
13
14
  "author": "WebriQ <info@webriq.com>",
14
15
  "devDependencies": {
@@ -28,14 +29,14 @@
28
29
  "typescript": "^5.6.2",
29
30
  "vite-tsconfig-paths": "^5.0.1",
30
31
  "vitest": "^2.1.1",
31
- "@stackshift-ui/eslint-config": "1.0.0",
32
- "@stackshift-ui/typescript-config": "2.0.0"
32
+ "@stackshift-ui/typescript-config": "6.0.2",
33
+ "@stackshift-ui/eslint-config": "6.0.2"
33
34
  },
34
35
  "dependencies": {
35
36
  "classnames": "^2.5.1",
36
- "@stackshift-ui/scripts": "1.0.0",
37
- "@stackshift-ui/system": "2.0.0",
38
- "@stackshift-ui/text": "1.0.0"
37
+ "@stackshift-ui/system": "6.0.3",
38
+ "@stackshift-ui/scripts": "6.0.2",
39
+ "@stackshift-ui/text": "6.0.3"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "@types/react": "16.8 - 19",
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./stats-card";
@@ -0,0 +1,19 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { StatsCard } from "./stats-card";
4
+
5
+ const ARGS = {
6
+ LABEL: "Total Revenue",
7
+ VALUE: "$33,261",
8
+ ICON: "https://cdn.sanity.io/images/9itgab5x/staging/97b6696849c90facc200537fd780b03d373e5212-980x830.png",
9
+ };
10
+
11
+ describe.concurrent("stats-card", () => {
12
+ afterEach(cleanup);
13
+
14
+ test("Common: Stats Card - test if renders without errors", ({ expect }) => {
15
+ const clx = "statscard-class";
16
+ render(<StatsCard className={clx} icon={ARGS.ICON} value={ARGS.VALUE} label={ARGS.LABEL} />);
17
+ expect(screen.getByTestId("div").classList).toContain(clx);
18
+ });
19
+ });
@@ -0,0 +1,63 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import { Text } from "@stackshift-ui/text";
3
+ import cn from "classnames";
4
+ import type { ElementType, HTMLProps, ReactNode } from "react";
5
+
6
+ type VariantType = "inline" | "stacked";
7
+
8
+ export interface StatsCardProps extends Omit<HTMLProps<HTMLElement>, "as"> {
9
+ variant?: VariantType;
10
+ icon: string;
11
+ value: string;
12
+ label: string;
13
+ alt?: string;
14
+ children?: ReactNode;
15
+ className?: string;
16
+ as?: ElementType;
17
+ }
18
+
19
+ const displayName = "StatsCard";
20
+
21
+ export const StatsCard: React.FC<StatsCardProps> = ({
22
+ variant = "inline",
23
+ icon,
24
+ value,
25
+ label,
26
+ alt,
27
+ children,
28
+ className,
29
+ as,
30
+ ...props
31
+ }) => {
32
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
33
+
34
+ const commonClass = `w-full px-4`;
35
+ const variantClass = {
36
+ inline: `${commonClass} flex items-center`,
37
+ stacked: `${commonClass} block`,
38
+ };
39
+
40
+ const imageVariantClass = {
41
+ inline: `inline-block p-4 mr-4 rounded bg-secondary-foreground`,
42
+ stacked: `inline-block p-4 mx-auto rounded bg-secondary-foreground`,
43
+ };
44
+
45
+ const classes = variantClass[variant] ?? variantClass["inline"];
46
+ const imageClasses = imageVariantClass[variant] ?? imageVariantClass["inline"];
47
+
48
+ return (
49
+ <Component as={as} className={cn(classes, className)} {...props} data-testid={displayName}>
50
+ {icon && (
51
+ <div className={imageClasses}>
52
+ <img src={icon} width={24} height={24} alt={alt ?? "statistics-icon"} />
53
+ </div>
54
+ )}
55
+ <div>
56
+ <p className="text-2xl text-gray-500 font-bold">{value}</p>
57
+ <Text muted>{label}</Text>
58
+ </div>
59
+ </Component>
60
+ );
61
+ };
62
+
63
+ StatsCard.displayName = displayName;