diff --git a/README.md b/README.md index c963ff3..292fd07 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,148 @@ enum InstallmentType { } ``` +## 🎨 UI Customization & Theming + +Customize the appearance of PagBank SDK modal dialogs to match your app's design. The library provides complete control over colors, themes, and UI elements displayed during payment transactions. + +
+ Customizable Payment Modal +

Payment modal with custom dark theme matching your app's design

+
+ +### ⚡ Quick Theme Setup + +```typescript +import { setStyleTheme } from 'react-native-plugpag-nitro'; + +// Create and apply a custom theme +await setStyleTheme({ + headBackgroundColor: '#1A1A1D', // Header background + headTextColor: '#FFFFFF', // Header text + positiveButtonBackground: '#22C55E', // "Confirm" button color + negativeButtonBackground: '#EF4444', // "Cancel" button color + contentTextColor: '#FFFFFF', // Body text color + lineColor: '#71717A' // Borders and lines +}); +``` + +### 🛠️ Custom Theme Creation + +Create themes that match your app's design system: + +```typescript +// Create a custom brand-based theme +const customTheme = { + headBackgroundColor: '#00D4FF', // Your primary brand color + headTextColor: '#FFFFFF', // White text on colored header + contentTextColor: '#1A1A1D', // Dark text for body content + positiveButtonBackground: '#00D4FF', // Consistent brand color + negativeButtonBackground: '#EF4444', // Standard red for cancel + lineColor: '#E5E7EB' // Light gray for borders +}; + +await setStyleTheme(customTheme); +``` + +### 🎨 Complete Style Properties + +
+📋 All available style properties + +```typescript +interface PlugpagStyleData { + // Header styling + headTextColor?: string; // Header text color + headBackgroundColor?: string; // Header background color + + // Content styling + contentTextColor?: string; // General content text + contentTextValue1Color?: string; // Primary monetary values + contentTextValue2Color?: string; // Secondary monetary values + + // Button styling + positiveButtonTextColor?: string; // Confirm button text + positiveButtonBackground?: string; // Confirm button background + negativeButtonTextColor?: string; // Cancel button text + negativeButtonBackground?: string; // Cancel button background + genericButtonBackground?: string; // Generic button background + genericButtonTextColor?: string; // Generic button text + + // Input field styling + genericSmsEditTextBackground?: string; // SMS input background + genericSmsEditTextTextColor?: string; // SMS input text + + // Interface elements + lineColor?: string; // Lines, borders, dividers +} +``` + +
+ +### 🔧 Theme Utilities + +```typescript +import { ThemeUtils } from 'react-native-plugpag-nitro'; + +// Validate theme colors +const errors = ThemeUtils.validateTheme(myTheme); +if (errors.length === 0) { + await setStyleTheme(myTheme); +} + +// Merge themes +const customizedTheme = ThemeUtils.mergeThemes( + baseTheme, // Your base theme + { positiveButtonBackground: '#FF6B6B' } +); + +// Preview theme colors (for debugging) +const preview = ThemeUtils.createThemePreview(myTheme); +console.log(preview); // { headBackgroundColor: '#1A1A1D', ... } +``` + +### 💡 Best Practices + +- **Apply early**: Set themes during app initialization, before payment operations +- **Match your design**: Use colors that complement your existing UI +- **Accessibility**: Ensure sufficient contrast between text and backgrounds +- **Validation**: Always validate themes before applying them +- **Error handling**: Wrap theme operations in try-catch blocks + +### 🏗️ Integration Example + +```typescript +import React, { useEffect } from 'react'; +import { setStyleTheme } from 'react-native-plugpag-nitro'; + +export default function App() { + useEffect(() => { + // Apply theme matching your app's design + const initializeTheme = async () => { + try { + const customTheme = { + headBackgroundColor: '#1A1A1D', + headTextColor: '#FFFFFF', + positiveButtonBackground: '#22C55E', + negativeButtonBackground: '#EF4444' + }; + + await setStyleTheme(customTheme); + console.log('Theme applied successfully'); + } catch (error) { + console.error('Failed to apply theme:', error); + } + }; + + initializeTheme(); + }, []); + + // ... rest of your app +} +``` + +> 📖 **Complete styling guide**: See [STYLING_GUIDE.md](STYLING_GUIDE.md) for detailed documentation and examples. + ## 💡 Usage Examples ### Complete Payment Flow diff --git a/STYLING_GUIDE.md b/STYLING_GUIDE.md new file mode 100644 index 0000000..7e3635e --- /dev/null +++ b/STYLING_GUIDE.md @@ -0,0 +1,340 @@ +````markdown +# PagBank SDK UI Customization + +This document explains how to customize the appearance of PagBank SDK modal dialogs, buttons, and text using the new styling API. + +## Overview + +The PagBank SDK displays modal dialogs during payment transactions. You can customize the colors and appearance of these dialogs to match your app's design by creating custom themes within your application. + +## Quick Start + +```typescript +import { setStyleTheme } from 'react-native-plugpag-nitro'; + +// Create and apply a custom theme +await setStyleTheme({ + headBackgroundColor: '#1A1A1D', + headTextColor: '#FFFFFF', + positiveButtonBackground: '#22C55E', + positiveButtonTextColor: '#FFFFFF', + negativeButtonBackground: '#EF4444', + negativeButtonTextColor: '#FFFFFF', +}); +``` + +## Available Style Properties + +### Header Styling +- `headTextColor` - Color for header text +- `headBackgroundColor` - Background color for header area + +### Content Styling +- `contentTextColor` - General content text color +- `contentTextValue1Color` - Primary monetary values color +- `contentTextValue2Color` - Secondary monetary values color + +### Button Styling +- `positiveButtonTextColor` - Text color for confirmation buttons (e.g., "Imprimir") +- `positiveButtonBackground` - Background color for confirmation buttons +- `negativeButtonTextColor` - Text color for cancel buttons (e.g., "Cancelar") +- `negativeButtonBackground` - Background color for cancel buttons +- `genericButtonBackground` - Background for generic buttons (e.g., "Enviar SMS") +- `genericButtonTextColor` - Text color for generic buttons + +### Input Fields +- `genericSmsEditTextBackground` - Background for SMS input fields +- `genericSmsEditTextTextColor` - Text color for SMS input fields + +### Interface Elements +- `lineColor` - Color for lines, borders, and dividers + +## Creating Custom Themes + +All themes are created within your application. The library provides utilities to help validate and manage themes, but no predefined themes are included. + +### Example: Dark Theme +```typescript +const darkTheme = { + headTextColor: '#FFFFFF', + headBackgroundColor: '#0A0A0B', + contentTextColor: '#F3F4F6', + contentTextValue1Color: '#00D4FF', + contentTextValue2Color: '#9CA3AF', + positiveButtonBackground: '#10B981', + positiveButtonTextColor: '#FFFFFF', + negativeButtonBackground: '#EF4444', + negativeButtonTextColor: '#FFFFFF', + genericButtonBackground: '#1F2937', + genericButtonTextColor: '#F3F4F6', + genericSmsEditTextBackground: '#1F2937', + genericSmsEditTextTextColor: '#F3F4F6', + lineColor: '#374151', +}; + +await setStyleTheme(darkTheme); +``` + +### Example: Light Theme +```typescript +const lightTheme = { + headTextColor: '#1F2937', + headBackgroundColor: '#FFFFFF', + contentTextColor: '#1F2937', + contentTextValue1Color: '#0EA5E9', + contentTextValue2Color: '#6B7280', + positiveButtonTextColor: '#FFFFFF', + positiveButtonBackground: '#10B981', + negativeButtonTextColor: '#FFFFFF', + negativeButtonBackground: '#EF4444', + genericButtonBackground: '#F3F4F6', + genericButtonTextColor: '#1F2937', + genericSmsEditTextBackground: '#F9FAFB', + genericSmsEditTextTextColor: '#1F2937', + lineColor: '#E5E7EB', +}; + +await setStyleTheme(lightTheme); +``` + +### Example: Brand-Based Theme +```typescript +const brandTheme = { + headTextColor: '#FFFFFF', + headBackgroundColor: '#7C3AED', // Your brand purple + contentTextColor: '#1F2937', + contentTextValue1Color: '#7C3AED', + contentTextValue2Color: '#6B7280', + positiveButtonTextColor: '#FFFFFF', + positiveButtonBackground: '#7C3AED', + negativeButtonTextColor: '#FFFFFF', + negativeButtonBackground: '#EF4444', + genericButtonBackground: '#F3F4F6', + genericButtonTextColor: '#1F2937', + genericSmsEditTextBackground: '#F9FAFB', + genericSmsEditTextTextColor: '#1F2937', + lineColor: '#E5E7EB', +}; + +await setStyleTheme(brandTheme); +``` + +## Usage in Your App + +### Apply Theme on App Initialization +```typescript +import { useEffect } from 'react'; +import { setStyleTheme } from 'react-native-plugpag-nitro'; + +export default function App() { + useEffect(() => { + const initializeTheme = async () => { + try { + const customTheme = { + headBackgroundColor: '#1A1A1D', + headTextColor: '#FFFFFF', + positiveButtonBackground: '#22C55E', + // ... other properties + }; + + await setStyleTheme(customTheme); + console.log('Theme applied successfully'); + } catch (error) { + console.error('Failed to apply theme:', error); + } + }; + + initializeTheme(); + }, []); + + // ... rest of your app +} +``` + +### Dynamic Theme Switching +```typescript +import { useState } from 'react'; +import { setStyleTheme } from 'react-native-plugpag-nitro'; + +function ThemeSelector() { + const [currentTheme, setCurrentTheme] = useState('dark'); + + const createDarkTheme = () => ({ + headBackgroundColor: '#0A0A0B', + headTextColor: '#FFFFFF', + positiveButtonBackground: '#10B981', + // ... other properties + }); + + const createLightTheme = () => ({ + headBackgroundColor: '#FFFFFF', + headTextColor: '#1F2937', + positiveButtonBackground: '#10B981', + // ... other properties + }); + + const switchTheme = async (themeName: string) => { + try { + let theme; + switch (themeName) { + case 'dark': + theme = createDarkTheme(); + break; + case 'light': + theme = createLightTheme(); + break; + default: + return; + } + + await setStyleTheme(theme); + setCurrentTheme(themeName); + } catch (error) { + console.error('Failed to switch theme:', error); + } + }; + + return ( + +