All Projects → djorg83 → React Bootstrap Sweetalert

djorg83 / React Bootstrap Sweetalert

Licence: mit
A React implementation of SweetAlert

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to React Bootstrap Sweetalert

React Native Alert Pro
The Pro Version of React Native Alert (Android & iOS)
Stars: ✭ 69 (-69.87%)
Mutual labels:  alert, confirm
Laravel Alert
A Bootstrap alert helper for Laravel
Stars: ✭ 110 (-51.97%)
Mutual labels:  alert, bootstrap
Smalltalk
Promise-based Alert, Confirm and Prompt replacement
Stars: ✭ 76 (-66.81%)
Mutual labels:  alert, confirm
Ng Bootstrap
Angular powered Bootstrap
Stars: ✭ 7,872 (+3337.55%)
Mutual labels:  alert, bootstrap
Notiflix
Notiflix is a JavaScript library for client-side non-blocking notifications, popup boxes, loading indicators, and more that makes your web projects much better.
Stars: ✭ 172 (-24.89%)
Mutual labels:  alert, confirm
Messg
Messages via CSS3 animations
Stars: ✭ 56 (-75.55%)
Mutual labels:  alert, confirm
Vue Simple Alert
Simple alert(), confirm(), prompt() for Vue.js
Stars: ✭ 93 (-59.39%)
Mutual labels:  alert, confirm
mobile-message
基于移动端的弹窗组件,默认提供info、success、warning、error、alert、confirm、multiple、vertical、bottomSheet、prompt,可自定义弹窗。它可以包含任何Html内容可以自定义弹窗的样式,也可以加入自定以的弹窗动画。
Stars: ✭ 13 (-94.32%)
Mutual labels:  alert, confirm
Alertifyjs
A javascript framework for developing pretty browser dialogs and notifications.
Stars: ✭ 1,922 (+739.3%)
Mutual labels:  alert, confirm
Jquery Confirm
A multipurpose plugin for alert, confirm & dialog, with extended features.
Stars: ✭ 1,776 (+675.55%)
Mutual labels:  alert, confirm
Notie
🔔 a clean and simple notification, input, and selection suite for javascript, with no dependencies
Stars: ✭ 6,170 (+2594.32%)
Mutual labels:  alert, confirm
Sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
Stars: ✭ 13,929 (+5982.53%)
Mutual labels:  alert, confirm
Vuejs Dialog
A lightweight, promise based alert, prompt and confirm dialog
Stars: ✭ 327 (+42.79%)
Mutual labels:  alert, confirm
Layer
丰富多样的 Web 弹出层组件,可轻松实现 Alert/Confirm/Prompt/ 普通提示/页面区块/iframe/tips等等几乎所有的弹出交互。目前已成为最多人使用的弹层解决方案
Stars: ✭ 8,202 (+3481.66%)
Mutual labels:  alert, confirm
Razor.SweetAlert2
A Razor class library for interacting with SweetAlert2
Stars: ✭ 98 (-57.21%)
Mutual labels:  alert, confirm
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+446.29%)
Mutual labels:  alert, confirm
jquery.dialog.js
A lightweight replacement for the browser's default dialog boxes.
Stars: ✭ 17 (-92.58%)
Mutual labels:  alert, confirm
PopOverAlert
PopOverAlert is a PopOver style alert view.
Stars: ✭ 56 (-75.55%)
Mutual labels:  alert, confirm
Hibiscus.js
Native Angular directives for Bootstrap4
Stars: ✭ 115 (-49.78%)
Mutual labels:  alert, bootstrap
Bdialog
Extend the Bootstrap Modal features, making dialog more functions and easier to use, dialog type including modal, alert, mask and toast types
Stars: ✭ 174 (-24.02%)
Mutual labels:  alert, bootstrap

react-bootstrap-sweetalert

NPM version Downloads David GitHub issues license GitHub stars

openbase Openbase Dashboard

NPM

SweetAlert for React/Bootstrap

An awesome replacement for JavaScript's alert.


Support

If you think I've done a good job, consider showing your support by buying me a beer. Cheers! 🍻

Buy me a beer


Demo & Examples

See the demo with examples of common use cases and a live editor.

👽 TAKE ME TO YOUR DEMO 👽

Demo GIF

Getting Started

Installation

$ npm i react-bootstrap-sweetalert

or

$ yarn add react-bootstrap-sweetalert

Import

const SweetAlert = require('react-bootstrap-sweetalert');

or

import SweetAlert from 'react-bootstrap-sweetalert';

Recommended Usage

It is recommended that you keep an alert in your state, and remove it when the onConfirm or onCancel callbacks are invoked.

You can have stackable alerts by keeping an array of alerts in your data store, and always providing the first alert in the array as the visible alert. When an alert is closed, remove it from the store.

