Web ComponentThe latest version of this package is: 0.6.9, Opens in new window

Webcomponent for Dialog

This component is compatible with ESM (ES6 module) and IIFE. See documentation examples below.

To be able to install this component, please refer to the Project Setup documentation.

$ npm i @ids-wc/dialog@0.6.9

Table of Contents

Usage

Markup

<ids-dialog data-title="Title" data-cancel-text="Cancel" data-confirm-text="OK">
  <p class="if">Do you want to proceed?</p>
</ids-dialog>
<script src="…dialog-webcomponent.iife.js"></script>

Or:

<ids-dialog
  data-title="Title"
  data-cancel-text="Cancel"
  data-confirm-text="OK"
  data-text="Do you want to proceed?"
  data-id="dialog-test"
  data-is-open="true"
  data-description="A confirmation dialog"
>
</ids-dialog>
<script src="…dialog-webcomponent.iife.js"></script>

Open on init

If you want the dialog to open on init without an external indicator, you can pass the data-is-open="true" attribute. This will open up the dialog on init.

Properties

Property Type Description Required
data-text String Use this attribute if you only want to use text No
data-title String Dialog title Yes
data-cancel-text String Cancel text Yes
data-confirm-text String Confirm text Yes
data-id String The id of the dialog Yes
data-is-open String/Boolean Should this dialog open on render? No
data-description String If you want to use aria-describedby, add description here No

Events

The webcomponent also listenes to a CustomEvent for toggling of the dialog.

Toggle

This event is ment to be fired of the initiator element for the dialog. It is implemented by the developer to be able to display the dialog.

See implementation example below.

The data-id attribute on the webcomponent needs to be set for this.

<button type="button" class="if primary button" id="open">Open dialog</button>
<ids-dialog
  data-title="Title"
  data-id="dialog-test"
  data-cancel-text="Cancel"
  data-confirm-text="OK"
>
  <p class="if text body">Do you want to proceed?</p>
</ids-dialog>
<script>
  const _dispatchEvent = (id) => {
    const _event = new CustomEvent(`ids:send:dialog:toggle:${id}`, {
      bubbles: !0,
      detail: {
        source: 'IDS_DIALOG',
        type: 'DIALOG_TOGGLE',
        payload: {
          id: id,
        },
      },
    });
    document.dispatchEvent(_event);
  };

  document.getElementById('open').addEventListener('click', (e) => {
    _dispatchEvent('dialog-test');
  });
</script>

And the Dialog Webcomponent will listen to this event:

document.addEventListener(`ids:send:dialog:toggle:${_id}`, (e) => {
  this.externalInitiatorEl = e.target;
  this.toggle();
});

Open/Close

document.addEventListener(`ids:send:dialog:${_id}`, (e) => {
  console.log(e);
});
Event Type Description
ids:send:dialog:<id> CustomEvent Event fired on open and close
ids:send:dialog:cancelled:<id> CustomEvent Event fired on cancel
ids:send:dialog:confirmed:<id> CustomEvent Event fired on confirm

The payload of the event looks something like this:

// For opened event
detail: { source: "IDS_DIALOG", type: "DIALOG_OPENED", payload: { id: "<id>" } }
// For closed event
detail: { source: "IDS_DIALOG", type: "DIALOG_CLOSED", payload: { id: "<id>" } }
// Cancelled
detail: { source: "IDS_DIALOG", type: "DIALOG_CANCELLED", payload: { id: "<id>" } }
// Confirmed
detail: { source: "IDS_DIALOG", type: "DIALOG_CONFIRMED", payload: { id: "<id>" } }

Changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.3.7 (2022-03-09)

Miscellaneous chores

0.3.6 (2022-03-09)

Miscellaneous chores

0.3.5 (2022-03-08)

Miscellaneous chores

0.3.4 (2021-11-10)

Miscellaneous chores

  • Manually testing inclusion of CHANGELOG.md (f91eb76)

0.3.0 (2021-11-10)

Miscellaneous chores

0.2.3 (2021-10-28)

Miscellaneous chores

  • reinstall (0f764a7)

  • update after change of navigational structure (e8962a1)

0.2.1 (2021-10-14)

Miscellaneous chores

  • 🤖 Update dependencies (079ff16)

0.2.0 (2021-10-14)

Documentation Updates

Contact us, Opens in new window