Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rn-custom-alert-prompt

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rn-custom-alert-prompt

ReactNative Alert & Prompt with no dependencies

  • 1.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
23
decreased by-14.81%
Maintainers
0
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 11 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc