@connectycube/react-ui-kit 0.0.17 → 0.0.19
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/configs/dependencies.json +27 -0
- package/configs/imports.json +9 -0
- package/dist/index.cjs +14 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/types/components/attachment.d.ts +45 -0
- package/dist/types/components/attachment.d.ts.map +1 -0
- package/dist/types/components/avatar.d.ts +3 -3
- package/dist/types/components/avatar.d.ts.map +1 -1
- package/dist/types/components/badge.d.ts +3 -3
- package/dist/types/components/badge.d.ts.map +1 -1
- package/dist/types/components/button.d.ts +2 -2
- package/dist/types/components/dialog-item.d.ts +46 -0
- package/dist/types/components/dialog-item.d.ts.map +1 -0
- package/dist/types/components/file-picker.d.ts +22 -0
- package/dist/types/components/file-picker.d.ts.map +1 -0
- package/dist/types/components/formatted-date.d.ts +8 -0
- package/dist/types/components/formatted-date.d.ts.map +1 -0
- package/dist/types/components/input.d.ts.map +1 -1
- package/dist/types/components/label.d.ts +5 -0
- package/dist/types/components/label.d.ts.map +1 -0
- package/dist/types/components/link-preview.d.ts +21 -0
- package/dist/types/components/link-preview.d.ts.map +1 -0
- package/dist/types/components/linkify-text.d.ts +9 -0
- package/dist/types/components/linkify-text.d.ts.map +1 -0
- package/dist/types/components/spinner.d.ts +3 -1
- package/dist/types/components/spinner.d.ts.map +1 -1
- package/dist/types/components/status-sent.d.ts +7 -0
- package/dist/types/components/status-sent.d.ts.map +1 -0
- package/dist/types/components/switch.d.ts +6 -0
- package/dist/types/components/switch.d.ts.map +1 -0
- package/dist/types/components/utils.d.ts +0 -1
- package/dist/types/components/utils.d.ts.map +1 -1
- package/dist/types/index.d.ts +21 -4
- package/dist/types/index.d.ts.map +1 -1
- package/gen/components/attachment.jsx +214 -0
- package/gen/components/avatar.jsx +13 -3
- package/gen/components/badge.jsx +3 -3
- package/gen/components/button.jsx +2 -2
- package/gen/components/dialog-item.jsx +149 -0
- package/gen/components/dismiss-layer.jsx +1 -1
- package/gen/components/file-picker.jsx +200 -0
- package/gen/components/formatted-date.jsx +57 -0
- package/gen/components/label.jsx +22 -0
- package/gen/components/link-preview.jsx +131 -0
- package/gen/components/linkify-text.jsx +31 -0
- package/gen/components/spinner.jsx +29 -5
- package/gen/components/status-sent.jsx +21 -0
- package/gen/components/switch.jsx +25 -0
- package/gen/components/utils.js +0 -7
- package/gen/index.js +46 -0
- package/package.json +5 -1
- package/src/components/attachment.tsx +270 -0
- package/src/components/avatar.tsx +16 -6
- package/src/components/badge.tsx +6 -6
- package/src/components/button.tsx +2 -2
- package/src/components/connectycube-ui/avatar.jsx +54 -0
- package/src/components/connectycube-ui/avatar.tsx +77 -0
- package/src/components/connectycube-ui/badge.jsx +45 -0
- package/src/components/connectycube-ui/badge.tsx +42 -0
- package/src/components/connectycube-ui/dialog-item.jsx +149 -0
- package/src/components/connectycube-ui/dialog-item.tsx +188 -0
- package/src/components/connectycube-ui/file-picker.jsx +200 -0
- package/src/components/connectycube-ui/file-picker.tsx +231 -0
- package/src/components/connectycube-ui/formatted-date.jsx +57 -0
- package/src/components/connectycube-ui/formatted-date.tsx +57 -0
- package/src/components/connectycube-ui/label.jsx +22 -0
- package/src/components/connectycube-ui/label.tsx +23 -0
- package/src/components/connectycube-ui/linkify-text.tsx +40 -0
- package/src/components/connectycube-ui/presence.jsx +81 -0
- package/src/components/connectycube-ui/presence.tsx +96 -0
- package/src/components/connectycube-ui/status-sent.jsx +21 -0
- package/src/components/connectycube-ui/status-sent.tsx +25 -0
- package/src/components/connectycube-ui/utils.js +10 -0
- package/src/components/connectycube-ui/utils.ts +10 -0
- package/src/components/dialog-item.tsx +188 -0
- package/src/components/dismiss-layer.tsx +1 -1
- package/src/components/file-picker.tsx +231 -0
- package/src/components/formatted-date.tsx +57 -0
- package/src/components/input.tsx +1 -1
- package/src/components/label.tsx +23 -0
- package/src/components/link-preview.tsx +149 -0
- package/src/components/linkify-text.tsx +41 -0
- package/src/components/spinner.tsx +31 -5
- package/src/components/status-sent.tsx +25 -0
- package/src/components/switch.tsx +27 -0
- package/src/components/utils.ts +0 -7
- package/src/index.ts +72 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { forwardRef } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
3
3
|
import { cva } from 'class-variance-authority';
|
|
4
4
|
import { cn } from './utils';
|
|
5
5
|
|
|
@@ -32,7 +32,7 @@ const buttonVariants = cva(
|
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
function ButtonBase({ asChild = false, variant, size, className, ...props }, ref) {
|
|
35
|
-
const Comp = asChild ?
|
|
35
|
+
const Comp = asChild ? Slot : 'button';
|
|
36
36
|
|
|
37
37
|
return (
|
|
38
38
|
<Comp
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { Avatar } from './avatar';
|
|
2
|
+
import { Users } from 'lucide-react';
|
|
3
|
+
import { forwardRef, memo } from 'react';
|
|
4
|
+
import { FormattedDate } from './formatted-date';
|
|
5
|
+
import { StatusSent } from './status-sent';
|
|
6
|
+
import { cn } from './utils';
|
|
7
|
+
import { Badge } from './badge';
|
|
8
|
+
|
|
9
|
+
function DialogItemBase(
|
|
10
|
+
{
|
|
11
|
+
index = -1,
|
|
12
|
+
isPrivateDialog,
|
|
13
|
+
selected,
|
|
14
|
+
onSelect = () => {},
|
|
15
|
+
name,
|
|
16
|
+
photo,
|
|
17
|
+
userOnline,
|
|
18
|
+
userPresence,
|
|
19
|
+
hasGroupIcon,
|
|
20
|
+
lastSentStatus,
|
|
21
|
+
lastSentDate,
|
|
22
|
+
lastSenderName,
|
|
23
|
+
lastMessage,
|
|
24
|
+
typingStatusText,
|
|
25
|
+
draft,
|
|
26
|
+
draftLabel = 'Draft',
|
|
27
|
+
unreadCount = 0,
|
|
28
|
+
language = 'en',
|
|
29
|
+
divider = 'bottom',
|
|
30
|
+
avatarProps,
|
|
31
|
+
contentProps,
|
|
32
|
+
headerProps,
|
|
33
|
+
headerLeftProps,
|
|
34
|
+
groupIconProps,
|
|
35
|
+
nameProps,
|
|
36
|
+
headerRightProps,
|
|
37
|
+
statusSentIconProps,
|
|
38
|
+
formattedDateProps,
|
|
39
|
+
footerProps,
|
|
40
|
+
lastMessageProps,
|
|
41
|
+
draftLabelProps,
|
|
42
|
+
lastSenderNameProps,
|
|
43
|
+
unreadBadgeProps,
|
|
44
|
+
dividerProps,
|
|
45
|
+
...props
|
|
46
|
+
},
|
|
47
|
+
ref
|
|
48
|
+
) {
|
|
49
|
+
const avatarSource = photo || avatarProps?.src;
|
|
50
|
+
const avatarFallback = name || avatarProps?.name;
|
|
51
|
+
const avatarOnline = isPrivateDialog ? userOnline || avatarProps?.online : false;
|
|
52
|
+
const avatarPresence = isPrivateDialog ? userPresence || avatarProps?.presence : undefined;
|
|
53
|
+
const showTopDivider = divider === 'top' || (divider === 'both' && index === 0);
|
|
54
|
+
const showBottomDivider = divider === 'bottom' || divider === 'both';
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div
|
|
58
|
+
ref={ref}
|
|
59
|
+
{...props}
|
|
60
|
+
onClick={onSelect}
|
|
61
|
+
className={cn(
|
|
62
|
+
'flex items-start gap-2 px-2 flex-1 cursor-pointer',
|
|
63
|
+
'transition-colors duration-200 ease-linear',
|
|
64
|
+
`${selected ? 'border-l-[0.25em] pl-1 border-l-ring bg-ring/20' : 'hover:bg-ring/5'}`,
|
|
65
|
+
props?.className
|
|
66
|
+
)}
|
|
67
|
+
>
|
|
68
|
+
<Avatar
|
|
69
|
+
src={avatarSource}
|
|
70
|
+
name={avatarFallback}
|
|
71
|
+
online={avatarOnline}
|
|
72
|
+
presence={avatarPresence}
|
|
73
|
+
{...avatarProps}
|
|
74
|
+
className={cn(`size-13 my-2 ${photo ? 'bg-ring/10' : 'bg-ring/30'}`, avatarProps?.className)}
|
|
75
|
+
/>
|
|
76
|
+
|
|
77
|
+
<div
|
|
78
|
+
{...contentProps}
|
|
79
|
+
className={cn('relative self-stretch flex-1 flex-col text-foreground', contentProps?.className)}
|
|
80
|
+
>
|
|
81
|
+
<div {...headerProps} className={cn('flex items-center justify-between gap-1', headerProps?.className)}>
|
|
82
|
+
<div {...headerLeftProps} className={cn('flex items-center gap-1', headerLeftProps?.className)}>
|
|
83
|
+
{!isPrivateDialog && hasGroupIcon && (
|
|
84
|
+
<Users
|
|
85
|
+
{...groupIconProps}
|
|
86
|
+
className={cn('text-muted-foreground size-4 min-w-4', groupIconProps?.className)}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
<span {...nameProps} className={cn('font-medium text-left line-clamp-1', nameProps?.className)}>
|
|
90
|
+
{name}
|
|
91
|
+
</span>
|
|
92
|
+
</div>
|
|
93
|
+
<div {...headerRightProps} className={cn('flex items-center gap-1', headerRightProps?.className)}>
|
|
94
|
+
<StatusSent status={lastSentStatus} {...statusSentIconProps} />
|
|
95
|
+
<FormattedDate date={lastSentDate} language={language} {...formattedDateProps} />
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
<div {...footerProps} className={cn('flex items-start justify-between gap-1', footerProps?.className)}>
|
|
99
|
+
<span
|
|
100
|
+
{...lastMessageProps}
|
|
101
|
+
className={cn('text-sm text-left text-muted-foreground line-clamp-2', lastMessageProps?.className)}
|
|
102
|
+
>
|
|
103
|
+
{typingStatusText ||
|
|
104
|
+
(draft ? (
|
|
105
|
+
<span>
|
|
106
|
+
<span
|
|
107
|
+
{...draftLabelProps}
|
|
108
|
+
className={cn('text-red-500 font-medium', draftLabelProps?.className)}
|
|
109
|
+
>{`${draftLabel}: `}</span>
|
|
110
|
+
{draft}
|
|
111
|
+
</span>
|
|
112
|
+
) : (
|
|
113
|
+
<span>
|
|
114
|
+
{lastSenderName && (
|
|
115
|
+
<span
|
|
116
|
+
{...lastSenderNameProps}
|
|
117
|
+
className={cn('font-semibold', lastSenderNameProps?.className)}
|
|
118
|
+
>{`${lastSenderName}: `}</span>
|
|
119
|
+
)}
|
|
120
|
+
{lastMessage}
|
|
121
|
+
</span>
|
|
122
|
+
))}
|
|
123
|
+
</span>
|
|
124
|
+
{unreadCount > 0 && (
|
|
125
|
+
<Badge
|
|
126
|
+
{...unreadBadgeProps}
|
|
127
|
+
className={cn(
|
|
128
|
+
'bg-ring text-background text-xs rounded-full p-1 h-6 min-w-6 mt-0.5',
|
|
129
|
+
unreadBadgeProps?.className
|
|
130
|
+
)}
|
|
131
|
+
>
|
|
132
|
+
{unreadCount}
|
|
133
|
+
</Badge>
|
|
134
|
+
)}
|
|
135
|
+
</div>
|
|
136
|
+
{showTopDivider && (
|
|
137
|
+
<div {...dividerProps} className={cn('absolute -top-px left-0 right-0 border-t', dividerProps?.className)} />
|
|
138
|
+
)}
|
|
139
|
+
{showBottomDivider && <div className="absolute bottom-0 left-0 right-0 border-b" />}
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const DialogItem = memo(forwardRef(DialogItemBase));
|
|
146
|
+
|
|
147
|
+
DialogItem.displayName = 'DialogItem';
|
|
148
|
+
|
|
149
|
+
export { DialogItem };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { forwardRef, useState } from 'react';
|
|
2
|
+
import { FilePlusCorner, Paperclip } from 'lucide-react';
|
|
3
|
+
import { Label } from './label';
|
|
4
|
+
import { cn } from './utils';
|
|
5
|
+
|
|
6
|
+
const areValidFiles = (files, accept) => {
|
|
7
|
+
if (files.length === 0) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const acceptList =
|
|
12
|
+
typeof accept === 'string' ? accept.split(/\s*,\s*|\s+/).map((type) => type.toLowerCase().trim()) : null;
|
|
13
|
+
|
|
14
|
+
if (acceptList === null || acceptList.length === 0) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return files.every((file) => {
|
|
19
|
+
const { type, size } = file;
|
|
20
|
+
|
|
21
|
+
if (typeof type !== 'string' || typeof size !== 'number' || size <= 0 || type.length === 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const fileMimeType = type.toLowerCase();
|
|
26
|
+
const [fileType, fileSubtype] = fileMimeType.split('/');
|
|
27
|
+
|
|
28
|
+
return acceptList.some(
|
|
29
|
+
(acceptType) =>
|
|
30
|
+
acceptType.startsWith('*') ||
|
|
31
|
+
acceptType === fileMimeType ||
|
|
32
|
+
(fileType && acceptType.endsWith('/*') && acceptType.startsWith(fileType)) ||
|
|
33
|
+
(acceptType.startsWith('.') && acceptType.slice(1) === fileSubtype)
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const handleFiles = (fileList, accept, multiple, onSelectFile, onInvalidFile) => {
|
|
38
|
+
const files = Array.from(fileList || []).filter(Boolean);
|
|
39
|
+
|
|
40
|
+
if (files.length === 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const validated = areValidFiles(files, accept);
|
|
45
|
+
|
|
46
|
+
if (validated) {
|
|
47
|
+
onSelectFile(multiple ? files : files[0] ? [files[0]] : []);
|
|
48
|
+
} else {
|
|
49
|
+
onInvalidFile();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function FilePickerInputBase(
|
|
54
|
+
{
|
|
55
|
+
onSelectFile = () => {},
|
|
56
|
+
onInvalidFile = () => {},
|
|
57
|
+
multiple = false,
|
|
58
|
+
accept = '*/*',
|
|
59
|
+
iconElement,
|
|
60
|
+
labelProps,
|
|
61
|
+
iconProps,
|
|
62
|
+
...props
|
|
63
|
+
},
|
|
64
|
+
ref
|
|
65
|
+
) {
|
|
66
|
+
const handleChange = (event) => {
|
|
67
|
+
handleFiles(event.currentTarget.files, accept, multiple, onSelectFile, onInvalidFile);
|
|
68
|
+
event.currentTarget.value = '';
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<Label
|
|
73
|
+
{...labelProps}
|
|
74
|
+
htmlFor="file-uploader"
|
|
75
|
+
className={cn(
|
|
76
|
+
'group p-2 rounded-full hover:bg-ring/10 transition-all duration-200 ease-in-out cursor-pointer',
|
|
77
|
+
labelProps?.className
|
|
78
|
+
)}
|
|
79
|
+
>
|
|
80
|
+
{iconElement || (
|
|
81
|
+
<Paperclip
|
|
82
|
+
{...iconProps}
|
|
83
|
+
className={cn(
|
|
84
|
+
'text-foreground group-hover:scale-110 transition-all duration-200 ease-in-out',
|
|
85
|
+
iconProps?.className
|
|
86
|
+
)}
|
|
87
|
+
/>
|
|
88
|
+
)}
|
|
89
|
+
<input
|
|
90
|
+
ref={ref}
|
|
91
|
+
id="file-uploader"
|
|
92
|
+
type="file"
|
|
93
|
+
multiple={multiple}
|
|
94
|
+
accept={accept}
|
|
95
|
+
onChange={handleChange}
|
|
96
|
+
{...props}
|
|
97
|
+
className={cn('hidden', props?.className)}
|
|
98
|
+
/>
|
|
99
|
+
</Label>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const FilePickerInput = forwardRef(FilePickerInputBase);
|
|
104
|
+
|
|
105
|
+
FilePickerInput.displayName = 'FilePickerInput';
|
|
106
|
+
|
|
107
|
+
function FilePickerDropzoneBase(
|
|
108
|
+
{
|
|
109
|
+
onSelectFile = () => {},
|
|
110
|
+
onInvalidFile = () => {},
|
|
111
|
+
multiple = false,
|
|
112
|
+
accept = '*/*',
|
|
113
|
+
children,
|
|
114
|
+
iconElement,
|
|
115
|
+
placeholder,
|
|
116
|
+
dropZoneProps,
|
|
117
|
+
placeholderContainerProps,
|
|
118
|
+
iconProps,
|
|
119
|
+
placeholderProps,
|
|
120
|
+
...props
|
|
121
|
+
},
|
|
122
|
+
ref
|
|
123
|
+
) {
|
|
124
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
125
|
+
const handleDragEvent = (event) => {
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
event.stopPropagation();
|
|
128
|
+
};
|
|
129
|
+
const handleDrop = (event) => {
|
|
130
|
+
handleDragEvent(event);
|
|
131
|
+
setIsDragging(false);
|
|
132
|
+
handleFiles(event.dataTransfer.files, accept, multiple, onSelectFile, onInvalidFile);
|
|
133
|
+
event.dataTransfer.clearData();
|
|
134
|
+
};
|
|
135
|
+
const handleDragEnter = (event) => {
|
|
136
|
+
handleDragEvent(event);
|
|
137
|
+
|
|
138
|
+
if (event.dataTransfer.items && event.dataTransfer.items.length > 0) {
|
|
139
|
+
setIsDragging(true);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
const handleDragLeave = (event) => {
|
|
143
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
144
|
+
setIsDragging(false);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<div
|
|
150
|
+
ref={ref}
|
|
151
|
+
onDragEnter={handleDragEnter}
|
|
152
|
+
onDragLeave={handleDragLeave}
|
|
153
|
+
onDragOver={handleDragEvent}
|
|
154
|
+
{...props}
|
|
155
|
+
className={cn('relative size-full min-h-0', props?.className)}
|
|
156
|
+
>
|
|
157
|
+
{children}
|
|
158
|
+
<div
|
|
159
|
+
onDrop={handleDrop}
|
|
160
|
+
{...dropZoneProps}
|
|
161
|
+
className={cn(
|
|
162
|
+
'absolute top-0 left-0 size-full',
|
|
163
|
+
'flex items-center justify-center',
|
|
164
|
+
'transition-all duration-300 ease-out',
|
|
165
|
+
'border-2 border-dashed border-ring bg-ring/25 rounded-md',
|
|
166
|
+
isDragging
|
|
167
|
+
? 'opacity-100 pointer-events-auto visible scale-100'
|
|
168
|
+
: 'opacity-0 pointer-events-none invisible scale-98',
|
|
169
|
+
dropZoneProps?.className
|
|
170
|
+
)}
|
|
171
|
+
>
|
|
172
|
+
<div
|
|
173
|
+
{...placeholderContainerProps}
|
|
174
|
+
className={cn(
|
|
175
|
+
'bg-muted flex flex-row items-center gap-2 rounded-full py-2 px-4 transition-all',
|
|
176
|
+
isDragging ? 'scale-100' : 'scale-90',
|
|
177
|
+
placeholderContainerProps?.className
|
|
178
|
+
)}
|
|
179
|
+
>
|
|
180
|
+
{iconElement || (
|
|
181
|
+
<FilePlusCorner
|
|
182
|
+
absoluteStrokeWidth
|
|
183
|
+
{...iconProps}
|
|
184
|
+
className={cn('text-ring size-6', iconProps?.className)}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
<span {...placeholderProps} className={cn('text-ring text-md font-bold', placeholderProps?.className)}>
|
|
188
|
+
{placeholder || 'Drop files here'}
|
|
189
|
+
</span>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const FilePickerDropzone = forwardRef(FilePickerDropzoneBase);
|
|
197
|
+
|
|
198
|
+
FilePickerDropzone.displayName = 'FilePickerDropzone';
|
|
199
|
+
|
|
200
|
+
export { FilePickerInput, FilePickerDropzone, FilePickerInput as Input, FilePickerDropzone as Dropzone };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { forwardRef, memo } from 'react';
|
|
2
|
+
import { differenceInCalendarDays, format, formatDistanceToNow, isToday } from 'date-fns';
|
|
3
|
+
import { el, enUS, uk } from 'date-fns/locale';
|
|
4
|
+
import { cn } from './utils';
|
|
5
|
+
|
|
6
|
+
const locales = {
|
|
7
|
+
en: enUS,
|
|
8
|
+
el: el,
|
|
9
|
+
ua: uk,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function formatDate(date, language = 'en', distanceToNow = false) {
|
|
13
|
+
const locale = locales[language] ?? enUS;
|
|
14
|
+
|
|
15
|
+
if (distanceToNow) {
|
|
16
|
+
return formatDistanceToNow(date, {
|
|
17
|
+
locale,
|
|
18
|
+
addSuffix: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const isWithinLast7Days = (date) => {
|
|
23
|
+
const diff = differenceInCalendarDays(new Date(), date);
|
|
24
|
+
|
|
25
|
+
return diff >= 0 && diff <= 6;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return isToday(date)
|
|
29
|
+
? format(date, 'p', {
|
|
30
|
+
locale,
|
|
31
|
+
})
|
|
32
|
+
: isWithinLast7Days(date)
|
|
33
|
+
? format(date, 'eeee', {
|
|
34
|
+
locale,
|
|
35
|
+
})
|
|
36
|
+
: format(date, 'P', {
|
|
37
|
+
locale,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function FormattedDateBase({ date, language, distanceToNow, ...props }, ref) {
|
|
42
|
+
if (!date) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<span ref={ref} {...props} className={cn('text-xs text-muted-foreground', props?.className)}>
|
|
48
|
+
{formatDate(date, language, distanceToNow)}
|
|
49
|
+
</span>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const FormattedDate = memo(forwardRef(FormattedDateBase));
|
|
54
|
+
|
|
55
|
+
FormattedDate.displayName = 'FormattedDate';
|
|
56
|
+
|
|
57
|
+
export { FormattedDate };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { forwardRef } from 'react';
|
|
2
|
+
import { Root as LabelRoot } from '@radix-ui/react-label';
|
|
3
|
+
import { cn } from './utils';
|
|
4
|
+
|
|
5
|
+
function LabelBase({ ...props }, ref) {
|
|
6
|
+
return (
|
|
7
|
+
<LabelRoot
|
|
8
|
+
ref={ref}
|
|
9
|
+
{...props}
|
|
10
|
+
className={cn(
|
|
11
|
+
'flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50',
|
|
12
|
+
props?.className
|
|
13
|
+
)}
|
|
14
|
+
/>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const Label = forwardRef(LabelBase);
|
|
19
|
+
|
|
20
|
+
Label.displayName = 'Label';
|
|
21
|
+
|
|
22
|
+
export { Label };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { forwardRef, memo, useCallback, useState } from 'react';
|
|
2
|
+
import { Globe } from 'lucide-react';
|
|
3
|
+
import { cn } from './utils';
|
|
4
|
+
|
|
5
|
+
const decodeHtmlEntities = (text) => {
|
|
6
|
+
if (text.length === 0) {
|
|
7
|
+
return text;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const element = document.createElement('div');
|
|
11
|
+
|
|
12
|
+
element.innerHTML = text;
|
|
13
|
+
|
|
14
|
+
return element.textContent.trim();
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
function LinkPreviewBase(
|
|
18
|
+
{
|
|
19
|
+
thin = false,
|
|
20
|
+
title = '',
|
|
21
|
+
description = '',
|
|
22
|
+
icon,
|
|
23
|
+
iconFallbackElement,
|
|
24
|
+
image,
|
|
25
|
+
onReady = () => {},
|
|
26
|
+
titleContainerProps,
|
|
27
|
+
iconProps,
|
|
28
|
+
iconFallbackProps,
|
|
29
|
+
titleProps,
|
|
30
|
+
descriptionProps,
|
|
31
|
+
imageContainerProps,
|
|
32
|
+
imageProps,
|
|
33
|
+
...props
|
|
34
|
+
},
|
|
35
|
+
ref
|
|
36
|
+
) {
|
|
37
|
+
const [iconSrc, setIconSrc] = useState(icon);
|
|
38
|
+
const [imageSrc, setImageSrc] = useState(image);
|
|
39
|
+
const handleOnLoad = useCallback(
|
|
40
|
+
(event) => {
|
|
41
|
+
imageProps?.onLoad?.(event);
|
|
42
|
+
onReady();
|
|
43
|
+
},
|
|
44
|
+
[onReady, imageProps]
|
|
45
|
+
);
|
|
46
|
+
const handleIconOnError = useCallback(
|
|
47
|
+
(event) => {
|
|
48
|
+
iconProps?.onError?.(event);
|
|
49
|
+
setIconSrc(undefined);
|
|
50
|
+
},
|
|
51
|
+
[iconProps]
|
|
52
|
+
);
|
|
53
|
+
const handleImageOnError = useCallback(
|
|
54
|
+
(event) => {
|
|
55
|
+
imageProps?.onError?.(event);
|
|
56
|
+
setImageSrc(undefined);
|
|
57
|
+
},
|
|
58
|
+
[imageProps]
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<a
|
|
63
|
+
ref={ref}
|
|
64
|
+
target="_blank"
|
|
65
|
+
rel="noopener noreferrer"
|
|
66
|
+
{...props}
|
|
67
|
+
className={cn(
|
|
68
|
+
'transition-color duration-300 ease-out',
|
|
69
|
+
'grid items-start gap-2 p-2 mt-1 overflow-hidden rounded border-l-4 border-l-ring bg-white hover:bg-ring/20',
|
|
70
|
+
thin ? 'grid-cols-3' : 'grid-cols-1',
|
|
71
|
+
props?.className
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
<div
|
|
75
|
+
{...titleContainerProps}
|
|
76
|
+
className={cn('flex items-start gap-2', thin ? 'col-span-3' : 'col-span-1', titleContainerProps?.className)}
|
|
77
|
+
>
|
|
78
|
+
{iconSrc ? (
|
|
79
|
+
<img
|
|
80
|
+
alt="icon"
|
|
81
|
+
src={iconSrc}
|
|
82
|
+
{...iconProps}
|
|
83
|
+
onError={handleIconOnError}
|
|
84
|
+
className={cn('size-5', iconProps?.className)}
|
|
85
|
+
/>
|
|
86
|
+
) : (
|
|
87
|
+
iconFallbackElement || <Globe {...iconFallbackProps} className={cn('size-5', iconFallbackProps?.className)} />
|
|
88
|
+
)}
|
|
89
|
+
<span
|
|
90
|
+
{...titleProps}
|
|
91
|
+
className={cn('text-sm font-bold', thin ? 'line-clamp-1' : 'line-clamp-2', titleProps?.className)}
|
|
92
|
+
>
|
|
93
|
+
{decodeHtmlEntities(title)}
|
|
94
|
+
</span>
|
|
95
|
+
</div>
|
|
96
|
+
{description && (
|
|
97
|
+
<span
|
|
98
|
+
{...descriptionProps}
|
|
99
|
+
className={cn(
|
|
100
|
+
'text-sm line-clamp-5',
|
|
101
|
+
thin ? (imageSrc ? 'col-span-2' : 'col-span-3') : 'col-span-1',
|
|
102
|
+
descriptionProps?.className
|
|
103
|
+
)}
|
|
104
|
+
>
|
|
105
|
+
{decodeHtmlEntities(description)}
|
|
106
|
+
</span>
|
|
107
|
+
)}
|
|
108
|
+
{imageSrc && (
|
|
109
|
+
<div
|
|
110
|
+
{...imageContainerProps}
|
|
111
|
+
className={cn('flex items-center justify-center', imageContainerProps?.className)}
|
|
112
|
+
>
|
|
113
|
+
<img
|
|
114
|
+
alt="banner"
|
|
115
|
+
src={imageSrc}
|
|
116
|
+
{...imageProps}
|
|
117
|
+
onLoad={handleOnLoad}
|
|
118
|
+
onError={handleImageOnError}
|
|
119
|
+
className={cn('rounded max-w-full object-contain', thin ? 'max-h-25' : 'max-h-60', imageProps?.className)}
|
|
120
|
+
/>
|
|
121
|
+
</div>
|
|
122
|
+
)}
|
|
123
|
+
</a>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const LinkPreview = memo(forwardRef(LinkPreviewBase));
|
|
128
|
+
|
|
129
|
+
LinkPreview.displayName = 'LinkPreview';
|
|
130
|
+
|
|
131
|
+
export { LinkPreview };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { forwardRef, memo, useMemo } from 'react';
|
|
2
|
+
import Linkify from 'linkify-react';
|
|
3
|
+
import { cn } from './utils';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_LINKIFY_OPTIONS = {
|
|
6
|
+
target: '_blank',
|
|
7
|
+
rel: 'noopener noreferrer',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function LinkifyTextBase({ text, linkifyProps, ...props }, ref) {
|
|
11
|
+
const options = useMemo(
|
|
12
|
+
() => ({
|
|
13
|
+
...DEFAULT_LINKIFY_OPTIONS,
|
|
14
|
+
...linkifyProps,
|
|
15
|
+
className: cn('text-blue-500 hover:text-blue-600 hover:underline', linkifyProps?.className),
|
|
16
|
+
}),
|
|
17
|
+
[linkifyProps]
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<p ref={ref} {...props} className={cn('wrap-break-word text-base', props?.className)}>
|
|
22
|
+
<Linkify options={options}>{text}</Linkify>
|
|
23
|
+
</p>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const LinkifyText = memo(forwardRef(LinkifyTextBase));
|
|
28
|
+
|
|
29
|
+
LinkifyText.displayName = 'LinkifyText';
|
|
30
|
+
|
|
31
|
+
export { LinkifyText };
|
|
@@ -1,10 +1,34 @@
|
|
|
1
|
-
import { LoaderCircle } from 'lucide-react';
|
|
1
|
+
import { Loader, LoaderCircle } from 'lucide-react';
|
|
2
2
|
import { cn } from './utils';
|
|
3
3
|
|
|
4
|
-
function Spinner({ loading =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
)
|
|
4
|
+
function Spinner({ loading = false, layout = 'flow', type = 'default', ...props }) {
|
|
5
|
+
const LoaderIcon = type === 'circle' ? LoaderCircle : Loader;
|
|
6
|
+
|
|
7
|
+
if (!loading) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const spinnerElement = (
|
|
12
|
+
<LoaderIcon
|
|
13
|
+
strokeWidth={2.5}
|
|
14
|
+
{...props}
|
|
15
|
+
className={cn('animate-spin text-ring', layout === 'flow' && 'mx-auto', props?.className)}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
switch (layout) {
|
|
20
|
+
case 'absolute':
|
|
21
|
+
return (
|
|
22
|
+
<div className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2">{spinnerElement}</div>
|
|
23
|
+
);
|
|
24
|
+
case 'centered':
|
|
25
|
+
return <div className="flex items-center justify-center size-full">{spinnerElement}</div>;
|
|
26
|
+
case 'overlay':
|
|
27
|
+
return <div className="flex items-center justify-center size-full absolute bg-muted/50">{spinnerElement}</div>;
|
|
28
|
+
case 'flow':
|
|
29
|
+
default:
|
|
30
|
+
return spinnerElement;
|
|
31
|
+
}
|
|
8
32
|
}
|
|
9
33
|
|
|
10
34
|
Spinner.displayName = 'Spinner';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Ban, Check, CheckCheck, Clock } from 'lucide-react';
|
|
2
|
+
import { cn } from './utils';
|
|
3
|
+
|
|
4
|
+
const StatusSent = ({ status, ...props }) => {
|
|
5
|
+
switch (status) {
|
|
6
|
+
case 'wait':
|
|
7
|
+
return <Clock {...props} className={cn('text-gray-500 size-4', props?.className)} />;
|
|
8
|
+
case 'sent':
|
|
9
|
+
return <Check {...props} className={cn('text-gray-500 size-4', props?.className)} />;
|
|
10
|
+
case 'read':
|
|
11
|
+
return <CheckCheck {...props} className={cn('text-gray-500 size-4', props?.className)} />;
|
|
12
|
+
case 'lost':
|
|
13
|
+
return <Ban {...props} className={cn('text-red-500 size-4', props?.className)} />;
|
|
14
|
+
default:
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
StatusSent.displayName = 'StatusSent';
|
|
20
|
+
|
|
21
|
+
export { StatusSent };
|