An open API service indexing awesome lists of open source software.

https://github.com/crystallizeapi/react-dialog

React component to display accessible dialogs
https://github.com/crystallizeapi/react-dialog

Last synced: about 1 month ago
JSON representation

React component to display accessible dialogs

Awesome Lists containing this project

README

        

![alt text](https://raw.githubusercontent.com/CrystallizeAPI/react-dialog/HEAD/media/logo.png "Speech bubble")

# @crystallize/react-dialog

React component to display accessible dialogs. This is a [general purpose component to build awesome and accessible dialogs in react](https://crystallize.com/developers/react-components/react-dialog). Built initially for use in the [Crystallize headless commerce service](https://crystallize.com).

Uses [styled-components](https://npmjs.org/package/styled-components) and [a11y-dialog](https://www.npmjs.com/package/a11y-dialog). Leverages the [native dialog HTML element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog) when possible

This module uses **Promises** and does *not* provide a polyfill. To easily
provide Promise polyfills for your users, try [polyfills.io](https://polyfill.io/v2/docs/)

## Demo
[Demo](https://react-dialog.milliseconds.io)

![alt text](https://raw.githubusercontent.com/CrystallizeAPI/react-dialog/HEAD/media/react-dialog.gif "React dialog in action")

## Usage

```
yarn add @crystallize/react-dialog styled-components
```

### In your app root

```
import { Wrapper } from '@crystallize/react-dialog';

export default () => (




);
```

### Use it

```
import { showDialog, showAlert, showConfirm, closeCurrent } from '@crystallize/react-dialog';

await showDialog('Hey dude');
await showDialog({
body: Hey dude
});

await showAlert('Wow');
const confirmResult = await showConfirm('Are you sure?');

const confirmResult = await showConfirm({
body:

JSX rules
,
buttons: {
ok: p => Allrighty,
cancel: p => Nope
}
});

// Closes any open dialog
closeCurrent();
```

## Wrapper props
| Prop Name | Default | Type | Description |
| ------------ | ------- | ---- | ------------------------------------------ |
| cleanTheme | false | bool | Use the clean theme instead of the default |
| ButtonOk | false | jsx | Set a custom default Ok button |
| ButtonCancel | false | jsx | Set a custom default Cancel button |
| ButtonClose | false | jsx | Set a custom default Close button |
| Heading | false | jsx | Set a custom default Heading |

## Dialog functions
All of the show dialog functions (showDialog, showAlert, showConfirm) returns a promise when called. The promise is resolved when the dialog is closed. The return value of the
promise changes depending on which type of dialog it is

The functions accepts a single string argument. They also support a single object as argument with these common properties:

```
{
title:

Hi there


body: 'you',
showCloseButton: false (default is true),
disableBackdropClick: false
}
```

showConfirm does however accept a few more:
```
...
buttons: {
ok: props => {props.children},
cancel: "Nope nope!"
}
```
showConfirm resolves its promise with either "ok" or "cancel"