Skip to content

:octocat: A simple react component to format multiple email as the user types.

License

Notifications You must be signed in to change notification settings

tooltime2019/react-multi-email

 
 

Repository files navigation

react-multi-email

A simple react component to format multiple email as the user types.

Development

Install with npm install

Run locally with nmp start, and make changes in the src directory. Review your changes on http://localhost:3000

Releasing a new version

Make your changes and run npm run publish:patch or npm run publish:minor - this will automatically build, increment the version and publish the dist folder.

Installation

npm install @tooltime2019/react-multi-email -S

Usage

import * as React from 'react';
import { ReactMultiEmail, isEmail } from '@tooltime2019/react-multi-email';
import '@tooltime2019/react-multi-email/style.css';

interface IProps {}
interface IState {
  emails: string[];
}
class Basic extends React.Component<IProps, IState> {
  state = {
    emails: [],
  };

  render() {
    const { emails } = this.state;

    return (
      <>
        <h3>Email</h3>
        <ReactMultiEmail
          placeholder="placeholder"
          emails={emails}
          onChange={(_emails: string[]) => {
            this.setState({ emails: _emails });
          }}
          validateEmail={email => {
            return isEmail(email); // return boolean
          }}
          getLabel={(
            email: string,
            index: number,
            removeEmail: (index: number) => void,
          ) => {
            return (
              <div data-tag key={index}>
                {email}
                <span data-tag-handle onClick={() => removeEmail(index)}>
                  ×
                </span>
              </div>
            );
          }}
        />
        <br />
        <h4>react-multi-email value</h4>
        <p>{emails.join(', ') || 'empty'}</p>
      </>
    );
  }
}

export default Basic;

License

MIT

About

:octocat: A simple react component to format multiple email as the user types.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 47.3%
  • Less 37.6%
  • CSS 5.5%
  • JavaScript 4.9%
  • HTML 4.7%