logo dile-components dile-components

dile-crud-list-lite

The dile-crud-list-lite component lists elements from a REST API resource, just like dile-crud-list, but without needing a big resource configuration object. Everything is configured through simple props: the endpoint, which properties of each item to use as label/link/icon, and which action buttons to show.

Use dile-crud-list-lite for quick, simple listings. If you need pagination, filtering, sorting or keyword search, use dile-crud-list instead.

Installation

npm i @dile/crud

Usage

Import the component.

import '@dile/crud/components/list-lite/crud-list-lite.js';

Use it, pointing it to an endpoint and telling it which properties to use as label and link:

<dile-crud-list-lite
  endpoint="https://example.com/api/countries"
  labelProperty="name"
  linkProperty="url"
></dile-crud-list-lite>

Properties

Data loading

Item rendering

Limiting the list / revealing more items

Footer link

Action buttons

Each action button is hidden by default and only appears when its corresponding property is set to true. Clicking a button doesn't perform any action itself — it only dispatches an event (see below).

Messages

Deferred start

Methods

Events

Action buttons are rendered through dile-crud-list-item, so the same events it dispatches bubble up from dile-crud-list-lite:

CSS Custom Properties

Custom property Description Default
--dile-crud-list-lite-icon-color Color of the item icon #888
--dile-crud-list-lite-icon-size Size of the item icon 20px
--dile-crud-list-lite-icon-margin-right Right margin of the item icon 0.5rem
--dile-crud-list-lite-show-more-link-color Color of the "show more" link var(--dile-primary-color, #7BB93D)
--dile-crud-list-lite-show-more-link-font-size Font size of the "show more" link 0.9rem
--dile-crud-list-lite-show-more-link-margin-top Top margin of the "show more" link 0.75rem
--dile-crud-list-lite-show-more-link-text-align Text alignment of the "show more" link right
--dile-crud-list-lite-footer-link-color Color of the footer link var(--dile-primary-color, #7BB93D)
--dile-crud-list-lite-footer-link-font-size Font size of the footer link 0.9rem
--dile-crud-list-lite-footer-link-margin-top Top margin of the footer link 0.75rem
--dile-crud-list-lite-footer-link-text-align Text alignment of the footer link right
--dile-crud-list-lite-error-color Color of the error message #c00

To customize the appearance of each row (separators, padding, action button colors...), check the CSS custom properties of dile-crud-list-item.

Example

<script type="module">
  import { LitElement, html, css } from 'lit';
  import '@dile/crud/components/list-lite/crud-list-lite.js';
  import '@dile/iconlib/material-icons/flag.js';

  class DemoCountryListLite extends LitElement {
    static styles = [
      css`
        :host {
          display: block;
        }
      `
    ];

    render() {
      return html`
        <dile-crud-list-lite
          endpoint="https://timer.escuelait.com/api/countries"
          labelProperty="name"
          icon="material.flag"
          maxItems="5"
          moreLinkLabel="Show more"
          showEditAction
          showDeleteAction
          @crud-item-edit=${this.showOnConsole}
          @crud-item-delete=${this.showOnConsole}
        ></dile-crud-list-lite>
      `;
    }

    showOnConsole(e) {
      console.log(e.detail);
    }
  }
  customElements.define('demo-country-list-lite', DemoCountryListLite);
</script>
<demo-country-list-lite></demo-country-list-lite>

Using a custom item template

You can pass an itemTemplate function for complete control over each item's inner content, reusing your own components:

<script type="module">
  import { LitElement, html, css } from 'lit';
  import '@dile/crud/components/list-lite/crud-list-lite.js';

  class DemoCountryItemLite extends LitElement {
    static get properties() {
      return { country: { type: Object } };
    }
    render() {
      return html`${this.country.name} - <i>${this.country.continent}</i>`;
    }
  }
  customElements.define('demo-country-item-lite', DemoCountryItemLite);

  class DemoCountryListLiteTemplate extends LitElement {
    static styles = [
      css`
        :host {
          display: block;
        }
      `
    ];

    render() {
      return html`
        <dile-crud-list-lite
          endpoint="https://timer.escuelait.com/api/countries"
          .itemTemplate=${(country) => html`<demo-country-item-lite .country=${country}></demo-country-item-lite>`}
        ></dile-crud-list-lite>
      `;
    }
  }
  customElements.define('demo-country-list-lite-template', DemoCountryListLiteTemplate);
</script>
<demo-country-list-lite-template></demo-country-list-lite-template>