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

@daypilot/modal

v3.17.0

Published

Build a modal dialog dynamically from code.

Downloads

796

Readme

DayPilot Modal

DayPilot Modal - build a modal dialog dynamically from code.

Modal dialog screenshot

What's New

New features and improvements:

Dynamic Form Features

  • Create a modal dialog with multiple fields programmatically
  • Auto-detection of fields from data if no form is specified
  • Keyboard support (escape, enter, tab)
  • Optional auto-focus on the first item
  • Returns the original object with changes merged (additional fields not modified)
  • Supported field types: text, date (with optional time), searchable drop-down list, radio list

Modal Dialog Features

  • Displays custom HTML or a standalone page
  • Includes one-line replacements for alert(), prompt() and confirm()
  • Modal - hides the background with a semi-transparent div
  • Draggable
  • Auto-stretching to show full content
  • Responsive and mobile-friendly
  • Minimal styling - will inherit your global styles
  • Allows styling using CSS themes

Build a modal dialog dynamically

Text field

Text field example

import {Modal} from "@daypilot/modal";

var form = [
  {name: "Name", id: "name"}
];

var data = {
  name: "John"
};

Modal.form(form, data).then(function(args) {
  console.log(args.result);
});

Multiple fields

Modal dialog with multiple fields

import {Modal} from "@daypilot/modal";

var resources = [
  {name: "Resource A", id: "A"},
  {name: "Resource B", id: "B"},
  {name: "Resource C", id: "C"},
];

var form = [
  {name: "Start", id: "start", type: "date"},
  {name: "End", id: "end", type: "date"},
  {name: "Text", id: "text"},
  {name: "Resource", id: "resource", options: resources},
];

var data = {
  text: "Event 1",
  start: "2020-11-01",
  end: "2020-11-02",
  resource: "B"
};

Modal.form(form, data).then(function(args) {
  console.log(args.result);
});

Complex dialog

Complex dialog

import {Modal} from "@daypilot/modal";

var resources = [
  {name: "Resource A", id: "A"},
  {name: "Resource B", id: "B"},
  {name: "Resource C", id: "C"},
];

var priorities = [
  {name: "Priority 1", id: 1},
  {name: "Priority 2", id: 2},
  {name: "Priority 3", id: 3},
];

var form = [
  {name: "Calendar Record"},
  {name: "Text", id: "text"},
  {name: "Display as", id: "displayAs", type: "radio", options: [
      {name: "Event", id: "event", children: [
          {name: "Start", id: "start", type: "date"},
          {name: "End", id: "end", type: "date"},
          {name: "Resource", id: "resource", options: resources},
        ]},
      {name: "Task", id: "task", children: [
          {name: "Priority", id: "priority", options: priorities},
        ]}
    ]}
];

var data = {
  text: "Event 1",
  start: "2020-11-01",
  end: "2020-11-02",
  resource: "B",
  priority: 2,
  displayAs: "event"
};

Modal.form(form, data).then(function(modal) {
  console.log(modal.result);
});

Drop-in alert() replacement

Modal dialog with simple message

import {Modal} from "@daypilot/modal";

Modal.alert("Hello, world!");

See it in action: DayPilot.Modal.alert() Demo

Drop-in confirm() replacement

Ok/Cancel modal dialog

import {Modal} from "@daypilot/modal";

Modal.confirm("Hello, world!").then(function(args) {
  console.log("Modal was closed");                           
});

See it in action: DayPilot.Modal.confirm() Demo

Drop-in prompt() replacement

Modal dialog with single input field

import {Modal} from "@daypilot/modal";

Modal.prompt("What's your name?").then(function(args) {
  console.log("Hello", args.result);                           
});

See it in action: DayPilot.Modal.prompt() Demo

Show custom HTML

import {Modal} from "@daypilot/modal";

var modal = new Modal();
modal.showHtml("<div>Hello, world!</div>");

Show custom page

import {Modal} from "@daypilot/modal";

var modal = new Modal();
modal.showUrl("hello-world.html");

Show custom DOM element

import {Modal} from "@daypilot/modal";

var div = document.createElement("div");
div.innerHTML = "Hello, world!"

var modal = new Modal();
modal.showHtml(div);

API Docs

https://api.daypilot.org/daypilot-modal-class/

CSS Themes

Default

Default theme

Flat

Flat theme

Rounded

Rounded theme

Tutorials

  • https://code.daypilot.org/67418/javascript-confirm-replacement
  • https://code.daypilot.org/17463/javascript-prompt-replacement
  • https://code.daypilot.org/11136/javascript-alert-replacement
  • https://code.daypilot.org/60333/using-daypilot-modal-in-angular-application-typescript

Compatibility

  • Chrome
  • Safari
  • Firefox
  • Edge

Issues

Please report issues in the forum:

https://forums.daypilot.org

License

Apache License 2.0

NOTICE

This product includes DayPilot Modal (https://modal.daypilot.org).

Demos