@semcore/inline-input 2.0.0 → 3.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.
@@ -33,19 +33,21 @@ var style = (
33
33
  /*__reshadow_css_start__*/
34
34
  _sstyled.insert(
35
35
  /*__inner_css_start__*/
36
- ".___SInlineInput_8s9nq_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}.___SInlineInput_8s9nq_gg_.__disabled_8s9nq_gg_{cursor:default;pointer-events:none;opacity:0.3}.___SValue_8s9nq_gg_{min-width:0;width:100%;height:100%;padding: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_8s9nq_gg_:focus{outline:none}.___SValue_8s9nq_gg_::-moz-placeholder{color:#aaaaaa}.___SValue_8s9nq_gg_:-ms-input-placeholder{color:#aaaaaa}.___SValue_8s9nq_gg_::placeholder{color:#aaaaaa}.___SValue_8s9nq_gg_.__disabled_8s9nq_gg_{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.___SUnderline_8s9nq_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_8s9nq_gg_{display:inline-flex;justify-content:center;align-items:center;flex:0 0 auto;height:100%;color:#a9abb6;padding:0 4px}.___SAddon_8s9nq_gg_.__disabled_8s9nq_gg_{opacity:0.3;cursor:default;pointer-events:none}.___SInlineInput_8s9nq_gg_.__focused_8s9nq_gg_{z-index:1}.___SInlineInput_8s9nq_gg_.__focused_8s9nq_gg_ .___SUnderline_8s9nq_gg_{border-color:#008ff8;box-shadow:0 0 0 3px rgba(43, 148, 225, 0.3)}.___SInlineInput_8s9nq_gg_._state_valid_8s9nq_gg_ .___SUnderline_8s9nq_gg_{border-color:#59ddaa}.___SInlineInput_8s9nq_gg_._state_valid_8s9nq_gg_.__focused_8s9nq_gg_ .___SUnderline_8s9nq_gg_{border-color:#009f81;box-shadow:0px 0px 0px 3px rgba(0, 159, 129, 0.2)}.___SInlineInput_8s9nq_gg_._state_invalid_8s9nq_gg_ .___SUnderline_8s9nq_gg_{border-color:#ffaeb5}.___SInlineInput_8s9nq_gg_._state_invalid_8s9nq_gg_.__focused_8s9nq_gg_ .___SUnderline_8s9nq_gg_{border-color:#ff4953;box-shadow:0px 0px 0px 3px rgba(255, 73, 83, 0.2)}"
36
+ ".___SInlineInput_xe56s_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:#ffffff}.___SInlineInput_xe56s_gg_.__disabled_xe56s_gg_{cursor:default;pointer-events:none;opacity:0.3}.___SValue_xe56s_gg_{min-width:0;width:100%;height:100%;padding:4px;border:none;box-sizing:border-box;color:#191b23;font-size:inherit;line-height:1.2;text-overflow:ellipsis;font-family:inherit;background:transparent;min-height:1em}.___SValue_xe56s_gg_:focus{outline:none}.___SValue_xe56s_gg_::-moz-placeholder{color:#a9abb6}.___SValue_xe56s_gg_:-ms-input-placeholder{color:#a9abb6}.___SValue_xe56s_gg_::placeholder{color:#a9abb6}.___SValue_xe56s_gg_.__disabled_xe56s_gg_{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.___SUnderline_xe56s_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_xe56s_gg_{display:inline-flex;justify-content:center;align-items:center;flex:0 0 auto;height:100%;color:#a9abb6;padding:0 4px}.___SAddon_xe56s_gg_.__disabled_xe56s_gg_{opacity:0.3;cursor:default;pointer-events:none}.___SConfirmIcon_xe56s_gg_{color:#00c192;cursor:pointer}.___SConfirmIcon_xe56s_gg_:hover{color:#009f81}.___SCancelIcon_xe56s_gg_{color:#a9abb6;cursor:pointer}.___SCancelIcon_xe56s_gg_:hover{color:#8a8e9b}.___SInlineInput_xe56s_gg_.__focused_xe56s_gg_{z-index:1}.___SInlineInput_xe56s_gg_.__focused_xe56s_gg_ .___SUnderline_xe56s_gg_{border-bottom-color:#008ff8;box-shadow:0 0 0 3px rgba(0, 143, 248, 0.2)}.___SInlineInput_xe56s_gg_._state_valid_xe56s_gg_ .___SUnderline_xe56s_gg_{border-bottom-color:#59ddaa}.___SInlineInput_xe56s_gg_._state_valid_xe56s_gg_.__focused_xe56s_gg_ .___SUnderline_xe56s_gg_{border-bottom-color:#009f81;box-shadow:0px 0px 0px 3px rgba(0, 159, 129, 0.2)}.___SInlineInput_xe56s_gg_._state_invalid_xe56s_gg_ .___SUnderline_xe56s_gg_{border-bottom-color:#ffaeb5}.___SInlineInput_xe56s_gg_._state_invalid_xe56s_gg_.__focused_xe56s_gg_ .___SUnderline_xe56s_gg_{border-bottom-color:#ff4953;box-shadow:0px 0px 0px 3px rgba(255, 73, 83, 0.2)}"
37
37
  /*__inner_css_end__*/
38
- , "hj0ctv_gg_")
38
+ , "1xjfing_gg_")
39
39
  /*__reshadow_css_end__*/
40
40
  , {
41
- "__SInlineInput": "___SInlineInput_8s9nq_gg_",
42
- "_disabled": "__disabled_8s9nq_gg_",
43
- "__SValue": "___SValue_8s9nq_gg_",
44
- "__SUnderline": "___SUnderline_8s9nq_gg_",
45
- "__SAddon": "___SAddon_8s9nq_gg_",
46
- "_focused": "__focused_8s9nq_gg_",
47
- "_state_valid": "_state_valid_8s9nq_gg_",
48
- "_state_invalid": "_state_invalid_8s9nq_gg_"
41
+ "__SInlineInput": "___SInlineInput_xe56s_gg_",
42
+ "_disabled": "__disabled_xe56s_gg_",
43
+ "__SValue": "___SValue_xe56s_gg_",
44
+ "__SUnderline": "___SUnderline_xe56s_gg_",
45
+ "__SAddon": "___SAddon_xe56s_gg_",
46
+ "__SConfirmIcon": "___SConfirmIcon_xe56s_gg_",
47
+ "__SCancelIcon": "___SCancelIcon_xe56s_gg_",
48
+ "_focused": "__focused_xe56s_gg_",
49
+ "_state_valid": "_state_valid_xe56s_gg_",
50
+ "_state_invalid": "_state_invalid_xe56s_gg_"
49
51
  });
