@openpeepshq/rn-components 0.6.0 → 0.6.2

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 (40) hide show
  1. package/package.json +7 -6
  2. package/src/components/conversations/ConversationMessageBubble.tsx +11 -1
  3. package/src/components/conversations/ConversationParticipantsModal.tsx +6 -1
  4. package/src/components/conversations/ConversationPreviewCard.tsx +1 -1
  5. package/src/components/custom/navigation/side-menu.tsx +2 -1
  6. package/src/components/icons/index.ts +8 -0
  7. package/src/components/index.ts +1 -0
  8. package/src/components/navigation/helpers.ts +3 -0
  9. package/src/components/navigation/main-navigator.tsx +4 -0
  10. package/src/components/navigation/nativeRouter.tsx +11 -0
  11. package/src/components/navigation/tab-navigator.tsx +13 -3
  12. package/src/components/navigation/types/main.ts +6 -0
  13. package/src/components/navigation/types/tabs.ts +2 -0
  14. package/src/components/post/CompactReplyParent.tsx +22 -0
  15. package/src/components/post/FeedPostContent.tsx +4 -0
  16. package/src/components/post/NewResourceButton.tsx +57 -0
  17. package/src/components/post/PostDetail.tsx +3 -0
  18. package/src/components/post/index.ts +1 -0
  19. package/src/components/post/pieces/PostMenu.tsx +15 -9
  20. package/src/components/post/post-form/PostTypeSwitcher.tsx +19 -1
  21. package/src/components/post/post-form/ResourceForm.tsx +221 -0
  22. package/src/components/post/post-form/index.ts +1 -0
  23. package/src/components/post/types/Event.tsx +39 -20
  24. package/src/components/post/types/index.ts +1 -0
  25. package/src/components/post/types/resource/FullResource.tsx +177 -0
  26. package/src/components/resources/ResourceCard.tsx +289 -0
  27. package/src/components/resources/ResourceLibrary.tsx +369 -0
  28. package/src/components/resources/index.ts +4 -0
  29. package/src/components/ui/button.tsx +2 -2
  30. package/src/global.css +16 -14
  31. package/src/pages/conversations/Show.tsx +54 -12
  32. package/src/pages/groups/Show.tsx +19 -1
  33. package/src/pages/index.ts +3 -0
  34. package/src/pages/resources/Edit.tsx +72 -0
  35. package/src/pages/resources/Index.tsx +25 -0
  36. package/src/pages/resources/New.tsx +55 -0
  37. package/src/theme/OpenPeepsThemeProvider.tsx +1 -5
  38. package/src/theme/defaults.ts +22 -106
  39. package/src/theme/utils.ts +22 -0
  40. package/tailwind.config.js +78 -14
package/src/global.css CHANGED
@@ -5,25 +5,26 @@
5
5
  @layer base {
6
6
  :root {
7
7
  --background: #ffffff;
8
- --foreground: #0a0a0f;
8
+ --foreground: #0a0a0b;
9
9
  --card: #ffffff;
10
- --card-foreground: #0a0a0f;
10
+ --card-foreground: #0a0a0b;
11
11
  --popover: #ffffff;
12
- --popover-foreground: #0a0a0f;
13
- --primary: #18181b;
12
+ --popover-foreground: #0a0a0b;
13
+ --primary: #16161a;
14
14
  --primary-foreground: #fafafa;
15
15
  --secondary: #f4f4f5;
16
- --secondary-foreground: #18181b;
17
- --muted: #f4f4f5;
16
+ --secondary-foreground: #16161a;
17
+ --muted: #f4f4f6;
18
18
  --muted-foreground: #71717a;
19
19
  --accent: #f4f4f5;
20
- --accent-foreground: #18181b;
20
+ --accent-foreground: #16161a;
21
21
  --destructive: #ef4444;
22
22
  --destructive-foreground: #fafafa;
23
23
  --border: #e4e4e7;
24
24
  --input: #e4e4e7;
25
- --ring: #18181b;
25
+ --ring: #16161a;
26
26
  --alpha: #fafafa;
27
+ --surface-2: #e4e4e7;
27
28
  }
28
29
 
29
30
  .dark:root {
@@ -34,18 +35,19 @@
34
35
  --popover: #0a0a0f;
35
36
  --popover-foreground: #fafafa;
36
37
  --primary: #fafafa;
37
- --primary-foreground: #18181b;
38
- --secondary: #27272a;
38
+ --primary-foreground: #16161a;
39
+ --secondary: #28282e;
39
40
  --secondary-foreground: #fafafa;
40
41
  --muted: #27272a;
41
42
  --muted-foreground: #a1a1aa;
42
- --accent: #27272a;
43
+ --accent: #28282e;
43
44
  --accent-foreground: #fafafa;
44
45
  --destructive: #dc2626;
45
46
  --destructive-foreground: #fafafa;
46
- --border: #27272a;
47
- --input: #27272a;
47
+ --border: #28282e;
48
+ --input: #28282e;
48
49
  --ring: #d4d4d8;
49
50
  --alpha: #18181b;
51
+ --surface-2: #3f3f46;
50
52
  }
51
- }
53
+ }
@@ -29,6 +29,8 @@ import {
29
29
  ConversationProfileHeader,
30
30
  MessageInThread,
31
31
  } from '../../components/conversations/index';
