All Projects → koddr → sweetconfirm.js

koddr / sweetconfirm.js

Licence: MIT license
👌A useful zero-dependencies, less than 434 Bytes (gzipped), pure JavaScript & CSS solution for drop an annoying pop-ups confirming the submission of form in your web apps.

Programming Languages

javascript
184084 projects - #8 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to sweetconfirm.js

Gradients
🌔 A curated collection of splendid 180+ gradients made in swift
Stars: ✭ 719 (+2014.71%)
Mutual labels:  ux, gradient
LC-switch
Superlight vanilla javascript plugin improving forms look and functionality
Stars: ✭ 31 (-8.82%)
Mutual labels:  forms, pure-javascript
react-cool-form
😎 📋 React hooks for forms state and validation, less code more performant.
Stars: ✭ 246 (+623.53%)
Mutual labels:  forms, ux
Basic-Image-Processing
Implementation of Basic Digital Image Processing Tasks in Python / OpenCV
Stars: ✭ 102 (+200%)
Mutual labels:  gradient
gradient-rs
A command line tool for playing with color gradients
Stars: ✭ 93 (+173.53%)
Mutual labels:  gradient
Fields
Good, solid base to build custom forms in iOS apps, using self-sizing compositional layout.
Stars: ✭ 80 (+135.29%)
Mutual labels:  forms
neodigm55
An eclectic low-code vanilla JavaScript UX micro-library for those that defiantly think for themselves.
Stars: ✭ 14 (-58.82%)
Mutual labels:  ux
Extract-Color-Palette-Api
Create gradient drawable by extracting prominent colors from image⚫⚪
Stars: ✭ 16 (-52.94%)
Mutual labels:  gradient
GradientProgressView
一个简单的进度条控件
Stars: ✭ 15 (-55.88%)
Mutual labels:  gradient
PastelXamarinIos
🌒 Gradient animations on Xamarin-iOS
Stars: ✭ 17 (-50%)
Mutual labels:  gradient
RMGradientView
A Custom Gradient View Control for iOS with inspectable properties.
Stars: ✭ 24 (-29.41%)
Mutual labels:  gradient
meetup-event-planner
GraphQL on Rails Demo Application and React Front End for planning meetup events
Stars: ✭ 22 (-35.29%)
Mutual labels:  ux
hookahjs
Add empty/dirty/touched CSS hooks to input and textarea elements automatically (1056 bytes)
Stars: ✭ 21 (-38.24%)
Mutual labels:  forms
pix
Interaction notation for UX design
Stars: ✭ 37 (+8.82%)
Mutual labels:  ux
PureForm
No description or website provided.
Stars: ✭ 22 (-35.29%)
Mutual labels:  forms
flutter scale aware
🎗 Scale-based layouts with a bit more ease, powered by extensions.
Stars: ✭ 26 (-23.53%)
Mutual labels:  ux
Android-SGTextView
同时带字体描边 渐变 阴影的TextView - both have stroker, gradient and shadow TextView
Stars: ✭ 18 (-47.06%)
Mutual labels:  gradient
forms-typed
Want types in your forms? Want to have nested forms? This is the place to be...
Stars: ✭ 79 (+132.35%)
Mutual labels:  forms
billing-form
Demo page for user-friendly billing form features
Stars: ✭ 23 (-32.35%)
Mutual labels:  ux
js-tldr
Zen mode javascript documentation
Stars: ✭ 96 (+182.35%)
Mutual labels:  ux

sweetconfirm.js logo github

Throw out pop-ups confirming the submission of form!

sweetconfirm.js demo gif

npm version bundle size jsDelivr download code style: prettier license twit link

A useful zero-dependencies, less than 434 Bytes (gzipped), pure JavaScript & CSS solution
for drop an annoying pop-ups confirming the submission of form in your web apps.

Docs, Change log

Install

Simple install to your project via npm:

npm install --save sweetconfirm.js

Or include to your html page from fast CDN jsDelivr:

<script src="https://cdn.jsdelivr.net/npm/sweetconfirm.js@0/sweetconfirm.min.js"></script>

How to use?

