@openpeepshq/rn-components 0.3.13 → 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.
Files changed (33) hide show
  1. package/package.json +2 -2
  2. package/src/components/configuration/ConfigMenuButton.tsx +6 -2
  3. package/src/components/groups/GroupAvatar.tsx +41 -12
  4. package/src/components/navigation/nativeRouter.tsx +30 -0
  5. package/src/components/navigation/tab-navigator.tsx +11 -8
  6. package/src/components/notifications/NotificationWrapper.tsx +2 -2
  7. package/src/components/notifications/NotificationsList.tsx +15 -4
  8. package/src/components/post/FeedPost.tsx +4 -1
  9. package/src/components/post/NewEventButton.tsx +4 -0
  10. package/src/components/post/NewNoteButton.tsx +2 -0
  11. package/src/components/post/pieces/PostActions.tsx +2 -0
  12. package/src/components/post/pieces/PostMenu.tsx +315 -340
  13. package/src/components/post/pieces/ShareMenu.tsx +68 -67
  14. package/src/components/post/pieces/UnreadPostIndicator.tsx +15 -2
  15. package/src/components/post/types/Article.tsx +2 -2
  16. package/src/components/post/types/Note.tsx +2 -2
  17. package/src/components/post/types/Poll.tsx +4 -2
  18. package/src/components/post/types/article/CardArticle.tsx +1 -1
  19. package/src/components/post/types/event/CardEvent.tsx +1 -1
  20. package/src/components/post/types/event/FullEvent.tsx +1 -1
  21. package/src/components/post/types/event/ProfileEventRelationship.tsx +1 -1
  22. package/src/components/profile/Avatar.tsx +24 -8
  23. package/src/components/profile/FollowUnfollowButton.tsx +4 -2
  24. package/src/components/profile/ProfileCard.tsx +48 -18
  25. package/src/components/ui/badge.tsx +36 -0
  26. package/src/components/ui/index.ts +6 -0
  27. package/src/components/ui/loading-spinner.tsx +24 -0
  28. package/src/components/ui/popup-menu-button.tsx +99 -0
  29. package/src/components/ui/popup-menu-section.tsx +21 -0
  30. package/src/components/ui/popup-menu-separator.tsx +10 -0
  31. package/src/components/ui/popup-menu.tsx +75 -0
  32. package/src/lib/utils.ts +11 -23
  33. package/src/pages/Members.tsx +1 -1
@@ -16,15 +16,11 @@ import {
16
16
  ShareIcon,
17
17
  } from '../../icons/index';
