3.0.0 • Published 6 years ago

cf-component-notifications v3.0.0

Weekly downloads
78
License
BSD-3-Clause
Repository
-
Last release
6 years ago

cf-component-notifications

Cloudflare Notifications Component

Installation

Installation with yarn is recommended

$ yarn add cf-component-notifications

Usage

import React from 'react';
import {
  NotificationList,
  Notification,
  NotificationGlobalContainer
} from 'cf-component-notifications';
import { Button } from 'cf-component-button';

let UNIQUE_ID = 0;

class NofiticationsComponent extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      notifications: []
    };
  }

  handleAdd(type, persist, delay) {
    const id = UNIQUE_ID++;

    this.setState({
      notifications: this.state.notifications.concat({
        id: id,
        type: type,
        message: 'Item ' + id,
        persist: persist,
        delay: delay
      })
    });
  }

  handleClear() {
    this.setState({
      notifications: []
    });
  }

  handleClose(id) {
    this.setState({
      notifications: this.state.notifications.filter(n => n.id !== id)
    });
  }

  render() {
    const notifications = this.state.notifications
      .map(n => {
        return (
          <Notification
            key={n.id}
            type={n.type}
            message={n.message}
            persist={n.persist}
            delay={n.delay}
            onClose={this.handleClose.bind(this, n.id)}
          />
        );
      })
      .reverse();

    return (
      <div>
        <Button
          type="danger"
          onClick={this.handleAdd.bind(this, 'error', false, 4000)}
        >
          Add Error Notification
        </Button>
        <Button
          type="warning"
          onClick={this.handleAdd.bind(this, 'warning', false, 4000)}
        >
          Add Warning Notification
        </Button>
        <Button
          type="success"
          onClick={this.handleAdd.bind(this, 'success', false, 4000)}
        >
          Add Success Notification
        </Button>
        <Button
          type="primary"
          onClick={this.handleAdd.bind(this, 'info', false, 4000)}
        >
          Add Info Notification
        </Button>

        <Button
          type="primary"
          onClick={this.handleAdd.bind(this, 'info', false, 10000)}
        >
          Add 10000ms Notification
        </Button>
        <Button
          type="primary"
          onClick={this.handleAdd.bind(this, 'info', true, null)}
        >
          Add Persistant Notification
        </Button>

        <Button type="default" onClick={this.handleClear.bind(this)}>
          Clear Notifications
        </Button>

        <p>
          {`NOTE: When passing a key to <Notification/> above, note that this must be a unique id that does not change in between renders. Do not use the index of the map function.`}
        </p>

        <NotificationGlobalContainer>
          <NotificationList>{notifications}</NotificationList>
        </NotificationGlobalContainer>
      </div>
    );
  }
}

export default NofiticationsComponent;
3.0.0

6 years ago

2.3.45

6 years ago

2.3.44

6 years ago

2.3.43

6 years ago

2.3.42

6 years ago

2.3.41

6 years ago

2.3.40

6 years ago

2.3.39

6 years ago

2.3.38

6 years ago

2.3.37

6 years ago

2.3.36

6 years ago

2.3.35

6 years ago

2.3.34

6 years ago

2.3.33

6 years ago

2.3.32

6 years ago

2.3.31

6 years ago

2.3.30

6 years ago

2.3.29

6 years ago

2.3.28

6 years ago

2.3.27

6 years ago

2.3.26

6 years ago

2.3.25

6 years ago

2.3.24

6 years ago

2.3.23

6 years ago

2.3.22

6 years ago

2.3.21

6 years ago

2.3.20

6 years ago

2.3.19

6 years ago

2.3.18

6 years ago

2.3.17

6 years ago

2.3.16

6 years ago

2.3.15

6 years ago

2.3.14

6 years ago

2.3.13

7 years ago

2.3.12

7 years ago

2.3.11

7 years ago

2.3.10

7 years ago

2.3.9

7 years ago

2.3.8

7 years ago

2.3.7

7 years ago

2.3.6

7 years ago

2.3.5

7 years ago

2.3.4

7 years ago

2.3.3

7 years ago

2.3.2

7 years ago

2.3.1

7 years ago

2.3.0

7 years ago

2.2.3

7 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago