UNPKG

aurora-topu

Version:
63 lines (62 loc) 2.94 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React from 'react'; import classNames from 'classnames'; import './_style.scss'; import AuroraIcon from '../AuroraIcon/AuroraIcon'; export var AuroraInput = function (props) { var _a; var disabled = props.disabled, size = props.size, icon = props.icon, prepend = props.prepend, value = props.value, append = props.append, style = props.style, restProps = __rest(props, ["disabled", "size", "icon", "prepend", "value", "append", "style"]); // 根据属性判断className var classes = classNames('viking-input-wrapper', (_a = {}, _a["input-size-".concat(size)] = size, _a['is-disabled'] = disabled, _a['input-group'] = prepend || append, _a['input-group-prepend'] = !!prepend, _a['input-group-append'] = !!append, _a)); // 让input中始终保持有值,避免出现undefined和null的情况出现 var fixControlledValue = function (value) { if (typeof value === 'undefined' || value === null) { return ''; } else { return value; } }; // 如果用户传递了value,就将原来的value经过处理换掉,防止出现undefined和null的情况出现 if ('value' in restProps) { delete restProps.defaultValue; restProps.value = fixControlledValue(restProps.value); } return (React.createElement("div", { className: classes, style: style }, prepend && React.createElement("div", { className: "viking-input-group-prepend" }, prepend), icon && (React.createElement("div", { className: "icon-wrapper" }, React.createElement(AuroraIcon, { icon: icon, title: "title-".concat(icon) }))), React.createElement("input", __assign({ className: "viking-input-inner", disabled: disabled }, restProps, { value: value })), append && React.createElement("div", { className: "viking-input-group-append" }, append))); }; AuroraInput.defaultProps = { style: { width: 300 }, }; export default AuroraInput;