18
18
  import {
19
- DropdownMenu,
20
- DropdownMenuContent,
21
- DropdownMenuGroup,
22
- DropdownMenuItem,
23
- DropdownMenuLabel,
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
- <DropdownMenu>
68
- <DropdownMenuTrigger asChild className="px-2">
69
- {menuButton ?? <ShareIcon size={18} className="text-foreground" />}
70
- </DropdownMenuTrigger>
71
- <DropdownMenuContent className="mt-1">
72
- <DropdownMenuLabel>{t('posts.shareMenu.title')}</DropdownMenuLabel>
73
- {signedIn ? (
74
- <>
75
- <DropdownMenuGroup>
76
- <DropdownMenuLabel className="text-muted-foreground">
77
- {t('posts.shareMenu.shareOnCommunity')}
78
- </DropdownMenuLabel>
79
- <DropdownMenuItem
80
- className="flex-row gap-x-2 items-center"
81
- onPress={() => void repost()}
82
- >
83
- <Repeat2Icon size={16} className="text-foreground" />
84
- <ThemedText>{t('posts.shareMenu.repostToFeed')}</ThemedText>
85
- </DropdownMenuItem>
86
- <DropdownMenuItem
87
- className="flex-row gap-x-2 items-center"
88
- onPress={() => {
89
- setDraftMessage(postUrl);
90
- navigation.navigate('SelectPrivateMessageMembers');
91
- }}
92
- >
93
- <SendIcon size={16} className="text-foreground" />
94
- <ThemedText>{t('posts.shareMenu.sendInMessage')}</ThemedText>
95
- </DropdownMenuItem>
96
- </DropdownMenuGroup>
97
- <DropdownMenuSeparator />
98
- <DropdownMenuLabel className="text-muted-foreground">
99
- {t('posts.shareMenu.otherOptions')}
100
- </DropdownMenuLabel>
101
- </>
102
- ) : null}
103
- <DropdownMenuGroup>
104
- {isEvent ? (
105
- <DropdownMenuItem
106
- className="flex-row gap-x-2 items-center"
107
- onPress={() => void shareEventIcs()}
108
- >
109
- <CalendarIcon size={16} className="text-foreground" />
110
- <ThemedText>
111
- {t('posts.shareMenu.downloadCalendarIcs')}
112
- </ThemedText>
113
- </DropdownMenuItem>
114
- ) : null}
115
- <DropdownMenuItem
116
- className="flex-row gap-x-2 items-center"
117
- onPress={copyLink}
118
- >
119
- <CopyIcon size={16} className="text-foreground" />
120
- <ThemedText>{t('posts.shareMenu.copyLink')}</ThemedText>
121
- </DropdownMenuItem>
122
- </DropdownMenuGroup>
123
- </DropdownMenuContent>
124
- </DropdownMenu>
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,21 +1,34 @@
1
1
  import { View } from 'react-native';
2
2
  import React from 'react';
3
+ import { cn } from '../../../lib/utils';
3
4
 
4
5
  interface UnreadPostIndicatorProps {
5
6
  show: boolean;
7
+ className?: string;
8
+ /** `corner` is a top-left fold on feed cards; `dot` is the in-flow mark.
9
+ * On RN only `dot` is supported — `corner` renders nothing (CSS-only effect). */
10
+ variant?: 'dot' | 'corner';
6
11
  }
7
12
 
8
13
  /**
9
14
  * Subtle unread marker positioned in the host's left margin.
10
15
  * Absolutely positioned so visibility changes never shift layout.
11
16
  */
12
- export const UnreadPostIndicator = ({ show }: UnreadPostIndicatorProps) => {
17
+ export const UnreadPostIndicator = ({
18
+ show,
19
+ className,
20
+ variant = 'dot',
21
+ }: UnreadPostIndicatorProps) => {
13
22
  if (!show) return null;
23
+ if (variant === 'corner') return null;
14
24
 
15
25
  return (
16
26
  <View
17
27
  pointerEvents="none"
18
- className="absolute left-1.5 top-6 size-1.5 rounded-full bg-muted-foreground/45"
28
+ className={cn(
29
+ 'absolute left-1.5 top-6 size-1.5 rounded-full bg-muted-foreground/45',
30
+ className
31
+ )}
19
32
  />
20
33
  );
21
34
  };
@@ -13,11 +13,11 @@ import { MainStackParamList } from '../../navigation/types/index';
13
13
  import { useTranslation } from 'react-i18next';
14
14
  import { CachedImage } from '../../custom/common/index';
15
15
 
16
- interface Props {
16
+ export interface FeedArticleProps {
17
17
  post: PublicPost;
18
18
  }
19
19
 
20
- export const FeedArticle = ({ post }: Props) => {
20
+ export const FeedArticle = ({ post }: FeedArticleProps) => {
21
21
  const article = useMemo(() => post.data as Article, [post]);
22
22
 
23
23
  const previewContent = useMemo(
@@ -7,11 +7,11 @@ import { View } from 'react-native';
7
7
  import { ThemedText } from '../../ui/themed-text';
8
8
  import { OpenpeepsMarkdown } from '../../markdown/index';
9
9
 
10
- interface Props {
10
+ export interface FeedNoteProps {
11
11
  post: PublicPost;
12
12
  }
13
13
 
14
- export const FeedNote = ({ post }: Props) =>
14
+ export const FeedNote = ({ post }: FeedNoteProps) =>
15
15
  post?.data?.type === 'note' ? (
16
16
  <View>
17
17
  <Attachments {...{ post }} />
@@ -8,11 +8,13 @@ import { OpenpeepsMarkdown } from '../../markdown/index';
8
8
  import { ThemedText } from '../../ui/themed-text';
9
9
  import { PollContent } from '../pieces/PollContent';
10
10
 
11
- interface Props {
11
+ export interface FeedPollProps {
12
12
  post: PublicPost;
13
+ /** When false, show static options only (no voting). */
14
+ interactive?: boolean;
13
15
  }
14
16
 
15
- export const FeedPoll = ({ post }: Props) =>
17
+ export const FeedPoll = ({ post, interactive = true }: FeedPollProps) =>
16
18
  post?.data?.type === 'question' ? (
17
19
  <View>
18
20
  <Attachments {...{ post }} />
@@ -8,7 +8,7 @@ import { NativeStackNavigationProp } from '@react-navigation/native-stack';
8
8
  import { MainStackParamList } from '../../../navigation/types/index';
9
9
  import { CachedImage } from '../../../custom/common/index';
10
10
 
11
- interface CardArticleProps {
11
+ export interface CardArticleProps {
12
12
  post: PublicPost;
13
13
  }
14
14
 
@@ -16,7 +16,7 @@ import { ProfileEventRelationship } from './ProfileEventRelationship';
16
16
  import { useTranslation } from 'react-i18next';
17
17
 
18
18
  import { ParticipantsCard } from '../../index';
19
- interface CardEventProps {
19
+ export interface CardEventProps {
20
20
  post: PublicPost;
21
21
  showEventDate?: boolean;
22
22
  }
@@ -76,7 +76,7 @@ import {
76
76
  } from '../../index';
77
77
  import { ReportProfileOrPostModal } from '../../../profile/index';
78
78
  import { OpenpeepsMarkdown } from '../../../markdown/index';
79
- interface FullEventProps {
79
+ export interface FullEventProps {
80
80
  post: PublicPost;
81
81
  occurrence?: string;
82
82
  }
@@ -9,7 +9,7 @@ import { useOpenpeeps } from '@openpeepshq/react';
9
9
  import { ThemedText } from '../../../ui/themed-text';
10
10
  import { useTranslation } from 'react-i18next';
11
11
 
12
- interface ProfileEventRelationshipProps {
12
+ export interface ProfileEventRelationshipProps {
13
13
  post: PublicPost;
14
14
  }
15
15
 
@@ -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 { cn, getInitials } from '../../lib/utils';
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 bg-background',
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 className={cn('text-foreground font-medium', textSizeClass)}>
49
- {getInitials(profile)}
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 { Profile } from '@openpeepshq/common';
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
- {rightComponent}
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: Profile;
70
- onPress?: (profile: Profile) => void;
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
+ };