GithubHelp home page GithubHelp logo

gustavosmanc / cute-alert Goto Github PK

View Code? Open in Web Editor NEW
68.0 4.0 34.0 2.79 MB

Simple open source JavaScript library that aims to provide beautiful alerts and toasts to your website.

Home Page: https://gustavosmanc.github.io/cute-alert/docs/

License: MIT License

JavaScript 1.56% CSS 0.66% Shell 0.31% TypeScript 74.80% SCSS 22.67%

cute-alert's Introduction

Cute Alert

NPM Version

Simple open source JavaScript library that aims to provide beautiful alerts and toasts to your website. Alerts inspired by Igor Ferrão de Souza's design.

Visit the documentation for more detailed instructions or Storybook if you want to play around / check out the library.

Table of Contents

  1. Getting Started
  2. TypeScript
  3. Contributing

Getting started

Installation

npm install cute-alert

Usage

Alerts

import { cuteAlert } from 'cute-alert'

cuteAlert({
  type: 'success',
  title: 'Title',
  description: 'Description',
  timer: 5000,
  primaryButtonText: 'Confirm',
  secondaryButtonText: 'Cancel'
})

Check out the documentation for more detailed instructions.

Toasts

import { cuteToast } from 'cute-alert'

cuteToast({
  type: 'success',
  title: 'Title',
  description: 'Description',
  timer: 5000
})

Check out the documentation for more detailed instructions.

TypeScript

Cute alert has built-in TypeScript support and provides a set of default exported types that you can import as named imports into your project like:

import type {
  AlertOptions,
  ToastOptions,
  AlertResolveValue,
  ToastResolveValue,
  AlertResolve,
  ToastResolve
} from 'cute-alert'

Contributing

Before pushing a PR, take into account the following checklist:

  • I have linked an issue or discussion.
  • I have added tests (if necessary).
  • I have updated the documentation accordingly (if necessary).
  • My commits are following the conventional commits specification.

Setting up the project

  1. Fork the repository and clone it.

  2. Install the dependencies on the repository:

    npm install
  3. Start storybook:

    npm run storybook

Unit tests

Running unit tests:

npm run test

Updating snapshots:

npm run test:update-snapshots

Coverage:

npm run coverage

Setting up the docs

Make sure you have the latest Ruby version installed.

  1. Open up your terminal and install the bundler gem on version 2.4.22:

    gem install bundler -v 2.4.22
  2. Go to the docs folder and install the dependencies:

    bundle install
  3. Run bundle exec jekyll serve to serve the docs locally.

cute-alert's People

Contributors

dutragames avatar gustavosmanc avatar lbert1 avatar nimbus321 avatar rahult0917 avatar syaidiputra avatar zelo0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cute-alert's Issues

typescript definitions

I started to use this project by importing it as an npm git dependency, but I found that the internals of the alerts actually interrogated the scripts and tried to pluck the svgs off of that, so I decided it wasn't worth the hassle to rewrite it to use base64 versions (since I'm bundling this).

Anyway, I did make a typescript definition file for the project, and I wanted to share it with you. Here's the definitions:

declare module 'cute-alert/cute-alert' {
  export declare type AlertType =
    | 'warning'
    | 'error'
    | 'success'
    | 'question'
    | 'info';

  export declare interface AlertArgs {
    type: AlertType;
    title: string;
    message: string;
    img: string;
    buttonText?: string;
    confirmText?: string;
    vibrate?: number | number[];
    playSound?: string;
    cancelText?: string;
    closeStyle: string;
  }

  export declare interface ToastArgs {
    type: AlertType;
    message: string;
    timer?: number;
    vibrate?: number | number[] | undefined;
    playSound?: string;
  }

  export function cuteAlert(
    args: AlertArgs,
  ): Promise<'confirm' | 'ok' | 'close' | void>;
  export function cuteToast(args: ToastArgs): Promise<void>;
}

new instances duplicate on page

This really is great, thanks first of all!
Second, If I confirm box, and choose cancel, then go into it again, it duplicates the confirmation box.
It's as if the first never disposes properly. So I have one confirmation box to close, then I have to close it again - you can also see the background gets darker each time you load a new one.

Do you have a dispose event I could use to ensure each new call is only done so once?

Uncaught (in promise) ReferenceError: img is not defined

As the title says I get an error trying to display a Toast - Uncaught (in promise) ReferenceError: img is not defined
line 152 of cute-alert.js
${img !== '' ? '

' : '
'}

CuteAlert works but doesn't display the icon.
My directory structure is:

app/static/cute-alert/img/image files here
js and css are in app/static/cute-alert/

I'm new to javascript so don't know how to troubleshoot this.

Add option for close Alert with timer

Add option for close Alert with timer
function cuteAlertAction(type, title, message){ return cuteAlert({ type: type, title: title, message: message, autoClose: true, timer: 2000 }); }

When adding this project to an addon for Firefox warnings are generated

I am using this beautiful library for my project, but now if I present it to Firefox to publish it as an add-on, there are warnings shown
Unsafe call to body.insertAdjacentHTML for argument 1
Warning: Due to both security and performance concerns, this may not be set using dynamic values which have not been adequately sanitized. This can lead to security issues or fairly serious performance degradation.

cute-alert.js
It would be great if this could be altered so this warning is prevented

Image in alert is undefined, returns 404 error

My folder structure is
public/diary-assets/libraries/cute-alert
with the HTML file + server root being public

Using cuteAlert of the box no image shows:

Screenshot 2022-05-07 at 18 30 16

The path it is trying to load from is:
/diary-assets/libraries/cute-alert/undefined

The problem seems to be line 65:

${img !== '' ? '<img class="alert-img" src="' + src + '/' + img + '" />' : ''}

img is undefined which does not strictly equal ''

Changing line 65 to the following appears to fix the issue:

${img !== '' ? '<img class="alert-img" src="' + src + '/img/' + type + '.svg" />' : ''}

It sees that surely the img filename must be made using the property type and the existing code does not appear to do this.

However I don't understand the original intention of checking if img != '', so maybe my fix breaks some other functionality I am not aware of.

May you make a tutorial to explain how your cade works?

Hi there, Im a newbie of js. Im doing my school project which wants to use your cute-alert. I had imported both files and tried to made the event happen. unfortunately, the alert-box didn't show. it made me so confused.

If you have included the library into an add-on, then the cute-alert.js is not recognised

I have added the library into an add-on without adding the cute-alert.js added into the pages.
That is not necessary if you use a manifest.
To make it work, I altered the following lines in the manifest
// 13-08-2021 Modified the code below to be able to use it in manifest
let src = chrome.extension.getURL('/');
for (let script of scripts) {
if (script.src.includes("cute-alert.js")) {
currScript = script;
src = currScript.src;
src = src.substring(0, src.lastIndexOf("/"));
}
}
This does work for me, but might not work for others, so needs to be tested in a page without using a manifest

Undefined variable 'url' in line number 215

Hi,

As you checking the the 'url' variable in the 215 no line (please see the attached image). It's actually undefined and in the same scope has na url variable so it's showing a console error.
error

Thank you

close button

After showing the Dialog want to close the window using Enter button of the keyboard . Is it possible?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.