See examples/redux for a working example of how to implement stackable alerts with a Redux store.


Tip: Receiving an input value

If you're using input type, the value of the input will be sent to the onConfirm callback as the first argument.

onConfirm={(response) => this.onRecieveInput(response)}

Custom Forms / Using Render Props

If you want to build an alert that re-renders based on external state changes, or simply want to build a custom form, then you will find the render props pattern to be your best option.

  • For re-rendering based on external state changes, use props.dependencies
  • See the SweetAlertRenderProps interface in types.ts for some information on the available render props.
<SweetAlert
 title={"Uses render props"}
 onConfirm={this.onConfirm}
 onCancel={this.onCancel}
 dependencies={[this.state.firstName, this.state.lastName]}
>
  {(renderProps: SweetAlertRenderProps) => (
    <form>
      Your name is: {this.state.firstName} {this.state.lastName}
      <hr/>
      <input
        type={'text'}
        ref={renderProps.setAutoFocusInputRef}
        className="form-control"
        value={this.state.firstName}
        onKeyDown={renderProps.onEnterKeyDownConfirm}
        onChange={(e) => this.setState({ firstName: e.target.value })}
        placeholder={'First name'}
      />
      <br />
      <input
        type={'text'}
        className="form-control"
        value={this.state.lastName}
        onKeyDown={renderProps.onEnterKeyDownConfirm}
        onChange={(e) => this.setState({ lastName: e.target.value })}
        placeholder={'Last name'}
      />
      <hr/>
    </form>
  )}
</SweetAlert>

Changes in version 5.2

  • Added props.dependencies that re-renders the alert whenever the provided Array of dependencies value changes.
  • Added new supported value of 'controlled' for props.type. If props.type === 'controlled' then props.onConfirm will return props.dependencies.
  • Added support for using a function as your alert content/children, aka render props.

For more see CHANGE_LOG.md

Props

Buttons
Input
Hooks
Styling
Animations

props.title

The text to display for the title. JSX/ReactNode allowed.

  • Type: ReactNode|string
  • Default: undefined

props.onConfirm

Invoked when user clicks confirm button. Also invoked if user hits ENTER key.

  • Type: (response?: any) => any
  • Default: undefined

props.onCancel

Invoked when user clicks cancel button. Also invoked if allowEscape is true and user hits ESCAPE key.

  • Type: () => any
  • Default: undefined

props.type

The type of alert to display.

  • Type: 'default'|'info'|'success'|'warning'|'danger'|'error'|'input'|'custom'|'controlled'
  • Default: 'default'

NOTE

  • If props.type === 'controlled' then props.onConfirm will receive props.dependencies as its first argument.
  • If props.type === 'input' then props.onConfirm will receive props.dependencies as its first argument.

props.btnSize

The type of alert to display.

  • Type: 'lg'|'sm'|'xs'
  • Default: 'lg'
  • Allowed values: 'lg', 'sm', 'xs'

props.confirmBtnText

Content of confirm button, or JSX/ReactNode.

  • Type: ReactNode|string
  • Default: 'OK'

props.confirmBtnBsStyle

Bootstrap style of confirm button.

  • Type: 'default'|'primary'|'link'|'info'|'success'|'warning'|'danger'|'secondary'|'outline-{variant}'
  • Default: 'primary'

props.confirmBtnCssClass

CSS class added to confirm button.

  • Type: string
  • Default: ''

props.confirmBtnStyle

Inline style added to confirm button.

  • Type: CSSProperties
  • Default: {}

props.cancelBtnText

Content of cancel button, or JSX/ReactNode.

  • Type: ReactNode|string
  • Default: 'Cancel'

props.cancelBtnBsStyle

Text of cancel button, or JSX/ReactNode.

  • Type: string
  • Default: 'link'
  • Recommended values: 'default'|'primary'|'link'|'info'|'success'|'warning'|'danger'|'secondary'|'outline-{variant}'

props.cancelBtnCssClass

CSS class added to cancel button.

  • Type: string
  • Default: ''

props.cancelBtnStyle

Inline style added to cancel button.

  • Type: CSSProperties
  • Default: {}

props.showCloseButton

If set to true, then an X close button will be shown in the top right of the alert.

NOTE: You must also implement props.onCancel in order for this props to work. This is because visibility of the component is controlled externally through either props.show or by removing the <SweetAlert /> in your render method.

  • Type: boolean
  • Default: false

props.reverseButtons

Reverses the order of the Confirm and Cancel buttons. Default positioning is [Cancel] [Confirm]

  • Type: boolean
  • Default: false

props.customButtons

