@openpeepshq/rn-components 0.4.0 → 0.5.0
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 +2 -2
- package/src/components/groups/GroupAvatar.tsx +41 -12
- package/src/components/navigation/tab-navigator.tsx +11 -8
- package/src/components/post/pieces/PostActions.tsx +2 -0
- package/src/components/post/pieces/PostMenu.tsx +315 -340
- package/src/components/post/pieces/ShareMenu.tsx +68 -67
- package/src/components/profile/Avatar.tsx +24 -8
- package/src/components/profile/FollowUnfollowButton.tsx +4 -2
- package/src/components/profile/ProfileCard.tsx +48 -18
- package/src/components/ui/badge.tsx +36 -0
- package/src/components/ui/index.ts +6 -0
- package/src/components/ui/loading-spinner.tsx +24 -0
- package/src/components/ui/popup-menu-button.tsx +99 -0
- package/src/components/ui/popup-menu-section.tsx +21 -0
- package/src/components/ui/popup-menu-separator.tsx +10 -0
- package/src/components/ui/popup-menu.tsx +75 -0
- package/src/lib/utils.ts +11 -23
- package/src/pages/Members.tsx +1 -1
|
@@ -16,15 +16,11 @@ import {
|
|
|
16
16
|
ShareIcon,
|
|
17
17
|
} from '../../icons/index';
|
|
18
18
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
DropdownMenuSeparator,
|
|
25
|
-
DropdownMenuTrigger,
|
|
26
|
-
} from '../../ui/dropdown-menu';
|
|
27
|
-
import { ThemedText } from '../../ui/themed-text';
|
|
19
|
+
PopupMenu,
|
|
20
|
+
PopupMenuButton,
|
|
21
|
+
PopupSeparator,
|
|
22
|
+
PopupSection,
|
|
23
|
+
} from '../../ui';
|
|
28
24
|
import { MainStackParamList } from '../../navigation/types/index';
|
|
29
25
|
import { BASE_URL } from '../../../lib/constants';
|
|
30
26
|
import { useNewConversationStore } from '../../../stores/useNewConversationStore';
|
|
@@ -64,63 +60,68 @@ export const ShareMenu = ({ post, menuButton }: ShareMenuProps) => {
|
|
|
64
60
|
};
|
|
65
61
|
|
|
66
62
|
return (
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
63
|
+
<PopupMenu
|
|
64
|
+
menuButton={
|
|
65
|
+
menuButton ?? <ShareIcon size={18} className="text-foreground" />
|
|
66
|
+
}
|
|
67
|
+
title={t('posts.shareMenu.title', { defaultValue: 'Share' })}
|
|
68
|
+
>
|
|
69
|
+
{signedIn ? (
|
|
70
|
+
<>
|
|
71
|
+
<PopupSection
|
|
72
|
+
title={t('posts.shareMenu.shareOnCommunity', {
|
|
73
|
+
defaultValue: 'Share on community',
|
|
74
|
+
})}
|
|
75
|
+
/>
|
|
76
|
+
<PopupMenuButton
|
|
77
|
+
title={t('posts.shareMenu.repostToFeed', {
|
|
78
|
+
defaultValue: 'Repost',
|
|
79
|
+
})}
|
|
80
|
+
text={t('posts.shareMenu.repostToFeed', {
|
|
81
|
+
defaultValue: 'Repost',
|
|
82
|
+
})}
|
|
83
|
+
icon={Repeat2Icon as any}
|
|
84
|
+
action={repost}
|
|
85
|
+
/>
|
|
86
|
+
<PopupMenuButton
|
|
87
|
+
title={t('posts.shareMenu.sendInMessage', {
|
|
88
|
+
defaultValue: 'Send in message',
|
|
89
|
+
})}
|
|
90
|
+
text={t('posts.shareMenu.sendInMessage', {
|
|
91
|
+
defaultValue: 'Send in message',
|
|
92
|
+
})}
|
|
93
|
+
icon={SendIcon as any}
|
|
94
|
+
action={() => {
|
|
95
|
+
setDraftMessage(postUrl);
|
|
96
|
+
navigation.navigate('SelectPrivateMessageMembers');
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
<PopupSeparator />
|
|
100
|
+
<PopupSection
|
|
101
|
+
title={t('posts.shareMenu.otherOptions', {
|
|
102
|
+
defaultValue: 'Other options',
|
|
103
|
+
})}
|
|
104
|
+
/>
|
|
105
|
+
</>
|
|
106
|
+
) : null}
|
|
107
|
+
{isEvent ? (
|
|
108
|
+
<PopupMenuButton
|
|
109
|
+
title={t('posts.shareMenu.downloadCalendarIcsTitle', {
|
|
110
|
+
defaultValue: 'Download calendar file',
|
|
111
|
+
})}
|
|
112
|
+
text={t('posts.shareMenu.downloadCalendarIcs', {
|
|
113
|
+
defaultValue: 'Add to calendar (.ics)',
|
|
114
|
+
})}
|
|
115
|
+
icon={CalendarIcon as any}
|
|
116
|
+
action={shareEventIcs}
|
|
117
|
+
/>
|
|
118
|
+
) : null}
|
|
119
|
+
<PopupMenuButton
|
|
120
|
+
title={t('posts.shareMenu.copyLink', { defaultValue: 'Copy link' })}
|
|
121
|
+
text={t('posts.shareMenu.copyLink', { defaultValue: 'Copy link' })}
|
|
122
|
+
icon={CopyIcon as any}
|
|
123
|
+
action={copyLink}
|
|
124
|
+
/>
|
|
125
|
+
</PopupMenu>
|
|
125
126
|
);
|
|
126
127
|
};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { Profile, isDeletedProfile } from '@openpeepshq/common';
|
|
3
|
-
import { Avatar, AvatarImage } from '../ui/avatar';
|
|
4
2
|
import { useTranslation } from 'react-i18next';
|
|
5
3
|
import { View, Text } from 'react-native';
|
|
6
|
-
import {
|
|
4
|
+
import { Profile, isDeletedProfile } from '@openpeepshq/common';
|
|
5
|
+
import {
|
|
6
|
+
useOpenpeeps,
|
|
7
|
+
getInitials,
|
|
8
|
+
hueFromHandle,
|
|
9
|
+
initialsBackground,
|
|
10
|
+
svgCoverSrc,
|
|
11
|
+
} from '@openpeepshq/react';
|
|
12
|
+
import { useOpenPeepsTheme } from '../../theme/OpenPeepsThemeProvider';
|
|
13
|
+
import { Avatar, AvatarImage } from '../ui/avatar';
|
|
7
14
|
import { UserXIcon } from '../icons/index';
|
|
15
|
+
import { cn } from '../../lib/utils';
|
|
8
16
|
|
|
9
17
|
export const ProfileAvatar = ({
|
|
10
18
|
profile,
|
|
@@ -14,16 +22,20 @@ export const ProfileAvatar = ({
|
|
|
14
22
|
className?: string;
|
|
15
23
|
}) => {
|
|
16
24
|
const { t } = useTranslation();
|
|
25
|
+
const { isDark } = useOpenPeepsTheme();
|
|
17
26
|
|
|
18
27
|
const isSmall = className?.includes('size-8');
|
|
19
28
|
const sizeClass = isSmall ? 'h-8 w-8' : 'h-16 w-16';
|
|
20
|
-
const textSizeClass = isSmall ? 'text-[14px]' : 'text-[24px]';
|
|
21
29
|
const iconSize = isSmall ? 16 : 28;
|
|
22
30
|
const roundedClass = 'rounded-full';
|
|
23
31
|
const deleted = isDeletedProfile(profile);
|
|
24
32
|
|
|
25
33
|
const avatarSource =
|
|
26
|
-
!deleted && profile?.avatar ? { uri: profile.avatar } : null;
|
|
34
|
+
!deleted && profile?.avatar ? { uri: svgCoverSrc(profile.avatar) } : null;
|
|
35
|
+
|
|
36
|
+
const hue = hueFromHandle(profile?.handle ?? '');
|
|
37
|
+
const backgroundColor =
|
|
38
|
+
!deleted && !avatarSource ? initialsBackground(hue, isDark) : undefined;
|
|
27
39
|
|
|
28
40
|
if (deleted || !avatarSource) {
|
|
29
41
|
return (
|
|
@@ -38,15 +50,19 @@ export const ProfileAvatar = ({
|
|
|
38
50
|
>
|
|
39
51
|
<View
|
|
40
52
|
className={cn(
|
|
41
|
-
'flex h-full w-full items-center justify-center
|
|
53
|
+
'flex h-full w-full items-center justify-center',
|
|
42
54
|
roundedClass
|
|
43
55
|
)}
|
|
56
|
+
style={{ backgroundColor }}
|
|
44
57
|
>
|
|
45
58
|
{deleted ? (
|
|
46
59
|
<UserXIcon size={iconSize} className="text-muted-foreground" />
|
|
47
60
|
) : (
|
|
48
|
-
<Text
|
|
49
|
-
|
|
61
|
+
<Text
|
|
62
|
+
className="text-foreground font-medium"
|
|
63
|
+
style={{ fontSize: isSmall ? 14 : 24 }}
|
|
64
|
+
>
|
|
65
|
+
{getInitials(profile?.displayName, profile?.handle)}
|
|
50
66
|
</Text>
|
|
51
67
|
)}
|
|
52
68
|
</View>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { PublicProfile } from '@openpeepshq/common';
|
|
2
|
+
import type { PublicProfile, Profile } from '@openpeepshq/common';
|
|
3
3
|
import { useFollowProfile, useOpenpeeps } from '@openpeepshq/react';
|
|
4
4
|
import { Button } from '../ui/button';
|
|
5
5
|
import { ThemedText } from '../ui/themed-text';
|
|
@@ -8,8 +8,10 @@ import { useTranslation } from 'react-i18next';
|
|
|
8
8
|
import { cn } from '../../lib/utils';
|
|
9
9
|
|
|
10
10
|
export interface FollowUnfollowButtonProps {
|
|
11
|
-
profile: PublicProfile;
|
|
11
|
+
profile: PublicProfile | Profile;
|
|
12
12
|
compact?: boolean;
|
|
13
|
+
/** Popup mode is a no-op on RN (web-only PopupMenuButton rendering). */
|
|
14
|
+
popup?: boolean;
|
|
13
15
|
onSuccess?: () => void;
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { View, TouchableWithoutFeedback, Pressable } from 'react-native';
|
|
2
1
|
import React from 'react';
|
|
3
|
-
import {
|
|
2
|
+
import { View, TouchableWithoutFeedback, Pressable } from 'react-native';
|
|
3
|
+
import type { PublicProfile, Profile } from '@openpeepshq/common/types';
|
|
4
|
+
import { markdownPlainText } from '@openpeepshq/common/lib';
|
|
4
5
|
import { XIcon } from '../icons/index';
|
|
5
6
|
import { ThemedText } from '../ui/themed-text';
|
|
6
7
|
import { truncateText } from '../../lib/utils';
|
|
@@ -8,18 +9,28 @@ import { useNavigation } from '@react-navigation/native';
|
|
|
8
9
|
import { MainStackParamList } from '../navigation/types/index';
|
|
9
10
|
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
10
11
|
import { ProfileAvatar } from './Avatar';
|
|
12
|
+
import { FollowUnfollowButton } from './FollowUnfollowButton';
|
|
11
13
|
|
|
12
|
-
interface ProfileCardProps {
|
|
13
|
-
profile: Profile;
|
|
14
|
+
export interface ProfileCardProps {
|
|
15
|
+
profile: PublicProfile | Profile;
|
|
16
|
+
/** When provided, clicking the card calls this instead of navigating. */
|
|
17
|
+
onSelect?: (profile: PublicProfile | Profile) => void;
|
|
18
|
+
showAction?: boolean;
|
|
19
|
+
/** Custom action node rendered on the right of the card. */
|
|
20
|
+
action?: React.ReactNode;
|
|
14
21
|
hasAction?: boolean;
|
|
15
22
|
actionType?: 'follow' | 'message' | 'unfollow' | 'link' | 'select';
|
|
16
23
|
handleSelectProfile?: () => void;
|
|
17
24
|
rightComponent?: React.ReactNode;
|
|
18
25
|
}
|
|
26
|
+
|
|
19
27
|
export const ProfileCard = ({
|
|
28
|
+
profile,
|
|
29
|
+
onSelect,
|
|
30
|
+
showAction = true,
|
|
31
|
+
action,
|
|
20
32
|
actionType = 'link',
|
|
21
33
|
handleSelectProfile,
|
|
22
|
-
profile,
|
|
23
34
|
rightComponent,
|
|
24
35
|
}: ProfileCardProps) => {
|
|
25
36
|
const navigation =
|
|
@@ -31,22 +42,28 @@ export const ProfileCard = ({
|
|
|
31
42
|
});
|
|
32
43
|
};
|
|
33
44
|
|
|
45
|
+
const onPress = () => {
|
|
46
|
+
if (actionType === 'select' && handleSelectProfile) {
|
|
47
|
+
handleSelectProfile();
|
|
48
|
+
}
|
|
49
|
+
if (actionType !== 'select') {
|
|
50
|
+
if (onSelect) {
|
|
51
|
+
onSelect(profile);
|
|
52
|
+
} else {
|
|
53
|
+
handleGoToProfile();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const bio = markdownPlainText(profile.bio);
|
|
59
|
+
|
|
34
60
|
return (
|
|
35
61
|
<View
|
|
36
62
|
className={`w-full flex-row items-center justify-between px-4 ${
|
|
37
63
|
actionType === 'select' ? 'mb-1 py-1' : 'mb-8'
|
|
38
64
|
}`}
|
|
39
65
|
>
|
|
40
|
-
<TouchableWithoutFeedback
|
|
41
|
-
onPress={() => {
|
|
42
|
-
if (actionType === 'select' && handleSelectProfile) {
|
|
43
|
-
handleSelectProfile();
|
|
44
|
-
}
|
|
45
|
-
if (actionType !== 'select') {
|
|
46
|
-
handleGoToProfile();
|
|
47
|
-
}
|
|
48
|
-
}}
|
|
49
|
-
>
|
|
66
|
+
<TouchableWithoutFeedback onPress={onPress}>
|
|
50
67
|
<View className="flex flex-row items-center gap-x-2">
|
|
51
68
|
<ProfileAvatar
|
|
52
69
|
profile={profile}
|
|
@@ -57,17 +74,30 @@ export const ProfileCard = ({
|
|
|
57
74
|
{truncateText(profile.displayName, 18) || profile.handle}
|
|
58
75
|
</ThemedText>
|
|
59
76
|
<ThemedText className="">@{profile.handle}</ThemedText>
|
|
77
|
+
{bio ? (
|
|
78
|
+
<ThemedText className="text-muted-foreground mt-1 text-sm">
|
|
79
|
+
{truncateText(bio, 100)}
|
|
80
|
+
</ThemedText>
|
|
81
|
+
) : null}
|
|
60
82
|
</View>
|
|
61
83
|
</View>
|
|
62
84
|
</TouchableWithoutFeedback>
|
|
63
|
-
{
|
|
85
|
+
{action ? (
|
|
86
|
+
<View className="flex-shrink-0">{action}</View>
|
|
87
|
+
) : rightComponent ? (
|
|
88
|
+
<View className="flex-shrink-0">{rightComponent}</View>
|
|
89
|
+
) : showAction ? (
|
|
90
|
+
<View className="flex-shrink-0">
|
|
91
|
+
<FollowUnfollowButton profile={profile} compact />
|
|
92
|
+
</View>
|
|
93
|
+
) : null}
|
|
64
94
|
</View>
|
|
65
95
|
);
|
|
66
96
|
};
|
|
67
97
|
|
|
68
98
|
interface MiniProfileCardProps {
|
|
69
|
-
profile:
|
|
70
|
-
onPress?: (profile:
|
|
99
|
+
profile: PublicProfile;
|
|
100
|
+
onPress?: (profile: PublicProfile) => void;
|
|
71
101
|
showAction?: boolean;
|
|
72
102
|
}
|
|
73
103
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { View } from 'react-native';
|
|
4
|
+
import { ThemedText } from './themed-text';
|
|
5
|
+
import { cn } from '../../lib/utils';
|
|
6
|
+
|
|
7
|
+
const badgeVariants = cva(
|
|
8
|
+
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold',
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: 'border-transparent bg-primary text-primary-foreground',
|
|
13
|
+
secondary: 'border-transparent bg-secondary text-secondary-foreground',
|
|
14
|
+
destructive:
|
|
15
|
+
'border-transparent bg-destructive text-destructive-foreground',
|
|
16
|
+
outline: 'text-foreground',
|
|
17
|
+
success: 'border-transparent bg-success text-success-foreground',
|
|
18
|
+
warning: 'border-transparent bg-warning text-warning-foreground',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
defaultVariants: { variant: 'default' },
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
export interface BadgeProps
|
|
26
|
+
extends
|
|
27
|
+
React.ComponentPropsWithoutRef<typeof View>,
|
|
28
|
+
VariantProps<typeof badgeVariants> {}
|
|
29
|
+
|
|
30
|
+
function Badge({ className, variant, ...props }: BadgeProps) {
|
|
31
|
+
return (
|
|
32
|
+
<View className={cn(badgeVariants({ variant }), className)} {...props} />
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { Badge, badgeVariants };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './alert';
|
|
2
2
|
export * from './avatar';
|
|
3
|
+
export * from './badge';
|
|
3
4
|
export * from './bottom-sheet';
|
|
4
5
|
export * from './button';
|
|
5
6
|
export * from './calendar';
|
|
@@ -10,6 +11,11 @@ export * from './dropdown-menu';
|
|
|
10
11
|
export * from './form';
|
|
11
12
|
export * from './input';
|
|
12
13
|
export * from './label';
|
|
14
|
+
export * from './loading-spinner';
|
|
15
|
+
export * from './popup-menu';
|
|
16
|
+
export * from './popup-menu-button';
|
|
17
|
+
export * from './popup-menu-separator';
|
|
18
|
+
export * from './popup-menu-section';
|
|
13
19
|
export * from './progress';
|
|
14
20
|
export * from './radio-group';
|
|
15
21
|
export * from './separator';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ActivityIndicator, View } from 'react-native';
|
|
3
|
+
import { cn } from '../../lib/utils';
|
|
4
|
+
|
|
5
|
+
export interface LoadingSpinnerProps {
|
|
6
|
+
size?: 'small' | 'large';
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Native equivalent of @openpeepshq/react-ui's LoadingSpinner.
|
|
12
|
+
* Uses React Native's ActivityIndicator, which respects the system's
|
|
13
|
+
* preferred indicator style and color scheme.
|
|
14
|
+
*/
|
|
15
|
+
export const LoadingSpinner = ({
|
|
16
|
+
size = 'small',
|
|
17
|
+
className,
|
|
18
|
+
}: LoadingSpinnerProps) => {
|
|
19
|
+
return (
|
|
20
|
+
<View className={cn('items-center justify-center', className)}>
|
|
21
|
+
<ActivityIndicator size={size} />
|
|
22
|
+
</View>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ActivityIndicator } from 'react-native';
|
|
3
|
+
import { DropdownMenuItem } from './dropdown-menu';
|
|
4
|
+
import { ThemedText } from './themed-text';
|
|
5
|
+
import { cn } from '../../lib/utils';
|
|
6
|
+
import { handleInternalURLNavigation } from '../../lib/utils';
|
|
7
|
+
import { buildGoto } from '../navigation/helpers';
|
|
8
|
+
import { useNavigation } from '@react-navigation/native';
|
|
9
|
+
import { MainStackParamList } from '../navigation/types/index';
|
|
10
|
+
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
|
|
11
|
+
|
|
12
|
+
export type ButtonAction = string | (() => unknown | Promise<unknown>);
|
|
13
|
+
export type IconType = React.ElementType;
|
|
14
|
+
|
|
15
|
+
export interface PopupMenuButtonProps {
|
|
16
|
+
action: ButtonAction;
|
|
17
|
+
text?: string;
|
|
18
|
+
loadingText?: string;
|
|
19
|
+
icon?: IconType;
|
|
20
|
+
danger?: boolean;
|
|
21
|
+
compact?: boolean;
|
|
22
|
+
title?: string;
|
|
23
|
+
textSlot?: React.ReactNode;
|
|
24
|
+
/** When false, the menu stays open after pressing (use for async actions). */
|
|
25
|
+
closeOnPress?: boolean;
|
|
26
|
+
/** Disable the button. */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const baseClass =
|
|
31
|
+
'flex w-full items-center gap-x-2 rounded-button p-2 text-left';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Menu item button that mirrors @openpeepshq/react-ui's PopupMenuButton.
|
|
35
|
+
* Accepts `action` as a URL string (navigated via the router adapter) or a
|
|
36
|
+
* callback function (invoked on press with loading state).
|
|
37
|
+
*/
|
|
38
|
+
export const PopupMenuButton = ({
|
|
39
|
+
action,
|
|
40
|
+
text = '',
|
|
41
|
+
loadingText = '',
|
|
42
|
+
icon: Icon,
|
|
43
|
+
danger = false,
|
|
44
|
+
compact = false,
|
|
45
|
+
title = '',
|
|
46
|
+
textSlot,
|
|
47
|
+
closeOnPress = true,
|
|
48
|
+
disabled,
|
|
49
|
+
}: PopupMenuButtonProps) => {
|
|
50
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
51
|
+
const navigation =
|
|
52
|
+
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
|
|
53
|
+
|
|
54
|
+
const handlePress = React.useCallback(async () => {
|
|
55
|
+
if (typeof action === 'string') {
|
|
56
|
+
void handleInternalURLNavigation(action, buildGoto(navigation));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setIsLoading(true);
|
|
60
|
+
try {
|
|
61
|
+
await action();
|
|
62
|
+
} finally {
|
|
63
|
+
setIsLoading(false);
|
|
64
|
+
}
|
|
65
|
+
}, [action, navigation]);
|
|
66
|
+
|
|
67
|
+
const content = isLoading ? (
|
|
68
|
+
<ActivityIndicator size="small" />
|
|
69
|
+
) : (
|
|
70
|
+
<>
|
|
71
|
+
{Icon && <Icon size={16} className="shrink-0" />}
|
|
72
|
+
{!compact && (
|
|
73
|
+
<ThemedText
|
|
74
|
+
className={cn(
|
|
75
|
+
'flex-1',
|
|
76
|
+
danger ? 'text-destructive' : 'text-foreground'
|
|
77
|
+
)}
|
|
78
|
+
>
|
|
79
|
+
{textSlot ?? text}
|
|
80
|
+
</ThemedText>
|
|
81
|
+
)}
|
|
82
|
+
</>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<DropdownMenuItem
|
|
87
|
+
onPress={() => void handlePress()}
|
|
88
|
+
closeOnPress={closeOnPress}
|
|
89
|
+
disabled={disabled ?? isLoading}
|
|
90
|
+
className={cn(
|
|
91
|
+
baseClass,
|
|
92
|
+
danger && 'text-destructive',
|
|
93
|
+
compact && 'justify-center'
|
|
94
|
+
)}
|
|
95
|
+
>
|
|
96
|
+
{content}
|
|
97
|
+
</DropdownMenuItem>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { ThemedText } from './themed-text';
|
|
4
|
+
import { cn } from '../../lib/utils';
|
|
5
|
+
|
|
6
|
+
export interface PopupSectionProps {
|
|
7
|
+
title: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Section header for PopupMenu, mirrors @openpeepshq/react-ui's PopupSection.
|
|
12
|
+
*/
|
|
13
|
+
export const PopupSection = ({ title }: PopupSectionProps) => {
|
|
14
|
+
return (
|
|
15
|
+
<View className="w-full py-2">
|
|
16
|
+
<ThemedText className={cn('text-xs font-semibold text-muted-foreground')}>
|
|
17
|
+
{title}
|
|
18
|
+
</ThemedText>
|
|
19
|
+
</View>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import { DropdownMenuSeparator } from './dropdown-menu';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Separator for PopupMenu, mirrors @openpeepshq/react-ui's PopupSeparator.
|
|
7
|
+
*/
|
|
8
|
+
export const PopupSeparator = () => {
|
|
9
|
+
return <DropdownMenuSeparator className="my-1" />;
|
|
10
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Pressable } from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
DropdownMenu,
|
|
5
|
+
DropdownMenuContent,
|
|
6
|
+
DropdownMenuTrigger,
|
|
7
|
+
} from './dropdown-menu';
|
|
8
|
+
import { cn } from '../../lib/utils';
|
|
9
|
+
import { EllipsisIcon } from '../icons';
|
|
10
|
+
|
|
11
|
+
export type PopupPlacement = 'top' | 'bottom';
|
|
12
|
+
|
|
13
|
+
export interface PopupMenuProps {
|
|
14
|
+
className?: string;
|
|
15
|
+
iconSize?: number;
|
|
16
|
+
compact?: boolean;
|
|
17
|
+
menuButton?: React.ReactNode;
|
|
18
|
+
children?: React.ReactNode;
|
|
19
|
+
title?: string;
|
|
20
|
+
triggerIcon?: React.ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const DEFAULT_ICON_SIZE = 22;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Popover-style menu that wraps the RN DropdownMenu to provide the same API
|
|
27
|
+
* surface as @openpeepshq/react-ui's PopupMenu.
|
|
28
|
+
*/
|
|
29
|
+
export const PopupMenu = ({
|
|
30
|
+
className,
|
|
31
|
+
iconSize = DEFAULT_ICON_SIZE,
|
|
32
|
+
compact = false,
|
|
33
|
+
menuButton,
|
|
34
|
+
children,
|
|
35
|
+
title = 'Open menu',
|
|
36
|
+
triggerIcon,
|
|
37
|
+
}: PopupMenuProps) => {
|
|
38
|
+
const actionName = title;
|
|
39
|
+
const [open, setOpen] = React.useState(false);
|
|
40
|
+
|
|
41
|
+
const TriggerIcon = () => {
|
|
42
|
+
if (triggerIcon) return <>{triggerIcon}</>;
|
|
43
|
+
return <EllipsisIcon className="text-foreground" size={iconSize} />;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const triggerProps = {
|
|
47
|
+
accessibilityRole: 'button' as const,
|
|
48
|
+
accessibilityLabel: actionName || 'Open menu',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<DropdownMenu onOpenChange={setOpen}>
|
|
53
|
+
<DropdownMenuTrigger asChild>
|
|
54
|
+
{menuButton ?? (
|
|
55
|
+
<Pressable
|
|
56
|
+
{...triggerProps}
|
|
57
|
+
className={cn(
|
|
58
|
+
'rounded-button inline-flex items-center justify-center',
|
|
59
|
+
compact ? 'h-8 w-8' : 'h-10 w-10'
|
|
60
|
+
)}
|
|
61
|
+
>
|
|
62
|
+
<TriggerIcon />
|
|
63
|
+
</Pressable>
|
|
64
|
+
)}
|
|
65
|
+
</DropdownMenuTrigger>
|
|
66
|
+
<DropdownMenuContent
|
|
67
|
+
side="bottom"
|
|
68
|
+
align="end"
|
|
69
|
+
className={cn('flex flex-col p-2', compact ? 'w-16' : 'w-52')}
|
|
70
|
+
>
|
|
71
|
+
{children}
|
|
72
|
+
</DropdownMenuContent>
|
|
73
|
+
</DropdownMenu>
|
|
74
|
+
);
|
|
75
|
+
};
|