Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasJang committed Nov 24, 2022
1 parent 1056c48 commit 364ed76
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 96 deletions.
6 changes: 3 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
/node_modules
/pages
/public
/@axframe-datagrid
/react-multi-email
/styles
/test
/tsconfigs
.eslintrc.json
.eslintignore
.eslintrc.js
.gitignore
.npmignore
.prettierignore
.prettierrc
jest.config.js
next.config.js
next-env.d.ts
package-lock.json
Expand Down
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[![npm version](https://badge.fury.io/js/react-multi-email.svg)](https://badge.fury.io/js/react-multi-email)
[![](https://img.shields.io/npm/dm/react-multi-email.svg)](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.
1 change: 0 additions & 1 deletion components/BodyRoot.tsx
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`
Expand Down
2 changes: 1 addition & 1 deletion components/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GithubFilled } from '@ant-design/icons';

interface Props {}

function Nav(props: Props) {
function Nav(_props: Props) {
const router = useRouter();

return (
Expand Down
13 changes: 0 additions & 13 deletions components/Spinner.css

This file was deleted.

20 changes: 0 additions & 20 deletions components/Spinner.tsx

This file was deleted.

10 changes: 1 addition & 9 deletions examples/BasicExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,11 @@ import { ReactMultiEmail } from '../react-multi-email';
interface Props {}

function BasicExample(props: Props) {
const [width, setWidth] = React.useState(600);
const [emails, setEmails] = React.useState<string[]>([]);
const [focused, setFocused] = React.useState(false);
const containerRef = React.useRef<HTMLDivElement>(null);

React.useEffect(() => {
if (containerRef.current) {
setWidth(containerRef.current.clientWidth);
}
}, []);

return (
<Container ref={containerRef}>
<Container>
<form>
<h3>Email</h3>
<ReactMultiEmail
Expand Down
48 changes: 48 additions & 0 deletions examples/CustomizeStyleExample.tsx
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;
1 change: 1 addition & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import '../styles/globals.css';
import '../react-multi-email/style.css';
import 'antd/dist/antd.css';
Expand Down
1 change: 1 addition & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import { Html, Head, Main, NextScript } from 'next/document';

export default function Document() {
Expand Down
13 changes: 0 additions & 13 deletions pages/api/hello.ts

This file was deleted.

23 changes: 23 additions & 0 deletions pages/customizeStyle.tsx
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;
1 change: 1 addition & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import type { NextPage } from 'next';
import { Container } from '../components/Layouts';
import styled from '@emotion/styled';
Expand Down
30 changes: 2 additions & 28 deletions react-multi-email/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
border-radius: 0.28571429rem;
-webkit-transition: box-shadow 0.1s ease, border-color 0.1s ease;
transition: box-shadow 0.1s ease, border-color 0.1s ease;
font-size: 13px;
position: relative;
display: flex;
flex-wrap: wrap;
Expand Down Expand Up @@ -44,7 +43,6 @@
}

.react-multi-email > input {
width: 100% !important;
flex: 1;
width: auto !important;
outline: none !important;
Expand All @@ -61,7 +59,7 @@
margin: 0.14285714em;
background-color: #f3f3f3;
background-image: none;
padding: 0.5833em 0.833em;
padding: 0.4em 0.8em;
color: rgba(0, 0, 0, 0.6);
text-transform: none;
font-weight: 600;
Expand All @@ -75,8 +73,8 @@
align-items: center;
justify-content: flex-start;
max-width: 100%;

}

.react-multi-email [data-tag] [data-tag-item] {
max-width: 100%;
overflow: hidden;
Expand All @@ -88,27 +86,3 @@
margin-left: 0.833em;
cursor: pointer;
}
ul{
list-style: none;
padding: 0;
}
.result_list.empty {
display: none;
}
.options{
vertical-align: baseline;
margin: 0 0.14285714em;
margin-top: 0.2em;
background-color: #f3f3f3;
background-image: none;
padding: 0.5833em 0.833em;
color: rgba(0, 0, 0, 0.6);
text-transform: none;
font-weight: 600;
border: 0 solid transparent;
border-radius: 0.28571429rem;
-webkit-transition: background 0.1s ease;
-o-transition: background 0.1s ease;
transition: background 0.1s ease;
font-size: 0.8rem;
}
2 changes: 1 addition & 1 deletion tsconfigs/tsconfig.es5.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"jsxImportSource": ""
},
"include": [
"../@axframe-datagrid/**/*"
"../react-multi-email/**/*"
],
"exclude": [
"node_modules",
Expand Down
9 changes: 2 additions & 7 deletions tsconfigs/tsconfig.es6.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
"jsx": "react",
"jsxImportSource": ""
},
"include": [
"../@axframe-datagrid/**/*"
],
"exclude": [
"node_modules",
"**/tree.ts"
]
"include": ["../react-multi-email/**/*"],
"exclude": ["node_modules", "**/tree.ts"]
}

0 comments on commit 364ed76

Please sign in to comment.