@semcore/inline-input 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +0 -0
- package/lib/cjs/InlineInput.js +488 -0
- package/lib/cjs/InlineInput.js.map +1 -0
- package/lib/cjs/index.js +14 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/style/inline-input.shadow.css +150 -0
- package/lib/es6/InlineInput.js +475 -0
- package/lib/es6/InlineInput.js.map +1 -0
- package/lib/es6/index.js +3 -0
- package/lib/es6/index.js.map +1 -0
- package/lib/es6/style/inline-input.shadow.css +150 -0
- package/lib/types/index.d.ts +199 -0
- package/package.json +40 -0
- package/src/InlineInput.tsx +387 -0
- package/src/index.d.ts +199 -0
- package/src/index.ts +2 -0
- package/src/style/inline-input.shadow.css +150 -0
- package/yarn-error.log +21221 -0
package/CHANGELOG.md
ADDED
package/README.md
ADDED
|
File without changes
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports["default"] = void 0;
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
|
|
16
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
|
+
|
|
18
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
+
|
|
20
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
|
+
|
|
22
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
|
+
|
|
24
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
+
|
|
26
|
+
var _core = _interopRequireWildcard(require("@semcore/core"));
|
|
27
|
+
|
|
28
|
+
var _react = _interopRequireDefault(require("react"));
|
|
29
|
+
|
|
30
|
+
var _flexBox = require("@semcore/flex-box");
|
|
31
|
+
|
|
32
|
+
var _autoFocusEnhance = _interopRequireDefault(require("@semcore/utils/lib/enhances/autoFocusEnhance"));
|
|
33
|
+
|
|
34
|
+
var _tooltip = _interopRequireDefault(require("@semcore/tooltip"));
|
|
35
|
+
|
|
36
|
+
var _m = _interopRequireDefault(require("@semcore/icon/Check/m"));
|
|
37
|
+
|
|
38
|
+
var _m2 = _interopRequireDefault(require("@semcore/icon/Close/m"));
|
|
39
|
+
|
|
40
|
+
var _spin = _interopRequireDefault(require("@semcore/spin"));
|
|
41
|
+
|
|
42
|
+
var _this3 = void 0;
|
|
43
|
+
|
|
44
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
45
|
+
|
|
46
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
47
|
+
|
|
48
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
49
|
+
|
|
50
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
51
|
+
|
|
52
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
53
|
+
|
|
54
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
55
|
+
|
|
56
|
+
/*__reshadow-styles__:"./style/inline-input.shadow.css"*/
|
|
57
|
+
var style = (
|
|
58
|
+
/*__reshadow_css_start__*/
|
|
59
|
+
_core.sstyled.insert(
|
|
60
|
+
/*__inner_css_start__*/
|
|
61
|
+
".___SInlineInput_1yp60_gg_{display:inline-flex;width:100%;height:100%;align-items:center;position:relative;z-index:0;vertical-align:middle;padding:1px;box-sizing:border-box;background-color:#fff}.___SControls_1yp60_gg_{display:flex;flex-direction:row;flex-shrink:0}.___SConfirmControl_1yp60_gg_{color:#00c192;cursor:pointer}.___SConfirmControl_1yp60_gg_:hover{color:#009f81}.___SCancelControl_1yp60_gg_{color:#a9abb6;cursor:pointer}.___SCancelControl_1yp60_gg_:hover{color:#8a8e9b}.___SValue_1yp60_gg_{min-width:0;width:100%;height:100%;padding:0 4px;border:none;box-sizing:border-box;color:#333333;font-size:inherit;line-height:1.2;text-overflow:ellipsis;font-family:inherit;background:transparent;min-height:1em}.___SValue_1yp60_gg_:focus{outline:none}.___SValue_1yp60_gg_::placeholder{color:#aaaaaa}.___SValue_1yp60_gg_.__disabled_1yp60_gg_,.___SValue_1yp60_gg_.__loading_1yp60_gg_{opacity:0.3}.___SValue_1yp60_gg_.__disabled_1yp60_gg_{user-select:none}.___SValue_1yp60_gg_.__disabled_1yp60_gg_~.___SUnderline_1yp60_gg_{cursor:default;pointer-events:none}.___SUnderline_1yp60_gg_{display:flex;flex-direction:row;align-items:center;flex-grow:1;width:100%;height:100%;min-height:1em;border:1px solid transparent;border-bottom:1px solid #c4c7cf}.___SAddon_1yp60_gg_{display:inline-flex;justify-content:center;align-items:center;flex:0 0 auto;height:100%;color:#a9abb6;padding:0 4px}.___SAddon_1yp60_gg_.__disabled_1yp60_gg_{opacity:0.3;cursor:default;pointer-events:none}.___SInlineInput_1yp60_gg_.__focused_1yp60_gg_{z-index:1}.___SInlineInput_1yp60_gg_.__focused_1yp60_gg_ .___SUnderline_1yp60_gg_{border-color:#008ff8;box-shadow:0 0 0 3px rgba(43, 148, 225, 0.3)}.___SInlineInput_1yp60_gg_._state_valid_1yp60_gg_ .___SUnderline_1yp60_gg_{border-color:#59ddaa}.___SInlineInput_1yp60_gg_._state_valid_1yp60_gg_.__focused_1yp60_gg_ .___SUnderline_1yp60_gg_{border-color:#009f81;box-shadow:0px 0px 0px 3px color-mod(var(--green-400_1aotv0j), a(20%))}.___SInlineInput_1yp60_gg_._state_invalid_1yp60_gg_ .___SUnderline_1yp60_gg_{border-color:#ffaeb5}.___SInlineInput_1yp60_gg_._state_invalid_1yp60_gg_.__focused_1yp60_gg_ .___SUnderline_1yp60_gg_{border-color:#ff4953;box-shadow:0px 0px 0px 3px color-mod(var(--red-400_1aotv0j), a(20%))}.___SInlineInput_1yp60_gg_.__loading_1yp60_gg_,.___SInlineInput_1yp60_gg_._state_disabled_1yp60_gg_{cursor:default}.___CloseM_1yp60_gg_.__disabled_1yp60_gg_{cursor:default;opacity:0.3}.controls-icon{display:flex;align-items:center}.spin{min-width:16px;cursor:default}"
|
|
62
|
+
/*__inner_css_end__*/
|
|
63
|
+
, "1aotv0j_gg_")
|
|
64
|
+
/*__reshadow_css_end__*/
|
|
65
|
+
, {
|
|
66
|
+
"__SInlineInput": "___SInlineInput_1yp60_gg_",
|
|
67
|
+
"__SControls": "___SControls_1yp60_gg_",
|
|
68
|
+
"__SConfirmControl": "___SConfirmControl_1yp60_gg_",
|
|
69
|
+
"__SCancelControl": "___SCancelControl_1yp60_gg_",
|
|
70
|
+
"__SValue": "___SValue_1yp60_gg_",
|
|
71
|
+
"_disabled": "__disabled_1yp60_gg_",
|
|
72
|
+
"_loading": "__loading_1yp60_gg_",
|
|
73
|
+
"__SUnderline": "___SUnderline_1yp60_gg_",
|
|
74
|
+
"__SAddon": "___SAddon_1yp60_gg_",
|
|
75
|
+
"_focused": "__focused_1yp60_gg_",
|
|
76
|
+
"_state_valid": "_state_valid_1yp60_gg_",
|
|
77
|
+
"--green-400": "--green-400_1aotv0j",
|
|
78
|
+
"_state_invalid": "_state_invalid_1yp60_gg_",
|
|
79
|
+
"--red-400": "--red-400_1aotv0j",
|
|
80
|
+
"_state_disabled": "_state_disabled_1yp60_gg_",
|
|
81
|
+
"__CloseM": "___CloseM_1yp60_gg_"
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
var isFocusOutsideOf = function isFocusOutsideOf(element) {
|
|
85
|
+
var traversed = document.activeElement;
|
|
86
|
+
|
|
87
|
+
for (var i = 0; i < 1000000; i++) {
|
|
88
|
+
if (traversed === element) return false;
|
|
89
|
+
if (traversed === document.body) return true;
|
|
90
|
+
traversed = traversed.parentElement;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
throw new Error('Failed to traverse parents chain in utilite `isFocusOutsideOf` reasonable count of iterations. Possibly Shadow DOM or come other uncommon DOM-way is used, that is not supported by utilite yet. If you are not doing weird things or that is reasonable, contact developers team for yours case support.');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
var InlineInputBase = /*#__PURE__*/function (_Component) {
|
|
97
|
+
(0, _inherits2["default"])(InlineInputBase, _Component);
|
|
98
|
+
|
|
99
|
+
var _super = _createSuper(InlineInputBase);
|
|
100
|
+
|
|
101
|
+
function InlineInputBase(props) {
|
|
102
|
+
var _this;
|
|
103
|
+
|
|
104
|
+
(0, _classCallCheck2["default"])(this, InlineInputBase);
|
|
105
|
+
_this = _super.call(this, props);
|
|
106
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
|
|
107
|
+
focused: false
|
|
108
|
+
});
|
|
109
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "rootRef", /*#__PURE__*/_react["default"].createRef());
|
|
110
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "inputRef", /*#__PURE__*/_react["default"].createRef());
|
|
111
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "initValue", '');
|
|
112
|
+
_this.handleConfirm = _this.handleConfirm.bind((0, _assertThisInitialized2["default"])(_this));
|
|
113
|
+
_this.handleCancel = _this.handleCancel.bind((0, _assertThisInitialized2["default"])(_this));
|
|
114
|
+
_this.handleFocus = _this.handleFocus.bind((0, _assertThisInitialized2["default"])(_this));
|
|
115
|
+
_this.handleBlur = _this.handleBlur.bind((0, _assertThisInitialized2["default"])(_this));
|
|
116
|
+
_this.handleKeyDown = _this.handleKeyDown.bind((0, _assertThisInitialized2["default"])(_this));
|
|
117
|
+
return _this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
(0, _createClass2["default"])(InlineInputBase, [{
|
|
121
|
+
key: "uncontrolledProps",
|
|
122
|
+
value: function uncontrolledProps() {
|
|
123
|
+
return {
|
|
124
|
+
value: null
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}, {
|
|
128
|
+
key: "componentDidMount",
|
|
129
|
+
value: function componentDidMount() {
|
|
130
|
+
var _this$asProps$value;
|
|
131
|
+
|
|
132
|
+
this.initValue = ((_this$asProps$value = this.asProps.value) !== null && _this$asProps$value !== void 0 ? _this$asProps$value : this.asProps.defaultValue) || '';
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "getContextProps",
|
|
136
|
+
value: function getContextProps() {
|
|
137
|
+
var _this$asProps = this.asProps,
|
|
138
|
+
loading = _this$asProps.loading,
|
|
139
|
+
value = _this$asProps.value,
|
|
140
|
+
defaultValue = _this$asProps.defaultValue,
|
|
141
|
+
state = _this$asProps.state,
|
|
142
|
+
_this$asProps$confirm = _this$asProps.confirmText,
|
|
143
|
+
confirmText = _this$asProps$confirm === void 0 ? 'Confirm' : _this$asProps$confirm,
|
|
144
|
+
_this$asProps$cancelT = _this$asProps.cancelText,
|
|
145
|
+
cancelText = _this$asProps$cancelT === void 0 ? 'Cancel' : _this$asProps$cancelT,
|
|
146
|
+
_this$asProps$tooltip = _this$asProps.tooltipsProps,
|
|
147
|
+
tooltipsProps = _this$asProps$tooltip === void 0 ? {} : _this$asProps$tooltip;
|
|
148
|
+
return {
|
|
149
|
+
loading: loading,
|
|
150
|
+
onConfirm: this.handleConfirm,
|
|
151
|
+
onCancel: this.handleCancel,
|
|
152
|
+
value: value,
|
|
153
|
+
defaultValue: defaultValue,
|
|
154
|
+
state: state,
|
|
155
|
+
confirmText: confirmText,
|
|
156
|
+
cancelText: cancelText,
|
|
157
|
+
tooltipsProps: tooltipsProps
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
}, {
|
|
161
|
+
key: "geAddonProps",
|
|
162
|
+
value: function geAddonProps() {
|
|
163
|
+
return this.getContextProps();
|
|
164
|
+
}
|
|
165
|
+
}, {
|
|
166
|
+
key: "getConfirmControlProps",
|
|
167
|
+
value: function getConfirmControlProps() {
|
|
168
|
+
return this.getContextProps();
|
|
169
|
+
}
|
|
170
|
+
}, {
|
|
171
|
+
key: "getCancelControlProps",
|
|
172
|
+
value: function getCancelControlProps() {
|
|
173
|
+
return this.getContextProps();
|
|
174
|
+
}
|
|
175
|
+
}, {
|
|
176
|
+
key: "getControlsProps",
|
|
177
|
+
value: function getControlsProps() {
|
|
178
|
+
return this.getContextProps();
|
|
179
|
+
}
|
|
180
|
+
}, {
|
|
181
|
+
key: "getValueProps",
|
|
182
|
+
value: function getValueProps() {
|
|
183
|
+
var _this$asProps2 = this.asProps,
|
|
184
|
+
autoFocus = _this$asProps2.autoFocus,
|
|
185
|
+
value = _this$asProps2.value,
|
|
186
|
+
inputId = _this$asProps2.inputId,
|
|
187
|
+
defaultValue = _this$asProps2.defaultValue,
|
|
188
|
+
onChange = _this$asProps2.onChange,
|
|
189
|
+
state = _this$asProps2.state,
|
|
190
|
+
loading = _this$asProps2.loading,
|
|
191
|
+
placeholder = _this$asProps2.placeholder;
|
|
192
|
+
return {
|
|
193
|
+
ref: this.inputRef,
|
|
194
|
+
autoFocus: autoFocus,
|
|
195
|
+
value: value,
|
|
196
|
+
defaultValue: defaultValue,
|
|
197
|
+
onChange: onChange,
|
|
198
|
+
state: state,
|
|
199
|
+
loading: loading,
|
|
200
|
+
placeholder: placeholder,
|
|
201
|
+
id: inputId
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "handleConfirm",
|
|
206
|
+
value: function handleConfirm(text, event) {
|
|
207
|
+
var onConfirm = this.asProps.onConfirm;
|
|
208
|
+
onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(text, event);
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}, {
|
|
212
|
+
key: "handleCancel",
|
|
213
|
+
value: function handleCancel(prevText, event) {
|
|
214
|
+
var onCancel = this.asProps.onCancel;
|
|
215
|
+
onCancel === null || onCancel === void 0 ? void 0 : onCancel(prevText, event);
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
}, {
|
|
219
|
+
key: "handleFocus",
|
|
220
|
+
value: function handleFocus(event) {
|
|
221
|
+
var onFocus = this.asProps.onFocus;
|
|
222
|
+
this.setState({
|
|
223
|
+
focused: true
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
if (onFocus) {
|
|
227
|
+
onFocus(event);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
key: "handleBlur",
|
|
232
|
+
value: function handleBlur(event) {
|
|
233
|
+
var _this2 = this;
|
|
234
|
+
|
|
235
|
+
var _this$asProps3 = this.asProps,
|
|
236
|
+
onConfirm = _this$asProps3.onConfirm,
|
|
237
|
+
onCancel = _this$asProps3.onCancel,
|
|
238
|
+
onBlur = _this$asProps3.onBlur,
|
|
239
|
+
onBlurBehavior = _this$asProps3.onBlurBehavior,
|
|
240
|
+
value = _this$asProps3.value;
|
|
241
|
+
this.setState({
|
|
242
|
+
focused: false
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
if (onBlurBehavior) {
|
|
246
|
+
setTimeout(function () {
|
|
247
|
+
if (isFocusOutsideOf(_this2.rootRef.current)) {
|
|
248
|
+
if (onBlurBehavior === 'confirm') onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(value, event);
|
|
249
|
+
if (onBlurBehavior === 'cancel') onCancel === null || onCancel === void 0 ? void 0 : onCancel(_this2.initValue, event);
|
|
250
|
+
}
|
|
251
|
+
}, 0);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (onBlur) {
|
|
255
|
+
onBlur(event);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "handleKeyDown",
|
|
260
|
+
value: function handleKeyDown(event) {
|
|
261
|
+
var _this$asProps4 = this.asProps,
|
|
262
|
+
onConfirm = _this$asProps4.onConfirm,
|
|
263
|
+
onCancel = _this$asProps4.onCancel,
|
|
264
|
+
value = _this$asProps4.value;
|
|
265
|
+
if (event.code === 'Enter') onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(value, event);
|
|
266
|
+
if (event.code === 'Escape') onCancel === null || onCancel === void 0 ? void 0 : onCancel(this.initValue, event);
|
|
267
|
+
}
|
|
268
|
+
}, {
|
|
269
|
+
key: "render",
|
|
270
|
+
value: function render() {
|
|
271
|
+
var _ref = this ? this.asProps : arguments[0],
|
|
272
|
+
_ref7;
|
|
273
|
+
|
|
274
|
+
var SInlineInput = _flexBox.Box;
|
|
275
|
+
var SUnderline = 'div';
|
|
276
|
+
var _this$asProps5 = this.asProps,
|
|
277
|
+
providedChildren = _this$asProps5.Children,
|
|
278
|
+
hasChildren = _this$asProps5.children,
|
|
279
|
+
styles = _this$asProps5.styles,
|
|
280
|
+
loading = _this$asProps5.loading;
|
|
281
|
+
var Children = hasChildren ? providedChildren : DefaultChildren;
|
|
282
|
+
var focused = this.state.focused;
|
|
283
|
+
return _ref7 = (0, _core.sstyled)(styles), /*#__PURE__*/_react["default"].createElement(SInlineInput, _ref7.cn("SInlineInput", _objectSpread({}, (0, _core.assignProps)({
|
|
284
|
+
"ref": this.rootRef,
|
|
285
|
+
"onFocus": this.handleFocus,
|
|
286
|
+
"onBlur": this.handleBlur,
|
|
287
|
+
"onKeyDown": this.handleKeyDown,
|
|
288
|
+
"focused": focused,
|
|
289
|
+
"loading": loading
|
|
290
|
+
}, _ref))), /*#__PURE__*/_react["default"].createElement(SUnderline, _ref7.cn("SUnderline", {}), /*#__PURE__*/_react["default"].createElement(Children, _ref7.cn("Children", {}))));
|
|
291
|
+
}
|
|
292
|
+
}]);
|
|
293
|
+
return InlineInputBase;
|
|
294
|
+
}(_core.Component);
|
|
295
|
+
|
|
296
|
+
(0, _defineProperty2["default"])(InlineInputBase, "displayName", 'InlineInput');
|
|
297
|
+
(0, _defineProperty2["default"])(InlineInputBase, "defaultProps", {
|
|
298
|
+
state: 'normal',
|
|
299
|
+
loading: false,
|
|
300
|
+
defaultValue: '',
|
|
301
|
+
__excludeProps: ['defaultValue', 'placeholder', 'tooltipsProps', 'confirmText', 'cancelText', 'autoFocus', 'inputId']
|
|
302
|
+
});
|
|
303
|
+
(0, _defineProperty2["default"])(InlineInputBase, "style", style);
|
|
304
|
+
|
|
305
|
+
var Value = /*#__PURE__*/function (_Component2) {
|
|
306
|
+
(0, _inherits2["default"])(Value, _Component2);
|
|
307
|
+
|
|
308
|
+
var _super2 = _createSuper(Value);
|
|
309
|
+
|
|
310
|
+
function Value() {
|
|
311
|
+
(0, _classCallCheck2["default"])(this, Value);
|
|
312
|
+
return _super2.apply(this, arguments);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
(0, _createClass2["default"])(Value, [{
|
|
316
|
+
key: "uncontrolledProps",
|
|
317
|
+
value: function uncontrolledProps() {
|
|
318
|
+
return {
|
|
319
|
+
value: function value(event) {
|
|
320
|
+
event.stopPropagation();
|
|
321
|
+
return event.target.value;
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}, {
|
|
326
|
+
key: "render",
|
|
327
|
+
value: function render() {
|
|
328
|
+
var _ref2 = this ? this.asProps : arguments[0],
|
|
329
|
+
_ref8;
|
|
330
|
+
|
|
331
|
+
var SValue = _flexBox.Box;
|
|
332
|
+
return _ref8 = (0, _core.sstyled)(this.asProps.styles), /*#__PURE__*/_react["default"].createElement(SValue, _ref8.cn("SValue", _objectSpread({}, (0, _core.assignProps)({
|
|
333
|
+
"tag": "input",
|
|
334
|
+
"type": "text",
|
|
335
|
+
"disabled": this.asProps.state === 'disabled' || this.asProps.loading
|
|
336
|
+
}, _ref2))));
|
|
337
|
+
}
|
|
338
|
+
}]);
|
|
339
|
+
return Value;
|
|
340
|
+
}(_core.Component);
|
|
341
|
+
|
|
342
|
+
(0, _defineProperty2["default"])(Value, "defaultProps", {
|
|
343
|
+
defaultValue: ''
|
|
344
|
+
});
|
|
345
|
+
(0, _defineProperty2["default"])(Value, "enhance", [(0, _autoFocusEnhance["default"])()]);
|
|
346
|
+
|
|
347
|
+
var Addon = function Addon(props) {
|
|
348
|
+
var _ref3 = _this3 ? _this3.asProps : arguments[0],
|
|
349
|
+
_ref9;
|
|
350
|
+
|
|
351
|
+
var SAddon = _flexBox.Box;
|
|
352
|
+
return _ref9 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SAddon, _ref9.cn("SAddon", _objectSpread({}, (0, _core.assignProps)({}, _ref3))));
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
var ConfirmControl = function ConfirmControl(props) {
|
|
356
|
+
var _ref4 = _this3 ? _this3.asProps : arguments[0],
|
|
357
|
+
_ref11,
|
|
358
|
+
_props$value;
|
|
359
|
+
|
|
360
|
+
var SConfirmControl = _flexBox.Box;
|
|
361
|
+
var Children = props.Children,
|
|
362
|
+
hasChildren = props.children;
|
|
363
|
+
|
|
364
|
+
var handleConfirm = _react["default"].useCallback(function (event) {
|
|
365
|
+
var _props$onConfirm;
|
|
366
|
+
|
|
367
|
+
(_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 ? void 0 : _props$onConfirm.call(props, props.value, event);
|
|
368
|
+
}, [props.onConfirm, props.value]);
|
|
369
|
+
|
|
370
|
+
var handleKeydown = _react["default"].useCallback(function (event) {
|
|
371
|
+
if (props.loading) return;
|
|
372
|
+
|
|
373
|
+
if (event.code === 'Enter' || event.code === 'Space') {
|
|
374
|
+
event.preventDefault();
|
|
375
|
+
event.stopPropagation();
|
|
376
|
+
handleConfirm(event);
|
|
377
|
+
}
|
|
378
|
+
}, [props.loading, handleConfirm]);
|
|
379
|
+
|
|
380
|
+
if (props.loading) {
|
|
381
|
+
var _ref10;
|
|
382
|
+
|
|
383
|
+
return _ref10 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SConfirmControl, _ref10.cn("SConfirmControl", _objectSpread({}, (0, _core.assignProps)({
|
|
384
|
+
"className": "controls-icon"
|
|
385
|
+
}, _ref4))), hasChildren ? /*#__PURE__*/_react["default"].createElement(Children, _ref10.cn("Children", {})) : /*#__PURE__*/_react["default"].createElement(_spin["default"], _ref10.cn("Spin", {
|
|
386
|
+
"size": "xxs",
|
|
387
|
+
"className": "spin"
|
|
388
|
+
})));
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return _ref11 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SConfirmControl, _ref11.cn("SConfirmControl", _objectSpread({}, (0, _core.assignProps)({
|
|
392
|
+
"onKeyDown": handleKeydown
|
|
393
|
+
}, _ref4))), hasChildren ? /*#__PURE__*/_react["default"].createElement(Children, _ref11.cn("Children", {})) : /*#__PURE__*/_react["default"].createElement(_tooltip["default"], _ref11.cn("Tooltip", _objectSpread({}, props.tooltipsProps)), /*#__PURE__*/_react["default"].createElement(_tooltip["default"].Trigger, {
|
|
394
|
+
className: "controls-icon"
|
|
395
|
+
}, /*#__PURE__*/_react["default"].createElement(_m["default"], _ref11.cn("CheckM", {
|
|
396
|
+
"tabIndex": 0,
|
|
397
|
+
"aria-label": "".concat(props.confirmText, " ").concat((_props$value = props.value) !== null && _props$value !== void 0 ? _props$value : ''),
|
|
398
|
+
"role": "button",
|
|
399
|
+
"onClick": handleConfirm
|
|
400
|
+
}))), /*#__PURE__*/_react["default"].createElement(_tooltip["default"].Popper, {
|
|
401
|
+
p: 2
|
|
402
|
+
}, props.confirmText)));
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
var CancelControl = function CancelControl(props) {
|
|
406
|
+
var _ref5 = _this3 ? _this3.asProps : arguments[0],
|
|
407
|
+
_ref13,
|
|
408
|
+
_props$value2;
|
|
409
|
+
|
|
410
|
+
var SCancelControl = _flexBox.Box;
|
|
411
|
+
var Children = props.Children,
|
|
412
|
+
hasChildren = props.children;
|
|
413
|
+
|
|
414
|
+
var initValue = _react["default"].useRef((_props$value2 = props.value) !== null && _props$value2 !== void 0 ? _props$value2 : props.defaultValue);
|
|
415
|
+
|
|
416
|
+
var handleCancel = _react["default"].useCallback(function (event) {
|
|
417
|
+
var _props$onCancel;
|
|
418
|
+
|
|
419
|
+
if (props.loading || !props.onCancel) return;
|
|
420
|
+
(_props$onCancel = props.onCancel) === null || _props$onCancel === void 0 ? void 0 : _props$onCancel.call(props, initValue.current, event);
|
|
421
|
+
}, [props.loading, props.onCancel]);
|
|
422
|
+
|
|
423
|
+
var handleKeydown = _react["default"].useCallback(function (event) {
|
|
424
|
+
if (props.loading) return;
|
|
425
|
+
|
|
426
|
+
if (event.code === 'Enter' || event.code === 'Space') {
|
|
427
|
+
event.preventDefault();
|
|
428
|
+
event.stopPropagation();
|
|
429
|
+
handleCancel(event);
|
|
430
|
+
}
|
|
431
|
+
}, [props.loading, handleCancel]);
|
|
432
|
+
|
|
433
|
+
if (props.loading) {
|
|
434
|
+
var _ref12;
|
|
435
|
+
|
|
436
|
+
return _ref12 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SCancelControl, _ref12.cn("SCancelControl", _objectSpread({}, (0, _core.assignProps)({
|
|
437
|
+
"className": "controls-icon"
|
|
438
|
+
}, _ref5))), hasChildren ? /*#__PURE__*/_react["default"].createElement(Children, _ref12.cn("Children", {})) : /*#__PURE__*/_react["default"].createElement(_m2["default"], _ref12.cn("CloseM", {
|
|
439
|
+
"disabled": true
|
|
440
|
+
})));
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return _ref13 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SCancelControl, _ref13.cn("SCancelControl", _objectSpread({}, (0, _core.assignProps)({
|
|
444
|
+
"onKeyDown": handleKeydown
|
|
445
|
+
}, _ref5))), hasChildren ? /*#__PURE__*/_react["default"].createElement(Children, _ref13.cn("Children", {})) : /*#__PURE__*/_react["default"].createElement(_tooltip["default"], _ref13.cn("Tooltip", _objectSpread({}, props.tooltipsProps)), /*#__PURE__*/_react["default"].createElement(_tooltip["default"].Trigger, {
|
|
446
|
+
className: "controls-icon"
|
|
447
|
+
}, /*#__PURE__*/_react["default"].createElement(_m2["default"], _ref13.cn("CloseM", {
|
|
448
|
+
"tabIndex": 0,
|
|
449
|
+
"aria-label": props.cancelText,
|
|
450
|
+
"role": "button",
|
|
451
|
+
"onClick": handleCancel
|
|
452
|
+
}))), /*#__PURE__*/_react["default"].createElement(_tooltip["default"].Popper, {
|
|
453
|
+
p: 2
|
|
454
|
+
}, props.cancelText)));
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
var Controls = function Controls(props) {
|
|
458
|
+
var _ref6 = _this3 ? _this3.asProps : arguments[0],
|
|
459
|
+
_ref14;
|
|
460
|
+
|
|
461
|
+
var SControls = _flexBox.Box;
|
|
462
|
+
return _ref14 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SControls, _ref14.cn("SControls", _objectSpread({}, (0, _core.assignProps)({}, _ref6))), /*#__PURE__*/_react["default"].createElement(InlineInput.ConfirmControl, {
|
|
463
|
+
tooltipsProps: props.tooltipsProps,
|
|
464
|
+
confirmText: props.confirmText,
|
|
465
|
+
onConfirm: props.onConfirm
|
|
466
|
+
}), /*#__PURE__*/_react["default"].createElement(InlineInput.CancelControl, {
|
|
467
|
+
tooltipsProps: props.tooltipsProps,
|
|
468
|
+
cancelText: props.cancelText,
|
|
469
|
+
onCancel: props.onCancel
|
|
470
|
+
}));
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
var DefaultChildren = function DefaultChildren(props) {
|
|
474
|
+
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(InlineInput.Value, props), /*#__PURE__*/_react["default"].createElement(InlineInput.Controls, null));
|
|
475
|
+
};
|
|
476
|
+
/** `createComponent` currently exposes unrelated junk instead of typings, that the reason of to any cast */
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
var InlineInput = (0, _core["default"])(InlineInputBase, {
|
|
480
|
+
Addon: Addon,
|
|
481
|
+
Value: Value,
|
|
482
|
+
ConfirmControl: ConfirmControl,
|
|
483
|
+
CancelControl: CancelControl,
|
|
484
|
+
Controls: Controls
|
|
485
|
+
});
|
|
486
|
+
var _default = InlineInput;
|
|
487
|
+
exports["default"] = _default;
|
|
488
|
+
//# sourceMappingURL=InlineInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/InlineInput.tsx"],"names":["isFocusOutsideOf","element","traversed","document","activeElement","i","body","parentElement","Error","InlineInputBase","props","focused","React","createRef","handleConfirm","bind","handleCancel","handleFocus","handleBlur","handleKeyDown","value","initValue","asProps","defaultValue","loading","state","confirmText","cancelText","tooltipsProps","onConfirm","onCancel","getContextProps","autoFocus","inputId","onChange","placeholder","ref","inputRef","id","text","event","prevText","onFocus","setState","onBlur","onBlurBehavior","setTimeout","rootRef","current","code","SInlineInput","Box","SUnderline","providedChildren","Children","hasChildren","children","styles","DefaultChildren","Component","__excludeProps","style","Value","stopPropagation","target","SValue","Addon","SAddon","ConfirmControl","SConfirmControl","useCallback","handleKeydown","preventDefault","CancelControl","SCancelControl","useRef","Controls","SControls","InlineInput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AADA;;AAEA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAMA,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,OAAD,EAA0B;AACjD,MAAIC,SAAS,GAAGC,QAAQ,CAACC,aAAzB;;AACA,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BAAO,mBAAQzC,KAAK,CAAC+C,MAAd,CAAP,eACE,gCAAC,SAAD,6FACE,gCAAC,WAAD,CAAa,cAAb;AACE,IAAA,aAAa,EAAE/C,KAAK,CAACkB,aADvB;AAEE,IAAA,WAAW,EAAElB,KAAK,CAACgB,WAFrB;AAGE,IAAA,SAAS,EAAEhB,KAAK,CAACmB;AAHnB,IADF,eAME,gCAAC,WAAD,CAAa,aAAb;AACE,IAAA,aAAa,EAAEnB,KAAK,CAACkB,aADvB;AAEE,IAAA,UAAU,EAAElB,KAAK,CAACiB,UAFpB;AAGE,IAAA,QAAQ,EAAEjB,KAAK,CAACoB;AAHlB,IANF,CADF;AAcD,CAhBD;;AAkBA,IAAM4B,eAAkC,GAAG,SAArCA,eAAqC,CAAChD,KAAD,EAAW;AACpD,sBACE,+EACE,gCAAC,WAAD,CAAa,KAAb,EAAuBA,KAAvB,CADF,eAEE,gCAAC,WAAD,CAAa,QAAb,OAFF,CADF;AAMD,CAPD;AASA;;;AACA,IAAMoE,WAAW,GAAG,sBAAgBrE,eAAhB,EAAiC;AACnDyD,EAAAA,KAAK,EAALA,KADmD;AAEnDJ,EAAAA,KAAK,EAALA,KAFmD;AAGnDM,EAAAA,cAAc,EAAdA,cAHmD;AAInDK,EAAAA,aAAa,EAAbA,aAJmD;AAKnDG,EAAAA,QAAQ,EAARA;AALmD,CAAjC,CAApB;eAQeE,W","sourcesContent":["import React from 'react';\nimport createComponent, { Component, sstyled, Root } from '@semcore/core';\nimport { Box } from '@semcore/flex-box';\nimport autoFocusEnhance from '@semcore/utils/lib/enhances/autoFocusEnhance';\nimport Tooltip, { ITooltipProps } from '@semcore/tooltip';\nimport style from './style/inline-input.shadow.css';\nimport CheckM from '@semcore/icon/Check/m';\nimport CloseM from '@semcore/icon/Close/m';\nimport Spin from '@semcore/spin';\n\nconst isFocusOutsideOf = (element: HTMLElement) => {\n let traversed = document.activeElement;\n for (let i = 0; i < 1000000; i++) {\n if (traversed === element) return false;\n if (traversed === document.body) return true;\n traversed = traversed.parentElement;\n }\n\n throw new Error(\n 'Failed to traverse parents chain in utilite `isFocusOutsideOf` reasonable count of iterations. Possibly Shadow DOM or come other uncommon DOM-way is used, that is not supported by utilite yet. If you are not doing weird things or that is reasonable, contact developers team for yours case support.',\n );\n};\n\ntype AsProps = {\n state?: 'normal' | 'valid' | 'invalid' | 'disabled';\n loading?: boolean;\n onConfirm?: (\n value: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n ) => void;\n onCancel?: (\n prevValue: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n ) => void;\n value?: string;\n defaultValue?: string;\n confirmText?: string;\n cancelText?: string;\n tooltipsProps?: ITooltipProps;\n autoFocus?: boolean;\n placeholder?: string;\n inputId?: string;\n onChange?: (value: string, event: React.ChangeEvent) => void;\n onBlur?: (event: React.FocusEvent) => void;\n onFocus?: (event: React.FocusEvent) => void;\n onBlurBehavior?: 'cancel' | 'confirm';\n styles?: React.CSSProperties;\n Children: React.FC;\n};\n\nclass InlineInputBase extends Component<AsProps> {\n static displayName = 'InlineInput';\n\n static defaultProps = {\n state: 'normal',\n loading: false,\n defaultValue: '',\n __excludeProps: [\n 'defaultValue',\n 'placeholder',\n 'tooltipsProps',\n 'confirmText',\n 'cancelText',\n 'autoFocus',\n 'inputId',\n ],\n };\n static style = style;\n\n state = {\n focused: false,\n };\n\n rootRef = React.createRef<HTMLElement>();\n inputRef = React.createRef();\n initValue: string = '';\n\n uncontrolledProps() {\n return {\n value: null,\n };\n }\n\n constructor(props) {\n super(props);\n this.handleConfirm = this.handleConfirm.bind(this);\n this.handleCancel = this.handleCancel.bind(this);\n this.handleFocus = this.handleFocus.bind(this);\n this.handleBlur = this.handleBlur.bind(this);\n this.handleKeyDown = this.handleKeyDown.bind(this);\n }\n\n componentDidMount() {\n this.initValue = ((this.asProps.value ?? this.asProps.defaultValue) as string) || '';\n }\n\n getContextProps() {\n const {\n loading,\n value,\n defaultValue,\n state,\n confirmText = 'Confirm',\n cancelText = 'Cancel',\n tooltipsProps = {},\n } = this.asProps;\n\n return {\n loading,\n onConfirm: this.handleConfirm,\n onCancel: this.handleCancel,\n value,\n defaultValue,\n state,\n confirmText,\n cancelText,\n tooltipsProps,\n };\n }\n\n geAddonProps() {\n return this.getContextProps();\n }\n getConfirmControlProps() {\n return this.getContextProps();\n }\n getCancelControlProps() {\n return this.getContextProps();\n }\n getControlsProps() {\n return this.getContextProps();\n }\n\n getValueProps() {\n const { autoFocus, value, inputId, defaultValue, onChange, state, loading, placeholder } =\n this.asProps;\n\n return {\n ref: this.inputRef,\n autoFocus,\n value,\n defaultValue,\n onChange,\n state,\n loading,\n placeholder,\n id: inputId,\n };\n }\n\n handleConfirm(text: string, event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent) {\n const { onConfirm } = this.asProps;\n onConfirm?.(text, event);\n return false;\n }\n handleCancel(prevText: string, event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent) {\n const { onCancel } = this.asProps;\n onCancel?.(prevText, event);\n return false;\n }\n\n handleFocus(event: React.FocusEvent) {\n const { onFocus } = this.asProps;\n this.setState({ focused: true });\n if (onFocus) {\n onFocus(event);\n }\n }\n handleBlur(event: React.FocusEvent) {\n const { onConfirm, onCancel, onBlur, onBlurBehavior, value } = this.asProps;\n this.setState({ focused: false });\n if (onBlurBehavior) {\n setTimeout(() => {\n if (isFocusOutsideOf(this.rootRef.current)) {\n if (onBlurBehavior === 'confirm') onConfirm?.(value, event);\n if (onBlurBehavior === 'cancel') onCancel?.(this.initValue, event);\n }\n }, 0);\n }\n if (onBlur) {\n onBlur(event);\n }\n }\n handleKeyDown(event: React.KeyboardEvent) {\n const { onConfirm, onCancel, value } = this.asProps;\n if (event.code === 'Enter') onConfirm?.(value, event);\n if (event.code === 'Escape') onCancel?.(this.initValue, event);\n }\n\n render() {\n const SInlineInput = Root;\n const SUnderline = 'div';\n const { Children: providedChildren, children: hasChildren, styles, loading } = this.asProps;\n const Children = hasChildren ? providedChildren : DefaultChildren;\n const { focused } = this.state;\n\n return sstyled(styles)(\n <SInlineInput\n ref={this.rootRef}\n onFocus={this.handleFocus}\n onBlur={this.handleBlur}\n onKeyDown={this.handleKeyDown}\n render={Box}\n focused={focused}\n loading={loading}\n >\n <SUnderline>\n <Children />\n </SUnderline>\n </SInlineInput>,\n );\n }\n}\n\nclass Value extends Component<AsProps> {\n static defaultProps = {\n defaultValue: '',\n };\n static enhance = [autoFocusEnhance()];\n\n uncontrolledProps() {\n return {\n value: (event) => {\n event.stopPropagation();\n return event.target.value;\n },\n };\n }\n\n render() {\n const SValue = Root;\n\n return sstyled(this.asProps.styles)(\n <SValue\n render={Box}\n tag=\"input\"\n type=\"text\"\n disabled={this.asProps.state === 'disabled' || this.asProps.loading}\n />,\n );\n }\n}\n\nconst Addon: React.FC<AsProps> = (props) => {\n const SAddon = Root;\n return sstyled(props.styles)(<SAddon render={Box} />) as React.ReactElement;\n};\n\nconst ConfirmControl: React.FC<AsProps> = (props) => {\n const SConfirmControl = Root;\n const { Children, children: hasChildren } = props;\n\n const handleConfirm = React.useCallback(\n (event: React.MouseEvent | React.KeyboardEvent) => {\n props.onConfirm?.(props.value, event);\n },\n [props.onConfirm, props.value],\n );\n const handleKeydown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (props.loading) return;\n if (event.code === 'Enter' || event.code === 'Space') {\n event.preventDefault();\n event.stopPropagation();\n handleConfirm(event);\n }\n },\n [props.loading, handleConfirm],\n );\n\n if (props.loading) {\n return sstyled(props.styles)(\n <SConfirmControl render={Box} className=\"controls-icon\">\n {hasChildren ? <Children /> : <Spin size=\"xxs\" className=\"spin\" />}\n </SConfirmControl>,\n ) as React.ReactElement;\n }\n\n return sstyled(props.styles)(\n <SConfirmControl render={Box} onKeyDown={handleKeydown}>\n {hasChildren ? (\n <Children />\n ) : (\n <Tooltip {...props.tooltipsProps}>\n <Tooltip.Trigger className=\"controls-icon\">\n <CheckM\n tabIndex={0}\n aria-label={`${props.confirmText} ${props.value ?? ''}`}\n role=\"button\"\n onClick={handleConfirm}\n />\n </Tooltip.Trigger>\n <Tooltip.Popper p={2}>{props.confirmText}</Tooltip.Popper>\n </Tooltip>\n )}\n </SConfirmControl>,\n ) as React.ReactElement;\n};\nconst CancelControl: React.FC<AsProps> = (props) => {\n const SCancelControl = Root;\n const { Children, children: hasChildren } = props;\n const initValue = React.useRef(props.value ?? props.defaultValue);\n const handleCancel = React.useCallback(\n (event: React.MouseEvent | React.KeyboardEvent) => {\n if (props.loading || !props.onCancel) return;\n props.onCancel?.(initValue.current, event);\n },\n [props.loading, props.onCancel],\n );\n const handleKeydown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (props.loading) return;\n if (event.code === 'Enter' || event.code === 'Space') {\n event.preventDefault();\n event.stopPropagation();\n handleCancel(event);\n }\n },\n [props.loading, handleCancel],\n );\n\n if (props.loading) {\n return sstyled(props.styles)(\n <SCancelControl render={Box} className=\"controls-icon\">\n {hasChildren ? <Children /> : <CloseM disabled={true} />}\n </SCancelControl>,\n ) as React.ReactElement;\n }\n\n return sstyled(props.styles)(\n <SCancelControl render={Box} onKeyDown={handleKeydown}>\n {hasChildren ? (\n <Children />\n ) : (\n <Tooltip {...props.tooltipsProps}>\n <Tooltip.Trigger className=\"controls-icon\">\n <CloseM\n tabIndex={0}\n aria-label={props.cancelText}\n role=\"button\"\n onClick={handleCancel}\n />\n </Tooltip.Trigger>\n <Tooltip.Popper p={2}>{props.cancelText}</Tooltip.Popper>\n </Tooltip>\n )}\n </SCancelControl>,\n ) as React.ReactElement;\n};\n\nconst Controls: React.FC<AsProps> = (props) => {\n const SControls = Root;\n return sstyled(props.styles)(\n <SControls render={Box}>\n <InlineInput.ConfirmControl\n tooltipsProps={props.tooltipsProps}\n confirmText={props.confirmText}\n onConfirm={props.onConfirm}\n />\n <InlineInput.CancelControl\n tooltipsProps={props.tooltipsProps}\n cancelText={props.cancelText}\n onCancel={props.onCancel}\n />\n </SControls>,\n ) as React.ReactElement;\n};\n\nconst DefaultChildren: React.FC<AsProps> = (props) => {\n return (\n <>\n <InlineInput.Value {...props} />\n <InlineInput.Controls />\n </>\n ) as React.ReactElement;\n};\n\n/** `createComponent` currently exposes unrelated junk instead of typings, that the reason of to any cast */\nconst InlineInput = createComponent(InlineInputBase, {\n Addon,\n Value,\n ConfirmControl,\n CancelControl,\n Controls,\n}) as any;\n\nexport default InlineInput;\n"],"file":"InlineInput.js"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var _InlineInput = _interopRequireDefault(require("./InlineInput"));
|
|
11
|
+
|
|
12
|
+
var _default = _InlineInput["default"];
|
|
13
|
+
exports["default"] = _default;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["InlineInputBase"],"mappings":";;;;;;;;;AAAA;;eACeA,uB","sourcesContent":["import InlineInputBase from './InlineInput';\nexport default InlineInputBase;\n"],"file":"index.js"}
|