@connectycube/react-ui-kit 0.0.18 → 0.0.20

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.
Files changed (53) hide show
  1. package/configs/dependencies.json +12 -0
  2. package/configs/imports.json +5 -1
  3. package/dist/index.cjs +1 -27
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.js +1 -27
  6. package/dist/index.js.map +1 -1
  7. package/dist/types/components/attachment.d.ts +45 -0
  8. package/dist/types/components/attachment.d.ts.map +1 -0
  9. package/dist/types/components/avatar.d.ts +2 -1
  10. package/dist/types/components/avatar.d.ts.map +1 -1
  11. package/dist/types/components/call-message.d.ts +17 -0
  12. package/dist/types/components/call-message.d.ts.map +1 -0
  13. package/dist/types/components/chat-message.d.ts +30 -0
  14. package/dist/types/components/chat-message.d.ts.map +1 -0
  15. package/dist/types/components/dialog-item.d.ts +4 -4
  16. package/dist/types/components/dialog-item.d.ts.map +1 -1
  17. package/dist/types/components/linkify-text.d.ts +6 -1
  18. package/dist/types/components/linkify-text.d.ts.map +1 -1
  19. package/dist/types/components/stream-view.d.ts.map +1 -1
  20. package/dist/types/components/switch.d.ts +6 -0
  21. package/dist/types/components/switch.d.ts.map +1 -0
  22. package/dist/types/components/utils.d.ts +1 -0
  23. package/dist/types/components/utils.d.ts.map +1 -1
  24. package/dist/types/index.d.ts +24 -4
  25. package/dist/types/index.d.ts.map +1 -1
  26. package/gen/components/attachment.jsx +216 -0
  27. package/gen/components/avatar.jsx +14 -2
  28. package/gen/components/call-message.jsx +62 -0
  29. package/gen/components/chat-message.jsx +120 -0
  30. package/gen/components/dialog-item.jsx +11 -8
  31. package/gen/components/dismiss-layer.jsx +1 -1
  32. package/gen/components/file-picker.jsx +2 -2
  33. package/gen/components/linkify-text.jsx +41 -2
  34. package/gen/components/stream-view.jsx +1 -5
  35. package/gen/components/switch.jsx +23 -0
  36. package/gen/components/utils.js +4 -0
  37. package/gen/index.js +50 -0
  38. package/package.json +12 -10
  39. package/src/components/attachment.tsx +269 -0
  40. package/src/components/avatar.tsx +4 -2
  41. package/src/components/call-message.tsx +75 -0
  42. package/src/components/chat-message.tsx +138 -0
  43. package/src/components/connectycube-ui/attachment.tsx +269 -0
  44. package/src/components/connectycube-ui/chat-message.tsx +138 -0
  45. package/src/components/connectycube-ui/link-preview.tsx +149 -0
  46. package/src/components/dialog-item.tsx +13 -10
  47. package/src/components/dismiss-layer.tsx +1 -1
  48. package/src/components/file-picker.tsx +2 -2
  49. package/src/components/linkify-text.tsx +44 -3
  50. package/src/components/stream-view.tsx +1 -5
  51. package/src/components/switch.tsx +25 -0
  52. package/src/components/utils.ts +4 -0
  53. package/src/index.ts +78 -4
