@connectycube/react-ui-kit 0.0.8 → 0.0.11
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/commands/add.js +72 -45
- package/configs/dependencies.json +16 -1
- package/configs/imports.json +8 -0
- package/gen/components/animated-loader.jsx +10 -0
- package/gen/components/avatar.jsx +34 -0
- package/gen/components/dismiss-layer.jsx +57 -0
- package/gen/components/placeholder-text.jsx +22 -0
- package/gen/components/presence.jsx +41 -0
- package/gen/components/stream-view.jsx +166 -28
- package/gen/components/utils.js +20 -0
- package/gen/index.js +3 -1
- package/package.json +6 -5
- package/src/components/animated-loader.tsx +15 -0
- package/src/components/avatar.tsx +45 -0
- package/src/components/connectycube-ui/animated-loader.jsx +10 -0
- package/src/components/connectycube-ui/animated-loader.tsx +15 -0
- package/src/components/connectycube-ui/avatar.jsx +34 -0
- package/src/components/connectycube-ui/avatar.tsx +45 -0
- package/src/components/connectycube-ui/dismiss-layer.jsx +57 -0
- package/src/components/connectycube-ui/dismiss-layer.tsx +74 -0
- package/src/components/connectycube-ui/placeholder-text.jsx +22 -0
- package/src/components/connectycube-ui/placeholder-text.tsx +28 -0
- package/src/components/connectycube-ui/presence.jsx +41 -0
- package/src/components/connectycube-ui/presence.tsx +55 -0
- package/src/components/connectycube-ui/stream-view.jsx +166 -28
- package/src/components/connectycube-ui/stream-view.tsx +231 -62
- package/src/components/connectycube-ui/utils.js +20 -0
- package/src/components/connectycube-ui/utils.ts +18 -0
- package/src/components/dismiss-layer.tsx +74 -0
- package/src/components/placeholder-text.tsx +28 -0
- package/src/components/presence.tsx +55 -0
- package/src/components/stream-view.tsx +231 -62
- package/src/components/utils.ts +18 -0
- package/src/index.ts +6 -2
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { PresenceStatus } from './presence';
|
|
3
|
+
import { forwardRef, memo } from 'react';
|
|
4
|
+
import * as AvatarPrimitive from '@radix-ui/react-avatar';
|
|
5
|
+
import { PresenceBadge } from './presence';
|
|
6
|
+
import { cn, getInitialsFromName } from './utils';
|
|
7
|
+
|
|
8
|
+
interface AvatarProps extends React.ComponentProps<typeof AvatarPrimitive.Root> {
|
|
9
|
+
src?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
online?: boolean;
|
|
12
|
+
presence?: PresenceStatus;
|
|
13
|
+
onlineClassName?: string;
|
|
14
|
+
presenceClassName?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function AvatarBase(
|
|
18
|
+
{ src, name = 'NA', online, presence, className, onlineClassName, presenceClassName, ...props }: AvatarProps,
|
|
19
|
+
ref: React.Ref<HTMLDivElement>
|
|
20
|
+
) {
|
|
21
|
+
const initials = getInitialsFromName(name);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<AvatarPrimitive.Root
|
|
25
|
+
ref={ref}
|
|
26
|
+
className={cn('relative flex size-8 shrink-0 overflow-hidden rounded-full', className)}
|
|
27
|
+
{...props}
|
|
28
|
+
>
|
|
29
|
+
<AvatarPrimitive.Image src={src} className={cn('aspect-square size-full object-cover')} />
|
|
30
|
+
<AvatarPrimitive.Fallback className={cn('bg-muted flex size-full items-center justify-center')}>
|
|
31
|
+
{initials}
|
|
32
|
+
</AvatarPrimitive.Fallback>
|
|
33
|
+
{online && (
|
|
34
|
+
<div className={cn('rounded-full border-2 bg-green-600 border-green-200 size-3.5', onlineClassName)} />
|
|
35
|
+
)}
|
|
36
|
+
<PresenceBadge status={presence} className={cn('absolute -bottom-0.5 -right-1', presenceClassName)} />
|
|
37
|
+
</AvatarPrimitive.Root>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const Avatar = memo(forwardRef<HTMLDivElement, AvatarProps>(AvatarBase));
|
|
42
|
+
|
|
43
|
+
Avatar.displayName = 'Avatar';
|
|
44
|
+
|
|
45
|
+
export { Avatar, type AvatarProps };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoaderCircle } from 'lucide-react';
|
|
2
|
+
import { cn } from './utils';
|
|
3
|
+
|
|
4
|
+
function AnimatedLoader({ loading = true, className }) {
|
|
5
|
+
return loading ? <LoaderCircle className={cn('animate-spin mx-auto', className)} /> : null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
AnimatedLoader.displayName = 'AnimatedLoader';
|
|
9
|
+
|
|
10
|
+
export { AnimatedLoader };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LucideProps } from 'lucide-react';
|
|
2
|
+
import { LoaderCircle } from 'lucide-react';
|
|
3
|
+
import { cn } from './utils';
|
|
4
|
+
|
|
5
|
+
interface AnimatedLoaderProps extends LucideProps {
|
|
6
|
+
loading?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function AnimatedLoader({ loading = true, className }: AnimatedLoaderProps) {
|
|
10
|
+
return loading ? <LoaderCircle className={cn('animate-spin mx-auto', className)} /> : null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
AnimatedLoader.displayName = 'AnimatedLoader';
|
|
14
|
+
|
|
15
|
+
export { AnimatedLoader, type AnimatedLoaderProps };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { forwardRef, memo } from 'react';
|
|
2
|
+
import * as AvatarPrimitive from '@radix-ui/react-avatar';
|
|
3
|
+
import { PresenceBadge } from './presence';
|
|
4
|
+
import { cn, getInitialsFromName } from './utils';
|
|
5
|
+
|
|
6
|
+
function AvatarBase(
|
|
7
|
+
{ src, name = 'NA', online, presence, className, onlineClassName, presenceClassName, ...props },
|
|
8
|
+
ref
|
|
9
|
+
) {
|
|
10
|
+
const initials = getInitialsFromName(name);
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<AvatarPrimitive.Root
|
|
14
|
+
ref={ref}
|
|
15
|
+
className={cn('relative flex size-8 shrink-0 overflow-hidden rounded-full', className)}
|
|
16
|
+
{...props}
|
|
17
|
+
>
|
|
18
|
+
<AvatarPrimitive.Image src={src} className={cn('aspect-square size-full object-cover')} />
|
|
19
|
+
<AvatarPrimitive.Fallback className={cn('bg-muted flex size-full items-center justify-center')}>
|
|
20
|
+
{initials}
|
|
21
|
+
</AvatarPrimitive.Fallback>
|
|
22
|
+
{online && (
|
|
23
|
+
<div className={cn('rounded-full border-2 bg-green-600 border-green-200 size-3.5', onlineClassName)} />
|
|
24
|
+
)}
|
|
25
|
+
<PresenceBadge presence={presence} className={cn('absolute -bottom-0.5 -right-1', presenceClassName)} />
|
|
26
|
+
</AvatarPrimitive.Root>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const Avatar = memo(forwardRef(AvatarBase));
|
|
31
|
+
|
|
32
|
+
Avatar.displayName = 'Avatar';
|
|
33
|
+
|
|
34
|
+
export { Avatar };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { PresenceStatus } from './presence';
|
|
3
|
+
import { forwardRef, memo } from 'react';
|
|
4
|
+
import * as AvatarPrimitive from '@radix-ui/react-avatar';
|
|
5
|
+
import { PresenceBadge } from './presence';
|
|
6
|
+
import { cn, getInitialsFromName } from './utils';
|
|
7
|
+
|
|
8
|
+
interface AvatarProps extends React.ComponentProps<typeof AvatarPrimitive.Root> {
|
|
9
|
+
src?: string;
|
|
10
|
+
name?: string;
|
|
11
|
+
online?: boolean;
|
|
12
|
+
presence?: PresenceStatus;
|
|
13
|
+
onlineClassName?: string;
|
|
14
|
+
presenceClassName?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function AvatarBase(
|
|
18
|
+
{ src, name = 'NA', online, presence, className, onlineClassName, presenceClassName, ...props }: AvatarProps,
|
|
19
|
+
ref: React.Ref<HTMLDivElement>
|
|
20
|
+
) {
|
|
21
|
+
const initials = getInitialsFromName(name);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<AvatarPrimitive.Root
|
|
25
|
+
ref={ref}
|
|
26
|
+
className={cn('relative flex size-8 shrink-0 overflow-hidden rounded-full', className)}
|
|
27
|
+
{...props}
|
|
28
|
+
>
|
|
29
|
+
<AvatarPrimitive.Image src={src} className={cn('aspect-square size-full object-cover')} />
|
|
30
|
+
<AvatarPrimitive.Fallback className={cn('bg-muted flex size-full items-center justify-center')}>
|
|
31
|
+
{initials}
|
|
32
|
+
</AvatarPrimitive.Fallback>
|
|
33
|
+
{online && (
|
|
34
|
+
<div className={cn('rounded-full border-2 bg-green-600 border-green-200 size-3.5', onlineClassName)} />
|
|
35
|
+
)}
|
|
36
|
+
<PresenceBadge presence={presence} className={cn('absolute -bottom-0.5 -right-1', presenceClassName)} />
|
|
37
|
+
</AvatarPrimitive.Root>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const Avatar = memo(forwardRef<HTMLDivElement, AvatarProps>(AvatarBase));
|
|
42
|
+
|
|
43
|
+
Avatar.displayName = 'Avatar';
|
|
44
|
+
|
|
45
|
+
export { Avatar, type AvatarProps };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useImperativeHandle, memo, forwardRef } from 'react';
|
|
2
|
+
import { cn } from './utils';
|
|
3
|
+
|
|
4
|
+
function DismissLayerBase(
|
|
5
|
+
{ active, onDismiss, disableClickOutside = false, disableEscKeyPress = false, disabled, className, ...props },
|
|
6
|
+
ref
|
|
7
|
+
) {
|
|
8
|
+
const innerRef = useRef(null);
|
|
9
|
+
|
|
10
|
+
useImperativeHandle(ref, () => innerRef.current);
|
|
11
|
+
|
|
12
|
+
const handleClickOrTouch = useCallback(
|
|
13
|
+
(e) => {
|
|
14
|
+
if (!disableClickOutside && active && e.target === innerRef.current) {
|
|
15
|
+
onDismiss();
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
[disableClickOutside, active, onDismiss]
|
|
19
|
+
);
|
|
20
|
+
const handleKeyEvent = useCallback(
|
|
21
|
+
(ev) => {
|
|
22
|
+
if (!disableEscKeyPress && active && ev.key === 'Escape') {
|
|
23
|
+
onDismiss();
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
[disableEscKeyPress, active, onDismiss]
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!disableEscKeyPress && active) {
|
|
31
|
+
document.addEventListener('keydown', handleKeyEvent);
|
|
32
|
+
|
|
33
|
+
return () => document.removeEventListener('keydown', handleKeyEvent);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return;
|
|
37
|
+
}, [disableEscKeyPress, active, handleKeyEvent]);
|
|
38
|
+
|
|
39
|
+
if (disabled || !active) return null;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div
|
|
43
|
+
ref={innerRef}
|
|
44
|
+
onClick={handleClickOrTouch}
|
|
45
|
+
onTouchStart={handleClickOrTouch}
|
|
46
|
+
className={cn('fixed top-0 left-0 z-40 size-full bg-black/20', className)}
|
|
47
|
+
aria-hidden
|
|
48
|
+
{...props}
|
|
49
|
+
/>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const DismissLayer = memo(forwardRef(DismissLayerBase));
|
|
54
|
+
|
|
55
|
+
DismissLayer.displayName = 'DismissLayer';
|
|
56
|
+
|
|
57
|
+
export { DismissLayer };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef, useImperativeHandle, memo, forwardRef } from 'react';
|
|
3
|
+
import { cn } from './utils';
|
|
4
|
+
|
|
5
|
+
interface DismissLayerProps extends React.ComponentProps<'div'> {
|
|
6
|
+
active: boolean;
|
|
7
|
+
onDismiss: () => void;
|
|
8
|
+
disableClickOutside?: boolean;
|
|
9
|
+
disableEscKeyPress?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function DismissLayerBase(
|
|
14
|
+
{
|
|
15
|
+
active,
|
|
16
|
+
onDismiss,
|
|
17
|
+
disableClickOutside = false,
|
|
18
|
+
disableEscKeyPress = false,
|
|
19
|
+
disabled,
|
|
20
|
+
className,
|
|
21
|
+
...props
|
|
22
|
+
}: DismissLayerProps,
|
|
23
|
+
ref: React.Ref<HTMLDivElement>
|
|
24
|
+
) {
|
|
25
|
+
const innerRef = useRef<HTMLDivElement>(null);
|
|
26
|
+
|
|
27
|
+
useImperativeHandle(ref, () => innerRef.current!);
|
|
28
|
+
|
|
29
|
+
const handleClickOrTouch = useCallback(
|
|
30
|
+
(e: React.MouseEvent | React.TouchEvent) => {
|
|
31
|
+
if (!disableClickOutside && active && e.target === innerRef.current) {
|
|
32
|
+
onDismiss();
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
[disableClickOutside, active, onDismiss]
|
|
36
|
+
);
|
|
37
|
+
const handleKeyEvent = useCallback(
|
|
38
|
+
(ev: KeyboardEvent) => {
|
|
39
|
+
if (!disableEscKeyPress && active && ev.key === 'Escape') {
|
|
40
|
+
onDismiss();
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
[disableEscKeyPress, active, onDismiss]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!disableEscKeyPress && active) {
|
|
48
|
+
document.addEventListener('keydown', handleKeyEvent);
|
|
49
|
+
|
|
50
|
+
return () => document.removeEventListener('keydown', handleKeyEvent);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return;
|
|
54
|
+
}, [disableEscKeyPress, active, handleKeyEvent]);
|
|
55
|
+
|
|
56
|
+
if (disabled || !active) return null;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div
|
|
60
|
+
ref={innerRef}
|
|
61
|
+
onClick={handleClickOrTouch}
|
|
62
|
+
onTouchStart={handleClickOrTouch}
|
|
63
|
+
className={cn('fixed top-0 left-0 z-40 size-full bg-black/20', className)}
|
|
64
|
+
aria-hidden
|
|
65
|
+
{...props}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const DismissLayer = memo(forwardRef<HTMLDivElement, DismissLayerProps>(DismissLayerBase));
|
|
71
|
+
|
|
72
|
+
DismissLayer.displayName = 'DismissLayer';
|
|
73
|
+
|
|
74
|
+
export { DismissLayer, type DismissLayerProps };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { forwardRef, memo } from 'react';
|
|
2
|
+
import { cn } from './utils';
|
|
3
|
+
|
|
4
|
+
function PlaceholderTextBase({ title, titles = [], className }, ref) {
|
|
5
|
+
const rows = typeof title === 'string' ? [title, ...titles] : titles;
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div ref={ref} className={cn('absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2', className)}>
|
|
9
|
+
{rows.map((row, index) => (
|
|
10
|
+
<div key={`placeholder-text-${index}`} className="text-center">
|
|
11
|
+
{row}
|
|
12
|
+
</div>
|
|
13
|
+
))}
|
|
14
|
+
</div>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const PlaceholderText = memo(forwardRef(PlaceholderTextBase));
|
|
19
|
+
|
|
20
|
+
PlaceholderText.displayName = 'PlaceholderText';
|
|
21
|
+
|
|
22
|
+
export { PlaceholderText };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { forwardRef, memo } from 'react';
|
|
3
|
+
import { cn } from './utils';
|
|
4
|
+
|
|
5
|
+
interface PlaceholderTextProps extends React.ComponentProps<'div'> {
|
|
6
|
+
title?: string;
|
|
7
|
+
titles?: string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function PlaceholderTextBase({ title, titles = [], className }: PlaceholderTextProps, ref: React.Ref<HTMLDivElement>) {
|
|
11
|
+
const rows = typeof title === 'string' ? [title, ...titles] : titles;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<div ref={ref} className={cn('absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2', className)}>
|
|
15
|
+
{rows.map((row, index) => (
|
|
16
|
+
<div key={`placeholder-text-${index}`} className="text-center">
|
|
17
|
+
{row}
|
|
18
|
+
</div>
|
|
19
|
+
))}
|
|
20
|
+
</div>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const PlaceholderText = memo(forwardRef(PlaceholderTextBase));
|
|
25
|
+
|
|
26
|
+
PlaceholderText.displayName = 'PlaceholderText';
|
|
27
|
+
|
|
28
|
+
export { PlaceholderText, type PlaceholderTextProps };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { memo } from 'react';
|
|
2
|
+
import { CircleCheck, CircleMinus, CircleQuestionMark, Clock } from 'lucide-react';
|
|
3
|
+
import { capitalize, cn, UserPresence } from './utils';
|
|
4
|
+
|
|
5
|
+
function PresenceBadgeBase({ presence, className, ...props }) {
|
|
6
|
+
switch (presence) {
|
|
7
|
+
case UserPresence.AVAILABLE || 'available':
|
|
8
|
+
return <CircleCheck className={cn('rounded-full text-white bg-green-600 size-4.5', className)} {...props} />;
|
|
9
|
+
case UserPresence.BUSY || 'busy':
|
|
10
|
+
return <CircleMinus className={cn('rounded-full text-white bg-red-600 size-4.5', className)} {...props} />;
|
|
11
|
+
case UserPresence.AWAY || 'away':
|
|
12
|
+
return <Clock className={cn('rounded-full text-white bg-yellow-500 size-4.5', className)} {...props} />;
|
|
13
|
+
case UserPresence.UNKNOWN || 'unknown':
|
|
14
|
+
return (
|
|
15
|
+
<CircleQuestionMark className={cn('rounded-full text-white bg-gray-500 size-4.5', className)} {...props} />
|
|
16
|
+
);
|
|
17
|
+
default:
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const PresenceBadge = memo(PresenceBadgeBase);
|
|
23
|
+
|
|
24
|
+
PresenceBadge.displayName = 'PresenceBadge';
|
|
25
|
+
|
|
26
|
+
function PresenceBase({ badge = true, className, presence, label, ...props }) {
|
|
27
|
+
const status = capitalize(label || presence);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className={cn('flex items-center gap-2', className)} {...props}>
|
|
31
|
+
{badge && <PresenceBadge presence={presence} />}
|
|
32
|
+
<span>{status}</span>
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const Presence = memo(PresenceBase);
|
|
38
|
+
|
|
39
|
+
Presence.displayName = 'Presence';
|
|
40
|
+
|
|
41
|
+
export { Presence, PresenceBadge };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { LucideProps } from 'lucide-react';
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import { CircleCheck, CircleMinus, CircleQuestionMark, Clock } from 'lucide-react';
|
|
5
|
+
import { capitalize, cn, UserPresence } from './utils';
|
|
6
|
+
|
|
7
|
+
type PresenceStatus = UserPresence | 'available' | 'busy' | 'away' | 'unknown' | undefined;
|
|
8
|
+
|
|
9
|
+
interface PresenceBadgeProps extends LucideProps {
|
|
10
|
+
presence: PresenceStatus;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface PresenceProps extends React.ComponentProps<'div'> {
|
|
14
|
+
badge?: boolean;
|
|
15
|
+
presence: PresenceStatus;
|
|
16
|
+
label: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function PresenceBadgeBase({ presence, className, ...props }: PresenceBadgeProps) {
|
|
20
|
+
switch (presence) {
|
|
21
|
+
case UserPresence.AVAILABLE || 'available':
|
|
22
|
+
return <CircleCheck className={cn('rounded-full text-white bg-green-600 size-4.5', className)} {...props} />;
|
|
23
|
+
case UserPresence.BUSY || 'busy':
|
|
24
|
+
return <CircleMinus className={cn('rounded-full text-white bg-red-600 size-4.5', className)} {...props} />;
|
|
25
|
+
case UserPresence.AWAY || 'away':
|
|
26
|
+
return <Clock className={cn('rounded-full text-white bg-yellow-500 size-4.5', className)} {...props} />;
|
|
27
|
+
case UserPresence.UNKNOWN || 'unknown':
|
|
28
|
+
return (
|
|
29
|
+
<CircleQuestionMark className={cn('rounded-full text-white bg-gray-500 size-4.5', className)} {...props} />
|
|
30
|
+
);
|
|
31
|
+
default:
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const PresenceBadge = memo(PresenceBadgeBase);
|
|
37
|
+
|
|
38
|
+
PresenceBadge.displayName = 'PresenceBadge';
|
|
39
|
+
|
|
40
|
+
function PresenceBase({ badge = true, className, presence, label, ...props }: PresenceProps) {
|
|
41
|
+
const status = capitalize(label || presence);
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className={cn('flex items-center gap-2', className)} {...props}>
|
|
45
|
+
{badge && <PresenceBadge presence={presence} />}
|
|
46
|
+
<span>{status}</span>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const Presence = memo(PresenceBase);
|
|
52
|
+
|
|
53
|
+
Presence.displayName = 'Presence';
|
|
54
|
+
|
|
55
|
+
export { Presence, PresenceBadge, type PresenceStatus, type PresenceProps, type PresenceBadgeProps };
|
|
@@ -1,63 +1,201 @@
|
|
|
1
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
1
|
+
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { Maximize, Minimize, PictureInPicture2 } from 'lucide-react';
|
|
2
3
|
import { cn, getRandomString } from './utils';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
const
|
|
5
|
+
function StreamViewBase({ id, stream, mirror, className, muted, ...props }, ref) {
|
|
6
|
+
const innerRef = useRef(null);
|
|
6
7
|
const elementId = useMemo(() => id ?? `stream-${getRandomString()}`, [id]);
|
|
7
|
-
const isMuted = typeof muted === 'boolean' ? muted :
|
|
8
|
+
const isMuted = typeof muted === 'boolean' ? muted : false;
|
|
8
9
|
const defaultClassName = 'size-full object-contain';
|
|
9
10
|
const mirrorClassName = mirror ? 'scale-x-[-1]' : '';
|
|
10
11
|
|
|
11
|
-
useImperativeHandle(
|
|
12
|
-
ref,
|
|
13
|
-
() => ({
|
|
14
|
-
id: elementId,
|
|
15
|
-
element: videoRef.current,
|
|
16
|
-
}),
|
|
17
|
-
[elementId]
|
|
18
|
-
);
|
|
12
|
+
useImperativeHandle(ref, () => innerRef.current);
|
|
19
13
|
|
|
20
14
|
useEffect(() => {
|
|
21
|
-
if (
|
|
22
|
-
|
|
15
|
+
if (innerRef.current && stream) {
|
|
16
|
+
innerRef.current.srcObject = stream;
|
|
23
17
|
|
|
24
18
|
const playVideo = () => {
|
|
25
19
|
try {
|
|
26
|
-
|
|
20
|
+
innerRef.current?.play();
|
|
27
21
|
} catch (error) {
|
|
28
|
-
console.error('
|
|
22
|
+
console.error('Error playing video:', error);
|
|
29
23
|
}
|
|
30
24
|
};
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
innerRef.current.onloadedmetadata = () => {
|
|
27
|
+
queueMicrotask(playVideo);
|
|
34
28
|
};
|
|
35
29
|
}
|
|
36
30
|
}, [stream]);
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
if (!stream) return null;
|
|
33
|
+
|
|
34
|
+
return (
|
|
39
35
|
<video
|
|
40
|
-
ref={
|
|
36
|
+
ref={innerRef}
|
|
41
37
|
id={elementId}
|
|
42
|
-
className={cn(defaultClassName, mirrorClassName, className)}
|
|
43
|
-
muted={isMuted}
|
|
44
38
|
autoPlay
|
|
45
39
|
playsInline
|
|
40
|
+
muted={isMuted}
|
|
41
|
+
className={cn(defaultClassName, mirrorClassName, className)}
|
|
46
42
|
{...props}
|
|
47
43
|
/>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const StreamView = forwardRef(StreamViewBase);
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
StreamView.displayName = 'StreamView';
|
|
50
|
+
|
|
51
|
+
function LocalStreamViewBase({ muted, mirror, ...props }, ref) {
|
|
52
52
|
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
53
53
|
const isMirror = typeof mirror === 'boolean' ? mirror : true;
|
|
54
54
|
|
|
55
55
|
return <StreamView ref={ref} muted={isMuted} mirror={isMirror} {...props} />;
|
|
56
|
-
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const LocalStreamView = forwardRef(LocalStreamViewBase);
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
LocalStreamView.displayName = 'LocalStreamView';
|
|
61
|
+
|
|
62
|
+
function RemoteStreamViewBase({ muted, mirror, ...props }, ref) {
|
|
59
63
|
const isMuted = typeof muted === 'boolean' ? muted : false;
|
|
60
64
|
const isMirror = typeof mirror === 'boolean' ? mirror : false;
|
|
61
65
|
|
|
62
66
|
return <StreamView ref={ref} muted={isMuted} mirror={isMirror} {...props} />;
|
|
63
|
-
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const RemoteStreamView = forwardRef(RemoteStreamViewBase);
|
|
70
|
+
|
|
71
|
+
RemoteStreamView.displayName = 'RemoteStreamView';
|
|
72
|
+
|
|
73
|
+
function FullscreenStreamViewBase(
|
|
74
|
+
{
|
|
75
|
+
element,
|
|
76
|
+
pipElement,
|
|
77
|
+
navElement,
|
|
78
|
+
hideIconElement,
|
|
79
|
+
showIconElement,
|
|
80
|
+
containerClassName,
|
|
81
|
+
fullscreenButtonClassName,
|
|
82
|
+
fullscreenButtonIconClassName,
|
|
83
|
+
pipContainerClassName,
|
|
84
|
+
pipButtonClassName,
|
|
85
|
+
pipButtonIconClassName,
|
|
86
|
+
containerProps,
|
|
87
|
+
fullscreenButtonProps,
|
|
88
|
+
fullscreenButtonIconProps,
|
|
89
|
+
pipContainerProps,
|
|
90
|
+
pipButtonProps,
|
|
91
|
+
pipButtonIconProps,
|
|
92
|
+
},
|
|
93
|
+
ref
|
|
94
|
+
) {
|
|
95
|
+
const innerRef = useRef(null);
|
|
96
|
+
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
97
|
+
const [isPictureInPicture, setIsPictureInPicture] = useState(false);
|
|
98
|
+
const toggleFullscreen = useCallback(async () => {
|
|
99
|
+
const container = innerRef.current;
|
|
100
|
+
|
|
101
|
+
if (!container) return;
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
if (!document.fullscreenElement) {
|
|
105
|
+
await container.requestFullscreen();
|
|
106
|
+
setIsFullscreen(true);
|
|
107
|
+
setIsPictureInPicture(true);
|
|
108
|
+
} else {
|
|
109
|
+
await document.exitFullscreen();
|
|
110
|
+
setIsFullscreen(false);
|
|
111
|
+
setIsPictureInPicture(false);
|
|
112
|
+
}
|
|
113
|
+
} catch (err) {
|
|
114
|
+
console.error('Fullscreen error:', err);
|
|
115
|
+
}
|
|
116
|
+
}, []);
|
|
117
|
+
const togglePictureInPicture = useCallback(() => {
|
|
118
|
+
if (pipElement) {
|
|
119
|
+
setIsPictureInPicture((prevState) => !prevState);
|
|
120
|
+
}
|
|
121
|
+
}, [pipElement]);
|
|
122
|
+
|
|
123
|
+
useImperativeHandle(
|
|
124
|
+
ref,
|
|
125
|
+
() =>
|
|
126
|
+
Object.assign(innerRef.current, {
|
|
127
|
+
isFullscreen,
|
|
128
|
+
isPictureInPicture,
|
|
129
|
+
toggleFullscreen,
|
|
130
|
+
togglePictureInPicture,
|
|
131
|
+
}),
|
|
132
|
+
[isFullscreen, isPictureInPicture, toggleFullscreen, togglePictureInPicture]
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
const onFullscreenChange = () => {
|
|
137
|
+
setIsFullscreen(!!document.fullscreenElement);
|
|
138
|
+
setIsPictureInPicture(!!document.fullscreenElement);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
document.addEventListener('fullscreenchange', onFullscreenChange);
|
|
142
|
+
|
|
143
|
+
return () => document.removeEventListener('fullscreenchange', onFullscreenChange);
|
|
144
|
+
}, []);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<div
|
|
148
|
+
ref={innerRef}
|
|
149
|
+
className={cn('relative flex items-center justify-center size-full', containerClassName)}
|
|
150
|
+
{...containerProps}
|
|
151
|
+
>
|
|
152
|
+
{element}
|
|
153
|
+
<button
|
|
154
|
+
onClick={toggleFullscreen}
|
|
155
|
+
className={cn(
|
|
156
|
+
'absolute top-2 right-2 p-1 rounded-md bg-black/50 text-white hover:bg-black/80 z-10 shadow-xs shadow-white/25',
|
|
157
|
+
fullscreenButtonClassName
|
|
158
|
+
)}
|
|
159
|
+
{...fullscreenButtonProps}
|
|
160
|
+
>
|
|
161
|
+
{isFullscreen
|
|
162
|
+
? hideIconElement || <Minimize className={fullscreenButtonIconClassName} {...fullscreenButtonIconProps} />
|
|
163
|
+
: showIconElement || <Maximize className={fullscreenButtonIconClassName} {...fullscreenButtonIconProps} />}
|
|
164
|
+
</button>
|
|
165
|
+
<div className="absolute size-full p-2 flex flex-col justify-end items-center">
|
|
166
|
+
{isFullscreen && pipElement && (
|
|
167
|
+
<div className="relative size-full flex items-end justify-end">
|
|
168
|
+
{isPictureInPicture && (
|
|
169
|
+
<div
|
|
170
|
+
className={cn(
|
|
171
|
+
'max-w-1/4 max-h-1/4 aspect-4/3 overflow-hidden rounded-md shadow-md shadow-white/25',
|
|
172
|
+
pipContainerClassName
|
|
173
|
+
)}
|
|
174
|
+
{...pipContainerProps}
|
|
175
|
+
>
|
|
176
|
+
{pipElement}
|
|
177
|
+
</div>
|
|
178
|
+
)}
|
|
179
|
+
<button
|
|
180
|
+
onClick={togglePictureInPicture}
|
|
181
|
+
className={cn(
|
|
182
|
+
'absolute bottom-2 right-2 p-1 rounded-md bg-black/50 text-white hover:bg-black/80 z-10 shadow-xs shadow-white/25',
|
|
183
|
+
pipButtonClassName
|
|
184
|
+
)}
|
|
185
|
+
{...pipButtonProps}
|
|
186
|
+
>
|
|
187
|
+
<PictureInPicture2 className={pipButtonIconClassName} {...pipButtonIconProps} />
|
|
188
|
+
</button>
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
{isFullscreen && navElement}
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const FullscreenStreamView = forwardRef(FullscreenStreamViewBase);
|
|
198
|
+
|
|
199
|
+
FullscreenStreamView.displayName = 'FullscreenStreamView';
|
|
200
|
+
|
|
201
|
+
export { StreamView, LocalStreamView, RemoteStreamView, FullscreenStreamView };
|