0.1.0 • Published 4 years ago

react-native-confirm-dialog v0.1.0

Weekly downloads
25
License
ISC
Repository
github
Last release
4 years ago

React Native Confirm Dialog

Fully customizable, plug-and-play confirmation and alert dialogs for your react-native / expo app.


Features

  • Get going fast with basic styling and sensible defaults.
  • Action buttons with loading states.
  • Theme-able.
  • Dissmisable on outside clicks.

Usage

  • Wrap your application in <ConfirmProvider>
  • Use anywhere with useConfirm() hook

Demo

Try it out on Expo snack

Basic Demo

import React from 'react';
import { Button } from 'react-native'
import { ConfirmProvider, useConfirm } from 'react-native-confirm-dialog'

const ConfirmableButton = () => {
  const confirm = useConfirm()
  const handlePress = () => {
    confirm({
      // ...config options
    })
  }
  
  return <Button onPress={ handlePress } title='Confirm this!' />
}

export default function App() {

  return (
    <ConfirmProvider>
        <ConfirmableButton />
    </ConfirmProvider>
  );
}

Check out the example folder for a full example.

Download & Installation

$ yarn add react-native-confirm-dialog

Configuration Options

All of the configurations are optional with sensible defaults, and can be overriden when calling confirm or provided to ConfirmProvider as a config prop. Configuration options provided when calling confirm take precedence over options provided to ConfirmProvider

NameDescriptionTypeDefault
actionsOverride the dialog buttons with a custom component(dismiss: VoidFunction) => JSX.Element | JSX.Element[]undefined
bodyDescription of the confirmationStringundefined
bodyStyleStyle overrides for dialog bodyTextStyleundefined
ButtonComponentOverride the component used for the buttonsFunction ComponentEnhancedButton
buttonPropscustom props to pass to both buttonsanyundefined
buttonLabelStyleStyle overrides for both button labelsTextStyleundefined
buttonStyleStyle overrides for both buttonsViewStyleundefined
cancelLabelText of the secondary buttonString"Cancel"
cancelButtonPropscustom props to pass to secondary buttonanyundefined
cancelButtonLabelStyleStyle overrides for secondary button labelTextStyleundefined
cancelButtonStyleStyle overrides for secondary buttonViewStyleundefined
confirmButtonPropscustom props to pass to primary buttonanyundefined
confirmButtonLabelStyleStyle overrides for primary button labelTextStyleundefined
confirmButtonStyleStyle overrides for primary buttonViewStyleundefined
confirmLabelText of the primary buttonString"OK"
dismissOnOutsideClickShould the dialog be dismissed on an outside click?Booleantrue
onConfirmCallback action for primary buttonVoidFunction() => {}
showCancelSet to default to hide the secondary buttonBooleantrue
subtitleDimmed text right below the titleStringundefined
subtitleStyleStyle overrides for subtitleTextStyleundefined
themeTheme overridesObjectsee Theme section
titleThe title displayed in the confirm dialogString"Are you sure?"
titleStyleStyle overrides for titleTextStyleundefined

Theme

Control dialog look with a theme. Theme can be passed the same way as all the props above.

NameDescriptionTypeDefault
spacingSpacing between elements base unitnumber8
primaryColorColor of primary elementsstring"rgba(0, 0, 255, 0.5)"
backshadowColorColor of dialog's backdropstring"rgba(0, 0, 0, 0.4)"

Contributing

Keep it simple. Keep it minimal. Add tests.

License

This project is licensed under the MIT License