50
52
  import CheckM from '@semcore/icon/Check/m';
51
53
  import CloseM from '@semcore/icon/Close/m';
@@ -55,11 +57,9 @@ var isFocusOutsideOf = function isFocusOutsideOf(element) {
55
57
  var traversed = document.activeElement;
56
58
 
57
59
  for (var i = 0; i < 1000000; i++) {
58
- var _traversed;
59
-
60
60
  if (traversed === element) return false;
61
61
  if (traversed === document.body) return true;
62
- traversed = (_traversed = traversed) === null || _traversed === void 0 ? void 0 : _traversed.parentElement;
62
+ traversed = traversed?.parentElement;
63
63
  }
64
64
 
65
65
  throw new Error('Failed to traverse parents chain in utilite `isFocusOutsideOf` in 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.');
@@ -85,9 +85,9 @@ var InlineInputBase = /*#__PURE__*/function (_Component) {
85
85
  focused: false
86
86
  });
87
87
 
88
- _defineProperty(_assertThisInitialized(_this), "rootRef", /*#__PURE__*/React.createRef());
88
+ _defineProperty(_assertThisInitialized(_this), "rootRef", React.createRef());
89
89
 
90
- _defineProperty(_assertThisInitialized(_this), "inputRef", /*#__PURE__*/React.createRef());
90
+ _defineProperty(_assertThisInitialized(_this), "inputRef", React.createRef());
91
91
 
92
92
  _defineProperty(_assertThisInitialized(_this), "initValue", '');
93
93
 
@@ -100,50 +100,40 @@ var InlineInputBase = /*#__PURE__*/function (_Component) {
100
100
  });
101
101
 
102
102
  _defineProperty(_assertThisInitialized(_this), "handleMouseDownAddon", function (event) {
103
- var _this$inputRef$curren;
104
-
105
103
  event.preventDefault();
106
- (_this$inputRef$curren = _this.inputRef.current) === null || _this$inputRef$curren === void 0 ? void 0 : _this$inputRef$curren.focus();
104
+ _this.inputRef.current?.focus();
107
105
  });
108
106
 
109
107
  _defineProperty(_assertThisInitialized(_this), "handleConfirm", function (text, event) {
110
- var _this$asProps$onConfi, _this$asProps;
111
-
112
- (_this$asProps$onConfi = (_this$asProps = _this.asProps).onConfirm) === null || _this$asProps$onConfi === void 0 ? void 0 : _this$asProps$onConfi.call(_this$asProps, text, event);
108
+ _this.asProps.onConfirm?.(text, event);
113
109
  });
114
110
 
115
111
  _defineProperty(_assertThisInitialized(_this), "handleCancel", function (prevText, event) {
116
- var _this$asProps$onCance, _this$asProps2;
117
-
118
- (_this$asProps$onCance = (_this$asProps2 = _this.asProps).onCancel) === null || _this$asProps$onCance === void 0 ? void 0 : _this$asProps$onCance.call(_this$asProps2, prevText, event);
112
+ _this.asProps.onCancel?.(prevText, event);
119
113
  });
120
114
 
121
115
  _defineProperty(_assertThisInitialized(_this), "handleBlur", function (event) {
122
- var _this$asProps3 = _this.asProps,
123
- onConfirm = _this$asProps3.onConfirm,
124
- onCancel = _this$asProps3.onCancel,
125
- onBlurBehavior = _this$asProps3.onBlurBehavior;
116
+ var _this$asProps = _this.asProps,
117
+ onConfirm = _this$asProps.onConfirm,
118
+ onCancel = _this$asProps.onCancel,
119
+ onBlurBehavior = _this$asProps.onBlurBehavior;
126
120
 
127
121
  if (onBlurBehavior) {
128
122
  setTimeout(function () {
129
123
  if (_this.rootRef.current && isFocusOutsideOf(_this.rootRef.current)) {
130
- var _this$inputRef$curren2, _this$inputRef$curren3;
131
-
132
- if (onBlurBehavior === 'confirm') onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm((_this$inputRef$curren2 = (_this$inputRef$curren3 = _this.inputRef.current) === null || _this$inputRef$curren3 === void 0 ? void 0 : _this$inputRef$curren3.value) !== null && _this$inputRef$curren2 !== void 0 ? _this$inputRef$curren2 : '', event);
133
- if (onBlurBehavior === 'cancel') onCancel === null || onCancel === void 0 ? void 0 : onCancel(_this.initValue, event);
124
+ if (onBlurBehavior === 'confirm') onConfirm?.(_this.inputRef.current?.value ?? '', event);
125
+ if (onBlurBehavior === 'cancel') onCancel?.(_this.initValue, event);
134
126
  }
135
127
  }, 0);
136
128
  }
137
129
  });
138
130
 
139
131
  _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (event) {
140
- var _this$inputRef$curren4, _this$inputRef$curren5;
141
-
142
- var _this$asProps4 = _this.asProps,
143
- onConfirm = _this$asProps4.onConfirm,
144
- onCancel = _this$asProps4.onCancel;
145
- if (event.code === 'Enter') onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm((_this$inputRef$curren4 = (_this$inputRef$curren5 = _this.inputRef.current) === null || _this$inputRef$curren5 === void 0 ? void 0 : _this$inputRef$curren5.value) !== null && _this$inputRef$curren4 !== void 0 ? _this$inputRef$curren4 : '', event);
146
- if (event.code === 'Escape') onCancel === null || onCancel === void 0 ? void 0 : onCancel(_this.initValue, event);
132
+ var _this$asProps2 = _this.asProps,
133
+ onConfirm = _this$asProps2.onConfirm,
134
+ onCancel = _this$asProps2.onCancel;
135
+ if (event.code === 'Enter') onConfirm?.(_this.inputRef.current?.value ?? '', event);
136
+ if (event.code === 'Escape') onCancel?.(_this.initValue, event);
147
137
  });
148
138
 
149
139
  return _this;
