0.4.0 • Published 5 years ago

flashy-js v0.4.0

Weekly downloads
35
License
ISC
Repository
github
Last release
5 years ago

Flashy

Build Status

Flashy is a 0 dependancy, lightweight flash messages library built using vanilla web components.

Demo

Demo Page

Installation

HTML

Simply include Flashy in your HTML using UNPKG

<script src="https://unpkg.com/flashy-js@latest/dist/flashy.min.js"></script>

or

<script src="./lib/flashy.min.js"></script>

Bower

Coming soon...

Contributing

To Do

  • Create core functionality
  • Allow for custom styles to be passed
  • Allow for custom emojis to be passed to the flash message
  • Allow for other icons (svg, fa etc.) to be passed to the flash message
  • Allow for custom flash message types

Usage

<flash-messages data-max-messages="5"></flash-messages>

To start with inject the flash-messages element into your HTML. This acts as a container to all the messages.

Attributes
AttributeTypeRequiredDefaultDescription
data-max-messagesintfalse10The maximum amount of messages to store in the queue. When the maximum is reached, the oldest message will be removed.

Importing the package exposes the global variable Flashy, which is a function.

Functions

Flashy(querySelector, options)

The Flashy function creates a new flash message to display to the user. The Flashy functions accepts two paramaters, querySelector and options.

Parameters
ParameterTypeRequiredDescription
querySelectorstringtrueThe query selector to the element
optionsobjecttrueFlash message config, see below table.
Options

The acceptable values in the options object.

KeyTypeRequiredAllowable ValuesDescription
typestringtrueerror / warning / info / successThe type of the flash message
titlestringfalseN/AThe title of the flash message
messagestringfalseN/AThe message displayede
expirystringfalseN/A (defaults to 0)Time in MS until message will expire and disappear
globalClosebooleanfalsetrue / falseAdds a close button to the flash message
stylesobjectfalseN/ACSS styles to customise the flash message. See below for the style definition
Buttons
KeyTypeRequiredAllowable ValuesDescription
textstringtrueN/AText to be shown on the button
actionfunctionfalseN/AFunction to be run when the button is clicked
closesFlashbooleanfalsetrue / falseIf set to true, clicking the button will remove the flash message
Styles
KeyTypeRequiredAllowable ValuesDescription
flashColorCSS ColorfalseN/ABackground color of the flash message
titleTextColorCSS ColorfalseN/AColor of the flash message title
titleTextFontCSS Font FamilyfalseN/AFont family attribute of the flash message title
msgTextColorCSS ColorfalseN/AColor of the flash message content
msgTextFontCSS Font FamilyfalseN/AFont family attribute of the flash message content
linkTextColorCSS ColorfalseN/AColor of the flash message buttons/links
linkTextFontCSS Font FamilyfalseN/AFont family attribute of the flash message buttons/links
iconobjectfalseN/AObject specifying the icon to be displayed with the message. See below for the icon definition
iconBackgroundColorCSS ColorfalseN/ABackground color behind the icon
Icon
KeyTypeRequiredAllowable ValuesDescription
typestringtrueunicodeType of the icon (more to be added soon)
valanytrueN/AValue of the icon. For unicode, character literal.
Examples
Generic flash message
    Flashy('flash-messages', 
        {
            type: 'success',
            title: 'It worked',
            message: 'Lets rejoice',
        }
    );
Expiring flash message
    Flashy('flash-messages', 
        {
            type: 'info',
            title: 'Act quick',
            message: 'This will be gone in 5 seconds!',
            expiry: 5000,
            globalClose: false,
        }
    );
Action required
    Flashy('flash-messages', 
        {
            type: 'warning',
            title: 'Action required',
            message: 'Something happened and you need to click the button below or this will stay here',
            globalClose: false,
            buttons: [
                {
                    text: 'OK',
                    action: myCoolFunction,
                    closesFlash: true,
                },
                {
                    text: 'Cancel',
                    action: myBoringFunction,
                    closesFlash: false,
                },
            ],
        }
    );
Custom styling
    Flashy('flash-messages', {
        type: 'error',
        title: 'Custom styled',
        message: 'This is really ugly, so it will only last for 5 seconds',
        expiry: 5000,
        buttons: [
            {
                text: 'Close it now!',
                closesFlash: true,
            },
        ],
        globalClose: true,
        styles: {
            flashColor: '#fff',

            titleTextColor: '#000',
            titleTextFont: '\'Arial\' sans-serif',

            msgTextColor: 'pink',
            msgTextFont: '\'Arial\' sans-serif',

            linkTextColor: 'black',
            linkTextFont: '\'Arial\' sans-serif',

            icon: {
                type: 'unicode',
                val: '🤑',
            },
            iconBackgroundColor: 'grey',
        }
    });

Check out the website for project website https://alex-zissis.github.io/flashy

0.4.0

5 years ago

0.3.0

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago