-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1056c48
commit 364ed76
Showing
16 changed files
with
158 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
[](https://badge.fury.io/js/react-multi-email) | ||
[](https://www.npmjs.com/package/react-multi-email) | ||
|
||
# react-multi-email | ||
|
||
A simple react component to format multiple email as the user types. | ||
|
||
- Simple code | ||
- No dependency | ||
- Small size | ||
- Simple customization | ||
|
||
[See Demo](https://codesandbox.io/s/jpvjk8m5o9) | ||
|
||
<img src="https://cdn.rawgit.com/axui/react-multi-email/c3098f94/react-multi-email.gif" /> | ||
|
||
## Installation | ||
|
||
```shell-script | ||
npm install react-multi-email | ||
``` | ||
|
||
## Usage | ||
|
||
```typescript jsx | ||
import * as React from 'react'; | ||
import { ReactMultiEmail, isEmail } from 'react-multi-email'; | ||
import 'react-multi-email/style.css'; | ||
|
||
interface Props {} | ||
|
||
function BasicExample(props: Props) { | ||
const [emails, setEmails] = React.useState<string[]>([]); | ||
const [focused, setFocused] = React.useState(false); | ||
|
||
return ( | ||
<form> | ||
<h3>Email</h3> | ||
<ReactMultiEmail | ||
placeholder='Input your email' | ||
emails={emails} | ||
onChange={(_emails: string[]) => { | ||
setEmails(_emails); | ||
}} | ||
autoFocus={true} | ||
onFocus={() => setFocused(true)} | ||
onBlur={() => setFocused(false)} | ||
getLabel={(email, index, removeEmail) => { | ||
return ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
); | ||
}} | ||
/> | ||
<br /> | ||
<h4>react-multi-email value</h4> | ||
<h3>Focused: {focused ? 'true' : 'false'}</h3> | ||
<p>{emails.join(', ') || 'empty'}</p> | ||
</form> | ||
); | ||
} | ||
|
||
export default BasicExample; | ||
``` | ||
|
||
## License | ||
|
||
[MIT](https://opensource.org/licenses/MIT) | ||
|
||
> If you don't mind, don't forget to press "star" before leaving. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import * as React from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
const BodyRoot = styled.div` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import * as React from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { ReactMultiEmail } from '../react-multi-email'; | ||
|
||
interface Props {} | ||
|
||
function CustomizeStyleExample(props: Props) { | ||
const [emails, setEmails] = React.useState<string[]>([]); | ||
|
||
return ( | ||
<Container> | ||
<form> | ||
<h3>Email</h3> | ||
<ReactMultiEmail | ||
placeholder={ | ||
<> | ||
<b>I</b> am <u style={{ color: '#1890ff' }}>placeholder</u> ! | ||
</> | ||
} | ||
style={{ minHeight: '100px' }} | ||
emails={emails} | ||
onChange={(_emails: string[]) => { | ||
setEmails(_emails); | ||
}} | ||
getLabel={(email, index, removeEmail) => { | ||
return ( | ||
<div data-tag key={index}> | ||
<div data-tag-item>{email}</div> | ||
<span data-tag-handle onClick={() => removeEmail(index)}> | ||
× | ||
</span> | ||
</div> | ||
); | ||
}} | ||
/> | ||
<br /> | ||
<h4>react-multi-email value</h4> | ||
<p>{emails.join(', ') || 'empty'}</p> | ||
</form> | ||
</Container> | ||
); | ||
} | ||
|
||
const Container = styled.div` | ||
font-size: 13px; | ||
`; | ||
|
||
export default CustomizeStyleExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as React from 'react'; | ||
import type { NextPage } from 'next'; | ||
import { Container } from '../components/Layouts'; | ||
import styled from '@emotion/styled'; | ||
import BodyRoot from '../components/BodyRoot'; | ||
import CustomizeStyleExample from '../examples/CustomizeStyleExample'; | ||
|
||
const Custom: NextPage = () => { | ||
return ( | ||
<PageContainer> | ||
<Container> | ||
<div> | ||
<h2>CustomizeStyle</h2> | ||
<CustomizeStyleExample /> | ||
</div> | ||
</Container> | ||
</PageContainer> | ||
); | ||
}; | ||
|
||
const PageContainer = styled(BodyRoot)``; | ||
|
||
export default Custom; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters