@mbao01/common 0.9.1 → 0.9.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/dist/types/components/KPICard/KPICard.d.ts +1 -1
- package/dist/types/components/KPICard/KPICardSkeleton.d.ts +11 -0
- package/dist/types/components/KPICard/index.d.ts +2 -0
- package/dist/types/components/KPICard/types.d.ts +0 -2
- package/dist/types/components/WidgetShell/WidgetShell.d.ts +20 -1
- package/dist/types/components/WidgetShell/WidgetShellSkeleton.d.ts +11 -0
- package/dist/types/components/WidgetShell/index.d.ts +3 -1
- package/dist/types/components/WidgetShell/types.d.ts +2 -11
- package/package.json +1 -1
- package/src/components/KPICard/KPICard.tsx +0 -26
- package/src/components/KPICard/KPICardSkeleton.tsx +42 -0
- package/src/components/KPICard/index.ts +2 -0
- package/src/components/KPICard/types.ts +0 -2
- package/src/components/WidgetShell/WidgetShell.tsx +72 -70
- package/src/components/WidgetShell/WidgetShellSkeleton.tsx +47 -0
- package/src/components/WidgetShell/index.ts +3 -1
- package/src/components/WidgetShell/types.ts +2 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { KPICardProps } from './types';
|
|
2
2
|
declare const KPICard: {
|
|
3
|
-
({ title, value, change, description, chart, icon,
|
|
3
|
+
({ title, value, change, description, chart, icon, className, ...props }: KPICardProps): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
displayName: string;
|
|
5
5
|
};
|
|
6
6
|
export { KPICard };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type KPICardSkeletonProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
2
|
+
/** Whether to show the icon placeholder */
|
|
3
|
+
icon?: boolean;
|
|
4
|
+
/** Whether to show the chart placeholder */
|
|
5
|
+
chart?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const KPICardSkeleton: {
|
|
8
|
+
({ icon, chart, className, ...props }: KPICardSkeletonProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
export { KPICardSkeleton };
|
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { WidgetShellProps } from './types';
|
|
2
2
|
declare const WidgetShell: {
|
|
3
|
-
({
|
|
3
|
+
({ title, description, action, children, className, ...props }: WidgetShellProps): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
displayName: string;
|
|
5
|
+
Empty: {
|
|
6
|
+
({ children }: {
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
}): string | number | bigint | boolean | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
Error: {
|
|
12
|
+
({ children, onRetry, }: {
|
|
13
|
+
children?: React.ReactNode;
|
|
14
|
+
onRetry?: () => void;
|
|
15
|
+
}): string | number | bigint | boolean | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
displayName: string;
|
|
17
|
+
};
|
|
18
|
+
Loading: {
|
|
19
|
+
({ lines }: {
|
|
20
|
+
lines?: number;
|
|
21
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
displayName: string;
|
|
23
|
+
};
|
|
5
24
|
};
|
|
6
25
|
export { WidgetShell };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type WidgetShellSkeletonProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
2
|
+
/** Number of skeleton lines to show */
|
|
3
|
+
lines?: number;
|
|
4
|
+
/** Whether to show the header skeleton */
|
|
5
|
+
header?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const WidgetShellSkeleton: {
|
|
8
|
+
({ lines, header, className, ...props }: WidgetShellSkeletonProps): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
export { WidgetShellSkeleton };
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { WidgetShell } from './WidgetShell';
|
|
2
|
-
export
|
|
2
|
+
export { WidgetShellSkeleton } from './WidgetShellSkeleton';
|
|
3
|
+
export type { WidgetShellProps } from './types';
|
|
4
|
+
export type { WidgetShellSkeletonProps } from './WidgetShellSkeleton';
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
-
export type WidgetShellState = "loading" | "error" | "empty" | "ready";
|
|
3
2
|
export type WidgetShellProps = HTMLAttributes<HTMLDivElement> & {
|
|
4
|
-
/** Current state of the widget */
|
|
5
|
-
state?: WidgetShellState;
|
|
6
3
|
/** Widget title */
|
|
7
4
|
title?: ReactNode;
|
|
8
5
|
/** Widget description */
|
|
9
6
|
description?: ReactNode;
|
|
7
|
+
/** Content rendered in the top-right of the header (e.g. actions, icons, badges) */
|
|
8
|
+
action?: ReactNode;
|
|
10
9
|
/** Content to show when state is "ready" */
|
|
11
10
|
children: ReactNode;
|
|
12
|
-
/** Custom content for error state */
|
|
13
|
-
errorContent?: ReactNode;
|
|
14
|
-
/** Custom content for empty state */
|
|
15
|
-
emptyContent?: ReactNode;
|
|
16
|
-
/** Number of skeleton lines to show in loading state */
|
|
17
|
-
skeletonLines?: number;
|
|
18
|
-
/** Callback when retry is clicked in error state */
|
|
19
|
-
onRetry?: () => void;
|
|
20
11
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { KPICardProps } from "./types";
|
|
2
2
|
import { cn } from "../../utilities";
|
|
3
|
-
import { Skeleton } from "../Skeleton";
|
|
4
3
|
import { TrendBadge } from "../TrendBadge";
|
|
5
4
|
|
|
6
5
|
const KPICard = ({
|
|
@@ -10,34 +9,9 @@ const KPICard = ({
|
|
|
10
9
|
description,
|
|
11
10
|
chart,
|
|
12
11
|
icon,
|
|
13
|
-
loading = false,
|
|
14
12
|
className,
|
|
15
13
|
...props
|
|
16
14
|
}: KPICardProps) => {
|
|
17
|
-
if (loading) {
|
|
18
|
-
return (
|
|
19
|
-
<div
|
|
20
|
-
className={cn(
|
|
21
|
-
"rounded-lg border bg-base-100 p-4 shadow-sm transition-shadow duration-300 hover:shadow-md",
|
|
22
|
-
className
|
|
23
|
-
)}
|
|
24
|
-
{...props}
|
|
25
|
-
>
|
|
26
|
-
<div className="flex items-center justify-between">
|
|
27
|
-
<Skeleton className="h-4 w-24 rounded" />
|
|
28
|
-
{icon && <Skeleton className="size-8 rounded-md" />}
|
|
29
|
-
</div>
|
|
30
|
-
<div className="mt-4 flex items-end justify-between gap-4">
|
|
31
|
-
<div className="flex flex-col gap-1.5">
|
|
32
|
-
<Skeleton className="h-7 w-28 rounded" />
|
|
33
|
-
<Skeleton className="h-3.5 w-20 rounded" />
|
|
34
|
-
</div>
|
|
35
|
-
<Skeleton className="h-8 w-20 rounded" />
|
|
36
|
-
</div>
|
|
37
|
-
</div>
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
15
|
return (
|
|
42
16
|
<div
|
|
43
17
|
className={cn(
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { cn } from "../../utilities";
|
|
2
|
+
import { Skeleton } from "../Skeleton";
|
|
3
|
+
|
|
4
|
+
export type KPICardSkeletonProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
5
|
+
/** Whether to show the icon placeholder */
|
|
6
|
+
icon?: boolean;
|
|
7
|
+
/** Whether to show the chart placeholder */
|
|
8
|
+
chart?: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const KPICardSkeleton = ({
|
|
12
|
+
icon = true,
|
|
13
|
+
chart = true,
|
|
14
|
+
className,
|
|
15
|
+
...props
|
|
16
|
+
}: KPICardSkeletonProps) => {
|
|
17
|
+
return (
|
|
18
|
+
<div
|
|
19
|
+
className={cn(
|
|
20
|
+
"w-full overflow-hidden rounded-lg border bg-base-100 p-4 shadow-sm",
|
|
21
|
+
className
|
|
22
|
+
)}
|
|
23
|
+
{...props}
|
|
24
|
+
>
|
|
25
|
+
<div className="flex items-center justify-between">
|
|
26
|
+
<Skeleton className="h-4 w-24 rounded" />
|
|
27
|
+
{icon && <Skeleton className="size-8 rounded-md" />}
|
|
28
|
+
</div>
|
|
29
|
+
<div className="mt-4 flex items-end justify-between gap-4">
|
|
30
|
+
<div className="flex flex-col gap-1.5">
|
|
31
|
+
<Skeleton className="h-7 w-28 rounded" />
|
|
32
|
+
<Skeleton className="h-3.5 w-20 rounded" />
|
|
33
|
+
</div>
|
|
34
|
+
{chart && <Skeleton className="h-8 w-20 rounded" />}
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
KPICardSkeleton.displayName = "KPICardSkeleton";
|
|
41
|
+
|
|
42
|
+
export { KPICardSkeleton };
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { AlertCircleIcon, InboxIcon, RefreshCwIcon } from "lucide-react";
|
|
2
|
-
import { cn } from "../../utilities";
|
|
3
2
|
import type { WidgetShellProps } from "./types";
|
|
3
|
+
import { cn } from "../../utilities";
|
|
4
|
+
import { Button } from "../Button";
|
|
4
5
|
|
|
5
6
|
const WidgetShell = ({
|
|
6
|
-
state = "ready",
|
|
7
7
|
title,
|
|
8
8
|
description,
|
|
9
|
+
action,
|
|
9
10
|
children,
|
|
10
11
|
className,
|
|
11
|
-
errorContent,
|
|
12
|
-
emptyContent,
|
|
13
|
-
skeletonLines = 3,
|
|
14
|
-
onRetry,
|
|
15
12
|
...props
|
|
16
13
|
}: WidgetShellProps) => {
|
|
17
14
|
return (
|
|
@@ -22,80 +19,85 @@ const WidgetShell = ({
|
|
|
22
19
|
)}
|
|
23
20
|
{...props}
|
|
24
21
|
>
|
|
25
|
-
{(title || description) && (
|
|
26
|
-
<div className="border-b px-4 py-3">
|
|
27
|
-
|
|
28
|
-
<h3 className="text-sm font-semibold">
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
title
|
|
33
|
-
)}
|
|
34
|
-
</h3>
|
|
35
|
-
)}
|
|
36
|
-
{description && (
|
|
37
|
-
<p className="mt-0.5 text-xs text-base-content/60">
|
|
38
|
-
{state === "loading" ? (
|
|
39
|
-
<span className="skeleton inline-block h-3 w-48 rounded" />
|
|
40
|
-
) : (
|
|
41
|
-
description
|
|
42
|
-
)}
|
|
43
|
-
</p>
|
|
44
|
-
)}
|
|
22
|
+
{(title || description || action) && (
|
|
23
|
+
<div className="flex items-start justify-between border-b px-4 py-3">
|
|
24
|
+
<div className="min-w-0">
|
|
25
|
+
{title && <h3 className="text-sm font-semibold">{title}</h3>}
|
|
26
|
+
{description && <p className="mt-0.5 text-xs text-base-content/60">{description}</p>}
|
|
27
|
+
</div>
|
|
28
|
+
{action && <div className="shrink-0">{action}</div>}
|
|
45
29
|
</div>
|
|
46
30
|
)}
|
|
47
31
|
|
|
48
|
-
<div className="p-4">
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
className="skeleton h-4 rounded"
|
|
55
|
-
style={{ width: `${100 - i * 15}%` }}
|
|
56
|
-
/>
|
|
57
|
-
))}
|
|
58
|
-
</div>
|
|
59
|
-
)}
|
|
32
|
+
<div className="p-4">{children}</div>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
WidgetShell.displayName = "WidgetShell";
|
|
60
38
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
>
|
|
75
|
-
<RefreshCwIcon className="size-3" />
|
|
76
|
-
Retry
|
|
77
|
-
</button>
|
|
78
|
-
)}
|
|
79
|
-
</div>
|
|
80
|
-
))}
|
|
39
|
+
const WidgetShellEmpty = ({ children }: { children?: React.ReactNode }) => {
|
|
40
|
+
return (
|
|
41
|
+
children ?? (
|
|
42
|
+
<div className="flex flex-col items-center justify-center gap-3 py-6 text-center">
|
|
43
|
+
<InboxIcon className="size-8 text-base-content/30" />
|
|
44
|
+
<div>
|
|
45
|
+
<p className="text-sm font-medium">No data</p>
|
|
46
|
+
<p className="text-xs text-base-content/60">Nothing to display yet</p>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
};
|
|
81
52
|
|
|
82
|
-
|
|
83
|
-
(emptyContent ?? (
|
|
84
|
-
<div className="flex flex-col items-center justify-center gap-3 py-6 text-center">
|
|
85
|
-
<InboxIcon className="size-8 text-base-content/30" />
|
|
86
|
-
<div>
|
|
87
|
-
<p className="text-sm font-medium">No data</p>
|
|
88
|
-
<p className="text-xs text-base-content/60">Nothing to display yet</p>
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
91
|
-
))}
|
|
53
|
+
WidgetShellEmpty.displayName = "WidgetShellEmpty";
|
|
92
54
|
|
|
93
|
-
|
|
55
|
+
const WidgetShellError = ({
|
|
56
|
+
children,
|
|
57
|
+
onRetry,
|
|
58
|
+
}: {
|
|
59
|
+
children?: React.ReactNode;
|
|
60
|
+
onRetry?: () => void;
|
|
61
|
+
}) => {
|
|
62
|
+
return (
|
|
63
|
+
children ?? (
|
|
64
|
+
<div className="flex flex-col items-center justify-center gap-3 py-6 text-center">
|
|
65
|
+
<AlertCircleIcon className="size-8 text-error/60" />
|
|
66
|
+
<div>
|
|
67
|
+
<p className="text-sm font-medium">Something went wrong</p>
|
|
68
|
+
<p className="text-xs text-base-content/60">Failed to load data</p>
|
|
69
|
+
</div>
|
|
70
|
+
{onRetry && (
|
|
71
|
+
<Button
|
|
72
|
+
type="button"
|
|
73
|
+
onClick={onRetry}
|
|
74
|
+
className="inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-xs font-medium transition-colors duration-200 hover:bg-base-200"
|
|
75
|
+
>
|
|
76
|
+
<RefreshCwIcon className="size-3 shrink-0" />
|
|
77
|
+
Retry
|
|
78
|
+
</Button>
|
|
79
|
+
)}
|
|
94
80
|
</div>
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
WidgetShellError.displayName = "WidgetShellError";
|
|
86
|
+
|
|
87
|
+
const WidgetShellLoading = ({ lines = 4 }: { lines?: number }) => {
|
|
88
|
+
return (
|
|
89
|
+
<div className="flex flex-col gap-3" role="status" aria-label="Loading">
|
|
90
|
+
{Array.from({ length: lines }, (_, i) => (
|
|
91
|
+
<span key={i} className="skeleton h-4 rounded" style={{ width: `${100 - i * 15}%` }} />
|
|
92
|
+
))}
|
|
95
93
|
</div>
|
|
96
94
|
);
|
|
97
95
|
};
|
|
98
96
|
|
|
99
|
-
|
|
97
|
+
WidgetShellLoading.displayName = "WidgetShellLoading";
|
|
98
|
+
|
|
99
|
+
WidgetShell.Empty = WidgetShellEmpty;
|
|
100
|
+
WidgetShell.Error = WidgetShellError;
|
|
101
|
+
WidgetShell.Loading = WidgetShellLoading;
|
|
100
102
|
|
|
101
103
|
export { WidgetShell };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { cn } from "../../utilities";
|
|
2
|
+
|
|
3
|
+
export type WidgetShellSkeletonProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
4
|
+
/** Number of skeleton lines to show */
|
|
5
|
+
lines?: number;
|
|
6
|
+
/** Whether to show the header skeleton */
|
|
7
|
+
header?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const WidgetShellSkeleton = ({
|
|
11
|
+
lines = 3,
|
|
12
|
+
header = true,
|
|
13
|
+
className,
|
|
14
|
+
...props
|
|
15
|
+
}: WidgetShellSkeletonProps) => {
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
className={cn(
|
|
19
|
+
"rounded-lg border bg-base-100 shadow-sm",
|
|
20
|
+
className
|
|
21
|
+
)}
|
|
22
|
+
{...props}
|
|
23
|
+
>
|
|
24
|
+
{header && (
|
|
25
|
+
<div className="border-b px-4 py-3">
|
|
26
|
+
<span className="skeleton inline-block h-4 w-32 rounded" />
|
|
27
|
+
<span className="skeleton mt-1.5 inline-block h-3 w-48 rounded" />
|
|
28
|
+
</div>
|
|
29
|
+
)}
|
|
30
|
+
<div className="p-4">
|
|
31
|
+
<div className="flex flex-col gap-3" role="status" aria-label="Loading">
|
|
32
|
+
{Array.from({ length: lines }, (_, i) => (
|
|
33
|
+
<span
|
|
34
|
+
key={i}
|
|
35
|
+
className="skeleton h-4 rounded"
|
|
36
|
+
style={{ width: `${100 - i * 15}%` }}
|
|
37
|
+
/>
|
|
38
|
+
))}
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
WidgetShellSkeleton.displayName = "WidgetShellSkeleton";
|
|
46
|
+
|
|
47
|
+
export { WidgetShellSkeleton };
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export { WidgetShell } from "./WidgetShell";
|
|
2
|
-
export
|
|
2
|
+
export { WidgetShellSkeleton } from "./WidgetShellSkeleton";
|
|
3
|
+
export type { WidgetShellProps } from "./types";
|
|
4
|
+
export type { WidgetShellSkeletonProps } from "./WidgetShellSkeleton";
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import type { HTMLAttributes, ReactNode } from "react";
|
|
2
2
|
|
|
3
|
-
export type WidgetShellState = "loading" | "error" | "empty" | "ready";
|
|
4
|
-
|
|
5
3
|
export type WidgetShellProps = HTMLAttributes<HTMLDivElement> & {
|
|
6
|
-
/** Current state of the widget */
|
|
7
|
-
state?: WidgetShellState;
|
|
8
4
|
/** Widget title */
|
|
9
5
|
title?: ReactNode;
|
|
10
6
|
/** Widget description */
|
|
11
7
|
description?: ReactNode;
|
|
8
|
+
/** Content rendered in the top-right of the header (e.g. actions, icons, badges) */
|
|
9
|
+
action?: ReactNode;
|
|
12
10
|
/** Content to show when state is "ready" */
|
|
13
11
|
children: ReactNode;
|
|
14
|
-
/** Custom content for error state */
|
|
15
|
-
errorContent?: ReactNode;
|
|
16
|
-
/** Custom content for empty state */
|
|
17
|
-
emptyContent?: ReactNode;
|
|
18
|
-
/** Number of skeleton lines to show in loading state */
|
|
19
|
-
skeletonLines?: number;
|
|
20
|
-
/** Callback when retry is clicked in error state */
|
|
21
|
-
onRetry?: () => void;
|
|
22
12
|
};
|