32
+ import { ProfileAvatar } from '../../components/profile/Avatar';
33
+ import { ProfileCard } from '../../components/profile/ProfileCard';
32
34
 
33
35
  type ConversationProps = MainScreenProps<'Conversation'>;
34
36
 
@@ -46,12 +48,18 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
46
48
  const [participantsOpen, setParticipantsOpen] = useState(false);
47
49
 
48
50
  const sendMessage = openpeepsApi.createConversationPostAction({ id });
49
- const audience = messages?.[0]?.audience || [];
50
- const headerParticipants =
51
- audience.length === 2
52
- ? audience.filter((p) => p.id !== currentProfile?.id)
53
- : audience;
54
- const isGroupChat = audience.length > 2;
51
+
52
+ // Mirror the web Show page: derive participants from the last message's
53
+ // audience, excluding the current profile.
54
+ const lastMessage = messages?.slice(-1)[0];
55
+ const participants =
56
+ lastMessage?.audience?.filter((a) => a.id !== currentProfile?.id) ?? [];
57
+ const multipleParticipants = participants.length > 1;
58
+
59
+ const participantNames =
60
+ participants.length > 0
61
+ ? participants.map((p) => p.displayName || `@${p.handle}`).join(', ')
62
+ : t('conversations.title', { defaultValue: 'Conversation' });
55
63
 
