1.1.4 • Published 6 months ago

rn-custom-alert-prompt v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

React Native custom Alert and Prompt

Spanish documentation

Installation

  1. Install library
npm i rn-custom-alert-prompt

or

yarn add rn-custom-alert-prompt

Configuration and personalization

  1. Import and use AlertContainer

Now, we need to import the AlertContainer component. Normally you would do this in your input file, such as App.js or App.tsx.

import {AlertContainer} from 'rn-custom-alert-prompt';

export const App = () => {
  return (
    <View>
      <AlertContainer />
      {/* Rest of your app code */}
    </View>
  );
};

Properties

You can send some optional properties in order to customize your alerts.

PropDescriptionTypeDefault
animationTypeChoose the animation with which your alert will appear.'none' \| 'fade' \| 'slide''none'
appearanceChoose between light and dark appearance for your alert.'light' \| 'dark'Device appearance
personalThemeCompletely customize how your alert will appear.PersonalThemePersonalTheme defaults
themeChoose the theme between iOS and Android for your alert.'ios' \| 'android'Auto detect OS

PersonalTheme Props

PropDescriptionTypeDefault iOSDefault Android
backgroundColorBackground color around your alert.rgba colorrgba(0,0,0,0.4)rgba(0,0,0,0.4)
backgroundInputColorBackground color of the text input in the prompt.stringLight: '#1C1C1E' \| Dark: '#FFFFFF'Light: 'transparent' \| Dark: 'transparent'
cardBackgroundColorAlert color.stringLight: '#EEEEEE' \| Dark: '#222222'Light: '#282F2C'\| Dark: '#FFFFFF'
descriptionColorColor of your alert description.stringLight: '#000000' \| Dark: '#FFFFFF'Light: '#000000'\| Dark: '#FFFFFF'
inputBorderColorBorder color for your prompt input.stringLight: '#C3C3C3' \| Dark: '#616161'Light: '#00D982'\| Dark: '#00D982'
inputColorColor of the text input in the prompt.stringLight: '#000000' \| Dark: '#FFFFFF'Light: '#000000' \| Dark: '#FFFFFF'
lineColorColor of the line border to separate buttons -iOS Only-.stringLight: '#C3C3C3' \| Dark: '#616161'N/A
placeholderColorColor of the placeholder in the prompt.stringLight: '#C3C3C3' \| Dark: '#666666'Light: '#C3C3C3' \| Dark: '#666666'
textButtonColorColor of the text on the buttons.stringLight: '#4F87FF' \| Dark: '#4F87FF'Light: '#00D982' \| Dark: '#00D982'
titleColorColor of your alert title.stringLight: '#000000' \| Dark: '#FFFFFF'Light: '#000000' \| Dark: '#FFFFFF'

Usage

  1. Use components

Alert component

This is the typical system alert with the big difference that we can customize it and it returns a promise with the user's response.

Basic usage

import {Text, TouchableOpacity, View} from  'react-native';
import {Alert} from  'rn-custom-alert-prompt';

const  MyComponent  = () => {

 const handlePress = () => {
   Alert.alert('Title', 'Description')
 }

 return (
   <View>
	  <TouchableOpacity onPress={handlePress} >
        <Text>Open Alert</Text>
      </TouchableOpacity>
   </View>
 )

Examples

iOS

Android

With props

import {Text, TouchableOpacity, View} from  'react-native';
import {Alert} from  'rn-custom-alert-prompt';

const  MyComponent  = () => {

 const handlePress = async () => {
   const response = await Alert.alert({
     title: 'Alert',
     description: 'Would you like to continue learning how to use React Native alerts?',
     showCancelButton: true,
   })

   console.log(response) // true or false
 }

 return (
   <View>
	  <TouchableOpacity onPress={handlePress} >
        <Text>Open Alert</Text>
      </TouchableOpacity>
   </View>
 )

Alert props

PropDescriptionTypeRequired
titleTitle for your alert.stringYes
buttonsPersonalized buttons for your alert.Button[]No
cancelColorTextCancel button text color.stringNo
cancelTextCancel button text.stringNo
confirmColorTextConfirm button text color.stringNo
confirmTextConfirm button text.stringNo
iconAlert icon.'error' \| 'info' \| 'success' \| 'question'No
iconColorIcon color.stringNo
showCancelButtonShows the cancel button.booleanNo

Button props

PropDescriptionTypeRequired
textButton text.stringYes
textStylePersonalized styles for your text button.StyleProp<TextStyle>No
onPressFunction that is executed when the button is pressed.functionNo

Examples

iOS

Android

With icon

Prompt

Prompt component

This is the system prompt that we can use in iOS, with the big difference that we can customize it and it returns a promise with the text entered by the user.

Basic usage

import {Text, TouchableOpacity, View} from  'react-native';
import {Alert} from  'rn-custom-alert-prompt';

const  MyComponent  = () => {

 const handlePress = () => {
   const response = await  Alert.prompt('Email', 'Please enter your email');

   console.log(response) // string | undefined
 }

 return (
   <View>
	  <TouchableOpacity onPress={handlePress} >
        <Text>Open Prompt</Text>
      </TouchableOpacity>
   </View>
 )

Examples

iOS

Android

With props

import {Text, TouchableOpacity, View} from  'react-native';
import {Alert} from  'rn-custom-alert-prompt';

const  MyComponent  = () => {

 const handlePress = async () => {
   const response = await Alert.prompt({
     title: 'Prompt',
     description: 'Enter your email to continue learning how to use React Native alerts!',
     label: 'Email',
     placeholder: 'example@example.com',
   })

   console.log(response) // string | undefined
 }

 return (
   <View>
	  <TouchableOpacity onPress={handlePress} >
        <Text>Open Prompt</Text>
      </TouchableOpacity>
   </View>
 )

Prompt props

PropDescriptionTypeRequired
titleTitle for your alert.stringYes
cancelColorTextCancel button text color.stringNo
cancelTextCancel button text.stringNo
confirmColorTextConfirm button text color.stringNo
confirmTextConfirm button text.stringNo
labelLabel for input -Android only-.stringNo
placeholderInput placeholder. default: title valuestringNo

Examples

iOS

Android

License

This project is licenced under the MIT License.

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.6

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.0

1 year ago