npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lakea/gravity-toast-adapter-ngneat-hot-toast

v3.0.2

Published

An adapter for `GrToast` using [`@ngneat/hot-toast`](https://ngneat.github.io/hot-toast/) as implementation.

Downloads

12

Readme

@lakea/gravity-toast-adapter-ngneat-hot-toast

An adapter for GrToast using @ngneat/hot-toast as implementation.

Installation

Install the library using NPM:

npm install @lakea/gravity-toast-adapter-ngneat-hot-toast @ngneat/overview @ngneat/hot-toast --save

Add this line to your main styles.scss:

@use 'node_modules/@lakea/gravity-toast-adapter-ngneat-hot-toast/styles/styles.scss';

Next, create a new file, toast-adapter-root.module.ts which exposes an Angular's module with a default configuration.

import {NgModule} from '@angular/core';
import {HotToastModule} from '@ngneat/hot-toast';
import {GrToast} from '@lakea/gravity/ui';
import {GrToastAdapterNgneatHotToast} from '@lakea/gravity-toast-adapter-ngneat-hot-toast';

const TOAST_STYLE = {
  style: {
    color: 'var(--gr-toast-color, var(--gr-color-background-contrast))',
    background: 'var(--gr-toast-background-color, var(--gr-color-background))',
    border: 'var(--gr-toast-border, 1px solid var(--gr-color-border))',
    padding: 'var(--gr-toast-padding, 8px 16px)',
    borderRadius: 'var(--gr-toast-border-radius, 8px)',
    wordBreak: 'break-word',
    maxWidth: 'var(--gr-toast-max-width, 60vw)',
  },
  closeStyle: {
    color: 'var(--gr-toast-close-btn-color, var(--gr-color-background-contrast))',
    marginLeft: 'var(--gr-toast-close-btn-margin-left, 16px)',
    cursor: 'pointer',
    backgroundImage:
      "var(--gr-toast-close-btn-background-image, url(\"data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='white' %3e%3cpath d='M.293.293a1 1 0 011.414 0L8 6.586 14.293.293a1 1 0 111.414 1.414L9.414 8l6.293 6.293a1 1 0 01-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 01-1.414-1.414L6.586 8 .293 1.707a1 1 0 010-1.414z'/%3e%3c/svg%3e\"))",
  },
};

@NgModule({
  imports: [
    HotToastModule.forRoot({
      ...TOAST_STYLE,
    }),
  ],
  providers: [
    {
      provide: GrToast,
      useClass: GrToastAdapterNgneatHotToast,
    },
  ],
})
export class ToastAdapterRootModule {}

Import ToastAdapterRootModule to application root module like app.module.ts.

You should import the ToastAdapterRootModule once in your root module.

The ToastAdapterRootModule file imports the HotToastModule from @ngneat/hot-toast library with a default style config and provide the adapter implementation too.

To configure the @ngneat/hot-toast library, read the docs here.


Creating your own adapter

Create your adapter implementation class extending GrToast abstraction:

import {Injectable} from '@angular/core';

import {GrToast, GrToastObservableMessages, GrToastOptions, GrToastRef} from '@lakea/gravity/ui';

@Injectable()
export class GrToastAdapter extends GrToast {
  constructor() {
    super();
  }

  public success(message: string, options?: GrToastOptions): GrToastRef {
    // YOUR IMPLEMENTATION
  }

  public info(message: string, options?: GrToastOptions): GrToastRef {
    // YOUR IMPLEMENTATION
  }

  public warning(message: string, options?: GrToastOptions): GrToastRef {
    // YOUR IMPLEMENTATION
  }

  public error(message: string, options?: GrToastOptions): GrToastRef {
    // YOUR IMPLEMENTATION
  }

  public loading(message: string, options?: GrToastOptions): GrToastRef {
    // YOUR IMPLEMENTATION
  }

  public observe<T>(messages: GrToastObservableMessages): (source: Observable<T>) => Observable<T> {
    // YOUR IMPLEMENTATION
  }
}

So, provide it on your application root module (maybe app.module.ts), like this:

  providers: [
    {
      provide: GrToast,
      useClass: GrToastAdapter,
    }
  ]