56
64
  const resetForm = useCallback(() => {
57
65
  setContent('');
@@ -65,7 +73,6 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
65
73
 
66
74
  try {
67
75
  setIsSending(true);
68
- const lastMessage = messages?.slice(-1)[0];
69
76
  await sendMessage({
70
77
  visibility: 'direct',
71
78
  audience: lastMessage?.audience,
@@ -105,8 +112,10 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
105
112
  useSetPageHeader(
106
113
  isLoading ? undefined : (
107
114
  <ConversationProfileHeader
108
- participants={headerParticipants}
109
- onPress={isGroupChat ? () => setParticipantsOpen(true) : undefined}
115
+ participants={participants}
116
+ onPress={
117
+ multipleParticipants ? () => setParticipantsOpen(true) : undefined
118
+ }
110
119
  />
111
120
  ),
112
121
  isLoading ? undefined : (
@@ -129,6 +138,39 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
129
138
  return (
130
139
  <ThemedView className="flex-1">
131
140
  <View className="flex-1">
141
+ {/* Section under the page header showing the participants,
142
+ mirroring the web conversation Show page. */}
143
+ <View className="border-b border-border">
144
+ {participants.length === 1 && participants[0] ? (
145
+ <ProfileCard
146
+ profile={participants[0]}
147
+ showAction={false}
148
+ hasAction={false}
149
+ />
150
+ ) : multipleParticipants ? (
151
+ <TouchableOpacity
152
+ onPress={() => setParticipantsOpen(true)}
153
+ className="w-full flex-row items-center gap-2 p-3"
154
+ >
155
+ <View className="flex-row -space-x-2 shrink-0">
156
+ {participants.slice(0, 4).map((p) => (
157
+ <ProfileAvatar
158
+ key={p.id}
159
+ profile={p}
160
+ className="size-9 border-0"
161
+ />
162
+ ))}
163
+ </View>
164
+ <ThemedText
165
+ className="min-w-0 truncate text-sm font-medium"
166
+ numberOfLines={1}
167
+ >
168
+ {participantNames}
169
+ </ThemedText>
170
+ </TouchableOpacity>
171
+ ) : null}
172
+ </View>
173
+
132
174
  <DropdownMenu>
133
175
  <KeyboardAvoidingView
134
176
  className="flex-1"
@@ -147,7 +189,7 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
147
189
  <MessageInThread
148
190
  previous={messages[idx - 1]}
149
191
  message={message}
150
- multipleParticipants={isGroupChat}
192
+ multipleParticipants={multipleParticipants}
151
193
  conversationRootId={id}
152
194
  />
153
195
  </View>
@@ -206,11 +248,11 @@ export const ConversationShow = ({ route, navigation }: ConversationProps) => {
206
248
  </View>
207
249
  </KeyboardAvoidingView>
208
250
  </DropdownMenu>
209
- {isGroupChat && participantsOpen ? (
251
+ {multipleParticipants && participantsOpen ? (
210
252
  <ConversationParticipantsModal
211
253
  open
212
254
  onOpenChange={setParticipantsOpen}
213
- participants={audience}
255
+ participants={participants}
214
256
  />
215
257
  ) : null}
216
258
  </View>
@@ -22,7 +22,9 @@ import {
22
22
  EventsFeed,
23
23
  NewEventButton,
24
24
  NewNoteButton,
25
+ NewResourceButton,
25
26
  } from '../../components/post/index';
27
+ import { ResourceLibrary } from '../../components/resources';
26
28
  import {
27
29
  Tabs,
28
30
  TabsContent,
@@ -38,7 +40,7 @@ type GroupProps = CompositeScreenProps<
38
40
  NativeStackScreenProps<TabStackParamList>
39
41
  >;
40
42
 
41
- type Tab = 'posts' | 'events' | 'description';
43
+ type Tab = 'posts' | 'events' | 'resources' | 'description';
42
44
 
43
45
  export const GroupShow = ({ route, navigation }: GroupProps) => {
44
46
  const { openpeepsApi } = useOpenpeeps();
@@ -114,6 +116,12 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
114
116
  <TabsTrigger value="events" className={tabClass('events')}>
115
117
  <ThemedText>{t('groups.sections.events')}</ThemedText>
116
118
  </TabsTrigger>
119
+ <TabsTrigger
120
+ value="resources"
121
+ className={tabClass('resources')}
122
+ >
123
+ <ThemedText>{t('groups.sections.resources')}</ThemedText>
124
+ </TabsTrigger>
117
125
  <TabsTrigger
118
126
  value="description"
119
127
  className={tabClass('description')}
@@ -159,6 +167,9 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
159
167
  query={eventsTab === 'upcoming' ? upcomingEvents : pastEvents}
160
168
  />
161
169
  </TabsContent>
170
+ <TabsContent value="resources" className="p-0">
171
+ <ResourceLibrary groupId={group.id} />
172
+ </TabsContent>
162
173
  <TabsContent value="description" className="p-2">
163
174
  <GroupInfoAsComponent id={group.id} />
164
175
  </TabsContent>
@@ -180,6 +191,13 @@ export const GroupShow = ({ route, navigation }: GroupProps) => {
180
191
  group={group}
181
192
  />
182
193
  ) : null}
194
+ {group && tab === 'resources' ? (
195
+ <NewResourceButton
196
+ visibility="group"
197
+ currentProfile={currentProfile}
198
+ group={group}
199
+ />
200
+ ) : null}
183
201
  </ThemedView>
184
202
  );
185
203
  };
@@ -49,6 +49,9 @@ export { Tags } from './Tags';
49
49
  export { Explore } from './Explore';
50
50
  export { FeedsBookmarks } from './feeds/Bookmarks';
51
51
  export { ArticlesIndex } from './articles/Index';
52
+ export { ResourcesIndex } from './resources/Index';
53
+ export { NewResource } from './resources/New';
54
+ export { EditResource } from './resources/Edit';
52
55
  export { LanguageSettings } from './settings/Language';
53
56
  export { TimezoneSettings } from './settings/Timezone';
54
57
  export { NotificationSettings } from './settings/Notifications';
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ import { ActivityIndicator } from 'react-native';
3
+ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
4
+ import { useTranslation } from 'react-i18next';
5
+ import Toast from 'react-native-toast-message';
6
+ import { truncateText } from '@openpeepshq/common/lib';
7
+ import { useEditResource } from '@openpeepshq/react';
8
+ import { HeaderActionButton, useSetPageHeader } from '../../components/layout';
9
+ import { ThemedView } from '../../components/ui/themed-view';
10
+ import { MainScreenProps } from '../../components/navigation/types/index';
11
+ import { ResourceForm } from '../../components/post/index';
12
+ import { ThemedText } from '../../components/ui/themed-text';
13
+
14
+ type EditResourceProps = MainScreenProps<'EditResource'>;
15
+
16
+ export const EditResource: React.FC<EditResourceProps> = ({ route }) => {
17
+ const { id } = route.params;
18
+ const { t } = useTranslation();
19
+ const {
20
+ postQuery,
21
+ postData,
22
+ setPostData,
23
+ resourceTitle,
24
+ submitting,
25
+ error,
26
+ clearError,
27
+ submit,
28
+ } = useEditResource(id);
29
+
30
+ React.useEffect(() => {
31
+ if (!error) return;
32
+ Toast.show({ type: 'error', text1: error });
33
+ clearError();
34
+ }, [error, clearError]);
35
+
36
+ const title = resourceTitle
37
+ ? `${t('resources.edit')} ${truncateText(resourceTitle)}`
38
+ : t('resources.edit');
39
+
40
+ useSetPageHeader(
41
+ title,
42
+ <HeaderActionButton
43
+ title={
44
+ submitting
45
+ ? t('common.saving', { defaultValue: 'Saving…' })
46
+ : t('resources.update.title', { defaultValue: 'Update resource' })
47
+ }
48
+ onPress={() => void submit()}
49
+ disabled={submitting || !postData}
50
+ loading={submitting}
51
+ />
52
+ );
53
+
54
+ return (
55
+ <ThemedView className="flex-1">
56
+ {postQuery.isLoading ? (
57
+ <ActivityIndicator size="small" />
58
+ ) : !postQuery.data || !postData ? (
59
+ <ThemedText className="p-8 text-center text-2xl">
60
+ {t('resources.notFound')}
61
+ </ThemedText>
62
+ ) : (
63
+ <KeyboardAwareScrollView
64
+ contentContainerClassName="grow"
65
+ className="pb-12"
66
+ >
67
+ <ResourceForm postData={postData} onChange={setPostData} isEdit />
68
+ </KeyboardAwareScrollView>
69
+ )}
70
+ </ThemedView>
71
+ );
72
+ };
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { useCurrentProfile, useDefaultVisibility } from '@openpeepshq/react';
4
+ import { useSetPageHeader } from '../../components/layout';
5
+ import { NewResourceButton } from '../../components/post/index';
6
+ import { ResourceLibrary } from '../../components/resources/index';
7
+ import { ThemedView } from '../../components/ui/themed-view';
8
+
9
+ export const ResourcesIndex = () => {
10
+ const { t } = useTranslation();
11
+ const currentProfile = useCurrentProfile();
12
+ const visibility = useDefaultVisibility();
13
+
14
+ useSetPageHeader(t('navigation.resources'));
15
+
16
+ return (
17
+ <ThemedView className="relative flex-1">
18
+ <ResourceLibrary />
19
+ <NewResourceButton
20
+ visibility={visibility}
21
+ currentProfile={currentProfile}
22
+ />
23
+ </ThemedView>
24
+ );
25
+ };
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Toast from 'react-native-toast-message';
5
+ import { useNewResource } from '@openpeepshq/react';
6
+ import { HeaderActionButton, useSetPageHeader } from '../../components/layout';
7
+ import { ThemedView } from '../../components/ui/themed-view';
8
+ import { MainScreenProps } from '../../components/navigation/types/index';
9
+ import { ResourceForm } from '../../components/post/index';
10
+
11
+ type NewResourceProps = MainScreenProps<'NewResource'>;
12
+
13
+ export const NewResource: React.FC<NewResourceProps> = () => {
14
+ const { t } = useTranslation();
15
+ const {
16
+ postData,
17
+ setPostData,
18
+ canSubmit,
19
+ submitting,
20
+ error,
21
+ clearError,
22
+ submit,
23
+ } = useNewResource();
24
+
25
+ React.useEffect(() => {
26
+ if (!error) return;
27
+ Toast.show({ type: 'error', text1: error });
28
+ clearError();
29
+ }, [error, clearError]);
30
+
31
+ useSetPageHeader(
32
+ t('resources.new', { defaultValue: 'New resource' }),
33
+ <HeaderActionButton
34
+ title={
35
+ submitting
36
+ ? t('common.submitting', { defaultValue: 'Submitting…' })
37
+ : t('resources.create.title', { defaultValue: 'Create resource' })
38
+ }
39
+ onPress={() => void submit()}
40
+ disabled={submitting || !canSubmit}
41
+ loading={submitting}
42
+ />
43
+ );
44
+
45
+ return (
46
+ <ThemedView className="flex-1">
47
+ <KeyboardAwareScrollView
48
+ contentContainerClassName="grow"
49
+ className="pb-12"
50
+ >
51
+ <ResourceForm postData={postData} onChange={setPostData} />
52
+ </KeyboardAwareScrollView>
53
+ </ThemedView>
54
+ );
55
+ };
@@ -48,11 +48,7 @@ export const OpenPeepsThemeProvider = ({
48
48
  buttonRadius: resolvedTheme.buttonRadius,
49
49
  radius: resolvedTheme.radius,
50
50
  }),
51
- [
52
- resolvedTheme.buttonRadius,
53
- resolvedTheme.radius,
54
- theme.colors,
55
- ]
51
+ [resolvedTheme.buttonRadius, resolvedTheme.radius, theme.colors]
56
52
  );
57
53
 
58
54
  useEffect(() => {
@@ -1,111 +1,27 @@
1
- import { OpenPeepsTheme, ColorName, ColorValue } from './types';
1
+ import type { OpenPeepsTheme, ColorName, ColorValue } from './types';
2
2
 
3
3
  export const DEFAULT_COLORS: ColorValue[] = [
4
- {
5
- name: 'background',
6
- light: '#ffffff',
7
- dark: '#0a0a0f',
8
- },
9
- {
10
- name: 'foreground',
11
- light: '#0a0a0f',
12
- dark: '#fafafa',
13
- },
14
- {
15
- name: 'card',
16
- light: '#ffffff',
17
- dark: '#0a0a0f',
18
- },
19
- {
20
- name: 'card-foreground',
21
- light: '#0a0a0f',
22
- dark: '#fafafa',
23
- },
24
- {
25
- name: 'popover',
26
- light: '#ffffff',
27
- dark: '#0a0a0f',
28
- },
29
- {
30
- name: 'popover-foreground',
31
- light: '#0a0a0f',
32
- dark: '#fafafa',
33
- },
34
- {
35
- name: 'primary',
36
- light: '#16161a',
37
- dark: '#fafafa',
38
- },
39
- {
40
- name: 'primary-foreground',
41
- light: '#fafafa',
42
- dark: '#16161a',
43
- },
44
- {
45
- name: 'secondary',
46
- light: '#f4f4f6',
47
- dark: '#28282e',
48
- },
49
- {
50
- name: 'secondary-foreground',
51
- light: '#16161a',
52
- dark: '#fafafa',
53
- },
54
- {
55
- name: 'muted',
56
- light: '#f4f4f6',
57
- dark: '#28282e',
58
- },
59
- {
60
- name: 'muted-foreground',
61
- light: '#71717a',
62
- dark: '#a1a1aa',
63
- },
64
- {
65
- name: 'accent',
66
- light: '#f4f4f6',
67
- dark: '#28282e',
68
- },
69
- {
70
- name: 'accent-foreground',
71
- light: '#16161a',
72
- dark: '#fafafa',
73
- },
74
- {
75
- name: 'destructive',
76
- light: '#ef4444',
77
- dark: '#dc2626',
78
- },
79
- {
80
- name: 'destructive-foreground',
81
- light: '#fafafa',
82
- dark: '#fafafa',
83
- },
84
- {
85
- name: 'border',
86
- light: '#e4e4e7',
87
- dark: '#28282e',
88
- },
89
- {
90
- name: 'input',
91
- light: '#e4e4e7',
92
- dark: '#28282e',
93
- },
94
- {
95
- name: 'ring',
96
- light: '#16161a',
97
- dark: '#d4d4d8',
98
- },
99
- {
100
- name: 'alpha',
101
- light: '#fafafa',
102
- dark: '#18181b',
103
- },
104
- {
105
- name: 'surface-2',
106
- light: '#e4e4e7',
107
- dark: '#3f3f46',
108
- },
4
+ { name: 'background', light: '#ffffff', dark: '#0a0a0f' },
5
+ { name: 'foreground', light: '#0a0a0b', dark: '#fafafa' },
6
+ { name: 'card', light: '#ffffff', dark: '#0a0a0f' },
7
+ { name: 'card-foreground', light: '#0a0a0b', dark: '#fafafa' },
8
+ { name: 'popover', light: '#ffffff', dark: '#0a0a0f' },
9
+ { name: 'popover-foreground', light: '#0a0a0b', dark: '#fafafa' },
10
+ { name: 'primary', light: '#16161a', dark: '#fafafa' },
11
+ { name: 'primary-foreground', light: '#fafafa', dark: '#16161a' },
12
+ { name: 'secondary', light: '#f4f4f5', dark: '#28282e' },
13
+ { name: 'secondary-foreground', light: '#16161a', dark: '#fafafa' },
14
+ { name: 'muted', light: '#f4f4f6', dark: '#27272a' },
15
+ { name: 'muted-foreground', light: '#71717a', dark: '#a1a1aa' },
16
+ { name: 'accent', light: '#f4f4f5', dark: '#28282e' },
17
+ { name: 'accent-foreground', light: '#16161a', dark: '#fafafa' },
18
+ { name: 'destructive', light: '#ef4444', dark: '#dc2626' },
19
+ { name: 'destructive-foreground', light: '#fafafa', dark: '#fafafa' },
20
+ { name: 'border', light: '#e4e4e7', dark: '#28282e' },
21
+ { name: 'input', light: '#e4e4e7', dark: '#28282e' },
22
+ { name: 'ring', light: '#16161a', dark: '#d4d4d8' },
23
+ { name: 'alpha', light: '#fafafa', dark: '#18181b' },
24
+ { name: 'surface-2', light: '#e4e4e7', dark: '#3f3f46' },
109
25
  ];
110
26
 
111
27
  export const mapColors = (isDark: boolean) =>
@@ -2,6 +2,28 @@ import { vars } from 'nativewind';
2
2
  import { mapColors } from './defaults';
3
3
  import type { OpenPeepsTheme } from './types';
4
4
 
5
+ /** Convert a hex color (#rrggbb) to "R G B" channel string for use in
6
+ * `rgb()` expressions in inline styles (NativeWind doesn't support `/N`
7
+ * opacity modifiers on CSS-variable colors). */
8
+ export const hexToRgbChannels = (hex: string): string => {
9
+ const sanitized = hex.replaceAll('##', '#');
10
+ const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitized);
11
+ if (!m) return hex;
12
+ const [, r, g, b] = m;
13
+ if (r === undefined || g === undefined || b === undefined) return hex;
14
+ return `${parseInt(r, 16)} ${parseInt(g, 16)} ${parseInt(b, 16)}`;
15
+ };
16
+
17
+ /** Convert a hex color to an `rgba(r, g, b, a)` string for inline styles. */
18
+ export const hexWithOpacity = (hex: string, opacity: number): string => {
19
+ const sanitized = hex.replaceAll('##', '#');
20
+ const m = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(sanitized);
21
+ if (!m) return hex;
22
+ const [, r, g, b] = m;
23
+ if (r === undefined || g === undefined || b === undefined) return hex;
24
+ return `rgba(${parseInt(r, 16)}, ${parseInt(g, 16)}, ${parseInt(b, 16)}, ${opacity})`;
25
+ };
26
+
5
27
  export const getThemeVars = (
6
28
  colors: OpenPeepsTheme['colors'],
7
29
  radii?: { buttonRadius?: string; radius?: string }