logo dile-components dile-components

Feedback Mixin

This mixin enables any application component to display feedback messages easily. By implementing the mixin, components gain methods to show toast messages, modal dialogs, or loading states.

Usage

To use this mixin, you must have @dile/lib installed as described on the @dile/lib homepage.

It works through Redux, so you need to implement the Redux store and the feedback slice provided by @dile/lib, as explained in the Redux implementation guide.

Once you have the store in your application, import it into the component where you want to use FeedbackMixin and apply the mixin by providing your application’s store.

Here’s an example:

import { store } from '../redux/store.js';
import { DileFeedback } from '@dile/lib';

export class DileApp extends DileFeedback(store)(LitElement) {
   // Component code
}

Available methods

The DileFeedback mixin adds methods to the component that dispatch actions to the provided Redux store. Below are the methods, their signatures, descriptions, parameters, and usage examples.

positiveFeedback(message)

Example:

this.positiveFeedback('Operation completed successfully');

negativeFeedback(message)

Example:

this.negativeFeedback('There was an error processing the request');

neutralFeedback(message)

Example:

this.neutralFeedback('This is an informational message');

startLoading()

Example:

this.startLoading();

stopLoading()

Example:

this.stopLoading();

modalFeedback(message, label = "Close", icon = null)

Example:

// Modal with success icon and custom label
this.modalFeedback('Saved successfully', 'OK', 'success');

closeModalFeedback()

Example:

this.closeModalFeedback();

Required components for mixin operation

As mentioned, these methods dispatch actions from the redux/feedback-slice provided by @dile/lib and require the store and feedback slice to be properly integrated into the application.

To receive state changes and display feedback messages, your application — typically in the root component or before </body> in web pages — needs a component correctly linked to the store.

The required components are included in @dile/lib. Their documentation pages are listed below: