All Projects → Nodlik → react-st-modal

Nodlik / react-st-modal

Licence: MIT license
Simple and flexible modal dialog component for React JS

Programming Languages

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

Projects that are alternatives of or similar to react-st-modal

Alertifyjs
A javascript framework for developing pretty browser dialogs and notifications.
Stars: ✭ 1,922 (+4587.8%)
Mutual labels:  alert, modal, dialog, prompt, confirm, modal-dialogs
jquery.dialog.js
A lightweight replacement for the browser's default dialog boxes.
Stars: ✭ 17 (-58.54%)
Mutual labels:  alert, modal, dialog, prompt, confirm
React Native Alert Pro
The Pro Version of React Native Alert (Android & iOS)
Stars: ✭ 69 (+68.29%)
Mutual labels:  alert, modal, dialog, confirm
Razor.SweetAlert2
A Razor class library for interacting with SweetAlert2
Stars: ✭ 98 (+139.02%)
Mutual labels:  alert, dialog, prompt, confirm
Smalltalk
Promise-based Alert, Confirm and Prompt replacement
Stars: ✭ 76 (+85.37%)
Mutual labels:  alert, modal, prompt, confirm
mobile-message
基于移动端的弹窗组件,默认提供info、success、warning、error、alert、confirm、multiple、vertical、bottomSheet、prompt,可自定义弹窗。它可以包含任何Html内容可以自定义弹窗的样式,也可以加入自定以的弹窗动画。
Stars: ✭ 13 (-68.29%)
Mutual labels:  alert, dialog, prompt, confirm
Sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
Stars: ✭ 13,929 (+33873.17%)
Mutual labels:  alert, dialog, prompt, confirm
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+2951.22%)
Mutual labels:  alert, modal, dialog, confirm
Vuejs Dialog
A lightweight, promise based alert, prompt and confirm dialog
Stars: ✭ 327 (+697.56%)
Mutual labels:  alert, dialog, prompt, confirm
Ng Popups
🎉 Alert, confirm and prompt dialogs for Angular. Simple as that.
Stars: ✭ 80 (+95.12%)
Mutual labels:  alert, modal, dialog, prompt
Wc Messagebox
基于 Vue 2.0 开发的 Alert, Toast, Confirm 插件, UI仿照 iOS 原生
Stars: ✭ 203 (+395.12%)
Mutual labels:  alert, modal, dialog, confirm
Sweetalert
A beautiful replacement for JavaScript's "alert"
Stars: ✭ 21,871 (+53243.9%)
Mutual labels:  alert, modal, dialog
Notie
🔔 a clean and simple notification, input, and selection suite for javascript, with no dependencies
Stars: ✭ 6,170 (+14948.78%)
Mutual labels:  alert, prompt, confirm
Layer
丰富多样的 Web 弹出层组件,可轻松实现 Alert/Confirm/Prompt/ 普通提示/页面区块/iframe/tips等等几乎所有的弹出交互。目前已成为最多人使用的弹层解决方案
Stars: ✭ 8,202 (+19904.88%)
Mutual labels:  alert, dialog, confirm
Ngx Sweetalert2
Declarative, reactive, and template-driven SweetAlert2 integration for Angular
Stars: ✭ 503 (+1126.83%)
Mutual labels:  alert, modal, dialog
Jquery Confirm
A multipurpose plugin for alert, confirm & dialog, with extended features.
Stars: ✭ 1,776 (+4231.71%)
Mutual labels:  alert, dialog, confirm
Nativepopup
Clone of Apple iOS App's feedback popup, and easily customizable.
Stars: ✭ 247 (+502.44%)
Mutual labels:  alert, modal, dialog
Popupdialog
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.
Stars: ✭ 3,709 (+8946.34%)
Mutual labels:  alert, modal, dialog
Customalertviewdialogue
Custom AlertView Dialogue is the world's most advanced alert view library. Custom AlertView Dialogue includes simple message popups, confirmation alerts, selector popups, action sheet bottom menus, and input/feedback contact forms.
Stars: ✭ 100 (+143.9%)
Mutual labels:  alert, modal, dialog
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 (+324.39%)
Mutual labels:  alert, modal, dialog

GitHub license npm npm


react-st-modal


React St Modal is a simple and flexible library for implementing modal dialogs.

Features

  • Simple and easy to use api
  • Compatible with mobile devices
  • Implemented standard interaction functions: alert, confirm, prompt
  • Async/await syntax
  • Customization via css variables
  • Accessibility and focus control
  • Dynamic call of modal dialogs, which does not require definition in code
  • No third party libraries

DEMO AND DOCS: https://nodlik.github.io/react-st-modal/


Getting started

Installation

You can install the latest version using npm:

  npm install react-st-modal

Overview

To implement the functionality of modal dialogs this library has four functions and one react component.

Functions Alert, Confirm, Prompt implement the behavior of existing browser functions.

Function CustomDialog shows any JSX element in a modal window.

React component StaticDialog is used to define modals in your JSX element.

Interaction: (Alert, Prompt, Confirm)

All interaction functions are async.

