5.1.2 • Published 2 years ago

@crystallize/react-dialog v5.1.2

Weekly downloads
65
License
MIT
Repository
github
Last release
2 years ago

alt text

@crystallize/react-dialog

React component to display accessible dialogs. This is a general purpose component to build awesome and accessible dialogs in react. Built initially for use in the Crystallize headless commerce service.

Uses styled-components and a11y-dialog. Leverages the native dialog HTML element when possible

This module uses Promises and does not provide a polyfill. To easily provide Promise polyfills for your users, try polyfills.io

Demo

Demo

alt text

Usage

yarn add @crystallize/react-dialog styled-components

In your app root

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

export default () => (
  <main>
    <YourApp />
  </main>
  <Wrapper />
);

Use it

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

await showDialog('Hey dude');
await showDialog({
  body: <strong>Hey dude</strong>
});

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

const confirmResult = await showConfirm({
  body: <div>JSX rules</div>,
  buttons: {
    ok: p => <button {...p}>Allrighty</button>,
    cancel: p => <button {...p}>Nope</button>
  }
});

// Closes any open dialog
closeCurrent();

Wrapper props

Prop NameDefaultTypeDescription
cleanThemefalseboolUse the clean theme instead of the default
ButtonOkfalsejsxSet a custom default Ok button
ButtonCancelfalsejsxSet a custom default Cancel button
ButtonClosefalsejsxSet a custom default Close button
HeadingfalsejsxSet 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<string|jsx>: <h1>Hi there</h1>
  body<string|jsx>: 'you',
  showCloseButton<bool>: false (default is true),
  disableBackdropClick<bool>: false
}

showConfirm does however accept a few more:

...
buttons: {
  ok: props => <button {...props}>{props.children}</button>,
  cancel: "Nope nope!"
}

showConfirm resolves its promise with either "ok" or "cancel"

5.1.2

2 years ago

5.1.1

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

1.0.0-beta.1

3 years ago

5.0.0-beta.0

4 years ago

5.0.0-beta.1

4 years ago

4.4.0

5 years ago

4.3.0

5 years ago

4.2.7

5 years ago

4.2.6

5 years ago

4.2.5

5 years ago

4.2.4

5 years ago

4.2.3

5 years ago

4.2.2

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.1

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago