mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-01 15:24:01 +00:00
sorry,rebuild folder structure,cry..
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import React, { PropTypes } from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import styles from './Search.less'
|
||||
import { Input, Select, Button, Icon } from 'antd'
|
||||
|
||||
class Search extends React.Component {
|
||||
state = {
|
||||
clearVisible: false,
|
||||
selectValue: (this.props.select && this.props.selectProps) ? this.props.selectProps.defaultValue : '',
|
||||
}
|
||||
handleSearch = () => {
|
||||
const data = {
|
||||
keyword: ReactDOM.findDOMNode(this.refs.searchInput).value,
|
||||
}
|
||||
if (this.props.select) {
|
||||
data.field = this.state.selectValue
|
||||
}
|
||||
if (this.props.onSearch) this.props.onSearch(data)
|
||||
}
|
||||
handleInputChange = e => {
|
||||
this.setState({
|
||||
...this.state,
|
||||
clearVisible: e.target.value !== '',
|
||||
})
|
||||
}
|
||||
handeleSelectChange = value => {
|
||||
this.setState({
|
||||
...this.state,
|
||||
selectValue: value,
|
||||
})
|
||||
}
|
||||
handleClearInput = () => {
|
||||
ReactDOM.findDOMNode(this.refs.searchInput).value = ''
|
||||
this.setState({
|
||||
clearVisible: false,
|
||||
})
|
||||
this.handleSearch()
|
||||
}
|
||||
render () {
|
||||
const { size, select, selectOptions, selectProps, style, keyword } = this.props
|
||||
const { clearVisible } = this.state
|
||||
return (
|
||||
<Input.Group compact size={size} className={styles.search} style={style}>
|
||||
{select && <Select ref="searchSelect" onChange={this.handeleSelectChange} size={size} {...selectProps}>
|
||||
{selectOptions && selectOptions.map((item, key) => <Select.Option value={item.value} key={key}>{item.name || item.value}</Select.Option>)}
|
||||
</Select>}
|
||||
<Input ref="searchInput" size={size} onChange={this.handleInputChange} onPressEnter={this.handleSearch} defaultValue={keyword} />
|
||||
<Button size={size} type="primary" onClick={this.handleSearch}>搜索</Button>
|
||||
{clearVisible && <Icon type="cross" onClick={this.handleClearInput} />}
|
||||
</Input.Group>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Search.propTypes = {
|
||||
size: PropTypes.string,
|
||||
select: PropTypes.bool,
|
||||
selectProps: PropTypes.object,
|
||||
onSearch: PropTypes.func,
|
||||
selectOptions: PropTypes.array,
|
||||
style: PropTypes.object,
|
||||
keyword: PropTypes.string,
|
||||
}
|
||||
|
||||
export default Search
|
||||
@@ -0,0 +1,55 @@
|
||||
.no-highlight() {
|
||||
border-color: #e5e5e5;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.search {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
|
||||
:global {
|
||||
.anticon-cross {
|
||||
position: absolute;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
right: 84px;
|
||||
cursor: pointer;
|
||||
color: #fff;
|
||||
line-height: 18px;
|
||||
border-radius: 50%!important;
|
||||
background-color: rgba(0, 0, 0, .16);
|
||||
top: 7px;
|
||||
// opacity:
|
||||
}
|
||||
|
||||
.ant-select {
|
||||
width: 80px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
|
||||
&.ant-select-focused .ant-select-selection,
|
||||
&.ant-select-open .ant-select-selection,
|
||||
.ant-select-selection:active,
|
||||
.ant-select-selection:focus,
|
||||
.ant-select-selection:hover {
|
||||
.no-highlight();
|
||||
}
|
||||
}
|
||||
|
||||
.ant-input {
|
||||
&:focus,
|
||||
&:hover {
|
||||
.no-highlight();
|
||||
}
|
||||
flex-shrink: 1;
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.ant-btn {
|
||||
width: 80px;
|
||||
flex-shrink: 0;
|
||||
flex-grow: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "Search",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"main": "./Search.js"
|
||||
}
|
||||
Reference in New Issue
Block a user