Method name Parameters Return type Description
Alert body: JSX.Element (string), title?: string, buttonText?: string void Shows a message (body) and waits for the user to press button
Confirm body: JSX.Element (string), title?: string, okButtonText?: string, cancelButtonText?: string boolean Shows a modal window with a text (body) and two buttons: OK and Cancel. The result is true if OK is pressed and false otherwise
Prompt title?: string, options?: PromptConfig string Shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel

PromptConfig allows you to specify the following optional parameters:

  • defaultValue: string | number
  • isRequired: boolean
  • errorText: string
  • okButtonText: string
  • cancelButtonText: string

Example

import { Confirm } from 'react-st-modal';

function ConfirmExample() {
  return (
    <div>
      <button
        onClick={async () => {
          const result = await Confirm('Сonfirmation text', 
            'Сonfirmation title');
          
          if (result) {
            // Сonfirmation confirmed
          } else {
            // Сonfirmation not confirmed
          }
        }}
      >
          Show confirm
      </button>
    </div>
  );
}

CustomDialog

CustomDialog is an async function that shows any element in a modal window.

Parameters

  • body: JSX.Element - the element shown in the modal dialog
  • options?: CustomConfig - specified options

CustomConfig allows you to specify the following optional parameters:

  • title?: string - modal dialog title
  • className?: string - css className
  • defaultBodyOverflow?: string (default: visible) - default value to body css property overflow
  • showCloseIcon?: boolean (default: false) - show close button in the top corner of the window
  • isCanClose?: boolean (default: true) - is it possible to close the dialog by clicking on the overlay or ESC button
  • isFocusLock?: boolean (default: true) - lock focus on modal
  • isBodyScrollLocked?: boolean (default: true) - content scrolling lock
  • replaceScrollBar?: boolean (default: true) - whether to replace the body scrollbar with a placeholder
  • scrollBarPlaceholderColor?: string (default: #eeeeee) - default color for the scrollbar placeholder
  • onAfterOpen?: () => void - event called after the dialog was opened

To control a dialog from an inner element, use useDialog<T> hook

useDialog<T> returns an object containing:

  • isOpen: boolean - the current state of the modal
  • close: (result?: T) => void - function that closes the dialog and returns the result

Example

import { CustomDialog, useDialog } from 'react-st-modal';

// The element to be shown in the modal window
function CustomDialogContent() {
  // use this hook to control the dialog
  const dialog = useDialog();

  const [value, setValue] = useState();

  return (
    <div>
      <input
        type="text"
        onChange={(e) => {
          setValue(e.target.value);
        }}
      />
      <button
        onClick={() => {
          // Сlose the dialog and return the value
          dialog.close(value);
        }}
      >
        Custom button
      </button>
    </div>
  );
}

function CustomExample() {
  return (
    <div>
      <button
        onClick={async () => {
          const result = await CustomDialog(
            <CustomDialogContent />,
            {
              title: 'Custom Dialog',
              showCloseIcon: true,
            }
          );
        }}
      >
        Custom
      </button>
    </div>
  );
}

StaticDialog

StaticDialog it is a React component that used to define modals in your JSX element

Props

  • isOpen: boolean - describing if the modal should be shown or not
  • children: React.ReactNode - the element shown in the modal dialog
  • title?: string - modal dialog title
  • className?: string - css className
  • defaultBodyOverflow?: string (default: visible) - default value to body css property overflow
  • showCloseIcon?: boolean (default: false) - show close button in the top corner of the window
  • isCanClose?: boolean (default: true) - is it possible to close the dialog by clicking on the overlay or ESC button
  • isFocusLock?: boolean (default: true) - lock focus on modal
  • isBodyScrollLocked?: boolean (default: true) - content scrolling lock
  • replaceScrollBar?: boolean (default: true) - whether to replace the body scrollbar with a placeholder
  • scrollBarPlaceholderColor?: string (default: #eeeeee) - default color for the scrollbar placeholder
  • onAfterClose?: (result?: T) => void - event called after the dialog was closed
  • onAfterOpen?: () => void - event called after the dialog was opened

Example

import { StaticDialog, useDialog } from 'react-st-modal';

function CustomStaticExample() {
  const [isOpen, setOpen] = useState(false);

  return (
    <div>
      <StaticDialog
        isOpen={isOpen}
        title="Custom static dialog"
        onAfterClose={(result) => {
          setOpen(false);
          // do something with dialog result
        }}
    >
        {/* see previous demo */}
          <CustomDialogContent />
      </StaticDialog>

      <div>
        <button
          onClick={() => {
              setOpen(true);
          }}
        >
          Custom static
        </button>
      <div>
    </div>
    );
}

UI Elements

To decorate your dialogs, you can use the following components: ModalButton, ModalContent, ModalFooter

Example

import { ModalContent, ModalFooter, ModalButton, useDialog } from 'react-st-modal';

function CustomDialogContent() {
  const dialog = useDialog();

  const [value, setValue] = useState<string>();

  return (
      <div>
        <ModalContent>
          <div>Custom dialog content</div>
          <label>
            Input value:
            <input
              type="text"
              onChange={(e) => {
                setValue(e.target.value);
              }}
            />
          </label>
        </ModalContent>
        <ModalFooter>
          <ModalButton
            onClick={() => {
              dialog.close(value);
            }}
          >
            Custom button
          </ModalButton>
        </ModalFooter>
      </div>
  );
}

Contacts

Oleg,

[email protected]

Buy me a coffee

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].