1 | function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
2 |
|
3 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
4 |
|
5 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
6 |
|
7 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
8 |
|
9 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
10 |
|
11 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
12 |
|
13 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
14 |
|
15 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
16 |
|
17 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
18 |
|
19 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
20 |
|
21 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
22 |
|
23 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
24 |
|
25 | import * as React from 'react';
|
26 | import classNames from 'classnames';
|
27 | import CloseCircleFilled from '@ant-design/icons/CloseCircleFilled';
|
28 | import { tuple } from '../_util/type';
|
29 | import { getInputClassName } from './Input';
|
30 | import { cloneElement } from '../_util/reactNode';
|
31 | var ClearableInputType = tuple('text', 'input');
|
32 | export function hasPrefixSuffix(props) {
|
33 | return !!(props.prefix || props.suffix || props.allowClear);
|
34 | }
|
35 |
|
36 | var ClearableLabeledInput = function (_React$Component) {
|
37 | _inherits(ClearableLabeledInput, _React$Component);
|
38 |
|
39 | var _super = _createSuper(ClearableLabeledInput);
|
40 |
|
41 | function ClearableLabeledInput() {
|
42 | var _this;
|
43 |
|
44 | _classCallCheck(this, ClearableLabeledInput);
|
45 |
|
46 | _this = _super.apply(this, arguments);
|
47 |
|
48 |
|
49 | _this.containerRef = React.createRef();
|
50 |
|
51 | _this.onInputMouseUp = function (e) {
|
52 | var _a;
|
53 |
|
54 | if ((_a = _this.containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target)) {
|
55 | var triggerFocus = _this.props.triggerFocus;
|
56 | triggerFocus();
|
57 | }
|
58 | };
|
59 |
|
60 | return _this;
|
61 | }
|
62 |
|
63 | _createClass(ClearableLabeledInput, [{
|
64 | key: "renderClearIcon",
|
65 | value: function renderClearIcon(prefixCls) {
|
66 | var _this$props = this.props,
|
67 | allowClear = _this$props.allowClear,
|
68 | value = _this$props.value,
|
69 | disabled = _this$props.disabled,
|
70 | readOnly = _this$props.readOnly,
|
71 | inputType = _this$props.inputType,
|
72 | handleReset = _this$props.handleReset;
|
73 |
|
74 | if (!allowClear) {
|
75 | return null;
|
76 | }
|
77 |
|
78 | var needClear = !disabled && !readOnly && value;
|
79 | var className = inputType === ClearableInputType[0] ? "".concat(prefixCls, "-textarea-clear-icon") : "".concat(prefixCls, "-clear-icon");
|
80 | return React.createElement(CloseCircleFilled, {
|
81 | onClick: handleReset,
|
82 | className: classNames(className, _defineProperty({}, "".concat(className, "-hidden"), !needClear)),
|
83 | role: "button"
|
84 | });
|
85 | }
|
86 | }, {
|
87 | key: "renderSuffix",
|
88 | value: function renderSuffix(prefixCls) {
|
89 | var _this$props2 = this.props,
|
90 | suffix = _this$props2.suffix,
|
91 | allowClear = _this$props2.allowClear;
|
92 |
|
93 | if (suffix || allowClear) {
|
94 | return React.createElement("span", {
|
95 | className: "".concat(prefixCls, "-suffix")
|
96 | }, this.renderClearIcon(prefixCls), suffix);
|
97 | }
|
98 |
|
99 | return null;
|
100 | }
|
101 | }, {
|
102 | key: "renderLabeledIcon",
|
103 | value: function renderLabeledIcon(prefixCls, element) {
|
104 | var _classNames2;
|
105 |
|
106 | var _this$props3 = this.props,
|
107 | focused = _this$props3.focused,
|
108 | value = _this$props3.value,
|
109 | prefix = _this$props3.prefix,
|
110 | className = _this$props3.className,
|
111 | size = _this$props3.size,
|
112 | suffix = _this$props3.suffix,
|
113 | disabled = _this$props3.disabled,
|
114 | allowClear = _this$props3.allowClear,
|
115 | direction = _this$props3.direction,
|
116 | style = _this$props3.style,
|
117 | readOnly = _this$props3.readOnly;
|
118 | var suffixNode = this.renderSuffix(prefixCls);
|
119 |
|
120 | if (!hasPrefixSuffix(this.props)) {
|
121 | return cloneElement(element, {
|
122 | value: value
|
123 | });
|
124 | }
|
125 |
|
126 | var prefixNode = prefix ? React.createElement("span", {
|
127 | className: "".concat(prefixCls, "-prefix")
|
128 | }, prefix) : null;
|
129 | var affixWrapperCls = classNames(className, "".concat(prefixCls, "-affix-wrapper"), (_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-affix-wrapper-focused"), focused), _defineProperty(_classNames2, "".concat(prefixCls, "-affix-wrapper-disabled"), disabled), _defineProperty(_classNames2, "".concat(prefixCls, "-affix-wrapper-sm"), size === 'small'), _defineProperty(_classNames2, "".concat(prefixCls, "-affix-wrapper-lg"), size === 'large'), _defineProperty(_classNames2, "".concat(prefixCls, "-affix-wrapper-input-with-clear-btn"), suffix && allowClear && value), _defineProperty(_classNames2, "".concat(prefixCls, "-affix-wrapper-rtl"), direction === 'rtl'), _defineProperty(_classNames2, "".concat(prefixCls, "-affix-wrapper-readonly"), readOnly), _classNames2));
|
130 | return React.createElement("span", {
|
131 | ref: this.containerRef,
|
132 | className: affixWrapperCls,
|
133 | style: style,
|
134 | onMouseUp: this.onInputMouseUp
|
135 | }, prefixNode, cloneElement(element, {
|
136 | style: null,
|
137 | value: value,
|
138 | className: getInputClassName(prefixCls, size, disabled)
|
139 | }), suffixNode);
|
140 | }
|
141 | }, {
|
142 | key: "renderInputWithLabel",
|
143 | value: function renderInputWithLabel(prefixCls, labeledElement) {
|
144 | var _classNames3, _classNames4;
|
145 |
|
146 | var _this$props4 = this.props,
|
147 | addonBefore = _this$props4.addonBefore,
|
148 | addonAfter = _this$props4.addonAfter,
|
149 | style = _this$props4.style,
|
150 | size = _this$props4.size,
|
151 | className = _this$props4.className,
|
152 | direction = _this$props4.direction;
|
153 |
|
154 | if (!addonBefore && !addonAfter) {
|
155 | return labeledElement;
|
156 | }
|
157 |
|
158 | var wrapperClassName = "".concat(prefixCls, "-group");
|
159 | var addonClassName = "".concat(wrapperClassName, "-addon");
|
160 | var addonBeforeNode = addonBefore ? React.createElement("span", {
|
161 | className: addonClassName
|
162 | }, addonBefore) : null;
|
163 | var addonAfterNode = addonAfter ? React.createElement("span", {
|
164 | className: addonClassName
|
165 | }, addonAfter) : null;
|
166 | var mergedWrapperClassName = classNames("".concat(prefixCls, "-wrapper"), (_classNames3 = {}, _defineProperty(_classNames3, wrapperClassName, addonBefore || addonAfter), _defineProperty(_classNames3, "".concat(wrapperClassName, "-rtl"), direction === 'rtl'), _classNames3));
|
167 | var mergedGroupClassName = classNames(className, "".concat(prefixCls, "-group-wrapper"), (_classNames4 = {}, _defineProperty(_classNames4, "".concat(prefixCls, "-group-wrapper-sm"), size === 'small'), _defineProperty(_classNames4, "".concat(prefixCls, "-group-wrapper-lg"), size === 'large'), _defineProperty(_classNames4, "".concat(prefixCls, "-group-wrapper-rtl"), direction === 'rtl'), _classNames4));
|
168 |
|
169 |
|
170 | return React.createElement("span", {
|
171 | className: mergedGroupClassName,
|
172 | style: style
|
173 | }, React.createElement("span", {
|
174 | className: mergedWrapperClassName
|
175 | }, addonBeforeNode, cloneElement(labeledElement, {
|
176 | style: null
|
177 | }), addonAfterNode));
|
178 | }
|
179 | }, {
|
180 | key: "renderTextAreaWithClearIcon",
|
181 | value: function renderTextAreaWithClearIcon(prefixCls, element) {
|
182 | var _this$props5 = this.props,
|
183 | value = _this$props5.value,
|
184 | allowClear = _this$props5.allowClear,
|
185 | className = _this$props5.className,
|
186 | style = _this$props5.style,
|
187 | direction = _this$props5.direction;
|
188 |
|
189 | if (!allowClear) {
|
190 | return cloneElement(element, {
|
191 | value: value
|
192 | });
|
193 | }
|
194 |
|
195 | var affixWrapperCls = classNames(className, "".concat(prefixCls, "-affix-wrapper"), _defineProperty({}, "".concat(prefixCls, "-affix-wrapper-rtl"), direction === 'rtl'), "".concat(prefixCls, "-affix-wrapper-textarea-with-clear-btn"));
|
196 | return React.createElement("span", {
|
197 | className: affixWrapperCls,
|
198 | style: style
|
199 | }, cloneElement(element, {
|
200 | style: null,
|
201 | value: value
|
202 | }), this.renderClearIcon(prefixCls));
|
203 | }
|
204 | }, {
|
205 | key: "render",
|
206 | value: function render() {
|
207 | var _this$props6 = this.props,
|
208 | prefixCls = _this$props6.prefixCls,
|
209 | inputType = _this$props6.inputType,
|
210 | element = _this$props6.element;
|
211 |
|
212 | if (inputType === ClearableInputType[0]) {
|
213 | return this.renderTextAreaWithClearIcon(prefixCls, element);
|
214 | }
|
215 |
|
216 | return this.renderInputWithLabel(prefixCls, this.renderLabeledIcon(prefixCls, element));
|
217 | }
|
218 | }]);
|
219 |
|
220 | return ClearableLabeledInput;
|
221 | }(React.Component);
|
222 |
|
223 | export default ClearableLabeledInput; |
\ | No newline at end of file |