@@ -0,0 +1,149 @@
1
+ import type React from 'react';
2
+ import { forwardRef, memo, useCallback, useState } from 'react';
3
+ import { Globe, type LucideProps } from 'lucide-react';
4
+ import { cn } from './utils';
5
+
6
+ const decodeHtmlEntities = (text: string) => {
7
+ if (text.length === 0) {
8
+ return text;
9
+ }
10
+
11
+ const element = document.createElement('div');
12
+
13
+ element.innerHTML = text;
14
+
15
+ return element.textContent.trim();
16
+ };
17
+
18
+ interface LinkPreviewProps extends React.ComponentProps<'a'> {
19
+ thin?: boolean;
20
+ title?: string;
21
+ description?: string;
22
+ icon?: React.ComponentProps<'img'>['src'];
23
+ image?: React.ComponentProps<'img'>['src'];
24
+ onReady?: () => void;
25
+ iconFallbackElement?: React.ReactElement;
26
+ titleContainerProps?: React.ComponentProps<'div'>;
27
+ iconProps?: React.ComponentProps<'img'>;
28
+ iconFallbackProps?: LucideProps;
29
+ titleProps?: React.ComponentProps<'span'>;
30
+ descriptionProps?: React.ComponentProps<'div'>;
31
+ imageContainerProps?: React.ComponentProps<'div'>;
32
+ imageProps?: React.ComponentProps<'img'>;
33
+ }
34
+
35
+ function LinkPreviewBase(
36
+ {
37
+ thin = false,
38
+ title = '',
39
+ description = '',
40
+ icon,
41
+ iconFallbackElement,
42
+ image,
43
+ onReady = () => {},
44
+ titleContainerProps,
45
+ iconProps,
46
+ iconFallbackProps,
47
+ titleProps,
48
+ descriptionProps,
49
+ imageContainerProps,
50
+ imageProps,
51
+ ...props
52
+ }: LinkPreviewProps,
53
+ ref: React.ForwardedRef<HTMLAnchorElement>
54
+ ) {
55
+ const [iconSrc, setIconSrc] = useState<React.ComponentProps<'img'>['src']>(icon);
56
+ const [imageSrc, setImageSrc] = useState<React.ComponentProps<'img'>['src']>(image);
57
+ const handleOnLoad = useCallback(
58
+ (event: React.SyntheticEvent<HTMLImageElement, Event>) => {
59
+ imageProps?.onLoad?.(event);
60
+ onReady();
61
+ },
62
+ [onReady, imageProps]
63
+ );
64
+ const handleIconOnError = useCallback(
65
+ (event: React.SyntheticEvent<HTMLImageElement, Event>) => {
66
+ iconProps?.onError?.(event);
67
+ setIconSrc(undefined);
68
+ },
69
+ [iconProps]
70
+ );
71
+ const handleImageOnError = useCallback(
72
+ (event: React.SyntheticEvent<HTMLImageElement, Event>) => {
73
+ imageProps?.onError?.(event);
74
+ setImageSrc(undefined);
75
+ },
76
+ [imageProps]
77
+ );
78
+
79
+ return (
80
+ <a
81
+ ref={ref}
82
+ target="_blank"
83
+ rel="noopener noreferrer"
84
+ {...props}
85
+ className={cn(
86
+ 'transition-color duration-300 ease-out',
87
+ 'grid items-start gap-2 p-2 mt-1 overflow-hidden rounded border-l-4 border-l-ring bg-white hover:bg-ring/20',
88
+ thin ? 'grid-cols-3' : 'grid-cols-1',
89
+ props?.className
90
+ )}
91
+ >
92
+ <div
93
+ {...titleContainerProps}
94
+ className={cn('flex items-start gap-2', thin ? 'col-span-3' : 'col-span-1', titleContainerProps?.className)}
95
+ >
96
+ {iconSrc ? (
97
+ <img
98
+ alt="icon"
99
+ src={iconSrc}
100
+ {...iconProps}
101
+ onError={handleIconOnError}
102
+ className={cn('size-5', iconProps?.className)}
103
+ />
104
+ ) : (
105
+ iconFallbackElement || <Globe {...iconFallbackProps} className={cn('size-5', iconFallbackProps?.className)} />
106
+ )}
107
+ <span
108
+ {...titleProps}
109
+ className={cn('text-sm font-bold', thin ? 'line-clamp-1' : 'line-clamp-2', titleProps?.className)}
110
+ >
111
+ {decodeHtmlEntities(title)}
112
+ </span>
113
+ </div>
114
+ {description && (
115
+ <span
116
+ {...descriptionProps}
117
+ className={cn(
118
+ 'text-sm line-clamp-5',
119
+ thin ? (imageSrc ? 'col-span-2' : 'col-span-3') : 'col-span-1',
120
+ descriptionProps?.className
121
+ )}
122
+ >
123
+ {decodeHtmlEntities(description)}
124
+ </span>
125
+ )}
126
+ {imageSrc && (
127
+ <div
128
+ {...imageContainerProps}
129
+ className={cn('flex items-center justify-center', imageContainerProps?.className)}
130
+ >
131
+ <img
132
+ alt="banner"
133
+ src={imageSrc}
134
+ {...imageProps}
135
+ onLoad={handleOnLoad}
136
+ onError={handleImageOnError}
137
+ className={cn('rounded max-w-full object-contain', thin ? 'max-h-25' : 'max-h-60', imageProps?.className)}
138
+ />
139
+ </div>
140
+ )}
141
+ </a>
142
+ );
143
+ }
144
+
145
+ const LinkPreview = memo(forwardRef<HTMLAnchorElement, LinkPreviewProps>(LinkPreviewBase));
146
+
147
+ LinkPreview.displayName = 'LinkPreview';
148
+
149
+ export { LinkPreview, type LinkPreviewProps };
@@ -1,11 +1,11 @@
1
1
  import type React from 'react';
