@openpeepshq/rn-components 0.6.3 → 0.6.4
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 +3 -3
- package/src/components/layout/PlusButton.tsx +6 -0
- package/src/components/ui/button.tsx +8 -2
- package/src/theme/OpenPeepsThemeProvider.tsx +23 -5
- package/src/theme/defaults.ts +1 -0
- package/src/theme/types.ts +1 -0
- package/src/theme/utils.ts +9 -0
- package/tailwind.config.js +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpeepshq/rn-components",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "React Native community screens and shared UI (extracted from the Black Ambition app) for the OpenPeeps stack.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -141,8 +141,8 @@
|
|
|
141
141
|
"timezones-list": "^3.1.0",
|
|
142
142
|
"validator": "^13.15.23",
|
|
143
143
|
"zustand": "^5.0.3",
|
|
144
|
-
"@openpeepshq/
|
|
145
|
-
"@openpeepshq/
|
|
144
|
+
"@openpeepshq/react": "^0.6.1",
|
|
145
|
+
"@openpeepshq/common": "^0.3.1"
|
|
146
146
|
},
|
|
147
147
|
"devDependencies": {
|
|
148
148
|
"@babel/core": "^7.26.7",
|
|
@@ -3,6 +3,11 @@ import { Pressable } from 'react-native';
|
|
|
3
3
|
import { PlusIcon } from '../icons/index';
|
|
4
4
|
import { usePageChrome } from './pageChrome';
|
|
5
5
|
|
|
6
|
+
// PlusButton is always fully round — it doesn't use the theme's buttonRadius
|
|
7
|
+
// setting (which is for regular buttons). On web, circular elements have a
|
|
8
|
+
// separate theme token; on RN we use a static 9999px (same as rounded-full).
|
|
9
|
+
const PLUS_BUTTON_RADIUS = 9999;
|
|
10
|
+
|
|
6
11
|
export const PlusButton = () => {
|
|
7
12
|
const { plus } = usePageChrome();
|
|
8
13
|
if (!plus || Array.isArray(plus)) return null;
|
|
@@ -20,6 +25,7 @@ export const PlusButton = () => {
|
|
|
20
25
|
accessibilityRole="button"
|
|
21
26
|
accessibilityLabel={plus.title || 'New'}
|
|
22
27
|
onPress={onPress}
|
|
28
|
+
style={{ borderRadius: PLUS_BUTTON_RADIUS }}
|
|
23
29
|
className="bg-primary absolute bottom-10 right-6 z-20 size-16 items-center justify-center rounded-button"
|
|
24
30
|
>
|
|
25
31
|
<Icon size={24} className="text-primary-foreground" />
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { Pressable } from 'react-native';
|
|
3
|
+
import { Pressable, type StyleProp, type ViewStyle } from 'react-native';
|
|
4
4
|
import { TextClassContext } from './themed-text';
|
|
5
5
|
import { cn } from '../../lib/utils';
|
|
6
|
+
import { useThemeBorderRadius } from '../../theme/OpenPeepsThemeProvider';
|
|
6
7
|
|
|
7
8
|
const buttonVariants = cva(
|
|
8
9
|
'group flex items-center justify-center rounded-button web:ring-offset-background web:transition-colors web:focus-visible:outline-none web:focus-visible:ring-2 web:focus-visible:ring-ring web:focus-visible:ring-offset-2',
|
|
@@ -65,7 +66,11 @@ type ButtonProps = React.ComponentPropsWithoutRef<typeof Pressable> &
|
|
|
65
66
|
const Button = React.forwardRef<
|
|
66
67
|
React.ElementRef<typeof Pressable>,
|
|
67
68
|
ButtonProps
|
|
68
|
-
>(({ className, variant, size, ...props }, ref) => {
|
|
69
|
+
>(({ className, variant, size, style, ...props }, ref) => {
|
|
70
|
+
// NativeWind v4 doesn't resolve CSS variables for borderRadius, so
|
|
71
|
+
// apply the theme button radius via inline style as a fallback.
|
|
72
|
+
const borderRadius = useThemeBorderRadius();
|
|
73
|
+
|
|
69
74
|
return (
|
|
70
75
|
<TextClassContext.Provider
|
|
71
76
|
value={cn(
|
|
@@ -80,6 +85,7 @@ const Button = React.forwardRef<
|
|
|
80
85
|
)}
|
|
81
86
|
ref={ref}
|
|
82
87
|
role="button"
|
|
88
|
+
style={cn({ borderRadius }, style) as StyleProp<ViewStyle>}
|
|
83
89
|
{...props}
|
|
84
90
|
/>
|
|
85
91
|
</TextClassContext.Provider>
|
|
@@ -4,7 +4,7 @@ import { colorScheme } from 'nativewind';
|
|
|
4
4
|
import { useOpenpeeps } from '@openpeepshq/react';
|
|
5
5
|
import { OpenPeepsTheme } from './types';
|
|
6
6
|
import { defaultTheme } from './defaults';
|
|
7
|
-
import { buildTheme, getThemeVars } from './utils';
|
|
7
|
+
import { buildTheme, getThemeVars, parseDimension } from './utils';
|
|
8
8
|
import { CommunityConfig, getTheme } from '@openpeepshq/common';
|
|
9
9
|
|
|
10
10
|
const OpenPeepsThemeContext = createContext<OpenPeepsTheme>(defaultTheme);
|
|
@@ -36,10 +36,20 @@ export const OpenPeepsThemeProvider = ({
|
|
|
36
36
|
|
|
37
37
|
const theme = useMemo(
|
|
38
38
|
() =>
|
|
39
|
-
buildTheme(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
buildTheme(
|
|
40
|
+
resolvedTheme.dark,
|
|
41
|
+
resolvedTheme.primaryHex,
|
|
42
|
+
resolvedTheme.buttonRadius,
|
|
43
|
+
() => {
|
|
44
|
+
refetchProfileSettings();
|
|
45
|
+
}
|
|
46
|
+
),
|
|
47
|
+
[
|
|
48
|
+
refetchProfileSettings,
|
|
49
|
+
resolvedTheme.dark,
|
|
50
|
+
resolvedTheme.primaryHex,
|
|
51
|
+
resolvedTheme.buttonRadius,
|
|
52
|
+
]
|
|
43
53
|
);
|
|
44
54
|
|
|
45
55
|
const themeVars = useMemo(
|
|
@@ -78,3 +88,11 @@ export const useOpenPeepsTheme = () => {
|
|
|
78
88
|
}
|
|
79
89
|
return context;
|
|
80
90
|
};
|
|
91
|
+
|
|
92
|
+
/** Returns the theme button border-radius as a React Native numeric value.
|
|
93
|
+
* NativeWind v4 does not resolve CSS variables for borderRadius, so
|
|
94
|
+
* components must apply this via inline style instead of `rounded-button`. */
|
|
95
|
+
export const useThemeBorderRadius = (): number => {
|
|
96
|
+
const { buttonRadius } = useOpenPeepsTheme();
|
|
97
|
+
return parseDimension(buttonRadius);
|
|
98
|
+
};
|
package/src/theme/defaults.ts
CHANGED
package/src/theme/types.ts
CHANGED
package/src/theme/utils.ts
CHANGED
|
@@ -36,9 +36,17 @@ export const getThemeVars = (
|
|
|
36
36
|
'--theme-rounded-container': radii?.radius || '0.5rem',
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
+
/** Parse a CSS dimension string (e.g. '9999px', '8px') into a React Native
|
|
40
|
+
* numeric pixel value. Returns 0 when the string can't be parsed. */
|
|
41
|
+
export const parseDimension = (value: string): number => {
|
|
42
|
+
const num = parseFloat(value);
|
|
43
|
+
return isNaN(num) ? 0 : num;
|
|
44
|
+
};
|
|
45
|
+
|
|
39
46
|
export const buildTheme = (
|
|
40
47
|
isDark: boolean,
|
|
41
48
|
primaryColor: string | undefined,
|
|
49
|
+
buttonRadius: string | undefined,
|
|
42
50
|
refresh: () => void | Promise<void>
|
|
43
51
|
) => {
|
|
44
52
|
const colors = mapColors(isDark);
|
|
@@ -48,6 +56,7 @@ export const buildTheme = (
|
|
|
48
56
|
...colors,
|
|
49
57
|
primary: primaryColor || colors.primary,
|
|
50
58
|
},
|
|
59
|
+
buttonRadius: buttonRadius || '9999px',
|
|
51
60
|
refresh,
|
|
52
61
|
};
|
|
53
62
|
};
|
package/tailwind.config.js
CHANGED
|
@@ -66,7 +66,11 @@ export default {
|
|
|
66
66
|
hairline: hairlineWidth(),
|
|
67
67
|
},
|
|
68
68
|
borderRadius: {
|
|
69
|
-
|
|
69
|
+
// NativeWind v4 does not resolve CSS variables for borderRadius
|
|
70
|
+
// (only for colors via processColor). Components apply the theme
|
|
71
|
+
// button radius via inline style (see useThemeBorderRadius).
|
|
72
|
+
// Static fallback ensures non-square buttons as a safety net.
|
|
73
|
+
button: '9999px',
|
|
70
74
|
lg: 'var(--theme-rounded-container, 0.5rem)',
|
|
71
75
|
md: 'calc(var(--theme-rounded-container, 0.5rem) - 2px)',
|
|
72
76
|
sm: 'calc(var(--theme-rounded-container, 0.5rem) - 4px)',
|