@umituz/web-design-system 1.5.1 → 1.7.1
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 +14 -1
- package/src/presentation/atoms/Label.tsx +25 -0
- package/src/presentation/atoms/index.ts +2 -0
- package/src/presentation/molecules/ListItem.tsx +128 -0
- package/src/presentation/molecules/ScrollArea.tsx +50 -0
- package/src/presentation/molecules/index.ts +5 -0
- package/src/presentation/organisms/Alert.tsx +10 -19
- package/src/presentation/organisms/Collapsible.tsx +14 -0
- package/src/presentation/organisms/ConfirmDialog.tsx +97 -0
- package/src/presentation/organisms/DataTable.tsx +233 -0
- package/src/presentation/organisms/Dialog.tsx +124 -0
- package/src/presentation/organisms/EmptyState.tsx +103 -0
- package/src/presentation/organisms/FormModal.tsx +126 -0
- package/src/presentation/organisms/HoverCard.tsx +31 -0
- package/src/presentation/organisms/LoadingState.tsx +87 -0
- package/src/presentation/organisms/MetricCard.tsx +126 -0
- package/src/presentation/organisms/Popover.tsx +33 -0
- package/src/presentation/organisms/QuickActionCard.tsx +110 -0
- package/src/presentation/organisms/Sheet.tsx +135 -0
- package/src/presentation/organisms/StatCard.tsx +161 -0
- package/src/presentation/organisms/index.ts +54 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dialog Component (Organism)
|
|
3
|
+
* @description Modal dialog (Shadcn/ui compatible)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
8
|
+
import { X } from 'lucide-react';
|
|
9
|
+
import { cn } from '../../infrastructure/utils';
|
|
10
|
+
|
|
11
|
+
const Dialog = DialogPrimitive.Root;
|
|
12
|
+
|
|
13
|
+
const DialogTrigger = DialogPrimitive.Trigger;
|
|
14
|
+
|
|
15
|
+
const DialogPortal = DialogPrimitive.Portal;
|
|
16
|
+
|
|
17
|
+
const DialogClose = DialogPrimitive.Close;
|
|
18
|
+
|
|
19
|
+
const DialogOverlay = React.forwardRef<
|
|
20
|
+
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
|
21
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
|
22
|
+
>(({ className, ...props }, ref) => (
|
|
23
|
+
<DialogPrimitive.Overlay
|
|
24
|
+
ref={ref}
|
|
25
|
+
className={cn(
|
|
26
|
+
'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
|
27
|
+
className
|
|
28
|
+
)}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
));
|
|
32
|
+
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
|
33
|
+
|
|
34
|
+
const DialogContent = React.forwardRef<
|
|
35
|
+
React.ElementRef<typeof DialogPrimitive.Content>,
|
|
36
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
|
|
37
|
+
>(({ className, children, ...props }, ref) => (
|
|
38
|
+
<DialogPortal>
|
|
39
|
+
<DialogOverlay />
|
|
40
|
+
<DialogPrimitive.Content
|
|
41
|
+
ref={ref}
|
|
42
|
+
className={cn(
|
|
43
|
+
'fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg',
|
|
44
|
+
className
|
|
45
|
+
)}
|
|
46
|
+
{...props}
|
|
47
|
+
>
|
|
48
|
+
{children}
|
|
49
|
+
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
|
|
50
|
+
<X className="h-4 w-4" />
|
|
51
|
+
<span className="sr-only">Close</span>
|
|
52
|
+
</DialogPrimitive.Close>
|
|
53
|
+
</DialogPrimitive.Content>
|
|
54
|
+
</DialogPortal>
|
|
55
|
+
));
|
|
56
|
+
DialogContent.displayName = DialogPrimitive.Content.displayName;
|
|
57
|
+
|
|
58
|
+
const DialogHeader = ({
|
|
59
|
+
className,
|
|
60
|
+
...props
|
|
61
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
62
|
+
<div
|
|
63
|
+
className={cn(
|
|
64
|
+
'flex flex-col space-y-1.5 text-center sm:text-left',
|
|
65
|
+
className
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
DialogHeader.displayName = 'DialogHeader';
|
|
71
|
+
|
|
72
|
+
const DialogFooter = ({
|
|
73
|
+
className,
|
|
74
|
+
...props
|
|
75
|
+
}: React.HTMLAttributes<HTMLDivElement>) => (
|
|
76
|
+
<div
|
|
77
|
+
className={cn(
|
|
78
|
+
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2',
|
|
79
|
+
className
|
|
80
|
+
)}
|
|
81
|
+
{...props}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
DialogFooter.displayName = 'DialogFooter';
|
|
85
|
+
|
|
86
|
+
const DialogTitle = React.forwardRef<
|
|
87
|
+
React.ElementRef<typeof DialogPrimitive.Title>,
|
|
88
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
|
|
89
|
+
>(({ className, ...props }, ref) => (
|
|
90
|
+
<DialogPrimitive.Title
|
|
91
|
+
ref={ref}
|
|
92
|
+
className={cn(
|
|
93
|
+
'text-lg font-semibold leading-none tracking-tight',
|
|
94
|
+
className
|
|
95
|
+
)}
|
|
96
|
+
{...props}
|
|
97
|
+
/>
|
|
98
|
+
));
|
|
99
|
+
DialogTitle.displayName = DialogPrimitive.Title.displayName;
|
|
100
|
+
|
|
101
|
+
const DialogDescription = React.forwardRef<
|
|
102
|
+
React.ElementRef<typeof DialogPrimitive.Description>,
|
|
103
|
+
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
|
|
104
|
+
>(({ className, ...props }, ref) => (
|
|
105
|
+
<DialogPrimitive.Description
|
|
106
|
+
ref={ref}
|
|
107
|
+
className={cn('text-sm text-muted-foreground', className)}
|
|
108
|
+
{...props}
|
|
109
|
+
/>
|
|
110
|
+
));
|
|
111
|
+
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
Dialog,
|
|
115
|
+
DialogPortal,
|
|
116
|
+
DialogOverlay,
|
|
117
|
+
DialogClose,
|
|
118
|
+
DialogTrigger,
|
|
119
|
+
DialogContent,
|
|
120
|
+
DialogHeader,
|
|
121
|
+
DialogFooter,
|
|
122
|
+
DialogTitle,
|
|
123
|
+
DialogDescription,
|
|
124
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EmptyState Component (Organism)
|
|
3
|
+
* @description Component for displaying empty states with optional actions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { forwardRef } from 'react';
|
|
7
|
+
import { cn } from '../../infrastructure/utils';
|
|
8
|
+
import type { BaseProps, SizeVariant } from '../../domain/types';
|
|
9
|
+
|
|
10
|
+
export interface EmptyStateProps extends BaseProps {
|
|
11
|
+
icon?: React.ComponentType<{ className?: string }>;
|
|
12
|
+
title: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
action?: {
|
|
15
|
+
label: string;
|
|
16
|
+
onClick: () => void;
|
|
17
|
+
};
|
|
18
|
+
size?: Extract<SizeVariant, 'sm' | 'md' | 'lg' | 'xl'>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const sizeStyles = {
|
|
22
|
+
sm: 'p-6 gap-3',
|
|
23
|
+
md: 'p-8 gap-4',
|
|
24
|
+
lg: 'p-12 gap-5',
|
|
25
|
+
xl: 'p-16 gap-6',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const iconSizeStyles = {
|
|
29
|
+
sm: 'h-8 w-8',
|
|
30
|
+
md: 'h-12 w-12',
|
|
31
|
+
lg: 'h-16 w-16',
|
|
32
|
+
xl: 'h-20 w-20',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const titleSizeStyles = {
|
|
36
|
+
sm: 'text-sm',
|
|
37
|
+
md: 'text-base',
|
|
38
|
+
lg: 'text-lg',
|
|
39
|
+
xl: 'text-xl',
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const descriptionSizeStyles = {
|
|
43
|
+
sm: 'text-xs',
|
|
44
|
+
md: 'text-sm',
|
|
45
|
+
lg: 'text-base',
|
|
46
|
+
xl: 'text-lg',
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const EmptyState = forwardRef<HTMLDivElement, EmptyStateProps>(
|
|
50
|
+
(
|
|
51
|
+
{
|
|
52
|
+
className,
|
|
53
|
+
icon: Icon,
|
|
54
|
+
title,
|
|
55
|
+
description,
|
|
56
|
+
action,
|
|
57
|
+
size = 'md',
|
|
58
|
+
...props
|
|
59
|
+
},
|
|
60
|
+
ref
|
|
61
|
+
) => {
|
|
62
|
+
return (
|
|
63
|
+
<div
|
|
64
|
+
ref={ref}
|
|
65
|
+
className={cn(
|
|
66
|
+
'flex flex-col items-center justify-center text-center',
|
|
67
|
+
sizeStyles[size],
|
|
68
|
+
className
|
|
69
|
+
)}
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
{Icon && (
|
|
73
|
+
<Icon className={cn(iconSizeStyles[size], 'text-muted-foreground/50 mx-auto mb-2')} />
|
|
74
|
+
)}
|
|
75
|
+
<h3 className={cn('font-semibold text-foreground', titleSizeStyles[size])}>{title}</h3>
|
|
76
|
+
{description && (
|
|
77
|
+
<p className={cn('text-muted-foreground max-w-md', descriptionSizeStyles[size])}>
|
|
78
|
+
{description}
|
|
79
|
+
</p>
|
|
80
|
+
)}
|
|
81
|
+
{action && (
|
|
82
|
+
<button
|
|
83
|
+
onClick={action.onClick}
|
|
84
|
+
className={cn(
|
|
85
|
+
'mt-4 inline-flex items-center justify-center',
|
|
86
|
+
'rounded-md font-medium',
|
|
87
|
+
'bg-primary text-primary-foreground',
|
|
88
|
+
'hover:bg-primary/90',
|
|
89
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
|
|
90
|
+
'disabled:pointer-events-none disabled:opacity-50',
|
|
91
|
+
'h-9 px-4 text-sm',
|
|
92
|
+
'transition-colors'
|
|
93
|
+
)}
|
|
94
|
+
>
|
|
95
|
+
{action.label}
|
|
96
|
+
</button>
|
|
97
|
+
)}
|
|
98
|
+
</div>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
EmptyState.displayName = 'EmptyState';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FormModal Component (Template)
|
|
3
|
+
* @description Pre-configured modal with form wrapper and loading state
|
|
4
|
+
* Reduces boilerplate in modal components like CampaignModal, ProjectListModal
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { forwardRef, type ComponentType, type ReactNode } from 'react';
|
|
8
|
+
import { cn } from '../../infrastructure/utils';
|
|
9
|
+
import {
|
|
10
|
+
Dialog,
|
|
11
|
+
DialogContent,
|
|
12
|
+
DialogDescription,
|
|
13
|
+
DialogFooter,
|
|
14
|
+
DialogHeader,
|
|
15
|
+
DialogTitle,
|
|
16
|
+
} from './Dialog';
|
|
17
|
+
import { Button } from '../atoms';
|
|
18
|
+
import { Loader2 } from 'lucide-react';
|
|
19
|
+
import type { BaseProps } from '../../domain/types';
|
|
20
|
+
|
|
21
|
+
export interface FormModalProps extends BaseProps {
|
|
22
|
+
open: boolean;
|
|
23
|
+
onOpenChange: (open: boolean) => void;
|
|
24
|
+
title: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
onSubmit?: (e: React.FormEvent) => void | Promise<void>;
|
|
28
|
+
loading?: boolean;
|
|
29
|
+
submitText?: string;
|
|
30
|
+
cancelText?: string;
|
|
31
|
+
showFooter?: boolean;
|
|
32
|
+
footer?: ReactNode;
|
|
33
|
+
size?: 'sm' | 'md' | 'lg' | 'xl' | 'full';
|
|
34
|
+
preventCloseOnSubmit?: boolean;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const sizeStyles = {
|
|
38
|
+
sm: 'sm:max-w-[400px]',
|
|
39
|
+
md: 'sm:max-w-[425px]',
|
|
40
|
+
lg: 'sm:max-w-[600px]',
|
|
41
|
+
xl: 'sm:max-w-[800px]',
|
|
42
|
+
full: 'sm:max-w-[95vw]',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const FormModal = forwardRef<HTMLDivElement, FormModalProps>(
|
|
46
|
+
(
|
|
47
|
+
{
|
|
48
|
+
className,
|
|
49
|
+
open,
|
|
50
|
+
onOpenChange,
|
|
51
|
+
title,
|
|
52
|
+
description,
|
|
53
|
+
children,
|
|
54
|
+
onSubmit,
|
|
55
|
+
loading = false,
|
|
56
|
+
submitText = 'Submit',
|
|
57
|
+
cancelText = 'Cancel',
|
|
58
|
+
showFooter = true,
|
|
59
|
+
footer,
|
|
60
|
+
size = 'md',
|
|
61
|
+
preventCloseOnSubmit = false,
|
|
62
|
+
...props
|
|
63
|
+
},
|
|
64
|
+
ref
|
|
65
|
+
) => {
|
|
66
|
+
const handleSubmit = async (e: React.FormEvent) => {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
if (onSubmit && !loading) {
|
|
69
|
+
await onSubmit(e);
|
|
70
|
+
if (!preventCloseOnSubmit) {
|
|
71
|
+
onOpenChange(false);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
78
|
+
<DialogContent className={cn(sizeStyles[size], className)} ref={ref} {...props}>
|
|
79
|
+
{onSubmit ? (
|
|
80
|
+
<form onSubmit={handleSubmit}>
|
|
81
|
+
<DialogHeader>
|
|
82
|
+
<DialogTitle>{title}</DialogTitle>
|
|
83
|
+
{description && <DialogDescription>{description}</DialogDescription>}
|
|
84
|
+
</DialogHeader>
|
|
85
|
+
<div className="grid gap-4 py-4">{children}</div>
|
|
86
|
+
{showFooter && (
|
|
87
|
+
<DialogFooter>
|
|
88
|
+
{footer || (
|
|
89
|
+
<>
|
|
90
|
+
<Button type="button" variant="outline" onClick={() => onOpenChange(false)} disabled={loading}>
|
|
91
|
+
{cancelText}
|
|
92
|
+
</Button>
|
|
93
|
+
<Button type="submit" disabled={loading}>
|
|
94
|
+
{loading && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
95
|
+
{submitText}
|
|
96
|
+
</Button>
|
|
97
|
+
</>
|
|
98
|
+
)}
|
|
99
|
+
</DialogFooter>
|
|
100
|
+
)}
|
|
101
|
+
</form>
|
|
102
|
+
) : (
|
|
103
|
+
<>
|
|
104
|
+
<DialogHeader>
|
|
105
|
+
<DialogTitle>{title}</DialogTitle>
|
|
106
|
+
{description && <DialogDescription>{description}</DialogDescription>}
|
|
107
|
+
</DialogHeader>
|
|
108
|
+
<div className="grid gap-4 py-4">{children}</div>
|
|
109
|
+
{showFooter && (
|
|
110
|
+
<DialogFooter>
|
|
111
|
+
{footer || (
|
|
112
|
+
<Button variant="outline" onClick={() => onOpenChange(false)} disabled={loading}>
|
|
113
|
+
{cancelText}
|
|
114
|
+
</Button>
|
|
115
|
+
)}
|
|
116
|
+
</DialogFooter>
|
|
117
|
+
)}
|
|
118
|
+
</>
|
|
119
|
+
)}
|
|
120
|
+
</DialogContent>
|
|
121
|
+
</Dialog>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
FormModal.displayName = 'FormModal';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HoverCard Component (Organism)
|
|
3
|
+
* @description Hover-triggered card (Shadcn/ui compatible)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import * as HoverCardPrimitive from '@radix-ui/react-hover-card';
|
|
8
|
+
import { cn } from '../../infrastructure/utils';
|
|
9
|
+
|
|
10
|
+
const HoverCard = HoverCardPrimitive.Root;
|
|
11
|
+
|
|
12
|
+
const HoverCardTrigger = HoverCardPrimitive.Trigger;
|
|
13
|
+
|
|
14
|
+
const HoverCardContent = React.forwardRef<
|
|
15
|
+
React.ElementRef<typeof HoverCardPrimitive.Content>,
|
|
16
|
+
React.ComponentPropsWithoutRef<typeof HoverCardPrimitive.Content>
|
|
17
|
+
>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (
|
|
18
|
+
<HoverCardPrimitive.Content
|
|
19
|
+
ref={ref}
|
|
20
|
+
align={align}
|
|
21
|
+
sideOffset={sideOffset}
|
|
22
|
+
className={cn(
|
|
23
|
+
'z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
));
|
|
29
|
+
HoverCardContent.displayName = HoverCardPrimitive.Content.displayName;
|
|
30
|
+
|
|
31
|
+
export { HoverCard, HoverCardTrigger, HoverCardContent };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LoadingState Component (Organism)
|
|
3
|
+
* @description Component for displaying loading states
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { forwardRef } from 'react';
|
|
7
|
+
import { cn } from '../../infrastructure/utils';
|
|
8
|
+
import { Spinner } from '../atoms/Spinner';
|
|
9
|
+
import type { BaseProps, SizeVariant } from '../../domain/types';
|
|
10
|
+
|
|
11
|
+
export interface LoadingStateProps extends BaseProps {
|
|
12
|
+
message?: string;
|
|
13
|
+
size?: Extract<SizeVariant, 'sm' | 'md' | 'lg'>;
|
|
14
|
+
variant?: 'spinner' | 'skeleton' | 'dots';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const sizeStyles = {
|
|
18
|
+
sm: 'gap-3',
|
|
19
|
+
md: 'gap-4',
|
|
20
|
+
lg: 'gap-5',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const spinnerSizeStyles = {
|
|
24
|
+
sm: 'sm' as const,
|
|
25
|
+
md: 'md' as const,
|
|
26
|
+
lg: 'lg' as const,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const messageSizeStyles = {
|
|
30
|
+
sm: 'text-xs',
|
|
31
|
+
md: 'text-sm',
|
|
32
|
+
lg: 'text-base',
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const LoadingState = forwardRef<HTMLDivElement, LoadingStateProps>(
|
|
36
|
+
(
|
|
37
|
+
{
|
|
38
|
+
className,
|
|
39
|
+
message,
|
|
40
|
+
size = 'md',
|
|
41
|
+
variant = 'spinner',
|
|
42
|
+
...props
|
|
43
|
+
},
|
|
44
|
+
ref
|
|
45
|
+
) => {
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
ref={ref}
|
|
49
|
+
className={cn(
|
|
50
|
+
'flex flex-col items-center justify-center p-8',
|
|
51
|
+
sizeStyles[size],
|
|
52
|
+
className
|
|
53
|
+
)}
|
|
54
|
+
{...props}
|
|
55
|
+
>
|
|
56
|
+
{variant === 'spinner' && <Spinner size={spinnerSizeStyles[size]} />}
|
|
57
|
+
{variant === 'dots' && (
|
|
58
|
+
<div className="flex gap-1">
|
|
59
|
+
{[0, 1, 2].map((i) => (
|
|
60
|
+
<div
|
|
61
|
+
key={i}
|
|
62
|
+
className={cn(
|
|
63
|
+
'w-2 h-2 bg-primary rounded-full animate-bounce',
|
|
64
|
+
size === 'sm' && 'w-1.5 h-1.5',
|
|
65
|
+
size === 'lg' && 'w-3 h-3'
|
|
66
|
+
)}
|
|
67
|
+
style={{ animationDelay: `${i * 0.15}s` }}
|
|
68
|
+
/>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
)}
|
|
72
|
+
{variant === 'skeleton' && (
|
|
73
|
+
<div className="w-full space-y-3">
|
|
74
|
+
<div className="h-4 bg-muted animate-pulse rounded" style={{ width: '40%' }} />
|
|
75
|
+
<div className="h-3 bg-muted animate-pulse rounded" style={{ width: '70%' }} />
|
|
76
|
+
<div className="h-3 bg-muted animate-pulse rounded" style={{ width: '60%' }} />
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
{message && variant !== 'skeleton' && (
|
|
80
|
+
<p className={cn('text-muted-foreground mt-2', messageSizeStyles[size])}>{message}</p>
|
|
81
|
+
)}
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
LoadingState.displayName = 'LoadingState';
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MetricCard Component (Organism)
|
|
3
|
+
* @description Card component for displaying metrics and statistics with trend indicators
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { forwardRef, type ComponentProps } from 'react';
|
|
7
|
+
import { cn } from '../../infrastructure/utils';
|
|
8
|
+
import { Card, CardContent } from './Card';
|
|
9
|
+
import type { BaseProps, ColorVariant, SizeVariant } from '../../domain/types';
|
|
10
|
+
|
|
11
|
+
export interface MetricCardProps extends BaseProps {
|
|
12
|
+
title: string;
|
|
13
|
+
value: string | number;
|
|
14
|
+
icon?: React.ComponentType<{ className?: string }>;
|
|
15
|
+
iconColor?: string;
|
|
16
|
+
trend?: {
|
|
17
|
+
value: number;
|
|
18
|
+
label?: string;
|
|
19
|
+
};
|
|
20
|
+
size?: Extract<SizeVariant, 'sm' | 'md' | 'lg'>;
|
|
21
|
+
variant?: ColorVariant;
|
|
22
|
+
trendValueFormatter?: (value: number) => string;
|
|
23
|
+
onClick?: () => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const sizeStyles = {
|
|
27
|
+
sm: 'p-3',
|
|
28
|
+
md: 'p-4',
|
|
29
|
+
lg: 'p-5',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const valueSizeStyles = {
|
|
33
|
+
sm: 'text-lg',
|
|
34
|
+
md: 'text-2xl',
|
|
35
|
+
lg: 'text-3xl',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const iconSizeStyles = {
|
|
39
|
+
sm: 'h-4 w-4',
|
|
40
|
+
md: 'h-8 w-8',
|
|
41
|
+
lg: 'h-10 w-10',
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const labelSizeStyles = {
|
|
45
|
+
sm: 'text-xs',
|
|
46
|
+
md: 'text-sm',
|
|
47
|
+
lg: 'text-base',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const trendColors: Record<ColorVariant, { positive: string; negative: string; bg: string }> = {
|
|
51
|
+
primary: { positive: 'text-primary', negative: 'text-destructive', bg: 'bg-primary' },
|
|
52
|
+
secondary: { positive: 'text-secondary', negative: 'text-destructive', bg: 'bg-secondary' },
|
|
53
|
+
success: { positive: 'text-success', negative: 'text-destructive', bg: 'bg-success' },
|
|
54
|
+
warning: { positive: 'text-warning', negative: 'text-destructive', bg: 'bg-warning' },
|
|
55
|
+
destructive: { positive: 'text-destructive', negative: 'text-success', bg: 'bg-destructive' },
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const MetricCard = forwardRef<HTMLDivElement, MetricCardProps>(
|
|
59
|
+
(
|
|
60
|
+
{
|
|
61
|
+
className,
|
|
62
|
+
title,
|
|
63
|
+
value,
|
|
64
|
+
icon: Icon,
|
|
65
|
+
iconColor = 'text-primary',
|
|
66
|
+
trend,
|
|
67
|
+
size = 'md',
|
|
68
|
+
variant = 'primary',
|
|
69
|
+
trendValueFormatter = (v) => `${v > 0 ? '+' : ''}${v}%`,
|
|
70
|
+
onClick,
|
|
71
|
+
...props
|
|
72
|
+
},
|
|
73
|
+
ref
|
|
74
|
+
) => {
|
|
75
|
+
const isPositive = trend?.value !== undefined && trend.value >= 0;
|
|
76
|
+
const TrendIcon = isPositive ? '↑' : '↓';
|
|
77
|
+
const colors = trendColors[variant];
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<Card
|
|
81
|
+
ref={ref}
|
|
82
|
+
className={cn(
|
|
83
|
+
'transition-all duration-200',
|
|
84
|
+
onClick && 'cursor-pointer hover:shadow-md hover:border-primary/50',
|
|
85
|
+
className
|
|
86
|
+
)}
|
|
87
|
+
onClick={onClick}
|
|
88
|
+
{...props}
|
|
89
|
+
>
|
|
90
|
+
<CardContent className={cn(sizeStyles[size])}>
|
|
91
|
+
<div className="flex items-center justify-between">
|
|
92
|
+
<div className="flex-1">
|
|
93
|
+
<p className={cn('text-muted-foreground font-medium', labelSizeStyles[size])}>{title}</p>
|
|
94
|
+
<p className={cn('font-bold text-foreground', valueSizeStyles[size])}>
|
|
95
|
+
{typeof value === 'number' ? value.toLocaleString() : value}
|
|
96
|
+
</p>
|
|
97
|
+
{trend && (
|
|
98
|
+
<div className="flex items-center gap-1 mt-1">
|
|
99
|
+
<span
|
|
100
|
+
className={cn(
|
|
101
|
+
'text-xs font-medium',
|
|
102
|
+
isPositive ? colors.positive : colors.negative
|
|
103
|
+
)}
|
|
104
|
+
>
|
|
105
|
+
{TrendIcon}
|
|
106
|
+
</span>
|
|
107
|
+
<p className={cn('text-xs', isPositive ? colors.positive : colors.negative)}>
|
|
108
|
+
{trendValueFormatter(trend.value)}
|
|
109
|
+
</p>
|
|
110
|
+
{trend.label && (
|
|
111
|
+
<p className="text-xs text-muted-foreground ml-1">{trend.label}</p>
|
|
112
|
+
)}
|
|
113
|
+
</div>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
{Icon && (
|
|
117
|
+
<Icon className={cn(iconSizeStyles[size], iconColor, 'flex-shrink-0')} />
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
</CardContent>
|
|
121
|
+
</Card>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
MetricCard.displayName = 'MetricCard';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Popover Component (Organism)
|
|
3
|
+
* @description Popover dialog (Shadcn/ui compatible)
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
8
|
+
import { cn } from '../../infrastructure/utils';
|
|
9
|
+
|
|
10
|
+
const Popover = PopoverPrimitive.Root;
|
|
11
|
+
|
|
12
|
+
const PopoverTrigger = PopoverPrimitive.Trigger;
|
|
13
|
+
|
|
14
|
+
const PopoverContent = React.forwardRef<
|
|
15
|
+
React.ElementRef<typeof PopoverPrimitive.Content>,
|
|
16
|
+
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
|
|
17
|
+
>(({ className, align = 'center', sideOffset = 4, ...props }, ref) => (
|
|
18
|
+
<PopoverPrimitive.Portal>
|
|
19
|
+
<PopoverPrimitive.Content
|
|
20
|
+
ref={ref}
|
|
21
|
+
align={align}
|
|
22
|
+
sideOffset={sideOffset}
|
|
23
|
+
className={cn(
|
|
24
|
+
'z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
|
|
25
|
+
className
|
|
26
|
+
)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
</PopoverPrimitive.Portal>
|
|
30
|
+
));
|
|
31
|
+
PopoverContent.displayName = PopoverPrimitive.Content.displayName;
|
|
32
|
+
|
|
33
|
+
export { Popover, PopoverTrigger, PopoverContent };
|