1.0.9 • Published 5 months ago

material-dialogs v1.0.9

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

Material Dialogs

Javascript library for styled dialogs with Material Design without dependencies.

Install

Install with npm or yarn

npm i material-dialogs --save
yarn add material-dialogs

Import into your project

ES6

import {xAlert, xConfirm, xPrompt} from 'material-dialogs.js';

If you are working with a standard HTML page without a library, you can use the following:

<script type="module">
    import {xAlert} from "/node_modules/material-dialogs/material-dialogs.js";

    const button = document.querySelector('button');
    button.addEventListener('click', () => {
        xAlert({title: 'Alert', message: 'Are you sure?'});
    })
    //...
</script>

How to use

All functions return a promise, that is, you can perform an action conditionally on the user's action, See the examples below:

Alert

No action

xAlert({title: 'Alert', message: 'Are you sure?'});

With action when clicking the button

xAlert({title: 'Alert', message: 'Are you sure?', textConfirm: 'Yes', textCancel: 'No'}).then(() => {
    console.log('alert');
}).catch(() => {
    console.log('cancel');
});

Confirm

xConfirm({title: 'Confirm', message: 'Are you sure?', textConfirm: 'Yes', textCancel: 'No'}).then(() => {
    console.log('confirm');
}).catch(() => {
    console.log('cancel');
});

Prompt

xPrompt({title: 'Prompt', message: 'Enter your name', textConfirm: 'Save', textCancel: 'Cancel', value: 'Mark'}).then((value) => {
    console.log(value);
}).catch(() => {
    console.log('cancel');
});

Custom

const formDemo = `<form>
                    <div class="xmodal-input">
                        <label for="name">Name</label><br>
                        <input type="text" class="xmodal-input" name="name"><br>
                    </div> 
                    <div class="xmodal-input">
                        <label for="email">Email</label><br>
                        <input type="email" class="xmodal-input" name="email"><br>
                    </div>
                    <div class="xmodal-buttons">
                        <button type="submit" class="xmodal-button">Submit</button>
                    </div>
                </form>`;
           xAlert({title: 'Personalized', message: formDemo, textConfirm: null}).then(() => {
               console.log('alert');
           }).catch(() => {
               console.log('cancel');
           });
        });

For more details, see the example file demo\index.html

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago