-
Notifications
You must be signed in to change notification settings - Fork 93
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
Showing
9 changed files
with
78 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { Component } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { AutoComplete } from 'antd' | ||
|
||
class InputAutoComplete extends Component { | ||
static propTypes = { | ||
value: PropTypes.string, | ||
placeholder: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
dataSource: PropTypes.array, | ||
onChange: PropTypes.func, | ||
} | ||
|
||
static defaultProps = { | ||
disabled: false, | ||
placeholder: '请输入邮箱', | ||
dataSource: ['newband.com', '163.com', 'qq.com', 'sina.com'], | ||
} | ||
|
||
state = { | ||
value: '', | ||
dataSource: [], | ||
} | ||
|
||
componentWillReceiveProps (nextProps) { | ||
// Should be a controlled component. | ||
if ('value' in nextProps) { | ||
const value = nextProps.value | ||
let dataSource | ||
if (!value || value.indexOf('@') >= 0) { | ||
dataSource = [] | ||
} else { | ||
dataSource = nextProps.dataSource.map(domain => `${value}@${domain}`) | ||
} | ||
this.setState({ value, dataSource }) | ||
} | ||
} | ||
|
||
handleChange = (value) => { | ||
if (!('value' in this.props)) { | ||
this.setState({ value }) | ||
} | ||
const onChange = this.props.onChange | ||
if (onChange) { | ||
onChange(value) | ||
} | ||
} | ||
|
||
render () { | ||
const { placeholder, disabled } = this.props | ||
const { value, dataSource } = this.state | ||
|
||
return ( | ||
<AutoComplete | ||
backfill | ||
dataSource={dataSource} | ||
onChange={this.handleChange} | ||
placeholder={placeholder} | ||
value={value} | ||
disabled={disabled} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default InputAutoComplete |
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 @@ | ||
export InputAutoComplete from './InputAutoComplete' |
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,6 @@ | ||
{ | ||
"name": "InputAutoComplete", | ||
"version": "0.0.1", | ||
"private": true, | ||
"main": "./InputAutoComplete.js" | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export DataTable from './DataTable' | ||
export DropMenu from './DropMenu' | ||
export InputEmail from './InputEmail' | ||
export InputAutoComplete from './InputAutoComplete' | ||
export MediaPlayer from './MediaPlayer' | ||
export SearchGroup from './Search' | ||
export UploadFile from './UploadFile' |
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