Let's start with HTML page and some CSS styles for submit button (./index.html):

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      button {
        display: block;
        border-radius: 30px;
        cursor: pointer;
      }
    </style>
  </head>
  <body>
    <button type="submit" id="button">💬 Push the button!</button>
    <script src="./script.js"></script>
  </body>
</html>

Next, time for JavaScript (./script.js):

import { SweetConfirm } from "sweetconfirm.js";

// Define element (button)
var button = document.getElementById("button");

// Init SweetConfirm.js to element with callback
new SweetConfirm(button, () => {
  console.log("This is fake data!");
});

Use via CDN

Similar to npm way, but easily (all-in-one ./index.html file):

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- ... -->
  </head>
  <body>
    <button type="submit" id="button">💬 Push the button!</button>

    <div id="message"></div>

    <script src="https://cdn.jsdelivr.net/npm/sweetconfirm.js@0/sweetconfirm.min.js"></script>
    <script>
      // Define vars
      var button, message;
      button = document.getElementById("button");
      message = document.getElementById("message");

      // Callback function
      function showMessage(element, text) {
        element.innerText = text;
      }

      // Init SweetConfirm.js
      new SweetConfirm(button, () => {
        showMessage(message, "OK! Refresh page for try again.");
      });
    </script>
  </body>
</html>

What about options?

function SweetConfirm ( element, function () {...}, [options, ...] )
Option Description Default value
bg Background color for initial state, usually equal to gradient.from_color #0f4c81
bgSize Size of background; for better effect must be greater than 100% at the first value 215% 100%
bgPositionIn Background position for init animation right bottom
bgPositionOut Background position for end animation left bottom
trans.init Enabled initial transition when page is loaded (DOMContentLoaded event) true
trans.in A transition speed in seconds for DOMContentLoaded event 0.5
trans.out A transition speed in seconds for mouseup event 0.5
gradient.deg Angle or position of the gradient line's starting point 135deg
gradient.from_color From (start) color #0f4c81 50%
gradient.to_color To (stop, end) color #fa7268 50%
question Message during holding mouse/key button on element 🤔 Are you sure?
success.message Message after callback function 👍 Success!
success.color Color of success message #00b16a
timeout Time for setTimeout() function in miliseconds; this option also define a transition speed 3000

Use SweetConfirm.js with custom options

// Define options
var options = {
  bg: "#0f4c81",
  bgSize: "215% 100%",
  bgPositionIn: "right bottom",
  bgPositionOut: "left bottom",
  trans: {
    init: true,
    in: 0.5,
    out: 0.5
  },
  gradient: {
    deg: "135deg",
    from_color: "#0f4c81 50%",
    to_color: "#fa7268 50%"
  },
  question: "🤔 Are you sure?",
  success: {
    message: "👍 Success!",
    color: "#00b16a"
  },
  timeout: 3000
};

// Init SweetConfirm.js with options
new SweetConfirm(element, () => {}, options);

Demo on localhost

You may serve downloaded repository by simple Python 3 CLI snippet (for macOS/Linux/Windows WSL).

First, clone repository:

git clone https://github.com/koddr/sweetconfirm.js.git
cd sweetconfirm.js

Let's serve it (with Python 3, for example):

python3 -m http.server 8080 --bind 127.0.0.1

And now, go to browser to see SweetConfirm.js Example page:

http://127.0.0.1:8080/examples

Size-limit report

npm run size

  Time limit:   70 ms
  Size:         434 B with all dependencies, minified and gzipped
  Loading time: 10 ms on slow 3G
  Running time: 51 ms on Snapdragon 410
  Total time:   61 ms

Thanks to Andrey Sitnik @ai/size-limit.

Developers

Project assistance

If you want to say «thank you» or/and support active development SweetConfirm.js:

  1. Add a GitHub Star to project.
  2. Twit about project on your Twitter.
  3. Donate some money to project author via PayPal: @paypal.me/koddr.
  4. Join DigitalOcean at our referral link (your profit is $100 and we get $25).

Thanks for your support! 😘 Together, we make this project better every day.

DigitalOcean Referral Badge

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].