logo polydile dile-components

dile-spinner

Web component to implement the tipical "Ajax loading" spinner interface.

Installation

npm i @dile/dile-spinner

Usage

The simpler implementation. Useful to show a inline spinner element, localized in the place where you put the dile-spinner element.

Usage

Import the component.

import '@dile/dile-spinner/dile-spinner.js';

Use the component.

<dile-spinner active></dile-spinner>

Properties

Styling

Custom propertyDescriptionDefault
--dile-spinner-colorThe ajax loading color#888
--dile-spinner-dot-sizeThe size of the dots in the spinner animation6px
--dile-spinner-backgroundSpinner backgroundtransparent

dile-spinner demos

Default spinner

<dile-spinner active></dile-spinner>

Styled spinner

<style>
  .styled {
    --dile-spinner-color: #fff;
    --dile-spinner-dot-size: 8px;
    --dile-spinner-background: #c64;
  }
</style>
<dile-spinner class="styled" active></dile-spinner>

Interactive demo

class MyComponent extends LitElement {

  render() {
    return html`
      <style>
      .green {
        --dile-spinner-color: #3a6;
      }
      </style>
      <p>
        <button id="start">Start spinner</button>
        <button id="stop">Stop Spinner</button>
      </p>
      <dile-spinner class="green"></dile-spinner>
    `
  }
  firstUpdated() {
    let spinner = this.shadowRoot.querySelector('dile-spinner');
    this.shadowRoot.getElementById('start').addEventListener('click', (e) => {
      spinner.active = true;
    });
    this.shadowRoot.getElementById('stop').addEventListener('click', (e) => {
      spinner.active = false;
    });
  }
}
customElements.define('my-component', MyComponent);
export const JsStory = () => html`<my-component></my-component>`;