logo polydile dile-components

dile-confirm

Web Component to implement a modal confirm dialog, based on dile-modal web component.

Installation

npm i @dile/dile-confirm

Use

Import the component.

import '@dile/dile-confirm/dile-confirm';

After that you can use the dile-confirm tag, with a code like this:

<dile-confirm id="myModal">
  <p>
    Delete this file?
  </p>
</dile-confirm> 

Whatever you place inside the <dile-confirm> tag will be the content displayed when the modal box opens.

In addition, the confirm box display two buttons inside the modal interface:

Properties

Methods

Custom events

Style customization

These are the dile-confirm CSS custom properties.

Remember, as this component is based on <dile-modal>, you may also customize the modal box interface by using the CSS custom properties of the dile-modal component.

Custom propertyDescriptionDefault
--dile-confirm-accept-button-colorAccept button background color#007bff
--dile-confirm-cancel-button-colorCancel button background color#dc3545
--dile-confirm-accept-text-button-colorAccept button text color#fff
--dile-confirm-cancel-text-button-colorCancel button text color#fff
--dile-confirm-border-radius-buttonButton border radius5px
--dile-confirm-padding-buttonButton padding7px
--dile-confirm-font-size-buttonButton font size1em
--dile-confirm-font-weight-cancel-buttonCancel button font weightnormal
--dile-confirm-font-weight-accept-buttonAccept button font weightnormal
--dile-confirm-font-weight-buttonDefault button font weight (--dile-confirm-font-weight-cancel-button and --dile-confirm-font-weight-accept-button takes precedence)normal
--dile-confirm-buttons-text-alignButtons element text alignright
--dile-confirm-text-transformButton text transformationuppercase
--dile-confirm-buttons-margin-topConfirm buttons section margin-top10px
--dile-confirm-buttons-margin-bottomConfirm buttons section margin-bottom10px
--dile-confirm-buttons-margin-leftConfirm buttons section margin-left0
--dile-confirm-buttons-margin-rightConfirm buttons section margin-right0

dile-confirm demo

Regular confirm dialog

class MyComponent extends LitElement {
  static get styles() {
    return css`
      
    `
  }

  render() {
    return html`
      <dile-confirm id="confirm">
        <p>
          ¿Do yo want to cook a pizza?
        </p>
      </dile-confirm>
      <button id="open">Show confirm dialog</button>
    `
  }
  firstUpdated() {
    this.shadowRoot.getElementById('open').addEventListener('click', () => {
      this.shadowRoot.getElementById('confirm').open();
    });
  }
}
customElements.define('my-component', MyComponent);
export const JsStory = () => html`<my-component></my-component>`;

Styled confirm dialog

class StyledComponent extends LitElement {
  static get styles() {
    return css`
      dile-confirm {
        --dile-modal-border-radius: 2px;
        --dile-modal-content-background-color: #303030;
        --dile-modal-width: 400px;
        --dile-modal-min-width: 100px;
        --dile-modal-content-shadow-color: #000;
        --dile-modal-background-color: #f66;
        --dile-modal-content-padding: 0.5rem;
        --dile-confirm-buttons-text-align: center;
        --dile-confirm-accept-button-color: #ddd;
        --dile-confirm-cancel-button-color: #ddd;
        --dile-confirm-cancel-text-button-color: #007bff;
        --dile-confirm-accept-text-button-color: #dc3545;
        --dile-confirm-border-radius-button: 5px;
        --dile-confirm-font-size-button: 0.8em;
        --dile-confirm-padding-button: 3px 5px;
      }
      dile-confirm p {
        color: #f66;
        font-size: 0.9em;
        margin: 0 0 10px;
        text-transform: uppercase;
        text-align: center;
      }
      dile-confirm div {
        padding-bottom: 10px;
      }
    `
  }

  render() {
    return html`
      <dile-confirm id="confirm" acceptLabel="Yes, delete" cancelLabel="No, thanks">
        <p>
          ¿Do yo want to delete the selected files?
        </p>
      </dile-confirm>
      <button id="open">Show styled confirm dialog</button>
    `
  }
  firstUpdated() {
    this.shadowRoot.getElementById('open').addEventListener('click', () => {
      this.shadowRoot.getElementById('confirm').open();
    });
  }
}
customElements.define('styled-component', StyledComponent);
export const JsStory2 = () => html`<styled-component></styled-component>`;