logo polydile logo polydile en modo oscuro dile-components

dile-relation-checker

The dile-relation-checker component is designed to manage and display a list of items with a toggleable status, allowing users to easily check or uncheck each item in relation to a specific entity.

It retrieves items from an API, displays them in a searchable list, and provides functionality to update each item's status through API requests. This component is ideal for managing many-to-many relationships or association lists within CRUD interfaces.

Installation

npm i @dile/crud

Usage

Import the dile-ajax component.

import '@dile/crud/components/relation-checker/relation-checker.js';

Use the component.

<dile-relation-checker 
  endpointGet="http://localhost/api/board-games/1/mechanics"
  endpointCheck="http://localhost/api/board-games/1/mechanics" 
  label="Board Game Mechanics"
></dile-relation-checker>

Properties

Methods

Custom events

These custom events allow for external handling of data loading and save operation outcomes, making it easy to display feedback to users or trigger other actions based on these events.

Styling

It is possible to use these custom CSS properties in the dile-relation-checker component:

Custom property Description Default
--relation-checker-title-font-size The font size of the title in the checker component 1.25rem
--relation-checker-title-font-weight The font weight of the title in the checker component bold
--relation-checker-title-color The color of the title in the checker component #303030
--relation-checker-checkbox-size The size of the checkbox in the relation checker item 24px
--relation-checker-tooltip-icon-size The size of the tooltip icon in the relation checker item 18px
--dile-chip-tooltip-padding The padding of the tooltip chip in the relation checker item when using the "onlyicon" class 0.15rem

In addition to the CSS custom properties mentioned above, the dile-relation-checker component relies on other components from the Dile Components catalog:

For this reason, you can also use the style customizations specified in their respective documentation pages.

dile-relation-checker Demo

<script type="module">
import { LitElement, html, css } from 'lit';
import '@dile/crud/components/relation-checker/relation-checker'
import '@dile/crud/components/ajax-select-crud/ajax-select-crud'

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

  static get properties() {
    return {
      gameId: { type: String },
    };
  }

  constructor() {
    super();
    this.gameId = 1;
  }
  render() {
    return html`
      <dile-ajax-select-crud
        id="countryselect"
        idProperty="id"
        name="game_id"
        label="Game"
        endpoint="https://timer.escuelait.com/api/board-games" 
        queryStringVariable="keyword"
        value="${this.gameId}"
        placeholder="Search Board Game"
        .getSelectResultList=${(response) => response.data.result.data}
        displayProperty="name"
        selectDefaultPlaceholder="Select board game..."
        @element-changed=${this.selectorChanged}
    ></dile-ajax-select-crud>
      <dile-relation-checker 
        endpointGet="https://timer.escuelait.com/api/board-games/${this.gameId}/mechanics"
        endpointCheck="https://timer.escuelait.com/api/board-games/${this.gameId}/mechanics" 
        label="Board Game Mechanics"
        .computeTooltip = ${(item) => item.description}
      ></dile-relation-checker>
    `;
  }
  selectorChanged(e) {
    console.log('selectorChanged', e.detail)
    this.gameId = e.detail.value;
    if(this.gameId) {
      this.updateComplete.then(() => 
        this.shadowRoot.querySelector('dile-relation-checker').refresh()
      )
    }
  }
}
customElements.define('demo-relation-checker', DemoRelationChecker);
</script>
<demo-relation-checker></demo-relation-checker>