@semcore/inline-input 1.0.0 → 2.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/src/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import React from 'react';
2
2
  import { PropGetterFn } from '@semcore/core';
3
- import { ITooltipProps } from '@semcore/tooltip';
4
3
  import { IBoxProps } from '@semcore/flex-box';
5
4
 
6
5
  /* utils type */
7
6
  type CProps<Props, Ctx = {}, UCProps = {}> = Props & {
8
- children?: ((props: Props & Ctx, handlers: UCProps) => React.ReactElement) | React.ReactElement;
7
+ children?:
8
+ | ((props: Props & Ctx, handlers: UCProps) => React.ReactNode)
9
+ | React.ReactNode
10
+ | React.ReactNode[];
9
11
  };
10
12
  /* utils type */
11
13
 
@@ -14,20 +16,31 @@ export interface IInlineInputProps extends IBoxProps {
14
16
  * Visual state of inline input
15
17
  * @default normal
16
18
  */
17
- state?: 'normal' | 'valid' | 'invalid' | 'disabled';
19
+ state?: 'normal' | 'valid' | 'invalid';
18
20
  /**
19
- * Disabled inputs and shows spinner instead of confirm control
21
+ * Disabled input and shows spinner instead of confirm control
20
22
  * @default false
21
23
  */
22
24
  loading?: boolean;
25
+ /**
26
+ * Disabled input and controls
27
+ * @default false
28
+ */
29
+ disabled?: boolean;
23
30
  /**
24
31
  * Fired with entered value when user clicks confirm control or hits `Enter` or `Space`
25
32
  */
26
- onConfirm?: (value: string, event: React.MouseEvent | React.KeyboardEvent) => void;
33
+ onConfirm?: (
34
+ value: string,
35
+ event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
36
+ ) => void;
27
37
  /**
28
38
  * Fired with value (or defaultValue) that was provided during component mount when user clicks cancel control or hits `Escape`
29
39
  */
30
- onCancel?: (prevValue: string) => void;
40
+ onCancel?: (
41
+ prevValue: string,
42
+ event: React.MouseEvent | React.FocusEvent | React.KeyboardEvent,
43
+ ) => void;
31
44
  /**
32
45
  * Text value of input. Should be used with `onChange` property together
33
46
  */
@@ -36,20 +49,6 @@ export interface IInlineInputProps extends IBoxProps {
36
49
  * Initial text value of input
37
50
  */
38
51
  defaultValue?: string;
39
- /**
40
- * Tooltip and aria-label text of the confirm control
41
- * @default Confirm
42
- */
43
- confirmText?: string;
44
- /**
45
- * Tooltip and aria-label text of the cancel control
46
- * @default Cancel
47
- */
48
- cancelText?: string;
49
- /**
50
- * Properties of control's tooltips
51
- */
52
- tooltipsProps?: ITooltipProps;
53
52
  /**
54
53
  * Makes component to catch browser focus on component mount
55
54
  * @default false
@@ -59,10 +58,6 @@ export interface IInlineInputProps extends IBoxProps {
59
58
  * Gray text displayed in empty input
60
59
  */
61
60
  placeholder?: string;
62
- /**
63
- * `id` attribute of `<input />` dom tag. Use it to attach `<label />` via `htmlFor` attribute to `<input />` tag
64
- */
65
- inputId?: string;
66
61
  /**
67
62
  * Fired on every input value change. Should be used with `value` property together
68
63
  */
@@ -76,124 +71,93 @@ export interface IInlineInputProps extends IBoxProps {
76
71
  */
77
72
  onFocus?: (event: React.FocusEvent) => void;
78
73
  /**
79
- * @description defines callback (`onCancel` or `onConfirm`) triggered when `blur` event out of container fired
74
+ * defines callback (`onCancel` or `onConfirm`) triggered when `blur` event out of container fired
80
75
  * Triggered after all previous macrotasks completed (internally called inside of `setTimeout`)
81
76
  */
82
77
  onBlurBehavior?: 'cancel' | 'confirm';
83
78
  }
84
79
 
85
- export interface IInlineInputAddonProps extends IBoxProps {
86
- size?: 's' | 'm' | 'l' | 'xl';
87
- }
88
- export interface IInlineInputUnderlineProps extends IBoxProps {}
80
+ export interface IInlineInputAddonProps extends IBoxProps {}
89
81
  export interface IInlineInputValueProps extends IBoxProps {
82
+ /**
83
+ * id attribute of input tag
84
+ */
90
85
  id?: string;
91
- size?: 's' | 'm' | 'l' | 'xl';
86
+ /**
87
+ * when `true`, element is focused immediately after mount
88
+ */
92
89
  autoFocus?: boolean;
90
+ /**
91
+ * value of input tag
92
+ */
93
93
  value?: string;
94
+ /**
95
+ * uncontrolled value of input tag
96
+ */
94
97
  defaultValue?: string;
98
+ /**
99
+ * callback invoked on every change of input tag value
100
+ */
95
101
  onChange?: (value: string, event: React.ChangeEvent) => void;
96
- state?: 'normal' | 'valid' | 'invalid' | 'disabled';
97
- loading?: boolean;
98
- placeholder?: string;
99
- }
100
- export interface IInlineInputConfirmIconProps extends IBoxProps {
101
- onConfirm?: (value: string) => void;
102
102
  /**
103
- * @default "Confirm"
103
+ * visual state of component
104
104
  */
105
- confirmText?: string;
106
- tooltipsProps?: ITooltipProps;
107
- }
108
- export interface IInlineInputCancelIconProps extends IBoxProps {
109
- onCancel?: (prevValue: string) => void;
105
+ state?: 'normal' | 'valid' | 'invalid';
110
106
  /**
111
- * @default "Cancel"
107
+ * shows spinner in `InlineInput.ConfirmControl` and disables other interactive elements
112
108
  */
113
- cancelText?: string;
114
- tooltipsProps?: ITooltipProps;
115
- }
116
- export interface IInlineInputControlIconsProps extends IBoxProps {
117
- onConfirm?: (value: string) => void;
118
- onCancel?: (prevValue: string) => void;
109
+ loading?: boolean;
119
110
  /**
120
- * @default "Confirm"
111
+ * disables interactive elements
121
112
  */
122
- confirmText?: string;
113
+ disabled?: boolean;
123
114
  /**
124
- * @default "Cancel"
115
+ * gray text in empty input tag
125
116
  */
126
- cancelText?: string;
127
- tooltipsProps?: ITooltipProps;
117
+ placeholder?: string;
128
118
  }
129
- export interface IInlineInputConfirmButtonProps extends IBoxProps {
130
- size?: 's' | 'm' | 'l' | 'xl';
131
-
132
- onConfirm?: (value: string) => void;
119
+ export interface IInlineInputConfirmControlProps extends IBoxProps {
133
120
  /**
134
- * @default "Confirm"
121
+ * Text of tooltip
122
+ * @default Confirm
135
123
  */
136
- confirmText?: string;
137
- }
138
- export interface IInlineInputCancelButtonProps extends IBoxProps {
139
- size?: 's' | 'm' | 'l' | 'xl';
140
-
141
- onCancel?: (prevValue: string) => void;
124
+ title?: string;
142
125
  /**
143
- * @default "Confirm"
126
+ * Icon component
127
+ * @default CheckM
144
128
  */
145
- cancelText?: string;
129
+ icon?: React.FC;
146
130
  }
147
- export interface IInlineInputControlButtonsProps extends IBoxProps {
148
- size?: 's' | 'm' | 'l' | 'xl';
149
-
150
- onConfirm?: (value: string) => void;
151
- onCancel?: (prevValue: string) => void;
131
+ export interface IInlineInputCancelControlProps extends IBoxProps {
152
132
  /**
153
- * @default "Confirm"
133
+ * Text of tooltip
134
+ * @default Cancel
154
135
  */
155
- confirmText?: string;
136
+ title?: string;
156
137
  /**
157
- * @default "Cancel"
138
+ * Icon component
139
+ * @default CloseM
158
140
  */
159
- cancelText?: string;
141
+ icon?: React.FC;
160
142
  }
161
143
 
162
144
  interface IInlineInputCtx {
163
145
  geAddonProps: PropGetterFn;
164
- getConfirmIconProps: PropGetterFn;
165
- getCancelIconProps: PropGetterFn;
166
- getControlIconsProps: PropGetterFn;
167
- getConfirmButtonProps: PropGetterFn;
168
- getCancelButtonProps: PropGetterFn;
169
- getControlButtonsProps: PropGetterFn;
146
+ getConfirmControlProps: PropGetterFn;
147
+ getCancelControlProps: PropGetterFn;
148
+ getValueProps: PropGetterFn;
170
149
  }
171
150
 
172
151
  declare const InlineInput: (<T>(
173
152
  props: CProps<IInlineInputProps & T, IInlineInputCtx>,
174
153
  ) => React.ReactElement) & {
175
154
  Addon: <T>(props: CProps<IInlineInputAddonProps & T, IInlineInputProps>) => React.ReactElement;
176
- Underline: <T>(
177
- props: CProps<IInlineInputUnderlineProps & T, IInlineInputProps>,
178
- ) => React.ReactElement;
179
155
  Value: <T>(props: CProps<IInlineInputValueProps & T, IInlineInputProps>) => React.ReactElement;
180
- ConfirmIcon: <T>(
181
- props: CProps<IInlineInputConfirmIconProps & T, IInlineInputProps>,
182
- ) => React.ReactElement;
183
- CancelIcon: <T>(
184
- props: CProps<IInlineInputCancelIconProps & T, IInlineInputProps>,
185
- ) => React.ReactElement;
186
- ControlIcons: <T>(
187
- props: CProps<IInlineInputControlIconsProps & T, IInlineInputProps>,
188
- ) => React.ReactElement;
189
- ConfirmButton: <T>(
190
- props: CProps<IInlineInputConfirmButtonProps & T, IInlineInputProps>,
191
- ) => React.ReactElement;
192
- CancelButton: <T>(
193
- props: CProps<IInlineInputCancelButtonProps & T, IInlineInputProps>,
156
+ ConfirmControl: <T>(
157
+ props: CProps<IInlineInputConfirmControlProps & T, IInlineInputProps>,
194
158
  ) => React.ReactElement;
195
- ControlButtons: <T>(
196
- props: CProps<IInlineInputControlButtonsProps & T, IInlineInputProps>,
159
+ CancelControl: <T>(
160
+ props: CProps<IInlineInputCancelControlProps & T, IInlineInputProps>,
197
161
  ) => React.ReactElement;
198
162
  };
199
163
  export default InlineInput;
@@ -14,26 +14,10 @@ SInlineInput {
14
14
  background-color: var(--white);
15
15
  }
16
16
 
17
- SControls {
18
- display: flex;
19
- flex-direction: row;
20
- flex-shrink: 0;
21
- }
22
-
23
- SConfirmControl {
24
- color: var(--green-300);
25
- cursor: pointer;
26
- }
27
- SConfirmControl:hover {
28
- color: var(--green-400);
29
- }
30
-
31
- SCancelControl {
32
- color: var(--gray-300);
33
- cursor: pointer;
34
- }
35
- SCancelControl:hover {
36
- color: var(--gray-400);
17
+ SInlineInput[disabled] {
18
+ cursor: default;
19
+ pointer-events: none;
20
+ opacity: var(--disabled-opacity);
37
21
  }
38
22
 
39
23
  SValue {
@@ -41,7 +25,7 @@ SValue {
41
25
  min-width: 0;
42
26
  width: 100%;
43
27
  height: 100%;
44
- padding: 0 4px;
28
+ padding: 4px;
45
29
  border: none;
46
30
  box-sizing: border-box;
47
31
  color: var(--gray20);
@@ -64,17 +48,8 @@ SValue {
64
48
  /* background: var(--gray96); */
65
49
  }
66
50
 
67
- &[disabled],
68
- &[loading] {
69
- opacity: var(--disabled-opacity);
70
- }
71
51
  &[disabled] {
72
52
  user-select: none;
73
-
74
- & ~ SUnderline {
75
- cursor: default;
76
- pointer-events: none;
77
- }
78
53
  }
79
54
  }
80
55
 
@@ -129,22 +104,3 @@ SInlineInput[state='invalid'][focused] SUnderline {
129
104
  border-color: var(--red-400);
130
105
  box-shadow: var(--keyboard-focus-invalid);
131
106
  }
132
- SInlineInput[state='disabled'],
133
- SInlineInput[loading] {
134
- cursor: default;
135
- }
136
-
137
- CloseM[disabled] {
138
- cursor: default;
139
- opacity: var(--disabled-opacity);
140
- }
141
-
142
- .controls-icon {
143
- display: flex;
144
- align-items: center;
145
- }
146
-
147
- .spin {
148
- min-width: 16px;
149
- cursor: default;
150
- }