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

typed-confirmation

v1.0.3

Published

A github-like action confirmation modal where a user is required to confirm an action by typing in specific text - but on steroids.

Downloads

3

Readme

Typed Confirmation

Angular library
A github-like action confirmation modal where a user is required to confirm an action by typing in specific text - but on steroids.

Installation

npm i typed-confirmation
Angular v16 or greater required

Demos

Browse demos (incl. code examples)
You can highly customize the modal through a wide variety of settings and settings combinations.
Demos are just a few examples.

Notes

This library was created out of necessity and I decided to enchance it and release it to the public. Due to lack of time it couldn't be documented as good as possible. It will be properly documented, better optimized and get enchanced with more features once I find the time to do so.

How to use

All fields are optional and have default values if not set.
Translations that can receive null value will be hidden if null value is provided.

providers: [
   TypedConfirmationModule.forRoot({
      translations?: {
         modalHeader?: string;
         instructionPrefix?: string | null;
         instructionSuffix?: string | null;
         cancelLabel?: string;
         confirmLabel?: string;
         regenerateLabel?: string;
         error?: string;
      };
      classes?: {
         cancelBtn?: string;
         confirmBtn?: string;
         regenerateBtn?: string;
      };
      settings: {
         /**
            * Hide modal header
            */
         hideHeader?: boolean;
         /**
            * Do not display instruction keyword (in text above input)
            */
         hideKeywordIndication?: boolean;
         /**
            * Do not display error message when input is incorrect
            */
         hideErrorMessage?: boolean;
         /**
            * Do not show loader in asynchronously validated modals
            */
         hideLoader?: boolean;
         /**
            * Do not indicate input validity state with colors
            */
         disableInputValidationColors?: boolean;
         /**
            * Do not emit "false" when popup closed without confirming
            */
         disableFalseEmission?: boolean;
         /**
            * The randomly generated text's length
            */
         randomKeywordLength?: number;
         /**
            * Hide random confirmation text regeneration button
            */
         disableRandomRegeneration?: boolean;
         /**
            * Replace white spaces with dashes in confirmation text
            */
         replaceKeywordSpaces?: boolean;
         /**
            * Do not display input placeholder
            * (confirmation text to be entered)
            */
         disablePlaceholder?: boolean;
         /**
            * Disable in and out modal animations
            */
         disableAnimations?: boolean;
         /**
            * Hides instruction keyword, input placeholder and input text
            */
         secretKeyword?: boolean;
         /**
            * Confirmation text is automatically submitted
            * when it is typed correctly
            */
         autoConfirm?: boolean;
         /**
            * The time needed to pass in order to start validation
            * after the user stops typing
            */
         asyncDebounceTime?: number;
      };
   })
]

Place the code below in your entry component's html file.

<ng-container typedConfirmationPlaceholder></ng-container>

Place buttons in your components

<button typedConfirmation="angular rocks"></button>

Buttons accept [options] and emit events via the (onConfirmation) event emitter. They also have their Classes set dynamically.

Override settings in lazy loaded modules

Only translations & settings can be overriden.
By setting the merged parameter to true, options provided in forChild will override only conflicting options provided in forRoot, otherwise all options will get replaced. classes are excluded and can only be provided in forRoot.

const options: WCOptions = {
   translations?: WCTranslations;
   settings?: TCSettings;
};

const merged: boolean = true;

providers: [
   TypedConfirmationModule.forChild(options, merged)
]

Override settings individually

Settings can be provided for a specific modal only by the [options] attribute.
Individual options override the global options (forRoot / forChild) when conflicting.

<button typedConfirmation="angular" [options]="customOptions">Click me</button>
public customOptions: TCOptions = {
   translations?: WCTranslations;
   settings?: TCSettings;
}

Technical details & features

Buttons

By default the button which triggers the modal has the "no-confirmation-action" class.
If modal has been open but confirmation has been cancelled the button's class is set to "not-confirmed".
After successful confirmation the button's class is set to "confirmed".

Events

Events can be received by the (onConfirmation) event emitter.

<button typedConfirmation="angular" (onConfirmation)="doSomething($event)">Click me</button>
public doSomething(event: ConfirmationEvent) {
   console.log(event);
}

Both actions (confirmation/cancellation) emit an event of type ConfirmationEvent.

ConfirmationEvent {
   /**
      * Unique linkage id between the modal and the button which triggers it
      */
   id: string;

   /**
      * The event value
      */
   value: boolean;

   /**
      * The html button which triggered the modal
      */
   element: HTMLButtonElement;
}

False emission can be omitted by setting

{
   settings: {
      disableFalseEmission: true
   }
}

Async validation

It is possible to validate input with observables as long as they return either a boolean or an object which includes success: boolean.

<button typedConfirmation="authenticateCurrentUser()">
public authenticateCurrentUser(): AsyncValidationFn {
   return (value: string) => this._http.post("https://my.server/auth", {
      userId: "hj5sCK3r",
      password: value
   }).pipe(
      map((response: any) => response.success)
   );
}

Styles

All modal elements (e.g. buttons, input etc) have no styles set and will inherit your application's styles.