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

inline-confirmation

v1.0.0

Published

A web component that shows an inline confirmation message

Downloads

2

Readme

<inline-confirmation>

A component to display a confirmation inline with a button. When you want to display a confirmation button when a user takes action on a button, such as a delete button but don't want to do the usual thing of display a dialog window as confirmation, inline-confirmation provides a nice alternative.

Example usage of inline-confirmation

Example

You can use inline-confirmation with unpkg:

<script type="module" src="https://unpkg.com/inline-confirmation/mod.js"></script>

<inline-confirmation>
  <span slot="confirm">Are you sure?</span>
  <button type="button" slot="content">Delete account</button>
</inline-confirmation>

Install

Available on npm:

npm install inline-confirmation

Or with Yarn:

yarn add inline-confirmation

API

The following is all you need to know:

Attributes

active: Displayed when the confirmation message is shown.

This can be set via a property:

let confirmation = document.querySelector('inline-confirmation');

confirmation.active = true;

Or via the attribute:

<inline-confirmation active> ... </inline-confirmation>

In addition to showing the confirmation message, this is also useful for styling.

inline-confirmation[active] {
  background: tomato;
  padding: .5em 1em;
  width: 15rem;
  --confirm-button-hover-color: #fff;
}

Events

confirm: Fired when the user confirms the action. By default this is the Yes button, but this can be modified with slots.

let confirmation = document.querySelector('inline-confirmation');

confirmation.addEventListener('confirm', () => {
  // Here's where we delete the account
});

cancel: Fired when the user selects to cancel the action. By default this is the No button.

let confirmation = document.querySelector('inline-confirmation');

confirmation.addEventListener('cancel', () => {
  // Might want to do something in response to this.
});

Slots

There are a few slots to customize the appearance.

confirm: A message to be displayed when confirmation mode is active. This could be more information about what the action will actually do, usually to act as a warning.

<inline-confirmation>
  <span slot="confirm">Are you sure?</span>
</inline-confirmation>

content: This is the content to display when confirmation mode is not active. Usually this is just the button you want to display for the action to perform. You might display something else here, like a Loading... message when the action actually occurs post-confirmation.

<inline-confirmation>
  <button type="button" slot="content">Delete account</button>
</inline-confirmation>

yes: This is a slot that allows you to customize the confirm button. By default it is a button that looks like a link displaying Yes. Here we change this slightly:

<inline-confirmation>
  <slot name="yes">Confirm</slot>
</inline-confirmation>

no: This is a slot that allows customizing the cancel button. By default this is a button that displays No.

<inline-confirmation>
  <slot name="no">Cancel</slot>
</inline-confirmation>

CSS Variables

--confirm-button-color: Changes the color of the confirm and cancel buttons. By default the color is inherited.

--confirm-button-hover-color: Changes the color of the confirm and cancel buttons in their hover state. Here we are showing a white color in the hover state:

inline-confirmation {
  --confirm-button-hover-color: #fff;
}

License

BSD-2-Clause