2
- import { forwardRef, memo } from 'react';
3
- import { Users, type LucideProps } from 'lucide-react';
4
- import { cn } from './utils';
5
2
  import { Avatar, type AvatarProps } from './avatar';
6
- import { type PresenceStatus } from './presence';
7
- import { StatusSent, type StatusSentProps } from './status-sent';
3
+ import { Users, type LucideProps } from 'lucide-react';
4
+ import { forwardRef, memo } from 'react';
8
5
  import { FormattedDate, type FormattedDateProps } from './formatted-date';
6
+ import { StatusSent, type StatusSentProps } from './status-sent';
7
+ import { type PresenceStatus } from './presence';
8
+ import { cn } from './utils';
9
9
  import { Badge, type BadgeProps } from './badge';
10
10
 
11
11
  interface DialogItemProps extends React.ComponentProps<'div'> {
@@ -85,9 +85,9 @@ function DialogItemBase(
85
85
  }: DialogItemProps,
86
86
  ref: React.ForwardedRef<HTMLDivElement>
87
87
  ) {
88
- const avatarSource = photo || avatarProps?.src || undefined;
89
- const avatarFallback = name || avatarProps?.name || undefined;
90
- const avatarOnline = isPrivateDialog ? userOnline || avatarProps?.online || false : false;
88
+ const avatarSource = photo || avatarProps?.src;
89
+ const avatarFallback = name || avatarProps?.name;
90
+ const avatarOnline = isPrivateDialog ? userOnline || avatarProps?.online : false;
91
91
  const avatarPresence = isPrivateDialog ? userPresence || avatarProps?.presence : undefined;
92
92
  const showTopDivider = divider === 'top' || (divider === 'both' && index === 0);
93
93
  const showBottomDivider = divider === 'bottom' || divider === 'both';
@@ -137,7 +137,10 @@ function DialogItemBase(
137
137
  <div {...footerProps} className={cn('flex items-start justify-between gap-1', footerProps?.className)}>
138
138
  <span
139
139
  {...lastMessageProps}
140
- className={cn('text-sm text-left text-muted-foreground line-clamp-2', lastMessageProps?.className)}
140
+ className={cn(
141
+ 'text-sm text-left text-muted-foreground break-all line-clamp-2',
142
+ lastMessageProps?.className
143
+ )}
141
144
  >
142
145
  {typingStatusText ||
143
146
  (draft ? (
@@ -185,4 +188,4 @@ const DialogItem = memo(forwardRef<HTMLDivElement, DialogItemProps>(DialogItemBa
185
188
 
186
189
  DialogItem.displayName = 'DialogItem';
187
190
 
188
- export { DialogItem };
191
+ export { DialogItem, type DialogItemProps };
@@ -16,7 +16,7 @@ function DismissLayerBase(
16
16
  ) {
17
17
  const innerRef = useRef<HTMLDivElement>(null);
18
18
 
19
- useImperativeHandle(ref, () => innerRef.current!);
19
+ useImperativeHandle(ref, () => innerRef.current!, []);
20
20
 
21
21
  const handleClickOrTouch = useCallback(
22
22
  (e: React.MouseEvent | React.TouchEvent) => {
@@ -176,14 +176,14 @@ function FilePickerDropzoneBase(
176
176
  onDragLeave={handleDragLeave}
177
177
  onDragOver={handleDragEvent}
178
178
  {...props}
179
- className={cn('size-full relative', props?.className)}
179
+ className={cn('relative size-full min-h-0', props?.className)}
180
180
  >
181
181
  {children}
182
182
  <div
183
183
  onDrop={handleDrop}
184
184
  {...dropZoneProps}
185
185
  className={cn(
186
- 'group absolute top-0 left-0 size-full',
186
+ 'absolute top-0 left-0 size-full',
187
187
  'flex items-center justify-center',
188
188
  'transition-all duration-300 ease-out',
189
189
  'border-2 border-dashed border-ring bg-ring/25 rounded-md',
@@ -1,6 +1,6 @@
1
1
  import type React from 'react';
2
2
  import type { Opts } from 'linkifyjs';
3
- import { forwardRef, memo, useMemo } from 'react';
3
+ import { forwardRef, memo, useEffect, useMemo, useRef } from 'react';
4
4
  import Linkify from 'linkify-react';
5
5
  import { cn } from './utils';
6
6
 
@@ -8,16 +8,32 @@ const DEFAULT_LINKIFY_OPTIONS: Opts = {
8
8
  target: '_blank',
9
9
  rel: 'noopener noreferrer',
10
10
  };
11
+ const DEFAULT_SKELETON_LINES_CLASS_NAMES = ['w-full', 'w-3/4', 'w-1/2'];
11
12
 
12
13
  interface LinkifyTextProps extends React.ComponentProps<'p'> {
13
- text: string;
14
+ text?: string;
15
+ pending?: boolean;
16
+ onReady?: () => void;
14
17
  linkifyProps?: Opts;
18
+ skeletonContainerProps?: React.ComponentProps<'div'>;
19
+ skeletonLineProps?: React.ComponentProps<'span'>;
20
+ skeletonLinesClassNames?: string[];
15
21
  }
16
22
 
17
23
  function LinkifyTextBase(
18
- { text, linkifyProps, ...props }: LinkifyTextProps,
24
+ {
25
+ text,
26
+ pending = false,
27
+ onReady = () => {},
28
+ linkifyProps,
29
+ skeletonContainerProps,
30
+ skeletonLineProps,
31
+ skeletonLinesClassNames = DEFAULT_SKELETON_LINES_CLASS_NAMES,
32
+ ...props
33
+ }: LinkifyTextProps,
19
34
  ref: React.ForwardedRef<HTMLParagraphElement>
20
35
  ) {
36
+ const pendingRef = useRef(pending);
21
37
  const options = useMemo(
22
38
  () => ({
23
39
  ...DEFAULT_LINKIFY_OPTIONS,
@@ -27,6 +43,31 @@ function LinkifyTextBase(
27
43
  [linkifyProps]
28
44
  );
29
45
 
46
+ useEffect(() => {
47
+ if (pendingRef.current && !pending) {
48
+ onReady();
49
+ }
50
+
51
+ pendingRef.current = pending;
52
+ }, [pending, onReady]);
53
+
54
+ if (pending) {
55
+ return (
56
+ <div
57
+ {...skeletonContainerProps}
58
+ className={cn('flex items-start flex-col size-full', skeletonContainerProps?.className)}
59
+ >
60
+ {skeletonLinesClassNames.map((width, index) => (
61
+ <span
62
+ {...skeletonLineProps}
63
+ key={`${width}_${index}`}
64
+ className={cn('bg-muted-foreground animate-pulse rounded-md my-1 h-4', skeletonLineProps?.className, width)}
65
+ ></span>
66
+ ))}
67
+ </div>
68
+ );
69
+ }
70
+
30
71
  return (
31
72
  <p ref={ref} {...props} className={cn('wrap-break-word text-base', props?.className)}>
32
73
  <Linkify options={options}>{text}</Linkify>
@@ -1,17 +1,13 @@
1
1
  import type React from 'react';
2
2
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
3
3
  import { Maximize, Minimize, PictureInPicture2, type LucideProps } from 'lucide-react';
4
- import { cn } from './utils';
4
+ import { cn, getRandomString } from './utils';
5
5
 
6
6
  interface StreamViewProps extends React.ComponentProps<'video'> {
7
7
  stream?: MediaStream | null;
8
8
  mirror?: boolean;
9
9
  }
10
10
 
11
- function getRandomString(length = 8): string {
12
- return (Date.now() / Math.random()).toString(36).replace('.', '').slice(0, length);
13
- }
14
-
15
11
  function StreamViewBase(
16
12
  { id, stream, mirror, className, muted, ...props }: StreamViewProps,
17
13
  ref: React.ForwardedRef<HTMLVideoElement>
@@ -0,0 +1,25 @@
1
+ import * as React from 'react';
2
+ import * as SwitchPrimitive from '@radix-ui/react-switch';
3
+ import { cn } from './utils';
4
+
5
+ type SwitchProps = React.ComponentProps<typeof SwitchPrimitive.Root>;
6
+
7
+ function Switch(props: SwitchProps) {
8
+ return (
9
+ <SwitchPrimitive.Root
10
+ {...props}
11
+ className={cn(
12
+ 'peer data-[state=checked]:bg-ring data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15em] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring disabled:cursor-not-allowed disabled:opacity-50',
13
+ props?.className
14
+ )}
15
+ >
16
+ <SwitchPrimitive.Thumb
17
+ className={cn(
18
+ 'bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0'
19
+ )}
20
+ />
21
+ </SwitchPrimitive.Root>
22
+ );
23
+ }
24
+
25
+ export { Switch, type SwitchProps };
@@ -5,6 +5,10 @@ export function cn(...inputs: ClassValue[]) {
5
5
  return twMerge(clsx(inputs));
6
6
  }
7
7
 
8
+ export function getRandomString(length = 8): string {
9
+ return (Date.now() / Math.random()).toString(36).replace('.', '').slice(0, length);
10
+ }
11
+
8
12
  export function capitalize(str?: string): string {
9
13
  return typeof str === 'string' && str.length > 0 ? `${str[0]?.toUpperCase()}${str.slice(1)}` : '';
10
14
  }
package/src/index.ts CHANGED
@@ -1,7 +1,81 @@
1
- export { DismissLayer } from './components/dismiss-layer';
1
+ export { AlertDialog, type AlertDialogProps } from './components/alert-dialog';
2
2
 
3
- export type { DismissLayerProps } from './components/dismiss-layer';
3
+ export {
4
+ Attachment,
5
+ AttachmentLink,
6
+ AttachmentImage,
7
+ AttachmentAudio,
8
+ AttachmentVideo,
9
+ AttachmentFile,
10
+ AttachmentFailed,
11
+ type AttachmentProps,
12
+ type AttachmentLinkProps,
13
+ type AttachmentImageProps,
14
+ type AttachmentAudioProps,
15
+ type AttachmentVideoProps,
16
+ type AttachmentFileProps,
17
+ type AttachmentFailedProps,
18
+ } from './components/attachment';
4
19
 
5
- export { StreamView, LocalStreamView, RemoteStreamView, FullscreenStreamView } from './components/stream-view';
20
+ export { Avatar, type AvatarProps } from './components/avatar';
6
21
 
7
- export type { StreamViewProps, FullscreenStreamViewProps, FullscreenStreamViewRef } from './components/stream-view';
22
+ export { Badge, type BadgeProps } from './components/badge';
23
+
24
+ export { Button, type ButtonProps } from './components/button';
25
+
26
+ export { CallMessage, type CallMessageProps } from './components/call-message';
27
+
28
+ export { ChatMessage, type ChatMessageProps } from './components/chat-message';
29
+
30
+ export { DialogItem, type DialogItemProps } from './components/dialog-item';
31
+
32
+ export { DismissLayer, type DismissLayerProps } from './components/dismiss-layer';
33
+
34
+ export {
35
+ FilePickerInput,
36
+ FilePickerDropzone,
37
+ type FilePickerInputProps,
38
+ type FilePickerDropzoneProps,
39
+ } from './components/file-picker';
40
+
41
+ export { FormattedDate, type FormattedDateProps } from './components/formatted-date';
42
+
43
+ export { Input, type InputProps } from './components/input';
44
+
45
+ export { Label, type LabelProps } from './components/label';
46
+
47
+ export { LinkPreview, type LinkPreviewProps } from './components/link-preview';
48
+
49
+ export { LinkifyText, type LinkifyTextProps } from './components/linkify-text';
50
+
51
+ export { PlaceholderText, type PlaceholderTextProps } from './components/placeholder-text';
52
+
53
+ export {
54
+ Presence,
55
+ PresenceBadge,
56
+ type PresenceStatus,
57
+ type PresenceProps,
58
+ type PresenceBadgeProps,
59
+ } from './components/presence';
60
+
61
+ export { Search, type SearchProps } from './components/search';
62
+
63
+ export { Spinner, type SpinnerProps } from './components/spinner';
64
+
65
+ export { StatusIndicator, type StatusName, type StatusIndicatorProps } from './components/status-indicator';
66
+
67
+ export { StatusSent, type StatusSentProps } from './components/status-sent';
68
+
69
+ export {
70
+ StreamView,
71
+ LocalStreamView,
72
+ RemoteStreamView,
73
+ FullscreenStreamView,
74
+ type StreamViewProps,
75
+ type FullscreenStreamViewProps,
76
+ type FullscreenStreamViewRef,
77
+ } from './components/stream-view';
78
+
79
+ export { Switch, type SwitchProps } from './components/switch';
80
+
81
+ export * from './components/utils';