Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
This lib is a JavaScript tool kit of alert. It's dedicated to lightweight, concise and highly customizable. We just give a simple realization of a alert so that you could do what ever you want easily based on it.
简体中文 | English
npm install gm-alert -S
# Or use yarn
yarn add gm-alert
Or just use <script>
tag:
<link rel="stylesheet" href="path/to/gm-alert.min.css" />
<script src="path/to/gm-alert.min.js"></script>
To get dist js and css files, please visit Releases Page or use CDN like jsDelivr
.
If you use import/require
:
import GmAlert from 'gm-alert'
import 'gm-alert/gm-alert.min.css'
// Create an alert instance
const instance = GmAlert({
// ...some options
})
// Show alert
instance.show()
// Hide alert
instance.hide()
If you use <script/>
tag to import, GmAlert
will be mounted on window
.
Don't forget to import css file.
Create a new alert instance with options:
option | type | description | default value |
---|---|---|---|
header | string|HTMLElement | header of modal | '' |
headerClassName | string | extra class for title element | '' |
body | string|HTMLElement | body of modal | '' |
bodyClassName | string | extra class for body element | '' |
showFooter | boolean | show footer or not | true |
footerClassName | string | extra class for footer element | '' |
okText | string | text of ok button | 'ok' |
onOK | function | callback when you click ok button | () => this.hide() |
cancelText | string | text of cancel button | 'cancel' |
onCancel | function | callback when you click cancel button | () => this.hide() |
maskClosAble | boolean | call onCancel when click mask of modal | true |
isShow | boolean | show alert or not | false |
It will return an alert instance, the relationship between them is:
instance.__proto = GmAlert.prototype
So that instance could use all of prototype methods on GmAlert
.
Instance will have those properties:
GmAlert {
$body
$cancel
$footer
$header
$mask
$modal
$ok
isShow,
id
}
Properties start with $
means it is a HTML element and you could operate it directly. In version 2.0.0, We had exposed all of options on instance but they were useless and unreactive after initialization, thus, they were removed.
header
instead of title
because we are considering changing the DOM structure of top part in modal:div[data-role='header']
|
+--div[data-role='title']
|
+--button[data-role='close']
Obviously, this is more semantic.
Type of header
and body
had been changed to string|HTMLElement
, if you give a string, we will change its innerHTML
, otherwise we'll call append()
to insert coming content.
onOK
and onCancel
will recevie alert instance as first argument.
You could use document.querySelector('gm-alert-' + id)
to get container of alert HTML node.
The
this
below means the instance created byGmAlert()
.
You can toggle alert by change this.isShow
to another truthy value. And you could also judge status of alert with it.
Show alert and change this.isShow
to true
.
Hide alert and change this.isShow
to false
.
Set header content and extra classnames.
header
{ string|HTMLElement }Content of header, it could be a string or a HTML element.
headerClassName
{ string } optionalExtra classnames for header, and if you have extra classname before and headerClassName
is not truthy, we'll not change it.
Set body content and extra classnames.
body
{ string|HTMLElement }Content of body, it could be a string or a HTML element.
bodyClassName
{ string } optionalExtra classnames for body, and if you have extra classname before and bodyClassName
is not truthy, we'll not change it.
Set footer show or not and extra classnames.
showFooter
{ boolean }Show footer or not, it is controlled by dispaly: none
so that it won't influence butons in footer even if footer is not show.
footerClassName
{ string } optionalExtra classnames for footer, and if you have extra classname before and footerClassName
is not truthy, we'll not change it.
Set inner content and click listener of ok button.
okText
{ string }Inner content of ok button, default is ok
.
onOK
{ function } optionalCallback when you click ok button, it will recive alert instance as first argument.
Set body content and extra classnames.
Set inner content and click listener of cancel button.
cancelText
{ string }Inner content of ok button, default is cancel
.
onCancel
{ function } optionalCallback when you click cancel button, it will recive alert instance as first argument. And pay attention that () => this.hide()
will be called before onCancel()
.
To aviod style conflict causing by same classnames, we use data-role
instead of class
:
div.gm-alert-mask
|
+--div[data-role='modal']
|
+--div[data-role='header']
|
+--div[data-role='body']
|
+--div[data-role='footer']
|
+--button[data-role='ok']
|
+--button[data-role='button']
Please visit this.
extend()
to extend alert.MIT
FAQs
javascript alert ui kit
We found that gm-alert demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.