zarm-web
Version:
基于 React 的桌面端UI库
92 lines (78 loc) • 2.97 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { Component } from 'react';
import classnames from 'classnames';
import Group from '../input-group';
import Input from '../index'; // @ts-ignore
import Icon from '../../icon';
const Style = {
group: {
alignItems: 'stretch'
}
};
class Search extends Component {
constructor(...args) {
super(...args);
this.onKeyPress = e => {
if (this.props.disabled) return;
if (this.props.onSearch) {
if (e.nativeEvent.keyCode === 13) {
this.props.onSearch(e);
}
}
};
}
render() {
const _this$props = this.props,
{
showIcon,
showButton,
shape,
button,
onSearch,
disabled,
size
} = _this$props,
others = _objectWithoutProperties(_this$props, ["showIcon", "showButton", "shape", "button", "onSearch", "disabled", "size"]);
const cls = classnames({
'ui-search-btn': true,
disabled,
[`shape-${shape}`]: true,
[`size-${size}`]: !!size
});
const addonIcon = {};
if (showIcon) {
addonIcon.addonBefore = {
fillType: 'transparent',
addon: React.createElement(Icon, {
type: "search"
})
};
}
if (!showButton) {
return React.createElement(Input, _extends({
shape: shape
}, others, {
onKeyPress: this.onKeyPress
}, addonIcon));
}
return React.createElement(Group, {
style: Style.group
}, React.createElement(Input, _extends({
shape: shape
}, others, {
onKeyPress: this.onKeyPress
}, addonIcon)), React.createElement("div", {
className: cls,
onClick: disabled ? undefined : onSearch
}, button));
}
}
Search.defaultProps = {
showIcon: true,
button: '搜索',
shape: 'radius',
showButton: true
};
export default Search;