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

qing-dialog-component

v0.10.0

Published

Dialog component for qing

Downloads

15

Readme

qing-dialog-component (WIP)

Build Status npm version Node.js Version

Dialog component for qing, based on qing-button and lit-element, mobile friendly.

Demo

Demo

Installation

qing-dialog-component is based on qing-button and lit-element

yarn add qing-dialog-component qing-button lit-element

Usage

Dialog size

Dialog size is fully customizable. By default, height defaults to auto (fits content size), width defaults to 100vw. You might need to add some CSS to fit your use case, some examples:

/** Example 1 **/
/** 80% of screen width on medium or large screens */
@media (min-width: 768px) {
  qing-dialog::part(overlay) {
    width: 80%;
  }
}

/** Example 2 **/
/** Auto width with min and max values on medium or large screens */
@media (min-width: 768px) {
  qing-dialog::part(overlay) {
    width: auto;
    max-width: min(100vw, 1000px);
    min-width: 400px;
  }
}

/** Example 3 **/
/** Fullscreen dialog with margins **/
qing-dialog::part(overlay) {
  display: flex;
  width: calc(100vw - 100px);
  height: calc(100vh - 100px);
}

Properties

// A group of pre-defined button types.
type PresetButtonType = 'ok' | 'yes' | 'no' | 'cancel';

// A more customized button if `PresetButtonType` doesn't fit.
// A customized dialog button.
interface DialogButton {
  // One of the preset types of the button, 'ok' | 'yes' | 'no' | 'cancel'.
  type?: string;
  // Used to identify a button if `type` is not set.
  name?: string;
  // Button content.
  text?: string;
  // qing-button style.
  style?: string;
  // Defaults to `true`. If true, clicking on the button closes the dialog.
  autoClose?: boolean;
}

// The reason a dialog is closed.
enum CloseReason {
  key = 1,
  button,
}

// `closed` event detail.
interface CloseReasonDetail {
  // The reason a dialog is closed, can be 'key' or 'button' or
  // `undefined` if it's closed programmatically.
  reason?: CloseReason;
  // Extra data for `reason`.
  // For `CloseReason.key`, it's key name.
  // For `CloseReason.button`, it's the `DialogButton` triggered the dismissal.
  data?: unknown;
}

// Dialog component: <qing-dialog>
class QingDialog {
  // Set localized button strings.
  static localizedButtonStrings: Record<string, string>;
  /**
   * Defaults to:
   * {
   *   yes: 'Yes',
   *   no: 'No',
   *   ok: 'OK',
   *   cancel: 'Cancel',
   * }
   */

  // Whether the dialog is visible.
  open: boolean;
  // Bottom buttons.
  buttons: (PresetButtonType | DialogButton)[];
  // Index of the default button, defaults to 0 (first button).
  defaultButtonIndex: number;
  // Index of the cancel button.
  // A cancel button will be clicked when user presses Esc key.
  cancelButtonIndex: number;

  // ------- Events -------

  // Fires when `open` property changes.
  shown: CustomEvent;
  closed: CustomEvent;

  // Fires when dialog button is clicked.
  buttonClick: CustomEvent<DialogButton>;
}

CSS Shadow Parts

  • Element containers:
    • overlay-background, overlay
  • Top-level elements:
    • content, footer
  • Footer elements:
    • footer-buttons: footer button container
    • footer-button: individual footer buttons

Autofocus

Use requestFocus event to auto focus an element when the dialog shows up, example:

html`
  <qing-dialog
    .buttons=${['ok']}
    @requestFocus=${() => {
      this.shadowRoot.getElementById('textInput').focus();
    }}
  >
    <form>
      <input type="text" id="textInput" />
    </form>
  </qing-dialog>
`;

Build Instructions

This project uses daizong to manage scripts. You need to run scripts through daizong via yarn r <script> or npm run r <script>.

For development

  • yarn r dev starts the development mode, which watches and compiles all source files including tests files.
  • yarn r serve starts demo page in browser in development mode.
  • yarn r t runs tests in development mode (requires build files).
  • yarn r tw runs tests in development + watch mode (requires build files).

Tip: You can keep 3 terminal tabs open to run the 3 scripts above during development.

For production

  • yarn r build cleans, lints, compiles the project and runs tests.

Other scripts

You do not need to manually run these scripts, they are already integrated into other scripts.

  • yarn r lint lints the project using ESLint, auto triggered by yarn r build.
  • yarn r clean deletes all build artifacts, auto triggered by yarn r dev or yarn r build.

No prepublishOnly

The prepublishOnly script was removed, we recommend using np to publish packages, which will automatically run yarn test, which runs yarn r build before publishing.