@semcore/inline-input 3.0.8 → 3.0.11

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 CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
4
4
 
5
+ ## [3.0.11] - 2022-07-21
6
+
7
+ ### Changed
8
+
9
+ - Version patch update due to children dependencies update (`@semcore/icon` [2.28.0 ~> 2.29.0]).
10
+
11
+ ## [3.0.10] - 2022-07-07
12
+
13
+ ### Changed
14
+
15
+ - Version patch update due to children dependencies update (`@semcore/flex-box` [4.5.5 ~> 4.5.6], `@semcore/icon` [2.27.0 ~> 2.28.0], `@semcore/utils` [3.33.0 ~> 3.34.0]).
16
+
17
+ ## [3.0.9] - 2022-06-03
18
+
19
+ ### Fixed
20
+
21
+ - Remove 4px vertical paddings.
22
+
5
23
  ## [3.0.8] - 2022-06-02
6
24
 
7
25
  ### Changed
package/README.md CHANGED
@@ -0,0 +1,67 @@
1
+ # @semcore/inline-input
2
+
3
+ [![version](https://img.shields.io/npm/v/@semcore/inline-input.svg)](https://www.npmjs.com/@semcore/inline-input)
4
+ [![downloads](https://img.shields.io/npm/dt/@semcore/inline-input.svg)](https://www.npmjs.com/package/@semcore/inline-input)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/semrush/intergalactic/blob/master/LICENSE)
6
+
7
+ > This component is part of the Intergalactic design system
8
+
9
+ ### 📖 [Component documentation](https://developer.semrush.com/intergalactic/components/inline-input/)
10
+
11
+ ### 🏠 [Design system](https://developer.semrush.com/intergalactic/)
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ npm install @semcore/ui
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```jsx
22
+ import InlineInput from '@semcore/ui/inline-input';
23
+ ```
24
+
25
+ <details>
26
+ <summary>Alternative installation and use</summary>
27
+
28
+ **We do not recommend this usage path due to possible dependency and update issues.**
29
+
30
+ ### Install
31
+
32
+ You can only install one package from the design system
33
+
34
+ ```sh
35
+ npm install @semcore/inline-input @semcore/core
36
+ ```
37
+
38
+ `@semcore/core` - _is the basic package by which we create our components, and it contains all of the common logic
39
+ of the components that is discussed below. There should only be one version of the package in the project._
40
+
41
+ ### Usage
42
+
43
+ You can use the package the same way but without `/ui/` in the import path.
44
+
45
+ ```jsx
46
+ import InlineInput from '@semcore/inline-input';
47
+ ```
48
+
49
+ </details>
50
+
51
+ ## 👤 Author
52
+
53
+ [UI-kit team](https://github.com/semrush/intergalactic/blob/master/MAINTAINERS) and [others ❤️](https://github.com/semrush/intergalactic/graphs/contributors)
54
+
55
+ ## 🤝 Contributing
56
+
57
+ Contributions, issues and feature requests are welcome!
58
+
59
+ Feel free to check [issues page](https://github.com/semrush/intergalactic/issues). You can also take a look at the [contributing guide](https://github.com/semrush/intergalactic/blob/master/CONTRIBUTING.md).
60
+
61
+ ## Show your support
62
+
63
+ Give a ⭐️ if this project helped you!
64
+
65
+ ## 📝 License
66
+
67
+ This project is [MIT](https://github.com/semrush/intergalactic/blob/master/LICENSE) licensed.
@@ -56,21 +56,21 @@ var style = (
56
56
  /*__reshadow_css_start__*/
57
57
  _core.sstyled.insert(
58
58
  /*__inner_css_start__*/
59
- ".___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)}"
59
+ ".___SInlineInput_1aw2u_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_1aw2u_gg_.__disabled_1aw2u_gg_{cursor:default;pointer-events:none;opacity:0.3}.___SValue_1aw2u_gg_{min-width:0;width:100%;height:100%;padding:0 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_1aw2u_gg_:focus{outline:none}.___SValue_1aw2u_gg_::-moz-placeholder{color:#a9abb6}.___SValue_1aw2u_gg_:-ms-input-placeholder{color:#a9abb6}.___SValue_1aw2u_gg_::placeholder{color:#a9abb6}.___SValue_1aw2u_gg_.__disabled_1aw2u_gg_{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.___SUnderline_1aw2u_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_1aw2u_gg_{display:inline-flex;justify-content:center;align-items:center;flex:0 0 auto;height:100%;color:#a9abb6;padding:0 4px}.___SAddon_1aw2u_gg_.__disabled_1aw2u_gg_{opacity:0.3;cursor:default;pointer-events:none}.___SConfirmIcon_1aw2u_gg_{color:#00c192;cursor:pointer}.___SConfirmIcon_1aw2u_gg_:hover{color:#009f81}.___SCancelIcon_1aw2u_gg_{color:#a9abb6;cursor:pointer}.___SCancelIcon_1aw2u_gg_:hover{color:#8a8e9b}.___SInlineInput_1aw2u_gg_.__focused_1aw2u_gg_{z-index:1}.___SInlineInput_1aw2u_gg_.__focused_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#008ff8;box-shadow:0 0 0 3px rgba(0, 143, 248, 0.2)}.___SInlineInput_1aw2u_gg_._state_valid_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#59ddaa}.___SInlineInput_1aw2u_gg_._state_valid_1aw2u_gg_.__focused_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#009f81;box-shadow:0px 0px 0px 3px rgba(0, 159, 129, 0.2)}.___SInlineInput_1aw2u_gg_._state_invalid_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#ffaeb5}.___SInlineInput_1aw2u_gg_._state_invalid_1aw2u_gg_.__focused_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#ff4953;box-shadow:0px 0px 0px 3px rgba(255, 73, 83, 0.2)}"
60
60
  /*__inner_css_end__*/
61
- , "1xjfing_gg_")
61
+ , "1aw2u_gg_")
62
62
  /*__reshadow_css_end__*/
63
63
  , {
64
- "__SInlineInput": "___SInlineInput_xe56s_gg_",
65
- "_disabled": "__disabled_xe56s_gg_",
66
- "__SValue": "___SValue_xe56s_gg_",
67
- "__SUnderline": "___SUnderline_xe56s_gg_",
68
- "__SAddon": "___SAddon_xe56s_gg_",
69
- "__SConfirmIcon": "___SConfirmIcon_xe56s_gg_",
70
- "__SCancelIcon": "___SCancelIcon_xe56s_gg_",
71
- "_focused": "__focused_xe56s_gg_",
72
- "_state_valid": "_state_valid_xe56s_gg_",
73
- "_state_invalid": "_state_invalid_xe56s_gg_"
64
+ "__SInlineInput": "___SInlineInput_1aw2u_gg_",
65
+ "_disabled": "__disabled_1aw2u_gg_",
66
+ "__SValue": "___SValue_1aw2u_gg_",
67
+ "__SUnderline": "___SUnderline_1aw2u_gg_",
68
+ "__SAddon": "___SAddon_1aw2u_gg_",
69
+ "__SConfirmIcon": "___SConfirmIcon_1aw2u_gg_",
70
+ "__SCancelIcon": "___SCancelIcon_1aw2u_gg_",
71
+ "_focused": "__focused_1aw2u_gg_",
72
+ "_state_valid": "_state_valid_1aw2u_gg_",
73
+ "_state_invalid": "_state_invalid_1aw2u_gg_"
74
74
  });
75
75
 
76
76
  var isFocusOutsideOf = function isFocusOutsideOf(element) {
@@ -26,7 +26,7 @@ SValue {
26
26
 
27
27
  width: 100%;
28
28
  height: 100%;
29
- padding: 4px;
29
+ padding: 0px 4px;
30
30
  border: none;
31
31
  box-sizing: border-box;
32
32
  color: var(--gray-800);
@@ -33,21 +33,21 @@ var style = (
33
33
  /*__reshadow_css_start__*/
34
34
  _sstyled.insert(
35
35
  /*__inner_css_start__*/
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)}"
36
+ ".___SInlineInput_1aw2u_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_1aw2u_gg_.__disabled_1aw2u_gg_{cursor:default;pointer-events:none;opacity:0.3}.___SValue_1aw2u_gg_{min-width:0;width:100%;height:100%;padding:0 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_1aw2u_gg_:focus{outline:none}.___SValue_1aw2u_gg_::-moz-placeholder{color:#a9abb6}.___SValue_1aw2u_gg_:-ms-input-placeholder{color:#a9abb6}.___SValue_1aw2u_gg_::placeholder{color:#a9abb6}.___SValue_1aw2u_gg_.__disabled_1aw2u_gg_{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.___SUnderline_1aw2u_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_1aw2u_gg_{display:inline-flex;justify-content:center;align-items:center;flex:0 0 auto;height:100%;color:#a9abb6;padding:0 4px}.___SAddon_1aw2u_gg_.__disabled_1aw2u_gg_{opacity:0.3;cursor:default;pointer-events:none}.___SConfirmIcon_1aw2u_gg_{color:#00c192;cursor:pointer}.___SConfirmIcon_1aw2u_gg_:hover{color:#009f81}.___SCancelIcon_1aw2u_gg_{color:#a9abb6;cursor:pointer}.___SCancelIcon_1aw2u_gg_:hover{color:#8a8e9b}.___SInlineInput_1aw2u_gg_.__focused_1aw2u_gg_{z-index:1}.___SInlineInput_1aw2u_gg_.__focused_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#008ff8;box-shadow:0 0 0 3px rgba(0, 143, 248, 0.2)}.___SInlineInput_1aw2u_gg_._state_valid_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#59ddaa}.___SInlineInput_1aw2u_gg_._state_valid_1aw2u_gg_.__focused_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#009f81;box-shadow:0px 0px 0px 3px rgba(0, 159, 129, 0.2)}.___SInlineInput_1aw2u_gg_._state_invalid_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#ffaeb5}.___SInlineInput_1aw2u_gg_._state_invalid_1aw2u_gg_.__focused_1aw2u_gg_ .___SUnderline_1aw2u_gg_{border-bottom-color:#ff4953;box-shadow:0px 0px 0px 3px rgba(255, 73, 83, 0.2)}"
37
37
  /*__inner_css_end__*/
38
- , "1xjfing_gg_")
38
+ , "1aw2u_gg_")
39
39
  /*__reshadow_css_end__*/
40
40
  , {
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_"
41
+ "__SInlineInput": "___SInlineInput_1aw2u_gg_",
42
+ "_disabled": "__disabled_1aw2u_gg_",
43
+ "__SValue": "___SValue_1aw2u_gg_",
44
+ "__SUnderline": "___SUnderline_1aw2u_gg_",
45
+ "__SAddon": "___SAddon_1aw2u_gg_",
46
+ "__SConfirmIcon": "___SConfirmIcon_1aw2u_gg_",
47
+ "__SCancelIcon": "___SCancelIcon_1aw2u_gg_",
48
+ "_focused": "__focused_1aw2u_gg_",
49
+ "_state_valid": "_state_valid_1aw2u_gg_",
50
+ "_state_invalid": "_state_invalid_1aw2u_gg_"
51
51
  });
52
52
  import CheckM from '@semcore/icon/Check/m';
53
53
  import CloseM from '@semcore/icon/Close/m';
@@ -26,7 +26,7 @@ SValue {
26
26
 
27
27
  width: 100%;
28
28
  height: 100%;
29
- padding: 4px;
29
+ padding: 0px 4px;
30
30
  border: none;
31
31
  box-sizing: border-box;
32
32
  color: var(--gray-800);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@semcore/inline-input",
3
3
  "description": "SEMRush Input Component",
4
- "version": "3.0.8",
4
+ "version": "3.0.11",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/es6/index.js",
7
7
  "typings": "lib/types/index.d.ts",
8
8
  "sideEffects": false,
9
- "author": "SEMRush UI-Kit team <ui-kit-team@semrush.com>",
9
+ "author": "UI-kit team <ui-kit-team@semrush.com>",
10
10
  "license": "MIT",
11
11
  "scripts": {
12
12
  "build": "build --source=js",
@@ -1,328 +0,0 @@
1
- import React from 'react';
2
- import createComponent, { Component, sstyled, Root } from '@semcore/core';
3
- import { Box } from '@semcore/flex-box';
4
- import autoFocusEnhance from '@semcore/utils/lib/enhances/autoFocusEnhance';
5
- import Tooltip, { ITooltipProps } from '@semcore/tooltip';
6
- import style from './style/inline-input.shadow.css';
7
- import CheckM from '@semcore/icon/Check/m';
8
- import CloseM from '@semcore/icon/Close/m';
9
- import Spin from '@semcore/spin';
10
-
11
- const isFocusOutsideOf = (element: HTMLElement) => {
12
- let traversed: Element | null | undefined = document.activeElement;
13
- for (let i = 0; i < 1000000; i++) {
14
- if (traversed === element) return false;
15
- if (traversed === document.body) return true;
16
- traversed = traversed?.parentElement;
17
- }
18
-
19
- throw new Error(
20
- '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.',
21
- );
22
- };
23
-
24
- type OnConfirm = (
25
- value: string,
26
- event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
27
- ) => void;
28
- type OnCancel = (
29
- prevValue: string,
30
- event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
31
- ) => void;
32
- type RootAsProps = {
33
- state?: 'normal' | 'valid' | 'invalid';
34
- loading?: boolean;
35
- disabled?: boolean;
36
- onConfirm?: OnConfirm;
37
- onCancel?: OnCancel;
38
- value?: string;
39
- defaultValue?: string;
40
- autoFocus?: boolean;
41
- placeholder?: string;
42
- onChange?: (value: string, event: React.ChangeEvent) => void;
43
- onBlur?: (event: React.FocusEvent) => void;
44
- onFocus?: (event: React.FocusEvent) => void;
45
- onBlurBehavior?: 'cancel' | 'confirm';
46
- styles?: React.CSSProperties;
47
- Children: React.FC;
48
- };
49
-
50
- type AddonAsProps = {
51
- styles?: React.CSSProperties;
52
- Children: React.FC;
53
- };
54
-
55
- type ControlAsProps = {
56
- Children: React.FC;
57
- styles?: React.CSSProperties;
58
- title?: string;
59
- $tooltipsProps?: ITooltipProps;
60
- loading?: boolean;
61
- disabled?: boolean;
62
- onCancel?: OnCancel;
63
- value?: string;
64
- icon?: React.FC;
65
- };
66
- type ConfirmControlAsProps = ControlAsProps & {
67
- onConfirm?: OnConfirm;
68
- };
69
- type CancelControlAsProps = ControlAsProps & {
70
- onCancel?: OnCancel;
71
- };
72
-
73
- class InlineInputBase extends Component<RootAsProps> {
74
- static displayName = 'InlineInput';
75
-
76
- static defaultProps = {
77
- state: 'normal',
78
- onBlurBehavior: 'confirm',
79
- };
80
- static style = style;
81
-
82
- state = {
83
- focused: false,
84
- };
85
-
86
- rootRef = React.createRef<HTMLElement>();
87
- inputRef = React.createRef<HTMLInputElement>();
88
- initValue: string = '';
89
-
90
- componentDidMount() {
91
- this.initValue = this.inputRef.current?.value || '';
92
- }
93
-
94
- getAddonProps() {
95
- return {
96
- onMouseDown: this.handleMouseDownAddon,
97
- };
98
- }
99
-
100
- getConfirmControlProps() {
101
- const { loading } = this.asProps;
102
- return {
103
- value: this.inputRef.current?.value,
104
- loading,
105
- onConfirm: this.handleConfirm,
106
- };
107
- }
108
-
109
- getCancelControlProps() {
110
- const { loading, disabled } = this.asProps;
111
- return {
112
- value: this.initValue,
113
- // because double disabled(root disabled and addon disabled)
114
- disabled: loading && !disabled,
115
- onCancel: this.handleCancel,
116
- };
117
- }
118
-
119
- getValueProps() {
120
- const { state } = this.asProps;
121
- return {
122
- ref: this.inputRef,
123
- state,
124
- onKeyDown: this.handleKeyDown,
125
- onFocus: this.bindHandlerValueFocused(true),
126
- onBlur: this.bindHandlerValueFocused(false),
127
- };
128
- }
129
-
130
- bindHandlerValueFocused = (focused: boolean) => () => {
131
- this.setState({ focused });
132
- };
133
-
134
- handleMouseDownAddon = (event: React.MouseEvent) => {
135
- event.preventDefault();
136
- this.inputRef.current?.focus();
137
- };
138
-
139
- handleConfirm = (
140
- text: string,
141
- event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
142
- ) => {
143
- this.asProps.onConfirm?.(text, event);
144
- };
145
- handleCancel = (
146
- prevText: string,
147
- event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
148
- ) => {
149
- this.asProps.onCancel?.(prevText, event);
150
- };
151
-
152
- handleBlur = (event: React.FocusEvent) => {
153
- const { onConfirm, onCancel, onBlurBehavior } = this.asProps;
154
- if (onBlurBehavior) {
155
- setTimeout(() => {
156
- if (this.rootRef.current && isFocusOutsideOf(this.rootRef.current)) {
157
- if (onBlurBehavior === 'confirm') onConfirm?.(this.inputRef.current?.value ?? '', event);
158
- if (onBlurBehavior === 'cancel') onCancel?.(this.initValue, event);
159
- }
160
- }, 0);
161
- }
162
- };
163
-
164
- handleKeyDown = (event: React.KeyboardEvent) => {
165
- const { onConfirm, onCancel } = this.asProps;
166
- if (event.code === 'Enter') onConfirm?.(this.inputRef.current?.value ?? '', event);
167
- if (event.code === 'Escape') onCancel?.(this.initValue, event);
168
- };
169
-
170
- render() {
171
- const SInlineInput = Root;
172
- const SUnderline = 'div';
173
- const { Children, styles } = this.asProps;
174
- const { focused } = this.state;
175
-
176
- return sstyled(styles)(
177
- <SInlineInput render={Box} ref={this.rootRef} focused={focused} onBlur={this.handleBlur}>
178
- <SUnderline>
179
- <Children />
180
- </SUnderline>
181
- </SInlineInput>,
182
- );
183
- }
184
- }
185
-
186
- class Value extends Component<RootAsProps> {
187
- static defaultProps = {
188
- defaultValue: '',
189
- };
190
- static enhance = [autoFocusEnhance()];
191
- static hoistProps = ['disabled'];
192
-
193
- uncontrolledProps() {
194
- return {
195
- value: (event: React.ChangeEvent<HTMLInputElement>) => event.target.value,
196
- };
197
- }
198
-
199
- render() {
200
- const SValue = Root;
201
-
202
- return sstyled(this.asProps.styles)(<SValue render={Box} tag="input" type="text" />);
203
- }
204
- }
205
-
206
- const Addon: React.FC<AddonAsProps> = (props) => {
207
- const SAddon = Root;
208
- return sstyled(props.styles)(<SAddon render={Box} />) as React.ReactElement;
209
- };
210
-
211
- const ConfirmControl: React.FC<ConfirmControlAsProps> = (props) => {
212
- const SAddon = Root;
213
- const { Children, children: hasChildren, title } = props;
214
-
215
- const handleConfirm = React.useCallback(
216
- (event: React.MouseEvent | React.KeyboardEvent) => {
217
- props.onConfirm?.(props.value ?? '', event);
218
- },
219
- [props.onConfirm, props.value],
220
- );
221
-
222
- const handleKeydown = React.useCallback(
223
- (event: React.KeyboardEvent) => {
224
- if (event.code === 'Enter' || event.code === 'Space') {
225
- event.preventDefault();
226
- event.stopPropagation();
227
- handleConfirm(event);
228
- }
229
- },
230
- [handleConfirm],
231
- );
232
-
233
- if (props.loading) {
234
- return sstyled(props.styles)(
235
- <SAddon render={Box}>{hasChildren ? <Children /> : <Spin size="xs" />}</SAddon>,
236
- ) as React.ReactElement;
237
- }
238
-
239
- const sstyles = sstyled(props.styles);
240
- const sConfirmIconStyles = sstyles.cn('SConfirmIcon', {});
241
-
242
- return sstyled(props.styles)(
243
- <SAddon render={Box} onKeyDown={handleKeydown}>
244
- {hasChildren ? (
245
- <Children />
246
- ) : (
247
- <Tooltip {...props.$tooltipsProps}>
248
- <Tooltip.Trigger
249
- tag={props.icon ?? CheckM}
250
- aria-label={`${title} ${props.value ?? ''}`}
251
- role="button"
252
- onClick={handleConfirm}
253
- className={sConfirmIconStyles.className}
254
- style={sConfirmIconStyles.style}
255
- />
256
- <Tooltip.Popper p={3}>{props.title}</Tooltip.Popper>
257
- </Tooltip>
258
- )}
259
- </SAddon>,
260
- ) as React.ReactElement;
261
- };
262
- ConfirmControl.defaultProps = {
263
- title: 'Confirm',
264
- };
265
- const CancelControl: React.FC<CancelControlAsProps> = (props) => {
266
- const SAddon = Root;
267
- const { Children, children: hasChildren, title } = props;
268
-
269
- const handleCancel = React.useCallback(
270
- (event: React.MouseEvent | React.KeyboardEvent) => {
271
- props.onCancel?.(props.value ?? '', event);
272
- },
273
- [props.onCancel, props.value],
274
- );
275
-
276
- const handleKeydown = React.useCallback(
277
- (event: React.KeyboardEvent) => {
278
- if (event.code === 'Enter' || event.code === 'Space') {
279
- event.preventDefault();
280
- event.stopPropagation();
281
- handleCancel(event);
282
- }
283
- },
284
- [handleCancel],
285
- );
286
-
287
- if (props.disabled) {
288
- return sstyled(props.styles)(
289
- <SAddon render={Box}>{hasChildren ? <Children /> : <CloseM disabled />}</SAddon>,
290
- ) as React.ReactElement;
291
- }
292
-
293
- const sstyles = sstyled(props.styles);
294
- const sCancelIconStyles = sstyles.cn('SCancelIcon', {});
295
-
296
- return sstyled(props.styles)(
297
- <SAddon render={Box} onKeyDown={handleKeydown}>
298
- {hasChildren ? (
299
- <Children />
300
- ) : (
301
- <Tooltip {...props.$tooltipsProps}>
302
- <Tooltip.Trigger
303
- tag={props.icon ?? CloseM}
304
- aria-label={title}
305
- role="button"
306
- onClick={handleCancel}
307
- className={sCancelIconStyles.className}
308
- style={sCancelIconStyles.style}
309
- />
310
- <Tooltip.Popper p={3}>{title}</Tooltip.Popper>
311
- </Tooltip>
312
- )}
313
- </SAddon>,
314
- ) as React.ReactElement;
315
- };
316
- CancelControl.defaultProps = {
317
- title: 'Cancel',
318
- };
319
-
320
- /** `createComponent` currently exposes unrelated junk instead of typings, that the reason of to any cast */
321
- const InlineInput = createComponent(InlineInputBase, {
322
- Addon,
323
- Value,
324
- ConfirmControl,
325
- CancelControl,
326
- }) as any;
327
-
328
- export default InlineInput;
package/src/index.d.ts DELETED
@@ -1,163 +0,0 @@
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;
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- import InlineInputBase from './InlineInput';
2
- export default InlineInputBase;
@@ -1,118 +0,0 @@
1
- @import '@semcore/utils/style/var.css';
2
-
3
- SInlineInput {
4
- display: inline-flex;
5
- width: 100%;
6
- height: 100%;
7
- align-items: center;
8
- position: relative;
9
- z-index: 0;
10
- vertical-align: middle;
11
- padding: 1px;
12
- box-sizing: border-box;
13
-
14
- background-color: var(--white);
15
- }
16
-
17
- SInlineInput[disabled] {
18
- cursor: default;
19
- pointer-events: none;
20
- opacity: var(--disabled-opacity);
21
- }
22
-
23
- SValue {
24
- /* hack for firefox */
25
- min-width: 0;
26
-
27
- width: 100%;
28
- height: 100%;
29
- padding: 4px;
30
- border: none;
31
- box-sizing: border-box;
32
- color: var(--gray-800);
33
- font-size: inherit;
34
- line-height: 1.2;
35
- text-overflow: ellipsis;
36
- font-family: inherit;
37
- background: transparent;
38
- min-height: 1em;
39
-
40
- &:focus {
41
- outline: none;
42
- }
43
-
44
- &::placeholder {
45
- color: var(--gray-300);
46
- }
47
-
48
- &[disabled] {
49
- user-select: none;
50
- }
51
- }
52
-
53
- SUnderline {
54
- display: flex;
55
- flex-direction: row;
56
- align-items: center;
57
- flex-grow: 1;
58
- width: 100%;
59
- height: 100%;
60
- min-height: 1em;
61
- border: 1px solid transparent;
62
- border-bottom: 1px solid var(--gray-200);
63
- }
64
-
65
- SAddon {
66
- display: inline-flex;
67
- justify-content: center;
68
- align-items: center;
69
- flex: 0 0 auto;
70
- height: 100%;
71
- color: var(--gray-300);
72
- padding: 0 4px;
73
- }
74
-
75
- SAddon[disabled] {
76
- opacity: var(--disabled-opacity);
77
- cursor: default;
78
- pointer-events: none;
79
- }
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
-
97
- SInlineInput[focused] {
98
- z-index: 1;
99
- }
100
- SInlineInput[focused] SUnderline {
101
- border-bottom-color: var(--blue-400);
102
- box-shadow: var(--keyboard-focus);
103
- }
104
-
105
- SInlineInput[state='valid'] SUnderline {
106
- border-bottom-color: var(--green-200);
107
- }
108
- SInlineInput[state='valid'][focused] SUnderline {
109
- border-bottom-color: var(--green-400);
110
- box-shadow: var(--keyboard-focus-valid);
111
- }
112
- SInlineInput[state='invalid'] SUnderline {
113
- border-bottom-color: var(--red-200);
114
- }
115
- SInlineInput[state='invalid'][focused] SUnderline {
116
- border-bottom-color: var(--red-400);
117
- box-shadow: var(--keyboard-focus-invalid);
118
- }