2.0.3 • Published 10 months ago

antd-notifications-messages v2.0.3

Weekly downloads
8
License
MIT
Repository
github
Last release
10 months ago

antd-notifications-messages

NOTE: This package working with React 18. If you used a version 16.x or 17.x, install antd-notifications-messages@1.5.6.

Obtain a behavior equal to the notifications and messages found in the great Ant-Design library, credit for this libraries. demo here

Why to use?

Sometimes you probably have a mini project or you just don't need to install the whole antd package to simply use notifications or messages.

How to install

Install from:

  • npm install antd-notifications-messages

or

  • yarn add antd-notifications-messages

for React 16.x and 17.x.

  • npm install antd-notifications-messages@1.5.6

or

  • yarn add antd-notifications-messages@1.5.6

How to use:

import css in first file to project

index.js

import 'antd-notifications-messages/lib/styles/style.css';

Now use the API.

Notifications

import { notification } from 'antd-notifications-messages';

function App() {
  const show = (type) => {
    notification({
      type,
      title: 'This is a Title',
      message: `This is a notification type ${type}`
    });
  };

  return (
    <div>
      <button onClick={() => show('success')}>Success</button>
      <button onClick={() => show('info')}>Info</button>
      <button onClick={() => show('warning')}>Warning</button>
      <button onClick={() => show('error')}>Error</button>
    </div>
  );
}

Message

import { message } from 'antd-notifications-messages';

function App() {
  const show = (type) => {
    message({
      type,
      message: `This is a notification type ${type}`
    });
  };

  return (
    <div>
      <button onClick={() => show('success')}>Success</button>
      <button onClick={() => show('info')}>Info</button>
      <button onClick={() => show('warning')}>Warning</button>
      <button onClick={() => show('error')}>Error</button>
    </div>
  );
}

Custom render

For more api props definition Message Render Props or Notification Render Props

import { message, notification } from 'antd-notifications-messages';

function App() {
  const showMessage = (type) => {
    message({
      type,
      message: 'The custom Render',
      render: ({ message, style, className, icon }) => {
        return (
          <div style={{ ...style, background: 'black' }} className={className}>
            <p style={{ color: 'white', display: 'flex' }}>
              <span>{icon}</span>
              <b> {message}</b>
            </p>
          </div>
        );
      }
    });
  };

  const showNotification = (type) => {
    notification({
      type,
      title: 'The title',
      message: 'The custom Render',
      render: ({ message, style, className, icon, title }) => {
        return (
          <div style={{ ...style, background: 'black' }} className={className}>
            <h5 style={{ color: 'white' }}>
              <span>{icon}</span> {title}
            </h5>
            <p style={{ color: 'white' }}>
              <b>{message}</b>
            </p>
          </div>
        );
      }
    });
  };

  return (
    <div>
      <button onClick={() => showMessage('success')}>Message custom</button>
      <button onClick={() => showNotification('info')}>
        Notification custom
      </button>
    </div>
  );
}

Notification Props

proptypedefaultdescription
titlestring""Required. Title of notification
messagestring""Required. Message of notification
typeenum"success"Optional. defines the type of notification. "success", "info", "warning", "error"
positionenum"topRight"Optional. defines the position of notification. "topRight", "topLeft", "topCenter", "bottomRight", "bottomLeft", "bottomCenter"
durationnumber7000Optional. Defines the time that the notification will be active on the screen

Message Props

proptypedefaultdescription
messagestring""Required. Message of notification
typeenum"success"Optional. defines the type of notification. "success", "info", "warning", "error"
positionenum"topCenter"Optional. defines the position of notification. "topRight", "topLeft", "topCenter", "bottomRight", "bottomLeft", "bottomCenter"
durationnumber7000Optional. Defines the time that the notification will be active on the screen
keynumber or string-Optional. Message key, useful to update the message.

Notification Render

const render = ({
  title,
  message,
  icon,
  type,
  id,
  onRemove,
  className,
  style,
  onClick
}) => {
  return (
    <div style={style} className={className} onClick={onClick}>
      <h5>{title}</h5>
      <p>{message}</p>
    </div>
  );
};

Message Render

const render = ({
  message,
  icon,
  type,
  id,
  onRemove,
  className,
  style,
  closable,
  onClick
}) => {
  return (
    <div style={style} className={className} onClick={onClick}>
      <p>{message}</p>
    </div>
  );
};

Credits

Portfolio

Linkedin

Create with Love ❤️ by Kevin Rivas.

2.0.3

10 months ago

2.0.2

12 months ago

2.0.1

12 months ago

2.0.0

2 years ago

1.5.5

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.9

2 years ago

1.5.6

2 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.9

3 years ago

1.3.8

3 years ago

1.3.7

3 years ago

1.3.6

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.0.0

3 years ago