Skip to main content

ew-message

NPM version npm npm GitHub stars GitHub stars

A message plugin encapsulated based on typescript.

Installation and Usage​

Installation​

npm install ew-message
# or
yarn add ew-message

@ew-color-picker/utils is a peer dependency; npm 7+ / pnpm 8+ installs it automatically.

Import​

import ewMessage from 'ew-message';
// styles are explicit
import 'ew-message/style.css';

CDN is also supported (the UMD build bundles @ew-color-picker/utils, so a single file is enough, which keeps historical usage working):

<link rel="stylesheet" href="https://www.unpkg.com/ew-message/dist/ew-message.min.css" />
<script src="https://www.unpkg.com/ew-message/dist/ew-message.min.js"></script>

If @ew-color-picker/utils is already loaded on the page, use the slim ew-message.external.min.js (no duplicate code) and load its UMD script first (global Utils):

<script src="https://www.unpkg.com/@ew-color-picker/utils/dist/utils.min.js"></script>
<script src="https://www.unpkg.com/ew-message/dist/ew-message.external.min.js"></script>

Basic usage​

const msg1 = ewMessage('the default message');
const msg2 = ewMessage({
content: 'the default message',
type: 'success'
});
// shorthand
ewMessage.success('success');
ewMessage.error({ content: 'failed', position: 'top-right' });

Options​

interface ewMessageOption {
content?: string | Node;
center?: boolean;
type?: 'info' | 'success' | 'warning' | 'error' | 'loading';
duration?: number;
showClose?: boolean;
showTypeIcon?: boolean;
typeIcon?: string;
closeIcon?: string;
container?: string | HTMLElement;
removeClassName?: string[];
startClassName?: string[];
top?: number | string;
html?: boolean;
position?: 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right';
offset?: number | string;
gap?: number;
maxCount?: number;
zIndex?: number;
maxDuration?: number;
clickToClose?: boolean;
pauseOnHover?: boolean;
prefix?: string;
onShow?: (info: { type: string; content: string | Node }) => void;
onClose?: (info: {
type: string;
content: string | Node;
reason: 'timeout' | 'manual' | 'destroy' | 'maxCount';
}) => void;
}

See the parameter api for the full option reference.

Update log​

Please refer to the changelog.