@@ -152,9 +142,7 @@ var InlineInputBase = /*#__PURE__*/function (_Component) {
152
142
  _createClass(InlineInputBase, [{
153
143
  key: "componentDidMount",
154
144
  value: function componentDidMount() {
155
- var _this$inputRef$curren6;
156
-
157
- this.initValue = ((_this$inputRef$curren6 = this.inputRef.current) === null || _this$inputRef$curren6 === void 0 ? void 0 : _this$inputRef$curren6.value) || '';
145
+ this.initValue = this.inputRef.current?.value || '';
158
146
  }
159
147
  }, {
160
148
  key: "getAddonProps",
@@ -166,11 +154,9 @@ var InlineInputBase = /*#__PURE__*/function (_Component) {
166
154
  }, {
167
155
  key: "getConfirmControlProps",
168
156
  value: function getConfirmControlProps() {
169
- var _this$inputRef$curren7;
170
-
171
157
  var loading = this.asProps.loading;
172
158
  return {
173
- value: (_this$inputRef$curren7 = this.inputRef.current) === null || _this$inputRef$curren7 === void 0 ? void 0 : _this$inputRef$curren7.value,
159
+ value: this.inputRef.current?.value,
174
160
  loading: loading,
175
161
  onConfirm: this.handleConfirm
176
162
  };
@@ -178,9 +164,9 @@ var InlineInputBase = /*#__PURE__*/function (_Component) {
178
164
  }, {
179
165
  key: "getCancelControlProps",
180
166
  value: function getCancelControlProps() {
181
- var _this$asProps5 = this.asProps,
182
- loading = _this$asProps5.loading,
183
- disabled = _this$asProps5.disabled;
167
+ var _this$asProps3 = this.asProps,
168
+ loading = _this$asProps3.loading,
169
+ disabled = _this$asProps3.disabled;
184
170
  return {
185
171
  value: this.initValue,
186
172
  // because double disabled(root disabled and addon disabled)
@@ -208,9 +194,9 @@ var InlineInputBase = /*#__PURE__*/function (_Component) {
208
194
 
209
195
  var SInlineInput = Box;
210
196
  var SUnderline = 'div';
211
- var _this$asProps6 = this.asProps,
212
- Children = _this$asProps6.Children,
213
- styles = _this$asProps6.styles;
197
+ var _this$asProps4 = this.asProps,
198
+ Children = _this$asProps4.Children,
199
+ styles = _this$asProps4.styles;
214
200
  var focused = this.state.focused;
215
201
  return _ref6 = sstyled(styles), /*#__PURE__*/React.createElement(SInlineInput, _ref6.cn("SInlineInput", _objectSpread({}, _assignProps({
216
202
  "ref": this.rootRef,
@@ -287,18 +273,14 @@ var Addon = function Addon(props) {
287
273
 
288
274
  var ConfirmControl = function ConfirmControl(props) {
289
275
  var _ref4 = arguments[0],
290
- _ref10,
291
- _props$icon,
292
- _props$value2;
276
+ _ref10;
293
277
 
294
278
  var SAddon = Box;
295
279
  var Children = props.Children,
296
280
  hasChildren = props.children,
297
281
  title = props.title;
298
282
  var handleConfirm = React.useCallback(function (event) {
299
- var _props$onConfirm, _props$value;
300
-
301
- (_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 ? void 0 : _props$onConfirm.call(props, (_props$value = props.value) !== null && _props$value !== void 0 ? _props$value : '', event);
283
+ props.onConfirm?.(props.value ?? '', event);
302
284
  }, [props.onConfirm, props.value]);
303
285
  var handleKeydown = React.useCallback(function (event) {
304
286
  if (event.code === 'Enter' || event.code === 'Space') {
@@ -312,19 +294,21 @@ var ConfirmControl = function ConfirmControl(props) {
312
294
  var _ref9;
313
295
 
314
296
  return _ref9 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref9.cn("SAddon", _objectSpread({}, _assignProps4({}, _ref4))), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref9.cn("Children", {})) : /*#__PURE__*/React.createElement(Spin, _ref9.cn("Spin", {
315
- "size": "xxs"
297
+ "size": "xs"
316
298
  })));
317
299
  }
318
300
 
301
+ var sstyles = sstyled(props.styles);
302
+ var sConfirmIconStyles = sstyles.cn('SConfirmIcon', {});
319
303
  return _ref10 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref10.cn("SAddon", _objectSpread({}, _assignProps5({
320
304
  "onKeyDown": handleKeydown
321
305
  }, _ref4))), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref10.cn("Children", {})) : /*#__PURE__*/React.createElement(Tooltip, _ref10.cn("Tooltip", _objectSpread({}, props.$tooltipsProps)), /*#__PURE__*/React.createElement(Tooltip.Trigger, {
322
- tag: (_props$icon = props.icon) !== null && _props$icon !== void 0 ? _props$icon : CheckM,
323
- "aria-label": "".concat(title, " ").concat((_props$value2 = props.value) !== null && _props$value2 !== void 0 ? _props$value2 : ''),
306
+ tag: props.icon ?? CheckM,
307
+ "aria-label": "".concat(title, " ").concat(props.value ?? ''),
324
308
  role: "button",
325
- interactive: true,
326
- color: "green-300",
327
- onClick: handleConfirm
309
+ onClick: handleConfirm,
310
+ className: sConfirmIconStyles.className,
311
+ style: sConfirmIconStyles.style
328
312
  }), /*#__PURE__*/React.createElement(Tooltip.Popper, {
329
313
  p: 3
330
314
  }, props.title)));
@@ -336,17 +320,14 @@ ConfirmControl.defaultProps = {
336
320
 
337
321
  var CancelControl = function CancelControl(props) {
338
322
  var _ref5 = arguments[0],
339
- _ref12,
340
- _props$icon2;
323
+ _ref12;
341
324
 
342
325
  var SAddon = Box;
343
326
  var Children = props.Children,
344
327
  hasChildren = props.children,
345
328
  title = props.title;
346
329
  var handleCancel = React.useCallback(function (event) {
347
- var _props$onCancel, _props$value3;
348
-
349
- (_props$onCancel = props.onCancel) === null || _props$onCancel === void 0 ? void 0 : _props$onCancel.call(props, (_props$value3 = props.value) !== null && _props$value3 !== void 0 ? _props$value3 : '', event);
330
+ props.onCancel?.(props.value ?? '', event);
350
331
  }, [props.onCancel, props.value]);
351
332
  var handleKeydown = React.useCallback(function (event) {
352
333
  if (event.code === 'Enter' || event.code === 'Space') {
@@ -364,15 +345,17 @@ var CancelControl = function CancelControl(props) {
364
345
  })));
365
346
  }
366
347
 
348
+ var sstyles = sstyled(props.styles);
349
+ var sCancelIconStyles = sstyles.cn('SCancelIcon', {});
367
350
  return _ref12 = sstyled(props.styles), /*#__PURE__*/React.createElement(SAddon, _ref12.cn("SAddon", _objectSpread({}, _assignProps7({
368
351
  "onKeyDown": handleKeydown
369
352
  }, _ref5))), hasChildren ? /*#__PURE__*/React.createElement(Children, _ref12.cn("Children", {})) : /*#__PURE__*/React.createElement(Tooltip, _ref12.cn("Tooltip", _objectSpread({}, props.$tooltipsProps)), /*#__PURE__*/React.createElement(Tooltip.Trigger, {
370
- tag: (_props$icon2 = props.icon) !== null && _props$icon2 !== void 0 ? _props$icon2 : CloseM,
353
+ tag: props.icon ?? CloseM,
371
354
  "aria-label": title,
372
355
  role: "button",
373
- interactive: true,
374
- color: "gray-300",
375
- onClick: handleCancel
356
+ onClick: handleCancel,
357
+ className: sCancelIconStyles.className,
358
+ style: sCancelIconStyles.style
376
359
  }), /*#__PURE__*/React.createElement(Tooltip.Popper, {
377
360
  p: 3
378
361
  }, title)));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/InlineInput.tsx"],"names":["React","createComponent","Component","sstyled","Root","Box","autoFocusEnhance","Tooltip","CheckM","CloseM","Spin","isFocusOutsideOf","element","traversed","document","activeElement","i","body","parentElement","Error","InlineInputBase","focused","createRef","setState","event","preventDefault","inputRef","current","focus","text","asProps","onConfirm","prevText","onCancel","onBlurBehavior","setTimeout","rootRef","value","initValue","code","onMouseDown","handleMouseDownAddon","loading","handleConfirm","disabled","handleCancel","state","ref","onKeyDown","handleKeyDown","onFocus","bindHandlerValueFocused","onBlur","SInlineInput","SUnderline","Children","styles","handleBlur","style","Value","target","SValue","defaultValue","Addon","props","SAddon","ConfirmControl","hasChildren","children","title","useCallback","handleKeydown","stopPropagation","$tooltipsProps","icon","defaultProps","CancelControl","InlineInput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,eAAP,IAA0BC,SAA1B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,eAA1D;AACA,SAASC,GAAT,QAAoB,mBAApB;AACA,OAAOC,gBAAP,MAA6B,8CAA7B;AACA,OAAOC,OAAP,MAAuC,kBAAvC;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOC,MAAP,MAAmB,uBAAnB;AACA,OAAOC,MAAP,MAAmB,uBAAnB;AACA,OAAOC,IAAP,MAAiB,eAAjB;;AAEA,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,OAAD,EAA0B;AACjD,MAAIC,SAAqC,GAAGC,QAAQ,CAACC,aAArD;;AACA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,OAApB,EAA6BA,CAAC,EAA9B,EAAkC;AAAA;;AAChC,QAAIH,SAAS,KAAKD,OAAlB,EAA2B,OAAO,KAAP;AAC3B,QAAIC,SAAS,KAAKC,QAAQ,CAACG,IAA3B,EAAiC,OAAO,IAAP;AACjCJ,IAAAA,SAAS,iBAAGA,SAAH,+CAAG,WAAWK,aAAvB;AACD;;AAED,QAAM,IAAIC,KAAJ,CACJ,8SADI,CAAN;AAGD,CAXD;;IA8DMC,e;;;;;;;;;;;;;;;;4DASI;AACNC,MAAAA,OAAO,EAAE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OAAO,EAAExB;AANX,IADF,eASE,oBAAC,OAAD,CAAS,MAAT;AAAgB,IAAA,CAAC,EAAE;AAAnB,KAAuBwB,KAAvB,CATF,CAJJ,CADF;AAmBD,CA/CD;;AAgDAO,aAAa,CAACD,YAAd,GAA6B;AAC3BN,EAAAA,KAAK,EAAE;AADoB,CAA7B;AAIA;;AACA,IAAMQ,WAAW,GAAG5E,eAAe,CAACmB,eAAD,EAAkB;AACnD2C,EAAAA,KAAK,EAALA,KADmD;AAEnDJ,EAAAA,KAAK,EAALA,KAFmD;AAGnDO,EAAAA,cAAc,EAAdA,cAHmD;AAInDU,EAAAA,aAAa,EAAbA;AAJmD,CAAlB,CAAnC;AAOA,eAAeC,WAAf","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: Element | null | undefined = 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` in 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 OnConfirm = (\n value: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n) => void;\ntype OnCancel = (\n prevValue: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n) => void;\ntype RootAsProps = {\n state?: 'normal' | 'valid' | 'invalid';\n loading?: boolean;\n disabled?: boolean;\n onConfirm?: OnConfirm;\n onCancel?: OnCancel;\n value?: string;\n defaultValue?: string;\n autoFocus?: boolean;\n placeholder?: 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\ntype AddonAsProps = {\n styles?: React.CSSProperties;\n Children: React.FC;\n};\n\ntype ControlAsProps = {\n Children: React.FC;\n styles?: React.CSSProperties;\n title?: string;\n $tooltipsProps?: ITooltipProps;\n loading?: boolean;\n disabled?: boolean;\n onCancel?: OnCancel;\n value?: string;\n icon?: React.FC;\n};\ntype ConfirmControlAsProps = ControlAsProps & {\n onConfirm?: OnConfirm;\n};\ntype CancelControlAsProps = ControlAsProps & {\n onCancel?: OnCancel;\n};\n\nclass InlineInputBase extends Component<RootAsProps> {\n static displayName = 'InlineInput';\n\n static defaultProps = {\n state: 'normal',\n onBlurBehavior: 'confirm',\n };\n static style = style;\n\n state = {\n focused: false,\n };\n\n rootRef = React.createRef<HTMLElement>();\n inputRef = React.createRef<HTMLInputElement>();\n initValue: string = '';\n\n componentDidMount() {\n this.initValue = this.inputRef.current?.value || '';\n }\n\n getAddonProps() {\n return {\n onMouseDown: this.handleMouseDownAddon,\n };\n }\n\n getConfirmControlProps() {\n const { loading } = this.asProps;\n return {\n value: this.inputRef.current?.value,\n loading,\n onConfirm: this.handleConfirm,\n };\n }\n\n getCancelControlProps() {\n const { loading, disabled } = this.asProps;\n return {\n value: this.initValue,\n // because double disabled(root disabled and addon disabled)\n disabled: loading && !disabled,\n onCancel: this.handleCancel,\n };\n }\n\n getValueProps() {\n const { state } = this.asProps;\n return {\n ref: this.inputRef,\n state,\n onKeyDown: this.handleKeyDown,\n onFocus: this.bindHandlerValueFocused(true),\n onBlur: this.bindHandlerValueFocused(false),\n };\n }\n\n bindHandlerValueFocused = (focused: boolean) => () => {\n this.setState({ focused });\n };\n\n handleMouseDownAddon = (event: React.MouseEvent) => {\n event.preventDefault();\n this.inputRef.current?.focus();\n };\n\n handleConfirm = (\n text: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n ) => {\n this.asProps.onConfirm?.(text, event);\n };\n handleCancel = (\n prevText: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n ) => {\n this.asProps.onCancel?.(prevText, event);\n };\n\n handleBlur = (event: React.FocusEvent) => {\n const { onConfirm, onCancel, onBlurBehavior } = this.asProps;\n if (onBlurBehavior) {\n setTimeout(() => {\n if (this.rootRef.current && isFocusOutsideOf(this.rootRef.current)) {\n if (onBlurBehavior === 'confirm') onConfirm?.(this.inputRef.current?.value ?? '', event);\n if (onBlurBehavior === 'cancel') onCancel?.(this.initValue, event);\n }\n }, 0);\n }\n };\n\n handleKeyDown = (event: React.KeyboardEvent) => {\n const { onConfirm, onCancel } = this.asProps;\n if (event.code === 'Enter') onConfirm?.(this.inputRef.current?.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, styles } = this.asProps;\n const { focused } = this.state;\n\n return sstyled(styles)(\n <SInlineInput render={Box} ref={this.rootRef} focused={focused} onBlur={this.handleBlur}>\n <SUnderline>\n <Children />\n </SUnderline>\n </SInlineInput>,\n );\n }\n}\n\nclass Value extends Component<RootAsProps> {\n static defaultProps = {\n defaultValue: '',\n };\n static enhance = [autoFocusEnhance()];\n static hoistProps = ['disabled'];\n\n uncontrolledProps() {\n return {\n value: (event: React.ChangeEvent<HTMLInputElement>) => event.target.value,\n };\n }\n\n render() {\n const SValue = Root;\n\n return sstyled(this.asProps.styles)(<SValue render={Box} tag=\"input\" type=\"text\" />);\n }\n}\n\nconst Addon: React.FC<AddonAsProps> = (props) => {\n const SAddon = Root;\n return sstyled(props.styles)(<SAddon render={Box} />) as React.ReactElement;\n};\n\nconst ConfirmControl: React.FC<ConfirmControlAsProps> = (props) => {\n const SAddon = Root;\n const { Children, children: hasChildren, title } = 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\n const handleKeydown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (event.code === 'Enter' || event.code === 'Space') {\n event.preventDefault();\n event.stopPropagation();\n handleConfirm(event);\n }\n },\n [handleConfirm],\n );\n\n if (props.loading) {\n return sstyled(props.styles)(\n <SAddon render={Box}>{hasChildren ? <Children /> : <Spin size=\"xxs\" />}</SAddon>,\n ) as React.ReactElement;\n }\n\n return sstyled(props.styles)(\n <SAddon render={Box} onKeyDown={handleKeydown}>\n {hasChildren ? (\n <Children />\n ) : (\n <Tooltip {...props.$tooltipsProps}>\n <Tooltip.Trigger\n tag={props.icon ?? CheckM}\n aria-label={`${title} ${props.value ?? ''}`}\n role=\"button\"\n interactive\n color=\"green-300\"\n onClick={handleConfirm}\n />\n <Tooltip.Popper p={3}>{props.title}</Tooltip.Popper>\n </Tooltip>\n )}\n </SAddon>,\n ) as React.ReactElement;\n};\nConfirmControl.defaultProps = {\n title: 'Confirm',\n};\nconst CancelControl: React.FC<CancelControlAsProps> = (props) => {\n const SAddon = Root;\n const { Children, children: hasChildren, title } = props;\n\n const handleCancel = React.useCallback(\n (event: React.MouseEvent | React.KeyboardEvent) => {\n props.onCancel?.(props.value ?? '', event);\n },\n [props.onCancel, props.value],\n );\n\n const handleKeydown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (event.code === 'Enter' || event.code === 'Space') {\n event.preventDefault();\n event.stopPropagation();\n handleCancel(event);\n }\n },\n [handleCancel],\n );\n\n if (props.disabled) {\n return sstyled(props.styles)(\n <SAddon render={Box}>{hasChildren ? <Children /> : <CloseM disabled />}</SAddon>,\n ) as React.ReactElement;\n }\n\n return sstyled(props.styles)(\n <SAddon render={Box} onKeyDown={handleKeydown}>\n {hasChildren ? (\n <Children />\n ) : (\n <Tooltip {...props.$tooltipsProps}>\n <Tooltip.Trigger\n tag={props.icon ?? CloseM}\n aria-label={title}\n role=\"button\"\n interactive\n color=\"gray-300\"\n onClick={handleCancel}\n />\n <Tooltip.Popper p={3}>{title}</Tooltip.Popper>\n </Tooltip>\n )}\n </SAddon>,\n ) as React.ReactElement;\n};\nCancelControl.defaultProps = {\n title: 'Cancel',\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}) as any;\n\nexport default InlineInput;\n"],"file":"InlineInput.js"}
1
+ {"version":3,"sources":["../../src/InlineInput.tsx"],"names":["React","createComponent","Component","sstyled","Root","Box","autoFocusEnhance","Tooltip","CheckM","CloseM","Spin","isFocusOutsideOf","element","traversed","document","activeElement","i","body","parentElement","Error","InlineInputBase","focused","createRef","setState","event","preventDefault","inputRef","current","focus","text","asProps","onConfirm","prevText","onCancel","onBlurBehavior","setTimeout","rootRef","value","initValue","code","onMouseDown","handleMouseDownAddon","loading","handleConfirm","disabled","handleCancel","state","ref","onKeyDown","handleKeyDown","onFocus","bindHandlerValueFocused","onBlur","SInlineInput","SUnderline","Children","styles","handleBlur","style","Value","target","SValue","defaultValue","Addon","props","SAddon","ConfirmControl","hasChildren","children","title","useCallback","handleKeydown","stopPropagation","sstyles","sConfirmIconStyles","cn","$tooltipsProps","icon","className","defaultProps","CancelControl","sCancelIconStyles","InlineInput"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,OAAOC,eAAP,IAA0BC,SAA1B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,eAA1D;AACA,SAASC,GAAT,QAAoB,mBAApB;AACA,OAAOC,gBAAP,MAA6B,8CAA7B;AACA,OAAOC,OAAP,MAAuC,kBAAvC;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAOC,MAAP,MAAmB,uBAAnB;AACA,OAAOC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CADF;AAGD;;AAED,MAAMM,OAAO,GAAGtE,OAAO,CAAC6D,KAAK,CAACR,MAAP,CAAvB;AACA,MAAMyB,iBAAiB,GAAGR,OAAO,CAACE,EAAR,CAAW,aAAX,EAA0B,EAA1B,CAA1B;AAEA,kBAAOxE,OAAO,CAAC6D,KAAK,CAACR,MAAP,CAAd,eACE,oBAAC,MAAD;AAAA,iBAAgCe;AAAhC,eACGJ,WAAW,gBACV,oBAAC,QAAD,4BADU,gBAGV,oBAAC,OAAD,yCAAaH,KAAK,CAACY,cAAnB,iBACE,oBAAC,OAAD,CAAS,OAAT;AACE,IAAA,GAAG,EAAEZ,KAAK,CAACa,IAAN,IAAcpE,MADrB;AAEE,kBAAY4D,KAFd;AAGE,IAAA,IAAI,EAAC,QAHP;AAIE,IAAA,OAAO,EAAExB,YAJX;AAKE,IAAA,SAAS,EAAEoC,iBAAiB,CAACH,SAL/B;AAME,IAAA,KAAK,EAAEG,iBAAiB,CAACvB;AAN3B,IADF,eASE,oBAAC,OAAD,CAAS,MAAT;AAAgB,IAAA,CAAC,EAAE;AAAnB,KAAuBW,KAAvB,CATF,CAJJ,CADF;AAmBD,CAlDD;;AAmDAW,aAAa,CAACD,YAAd,GAA6B;AAC3BV,EAAAA,KAAK,EAAE;AADoB,CAA7B;AAIA;;AACA,IAAMa,WAAW,GAAGjF,eAAe,CAACmB,eAAD,EAAkB;AACnD2C,EAAAA,KAAK,EAALA,KADmD;AAEnDJ,EAAAA,KAAK,EAALA,KAFmD;AAGnDO,EAAAA,cAAc,EAAdA,cAHmD;AAInDc,EAAAA,aAAa,EAAbA;AAJmD,CAAlB,CAAnC;AAOA,eAAeE,WAAf","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: Element | null | undefined = 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` in 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 OnConfirm = (\n value: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n) => void;\ntype OnCancel = (\n prevValue: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n) => void;\ntype RootAsProps = {\n state?: 'normal' | 'valid' | 'invalid';\n loading?: boolean;\n disabled?: boolean;\n onConfirm?: OnConfirm;\n onCancel?: OnCancel;\n value?: string;\n defaultValue?: string;\n autoFocus?: boolean;\n placeholder?: 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\ntype AddonAsProps = {\n styles?: React.CSSProperties;\n Children: React.FC;\n};\n\ntype ControlAsProps = {\n Children: React.FC;\n styles?: React.CSSProperties;\n title?: string;\n $tooltipsProps?: ITooltipProps;\n loading?: boolean;\n disabled?: boolean;\n onCancel?: OnCancel;\n value?: string;\n icon?: React.FC;\n};\ntype ConfirmControlAsProps = ControlAsProps & {\n onConfirm?: OnConfirm;\n};\ntype CancelControlAsProps = ControlAsProps & {\n onCancel?: OnCancel;\n};\n\nclass InlineInputBase extends Component<RootAsProps> {\n static displayName = 'InlineInput';\n\n static defaultProps = {\n state: 'normal',\n onBlurBehavior: 'confirm',\n };\n static style = style;\n\n state = {\n focused: false,\n };\n\n rootRef = React.createRef<HTMLElement>();\n inputRef = React.createRef<HTMLInputElement>();\n initValue: string = '';\n\n componentDidMount() {\n this.initValue = this.inputRef.current?.value || '';\n }\n\n getAddonProps() {\n return {\n onMouseDown: this.handleMouseDownAddon,\n };\n }\n\n getConfirmControlProps() {\n const { loading } = this.asProps;\n return {\n value: this.inputRef.current?.value,\n loading,\n onConfirm: this.handleConfirm,\n };\n }\n\n getCancelControlProps() {\n const { loading, disabled } = this.asProps;\n return {\n value: this.initValue,\n // because double disabled(root disabled and addon disabled)\n disabled: loading && !disabled,\n onCancel: this.handleCancel,\n };\n }\n\n getValueProps() {\n const { state } = this.asProps;\n return {\n ref: this.inputRef,\n state,\n onKeyDown: this.handleKeyDown,\n onFocus: this.bindHandlerValueFocused(true),\n onBlur: this.bindHandlerValueFocused(false),\n };\n }\n\n bindHandlerValueFocused = (focused: boolean) => () => {\n this.setState({ focused });\n };\n\n handleMouseDownAddon = (event: React.MouseEvent) => {\n event.preventDefault();\n this.inputRef.current?.focus();\n };\n\n handleConfirm = (\n text: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n ) => {\n this.asProps.onConfirm?.(text, event);\n };\n handleCancel = (\n prevText: string,\n event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,\n ) => {\n this.asProps.onCancel?.(prevText, event);\n };\n\n handleBlur = (event: React.FocusEvent) => {\n const { onConfirm, onCancel, onBlurBehavior } = this.asProps;\n if (onBlurBehavior) {\n setTimeout(() => {\n if (this.rootRef.current && isFocusOutsideOf(this.rootRef.current)) {\n if (onBlurBehavior === 'confirm') onConfirm?.(this.inputRef.current?.value ?? '', event);\n if (onBlurBehavior === 'cancel') onCancel?.(this.initValue, event);\n }\n }, 0);\n }\n };\n\n handleKeyDown = (event: React.KeyboardEvent) => {\n const { onConfirm, onCancel } = this.asProps;\n if (event.code === 'Enter') onConfirm?.(this.inputRef.current?.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, styles } = this.asProps;\n const { focused } = this.state;\n\n return sstyled(styles)(\n <SInlineInput render={Box} ref={this.rootRef} focused={focused} onBlur={this.handleBlur}>\n <SUnderline>\n <Children />\n </SUnderline>\n </SInlineInput>,\n );\n }\n}\n\nclass Value extends Component<RootAsProps> {\n static defaultProps = {\n defaultValue: '',\n };\n static enhance = [autoFocusEnhance()];\n static hoistProps = ['disabled'];\n\n uncontrolledProps() {\n return {\n value: (event: React.ChangeEvent<HTMLInputElement>) => event.target.value,\n };\n }\n\n render() {\n const SValue = Root;\n\n return sstyled(this.asProps.styles)(<SValue render={Box} tag=\"input\" type=\"text\" />);\n }\n}\n\nconst Addon: React.FC<AddonAsProps> = (props) => {\n const SAddon = Root;\n return sstyled(props.styles)(<SAddon render={Box} />) as React.ReactElement;\n};\n\nconst ConfirmControl: React.FC<ConfirmControlAsProps> = (props) => {\n const SAddon = Root;\n const { Children, children: hasChildren, title } = 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\n const handleKeydown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (event.code === 'Enter' || event.code === 'Space') {\n event.preventDefault();\n event.stopPropagation();\n handleConfirm(event);\n }\n },\n [handleConfirm],\n );\n\n if (props.loading) {\n return sstyled(props.styles)(\n <SAddon render={Box}>{hasChildren ? <Children /> : <Spin size=\"xs\" />}</SAddon>,\n ) as React.ReactElement;\n }\n\n const sstyles = sstyled(props.styles);\n const sConfirmIconStyles = sstyles.cn('SConfirmIcon', {});\n\n return sstyled(props.styles)(\n <SAddon render={Box} onKeyDown={handleKeydown}>\n {hasChildren ? (\n <Children />\n ) : (\n <Tooltip {...props.$tooltipsProps}>\n <Tooltip.Trigger\n tag={props.icon ?? CheckM}\n aria-label={`${title} ${props.value ?? ''}`}\n role=\"button\"\n onClick={handleConfirm}\n className={sConfirmIconStyles.className}\n style={sConfirmIconStyles.style}\n />\n <Tooltip.Popper p={3}>{props.title}</Tooltip.Popper>\n </Tooltip>\n )}\n </SAddon>,\n ) as React.ReactElement;\n};\nConfirmControl.defaultProps = {\n title: 'Confirm',\n};\nconst CancelControl: React.FC<CancelControlAsProps> = (props) => {\n const SAddon = Root;\n const { Children, children: hasChildren, title } = props;\n\n const handleCancel = React.useCallback(\n (event: React.MouseEvent | React.KeyboardEvent) => {\n props.onCancel?.(props.value ?? '', event);\n },\n [props.onCancel, props.value],\n );\n\n const handleKeydown = React.useCallback(\n (event: React.KeyboardEvent) => {\n if (event.code === 'Enter' || event.code === 'Space') {\n event.preventDefault();\n event.stopPropagation();\n handleCancel(event);\n }\n },\n [handleCancel],\n );\n\n if (props.disabled) {\n return sstyled(props.styles)(\n <SAddon render={Box}>{hasChildren ? <Children /> : <CloseM disabled />}</SAddon>,\n ) as React.ReactElement;\n }\n\n const sstyles = sstyled(props.styles);\n const sCancelIconStyles = sstyles.cn('SCancelIcon', {});\n\n return sstyled(props.styles)(\n <SAddon render={Box} onKeyDown={handleKeydown}>\n {hasChildren ? (\n <Children />\n ) : (\n <Tooltip {...props.$tooltipsProps}>\n <Tooltip.Trigger\n tag={props.icon ?? CloseM}\n aria-label={title}\n role=\"button\"\n onClick={handleCancel}\n className={sCancelIconStyles.className}\n style={sCancelIconStyles.style}\n />\n <Tooltip.Popper p={3}>{title}</Tooltip.Popper>\n </Tooltip>\n )}\n </SAddon>,\n ) as React.ReactElement;\n};\nCancelControl.defaultProps = {\n title: 'Cancel',\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}) as any;\n\nexport default InlineInput;\n"],"file":"InlineInput.js"}
@@ -0,0 +1,163 @@
1
+ import React from 'react';
2
+ import { PropGetterFn } from '@semcore/core';
3
+ import { IBoxProps } from '@semcore/flex-box';
4
+
5
+ /* utils type */
6
+ type CProps<Props, Ctx = {}, UCProps = {}> = Props & {
7
+ children?:
8
+ | ((props: Props & Ctx, handlers: UCProps) => React.ReactNode)
9
+ | React.ReactNode
10
+ | React.ReactNode[];
11
+ };
12
+ /* utils type */
13
+
14
+ export interface IInlineInputProps extends IBoxProps {
15
+ /**
16
+ * Visual state of inline input
17
+ * @default normal
18
+ */
19
+ state?: 'normal' | 'valid' | 'invalid';
20
+ /**
21
+ * Disabled input and shows spinner instead of confirm control
22
+ * @default false
23
+ */
24
+ loading?: boolean;
25
+ /**
26
+ * Disabled input and controls
27
+ * @default false
28
+ */
29
+ disabled?: boolean;
30
+ /**
31
+ * Fired with entered value when user clicks confirm control or hits `Enter` or `Space`
32
+ */
33
+ onConfirm?: (
34
+ value: string,
35
+ event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
36
+ ) => void;
37
+ /**
38
+ * Fired with value (or defaultValue) that was provided during component mount when user clicks cancel control or hits `Escape`
39
+ */
40
+ onCancel?: (
41
+ prevValue: string,
42
+ event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
43
+ ) => void;
44
+ /**
45
+ * Text value of input. Should be used with `onChange` property together
46
+ */
47
+ value?: string;
48
+ /**
49
+ * Initial text value of input
50
+ */
51
+ defaultValue?: string;
52
+ /**
53
+ * Makes component to catch browser focus on component mount
54
+ * @default false
55
+ */
56
+ autoFocus?: boolean;
57
+ /**
58
+ * Gray text displayed in empty input
59
+ */
60
+ placeholder?: string;
61
+ /**
62
+ * Fired on every input value change. Should be used with `value` property together
63
+ */
64
+ onChange?: (value: string, event: React.ChangeEvent) => void;
65
+ /**
66
+ * Fired when browser focus leaves component.
67
+ */
68
+ onBlur?: (event: React.FocusEvent) => void;
69
+ /**
70
+ * Fired when browser focus enters component.
71
+ */
72
+ onFocus?: (event: React.FocusEvent) => void;
73
+ /**
74
+ * defines callback (`onCancel` or `onConfirm`) triggered when `blur` event out of container fired
75
+ * Triggered after all previous macrotasks completed (internally called inside of `setTimeout`)
76
+ */
77
+ onBlurBehavior?: 'cancel' | 'confirm';
78
+ }
79
+
80
+ export interface IInlineInputAddonProps extends IBoxProps {}
81
+ export interface IInlineInputValueProps extends IBoxProps {
82
+ /**
83
+ * id attribute of input tag
84
+ */
85
+ id?: string;
86
+ /**
87
+ * when `true`, element is focused immediately after mount
88
+ */
89
+ autoFocus?: boolean;
90
+ /**
91
+ * value of input tag
92
+ */
93
+ value?: string;
94
+ /**
95
+ * uncontrolled value of input tag
96
+ */
97
+ defaultValue?: string;
98
+ /**
99
+ * callback invoked on every change of input tag value
100
+ */
101
+ onChange?: (value: string, event: React.ChangeEvent) => void;
102
+ /**
103
+ * visual state of component
104
+ */
105
+ state?: 'normal' | 'valid' | 'invalid';
106
+ /**
107
+ * shows spinner in `InlineInput.ConfirmControl` and disables other interactive elements
108
+ */
109
+ loading?: boolean;
110
+ /**
111
+ * disables interactive elements
112
+ */
113
+ disabled?: boolean;
114
+ /**
115
+ * gray text in empty input tag
116
+ */
117
+ placeholder?: string;
118
+ }
119
+ export interface IInlineInputConfirmControlProps extends IBoxProps {
120
+ /**
121
+ * Text of tooltip
122
+ * @default Confirm
123
+ */
124
+ title?: string;
125
+ /**
126
+ * Icon component
127
+ * @default CheckM
128
+ */
129
+ icon?: React.FC;
130
+ }
131
+ export interface IInlineInputCancelControlProps extends IBoxProps {
132
+ /**
133
+ * Text of tooltip
134
+ * @default Cancel
135
+ */
136
+ title?: string;
137
+ /**
138
+ * Icon component
139
+ * @default CloseM
140
+ */
141
+ icon?: React.FC;
142
+ }
143
+
144
+ interface IInlineInputCtx {
145
+ geAddonProps: PropGetterFn;
146
+ getConfirmControlProps: PropGetterFn;
147
+ getCancelControlProps: PropGetterFn;
148
+ getValueProps: PropGetterFn;
149
+ }
150
+
151
+ declare const InlineInput: (<T>(
152
+ props: CProps<IInlineInputProps & T, IInlineInputCtx>,
153
+ ) => React.ReactElement) & {
154
+ Addon: <T>(props: CProps<IInlineInputAddonProps & T, IInlineInputProps>) => React.ReactElement;
155
+ Value: <T>(props: CProps<IInlineInputValueProps & T, IInlineInputProps>) => React.ReactElement;
156
+ ConfirmControl: <T>(
157
+ props: CProps<IInlineInputConfirmControlProps & T, IInlineInputProps>,
158
+ ) => React.ReactElement;
159
+ CancelControl: <T>(
160
+ props: CProps<IInlineInputCancelControlProps & T, IInlineInputProps>,
161
+ ) => React.ReactElement;
162
+ };
163
+ export default InlineInput;
@@ -23,12 +23,13 @@ SInlineInput[disabled] {
23
23
  SValue {
24
24
  /* hack for firefox */
25
25
  min-width: 0;
26
+
26
27
  width: 100%;
27
28
  height: 100%;
28
29
  padding: 4px;
29
30
  border: none;
30
31
  box-sizing: border-box;
31
- color: var(--gray20);
32
+ color: var(--gray-800);
32
33
  font-size: inherit;
33
34
  line-height: 1.2;
34
35
  text-overflow: ellipsis;
@@ -41,11 +42,7 @@ SValue {
41
42
  }
42
43
 
43
44
  &::placeholder {
44
- color: var(--gray70);
45
- }
46
-
47
- &:read-only ~ SUnderline {
48
- /* background: var(--gray96); */
45
+ color: var(--gray-300);
49
46
  }
50
47
 
51
48
  &[disabled] {
@@ -81,26 +78,41 @@ SAddon[disabled] {
81
78
  pointer-events: none;
82
79
  }
83
80
 
81
+ SConfirmIcon {
82
+ color: var(--green-300);
83
+ cursor: pointer;
84
+ }
85
+ SConfirmIcon:hover {
86
+ color: var(--green-400);
87
+ }
88
+
89
+ SCancelIcon {
90
+ color: var(--gray-300);
91
+ cursor: pointer;
92
+ }
93
+ SCancelIcon:hover {
94
+ color: var(--gray-400);
95
+ }
96
+
84
97
  SInlineInput[focused] {
85
98
  z-index: 1;
86
99
  }
87
-
88
100
  SInlineInput[focused] SUnderline {
89
- border-color: var(--blue-400);
90
- box-shadow: var(--keyborad-focus);
101
+ border-bottom-color: var(--blue-400);
102
+ box-shadow: var(--keyboard-focus);
91
103
  }
92
104
 
93
105
  SInlineInput[state='valid'] SUnderline {
94
- border-color: var(--green-200);
106
+ border-bottom-color: var(--green-200);
95
107
  }
96
108
  SInlineInput[state='valid'][focused] SUnderline {
97
- border-color: var(--green-400);
109
+ border-bottom-color: var(--green-400);
98
110
  box-shadow: var(--keyboard-focus-valid);
99
111
  }
100
112
  SInlineInput[state='invalid'] SUnderline {
101
- border-color: var(--red-200);
113
+ border-bottom-color: var(--red-200);
102
114
  }
103
115
  SInlineInput[state='invalid'][focused] SUnderline {
104
- border-color: var(--red-400);
116
+ border-bottom-color: var(--red-400);
105
117
  box-shadow: var(--keyboard-focus-invalid);
106
118
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@semcore/inline-input",
3
3
  "description": "SEMRush Input Component",
4
- "version": "2.0.0",
4
+ "version": "3.0.0",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
@@ -15,8 +15,8 @@
15
15
  "dependencies": {
16
16
  "@semcore/flex-box": "^4.5.0",
17
17
  "@semcore/icon": "^2.19.3",
18
- "@semcore/spin": "^3.4.0",
19
- "@semcore/tooltip": "^4.3.5",
18
+ "@semcore/spin": "^4",
19
+ "@semcore/tooltip": "^5",
20
20
  "@semcore/utils": "^3.31.1"
21
21
  },
22
22
  "devDependencies": {