Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Add code samples for alert widget and add information about modalClass option #4731

Merged
merged 4 commits into from
Jun 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added common/images/widget/alert-widget-result.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions guides/v2.1/javascript-dev-guide/widgets/widget_alert.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The alert widget has the following options:
- [content]
- [focus]
- [title]
- [modalClass]

### `actions` {#alert_actions}
Widget callbacks.
Expand Down Expand Up @@ -105,14 +106,83 @@ The title of the alert window.

**Default value**: `''`

### `modalClass` {#alert_modalClass}
The CSS class of the alert window.

**Type**: String.

**Default value**: `'confirm'`

## Events {#alert_events}

The alert widget implements a single event: the `always` callback.
The `always` callback is invoked when a modal window is closed.

## Keyboard navigation {#alert_key_navigation}

The keyboard navigation for the alert windows is similar to the [navigation of the modal widget].

## Code Sample

### Code sample of standalone initialization

```html
<div class="alert-modal-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci amet aut consequuntur culpa cum, distinctio earum harum, iste magnam nobis numquam pariatur tempora ullam vero vitae. Hic ipsam itaque velit.</p>
</div>

<script>
require([
'jquery',
'Magento_Ui/js/modal/alert'
], function ($, alert) {
'use strict';

alert({
title: 'Alert Title',
content: $('.alert-modal-content'),
modalClass: 'alert',
actions: {
always: function() {
// do something when the modal is closed
}
}
});
});
</script>
```

### Code sample of initialization on an element

```html
<div class="alert-modal-content">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Adipisci amet aut consequuntur culpa cum, distinctio earum harum, iste magnam nobis numquam pariatur tempora ullam vero vitae. Hic ipsam itaque velit.</p>
</div>

<script>
require([
'jquery',
'Magento_Ui/js/modal/alert'
], function ($) {
'use strict';

$('.alert-modal-content').alert({
title: 'Alert Title',
modalClass: 'alert',
actions: {
always: function() {
// do something when the modal is closed
}
}
});
});
</script>
```

## Result

![Alert Widget]({{ site.baseurl }}/common/images/widget/alert-widget-result.png)

[Magento modal widget]: {{ page.baseurl }}/javascript-dev-guide/widgets/widget_modal.html
[`<Magento_Ui_module_dir>/view/base/web/js/modal/alert.js`]: {{ site.mage2bloburl }}/{{ page.guide_version }}/app/code/Magento/Ui/view/base/web/js/modal/alert.js
[Magento Admin Pattern Library, the Slide-out Panels, Modal Windows, and Overlays topic.]: {{ page.baseurl }}/pattern-library/containers/slideouts-modals-overlays/slideouts-modals-overalys.html#modals
Expand All @@ -123,4 +193,5 @@ The keyboard navigation for the alert windows is similar to the [navigation of t
[content]: #alert_content
[focus]: #alert_focus
[title]: #alert_title
[modalClass]: #alert_modalClass
[navigation of the modal widget]: {{ page.baseurl }}/javascript-dev-guide/widgets/widget_modal.html#key_navigation