Custom buttons to use in place of the default Confirm and Cancel buttons. Can render any JSX/ReactNodes here.

  • Type: ReactNode
  • Default: undefined

props.customIcon

Either a string url for an image to use as the icon, or JSX/ReactNode.

  • Type: ReactNode|string
  • Default: undefined

props.placeholder

If props.type is 'input', this is the placeholder for the input field.

  • Type: string
  • Default: undefined

props.show

If false, the alert will not be rendered. Warning: Using this option should be a last resort, and is somewhat of an anti-pattern for this library. The recommended way to control visibility is to only render a <SweetAlert/> element when you want one to be displayed, and remove it when the onConfirm or onCancel methods are called.

  • Type: boolean
  • Default: true

props.dependencies

If you have external state that should trigger your alert to re-render it's content, you can provide an Array of dependencies. Whenever the dependencies are changed, using === comparision, the content of the alert will be re-rendered.

  • Type: any[]
  • Default: true

Example

const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');

<SweetAlert dependencies={[firstName, lastName]}>
  <div>
    <h4>Hello {{firstName}} {{lastName}}</h4>
    <input value={firstName} onChange={(e) => setFirstName(e.target.value)} />
    <input value={lastName} onChange={(e) => setLastName(e.target.value)} />
  </div>
</SweetAlert>

props.focusConfirmBtn

If true the Confirm button will receive focus automatically. NOTE: Does not apply when props.type is 'input'

  • Type: boolean
  • Default: true

props.focusCancelBtn

If true the Cancel button will receive focus automatically. NOTE: Does not apply when props.type is 'input'

  • Type: boolean
  • Default: false

props.required

If props.type is 'input', this prop controls whether the input field is required to have a value.

  • Type: boolean
  • Default: true

props.validationMsg

If props.type is 'input' and props.required is true, this is the message to display when the user clicks confirm without entering a value.

  • Type: string
  • Default: 'Please enter a response!'

props.validationRegex

If props.type is 'input' and props.required is true, this Regex is used to validate input value.

  • Type: RegExp
  • Default: /^.+$/

props.defaultValue

If props.type is 'input', this is the default value for the input field.

  • Type: number|string
  • Default: undefined

props.inputType

If props.type is 'input', this is the default value for the input field.

  • Type: string
  • Default: 'text'
  • Recommended values: 'text'|'password'|'number'|'textarea'

props.style

Style overrides applied to the sweetalert wrapper.

  • Type: CSSProperties
  • Default: {}

props.closeBtnStyle

Style overrides applied to the X close button.

  • Type: CSSProperties
  • Default: {}

props.customClass

Custom CSS class applied to the sweetalert wrapper.

  • Type: string
  • Default: ''

props.showConfirm

If true, the Confirm button will show.

  • Type: boolean
  • Default: true

props.showCancel

If true, the Cancel button will show.

  • Type: boolean
  • Default: false

props.allowEscape

If true, the onCancel function will be invoked when the user hits the ESCAPE key.

  • Type: boolean
  • Default: true

props.closeOnClickOutside

If true, the onCancel function will be invoked when clicking outside the modal.

  • Type: boolean
  • Default: true

props.hideOverlay

If true, then the modal overlay will not be rendered.

  • Type: boolean
  • Default: false

props.disabled

If true, then the Confirm button will be disabled. (NOTE: This does not effect the props.allowEscape behavior.) If you set disabled to true but do not provide an onCancel function, then the disabled property will not be honored.

  • Type: boolean
  • Default: false

props.beforeMount

Hook which is invoked at the end of the component constructor function.

  • Type: () => any
  • Default: () => {}

props.afterMount

Hook which is invoked at the end of the componentDidMount method.

  • Type: () => any
  • Default: () => {}

props.afterUpdate

Hook which is invoked at the end of the componentDidUpdate method.

  • Type: () => any
  • Default: () => {}

props.beforeUnmount

Hook which is invoked at the end of the componentWillUnmount method.

  • Type: () => any
  • Default: () => {}

props.timeout

If defined, and greater than 0, props.onConfirm will be invoked to close the alert automatically after the specified number of milliseconds.

  • Type: number
  • Default: 0

props.openAnim

Provide custom show animation or false to have no animation. To specify a custom animation, provide the name of your css animation and duration of the animation in milliseconds.

  • Type: boolean|SweetAlertAnimationProps
  • Default: { name: 'showSweetAlert', duration: 300 }

props.closeAnim

Provide custom hide animation or false to have no animation. To specify a custom animation, provide the name of your css animation and duration of the animation in milliseconds. For a simple hide animation you can use { name: 'hideSweetAlert', duration: 100 }

  • Type: boolean|SweetAlertAnimationProps
  • Default: false

Related projects

Development

$ yarn demo && open http://localhost:3000
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].