1.7.1 • Published 3 years ago

@weareluastudio/lualert v1.7.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

SEE A DEMO HERE

Install

npm install --save @weareluastudio/lualert

Usage

import React from 'react'
import withAlerts from '@weareluastudio/lualert'

const App = () => {
  // ALERT
  const showAlert = () => window.Alert('Hello world')

  return <button onClick={showAlert}>Show</button>
}

// ALERT HOC
export default withAlerts()(App)

withAlerts() Props

You can define some properties for all alerts in your application, such as color, text, and effects. For example with the hoc:

IMPORTANT: you need only one withAlerts() in your project. As a recommendation put it in the App component.

// ALERT HOC
export default withAlerts()(App)
// ALERT HOC WITH GLOBAL PROPS
export default withAlerts({ ...props })(App)

With typescript you must define the component props type

// ALERT HOC WITH GLOBAL PROPS
export default withAlerts<PropsType>({ ...props })(Component)

All HOC props

NameTypeDescriptionDefaultOptional
confirmColorstringThe background color for "Accept" button.#2196f3true
confirmTextstringThe label for "Accept" button.Accepttrue
cancelTextstringThe label for "Cancel" button.Canceltrue
errColorstringThe background color for "Accept" button on alert with error type.#ff5252true
blurredboolean(Experimental) define the background effect on alerts.falsetrue

Alert props

You can define custom alerts with titles, texts, buttons and reactjs components within the alert, you can also define the interaction with the user. For example, this custom alert:

window.Alert({
  title: 'My alert title',
  body: 'My alert plain text',
  type: 'confirm'
})

Or with custom react elements:

window.Alert({
  title: 'My alert title',
  body: 'My alert plain text',
  type: 'confirm',
  customElements: <MyComponent>
})

Nested alerts

window.Alert({
  title: 'Test1',
  body: 'Test1',
  type: 'confirm',
  nested: 'Test2'
})
window.Alert({
  title: 'Test1',
  body: 'Test1',
  type: 'confirm',

  nested: {
    title: 'Test2',
    body: 'Test2',
    type: 'confirm',

    nested: {
      title: 'Test3',
      body: 'Test3',
      type: 'confirm'
    }
  }
})

All alert props

NameTypeDescriptionDefaultOptional
type'confirm' | 'window' | 'alert' | 'error'Define the alert style and interaction.'alert'false
titlestringTitle of the alert.''false
bodystringAlert content in text plain.''false
onConfirmmethodDispatch onConfirm method when Accept button is pressed.voidtrue
onHidemethodThis method its always called when the Alert is closed.voidtrue
onCancelmethodThis method its called when the cancel button is pressed.voidtrue
fixedbooleanIf you set true, the alert never close on some conditions.falsetrue
customElementsJSX.ElementWraps a custom elements or nested elements inside the alert body.nulltrue
confirmTextstringReplace the "Accept" label for the current instance."Accept"true
confirmBtnJSX.ELementReplace the whole "Accept" button for the current instance.nulltrue
cancelTextstringReplace the "Cancel" label for the current instance."Cancel"true
cancelBtnJSX.ElementReplace the whole "Cancel" button for the current instance.nulltrue
nestedAlertProps | stringShow an alert after the current hides.nulltrue
resetOnHidebooleanReset alert content on hide (doesn't work with nested option).falsetrue
maxWidthnumberSet the content box max width.nulltrue
marginsnumberSet the content box margins.nulltrue
zIndexnumberSet the content box z position.100true

Global API

LUAlert has a global api that is exposed to the window object, which allows controlling the life cycle of an alert.

NameParam typesDescriptionDefaultExample
window.Alert()string | AlertPropsDispatch a new alert in app.voidwindow.Alert('Hello')
window.hideAlert()NO PARAMSForce close the alert (not recommended)voidwindow.hideAlert()

License

MIT © weareluastudio

1.7.1

3 years ago

1.7.0

3 years ago

1.5.0

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.11

3 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago