UNPKG

@oxyhq/services

Version:

Reusable OxyHQ module to handle authentication, user management, karma system, device-based session management and more 🚀

178 lines (170 loc) • 4.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.OxySignInButton = void 0; var _react = _interopRequireDefault(require("react")); var _reactNative = require("react-native"); var _OxyContext = require("../context/OxyContext"); var _OxyLogo = _interopRequireDefault(require("./OxyLogo")); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** * A pre-styled button component for signing in with Oxy services * * This component automatically integrates with the OxyProvider context * and will control the authentication bottom sheet when pressed. * * @example * ```tsx * // Basic usage * <OxySignInButton /> * * // Custom styling * <OxySignInButton * variant="contained" * style={{ marginTop: 20 }} * text="Login with Oxy" * /> * * // Custom handler * <OxySignInButton onPress={() => { * // Custom authentication flow * console.log('Custom auth flow initiated'); * }} /> * ``` */ const OxySignInButton = ({ variant = 'default', onPress, style, textStyle, text = 'Sign in with Oxy', disabled = false, showWhenAuthenticated = false, screen = 'SignIn' }) => { // Get all needed values from context in a single call const { user, showBottomSheet } = (0, _OxyContext.useOxy)(); // Don't show the button if already authenticated (unless explicitly overridden) if (user && !showWhenAuthenticated) return null; // Default handler that uses the context methods const handlePress = () => { if (onPress) { onPress(); return; } // Allow passing any screen name, including 'SignUp', 'AccountCenter', etc. if (showBottomSheet) { showBottomSheet(screen); } else { console.warn('OxySignInButton: showBottomSheet is not available. Either provide an onPress prop or ensure this component is used within an OxyProvider.'); } }; // Determine the button style based on the variant const getButtonStyle = () => { switch (variant) { case 'outline': return [styles.buttonOutline, style]; case 'contained': return [styles.buttonContained, style]; default: return [styles.buttonDefault, style]; } }; // Determine the text style based on the variant const getTextStyle = () => { switch (variant) { case 'outline': return [styles.textOutline, textStyle]; case 'contained': return [styles.textContained, textStyle]; default: return [styles.textDefault, textStyle]; } }; // This function was previously used for logo container styling // Now removed as we're not using the container anymore return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TouchableOpacity, { style: [styles.button, getButtonStyle(), disabled && styles.buttonDisabled], onPress: handlePress, disabled: disabled, children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, { style: styles.buttonContent, children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_OxyLogo.default, { width: 20, height: 20, fillColor: variant === 'contained' ? 'white' : '#d169e5', secondaryFillColor: variant === 'contained' ? '#d169e5' : undefined, style: disabled ? { opacity: 0.6 } : undefined }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, { style: [styles.text, getTextStyle(), disabled && styles.textDisabled], children: text })] }) }); }; exports.OxySignInButton = OxySignInButton; const styles = _reactNative.StyleSheet.create({ button: { padding: 14, borderRadius: 35, alignItems: 'center', justifyContent: 'center' }, buttonDefault: { backgroundColor: '#FFFFFF', borderWidth: 1, borderColor: '#DDDDDD', shadowColor: '#000000', shadowOffset: { width: 0, height: 2 }, shadowOpacity: 0.1, shadowRadius: 4, elevation: 2 }, buttonOutline: { backgroundColor: 'transparent', borderWidth: 1, borderColor: '#d169e5' }, buttonContained: { backgroundColor: '#d169e5' }, buttonDisabled: { opacity: 0.6 }, buttonContent: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center' }, text: { fontFamily: _reactNative.Platform.OS === 'web' ? 'Phudu' : 'Phudu-SemiBold', fontWeight: _reactNative.Platform.OS === 'web' ? '600' : undefined, // Only apply fontWeight on web fontSize: 16, marginLeft: 10 }, textDefault: { color: '#333333' }, textOutline: { color: '#d169e5' }, textContained: { color: '#FFFFFF' }, textDisabled: { color: '#888888' } }); var _default = exports.default = OxySignInButton; //# sourceMappingURL=OxySignInButton.js.map