@synerise/ds-inline-edit 0.6.102 → 0.6.104
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 +19 -0
- package/dist/InlineEdit.d.ts +1 -2
- package/dist/InlineEdit.js +31 -56
- package/dist/InlineSelect/InlineSelect.d.ts +1 -2
- package/dist/InlineSelect/InlineSelect.js +29 -48
- package/dist/autosize/autosize.d.ts +30 -0
- package/dist/autosize/autosize.js +169 -0
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.6.104](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.6.103...@synerise/ds-inline-edit@0.6.104) (2024-04-05)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-inline-edit
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.6.103](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.6.102...@synerise/ds-inline-edit@0.6.103) (2024-04-02)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **inline-edit:** fixed autosize ([3dba994](https://github.com/Synerise/synerise-design/commit/3dba9947e3a0c43297fce8d66ba5be2514db4f4c))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.6.102](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.6.101...@synerise/ds-inline-edit@0.6.102) (2024-03-29)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @synerise/ds-inline-edit
|
package/dist/InlineEdit.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { InlineEditProps } from './InlineEdit.types';
|
|
3
|
-
declare const InlineEdit:
|
|
2
|
+
declare const InlineEdit: ({ className, style, size, disabled, autoFocus, hideIcon, tooltipTitle, error, input, }: InlineEditProps) => JSX.Element;
|
|
4
3
|
export default InlineEdit;
|
package/dist/InlineEdit.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import AutosizeInput from 'react-input-autosize';
|
|
1
|
+
import React, { useCallback, useRef, useState, useEffect } from 'react';
|
|
3
2
|
import Tooltip from '@synerise/ds-tooltip';
|
|
4
3
|
import Icon, { EditS } from '@synerise/ds-icon';
|
|
5
4
|
import { toCamelCase } from '@synerise/ds-utils';
|
|
5
|
+
import AutosizeInput from './autosize/autosize';
|
|
6
6
|
import * as S from './InlineEdit.styles';
|
|
7
|
-
import { attachWidthWatcher } from './utils';
|
|
8
|
-
var SAMPLE = String.fromCharCode.apply(String, [].concat(Array(26).keys()).map(function (i) {
|
|
9
|
-
return i + 65;
|
|
10
|
-
}));
|
|
11
7
|
|
|
12
8
|
var InlineEdit = function InlineEdit(_ref) {
|
|
13
9
|
var className = _ref.className,
|
|
@@ -20,21 +16,21 @@ var InlineEdit = function InlineEdit(_ref) {
|
|
|
20
16
|
tooltipTitle = _ref.tooltipTitle,
|
|
21
17
|
error = _ref.error,
|
|
22
18
|
input = _ref.input;
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
var autoWidthRef = useRef(null);
|
|
20
|
+
var inputRef = useRef();
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
if (autoWidthRef.current) {
|
|
23
|
+
inputRef.current = autoWidthRef.current.inputRef.current;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
29
26
|
|
|
30
|
-
var
|
|
31
|
-
scrolled =
|
|
32
|
-
setScrolled =
|
|
27
|
+
var _useState = useState(),
|
|
28
|
+
scrolled = _useState[0],
|
|
29
|
+
setScrolled = _useState[1];
|
|
33
30
|
|
|
34
|
-
var handleScroll =
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
var scrolledPixels = (inputRef == null ? void 0 : inputRef.current).input.scrollLeft;
|
|
31
|
+
var handleScroll = useCallback(function () {
|
|
32
|
+
if (inputRef.current) {
|
|
33
|
+
var scrolledPixels = inputRef.current.scrollLeft;
|
|
38
34
|
|
|
39
35
|
if (scrolledPixels > 0) {
|
|
40
36
|
setScrolled(true);
|
|
@@ -43,41 +39,27 @@ var InlineEdit = function InlineEdit(_ref) {
|
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
}, [inputRef]);
|
|
46
|
-
var handleChange =
|
|
47
|
-
input.onChange(
|
|
42
|
+
var handleChange = useCallback(function (event) {
|
|
43
|
+
input.onChange(event);
|
|
48
44
|
}, [input]);
|
|
49
|
-
var handleBlur =
|
|
50
|
-
input.onBlur && input.onBlur(
|
|
51
|
-
|
|
52
|
-
inputRef.current.input && inputRef.current.input.scrollTo({
|
|
45
|
+
var handleBlur = useCallback(function (event) {
|
|
46
|
+
input.onBlur && input.onBlur(event);
|
|
47
|
+
inputRef.current && inputRef.current.scrollTo({
|
|
53
48
|
left: 0
|
|
54
49
|
});
|
|
55
50
|
}, [input, inputRef]);
|
|
56
|
-
var handleKeyPress =
|
|
57
|
-
if (
|
|
58
|
-
input.onEnterPress && input.onEnterPress(
|
|
51
|
+
var handleKeyPress = useCallback(function (event) {
|
|
52
|
+
if (event.key === 'Enter') {
|
|
53
|
+
input.onEnterPress && input.onEnterPress(event);
|
|
59
54
|
inputRef.current && inputRef.current.blur();
|
|
60
55
|
}
|
|
61
56
|
}, [input, inputRef]);
|
|
62
|
-
var handleFocusInput =
|
|
57
|
+
var handleFocusInput = useCallback(function () {
|
|
63
58
|
inputRef.current && inputRef.current.focus();
|
|
64
59
|
}, [inputRef]);
|
|
65
|
-
|
|
66
|
-
if (inputRef.current) {
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
-
inputRef.current.copyInputStyles(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
69
|
-
|
|
70
|
-
inputRef.current.updateInputWidth();
|
|
71
|
-
}
|
|
72
|
-
}, [inputRef]);
|
|
73
|
-
React.useEffect(function () {
|
|
60
|
+
useEffect(function () {
|
|
74
61
|
autoFocus && inputRef.current && inputRef.current.focus();
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (fontStyleWatcher) {
|
|
78
|
-
attachWidthWatcher(fontStyleWatcher.current, updateInputWidth);
|
|
79
|
-
}
|
|
80
|
-
}, [autoFocus, fontStyleWatcher, inputRef, updateInputWidth]);
|
|
62
|
+
}, [autoFocus, inputRef]);
|
|
81
63
|
return /*#__PURE__*/React.createElement(S.InPlaceEditableInputContainer, {
|
|
82
64
|
className: "ds-inline-edit " + (className || ''),
|
|
83
65
|
style: style,
|
|
@@ -93,15 +75,15 @@ var InlineEdit = function InlineEdit(_ref) {
|
|
|
93
75
|
onKeyPress: handleKeyPress,
|
|
94
76
|
disabled: disabled,
|
|
95
77
|
name: input.name,
|
|
78
|
+
extraWidth: 2,
|
|
96
79
|
value: input.value || '',
|
|
97
80
|
onChange: handleChange,
|
|
98
81
|
onBlur: handleBlur,
|
|
99
82
|
autoComplete: input.autoComplete,
|
|
100
83
|
placeholderIsMinWidth: false,
|
|
101
|
-
onScroll: handleScroll
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
ref: inputRef
|
|
84
|
+
onScroll: handleScroll,
|
|
85
|
+
wrapperClassName: "autosize-input",
|
|
86
|
+
ref: autoWidthRef
|
|
105
87
|
}), !hideIcon && /*#__PURE__*/React.createElement(Tooltip, {
|
|
106
88
|
"data-testid": "inline-edit-icon",
|
|
107
89
|
title: tooltipTitle
|
|
@@ -112,14 +94,7 @@ var InlineEdit = function InlineEdit(_ref) {
|
|
|
112
94
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
113
95
|
component: /*#__PURE__*/React.createElement(EditS, null),
|
|
114
96
|
size: 24
|
|
115
|
-
})))
|
|
116
|
-
ref: fontStyleWatcher,
|
|
117
|
-
style: {
|
|
118
|
-
position: 'absolute',
|
|
119
|
-
visibility: 'hidden',
|
|
120
|
-
pointerEvents: 'none'
|
|
121
|
-
}
|
|
122
|
-
}, SAMPLE));
|
|
97
|
+
}))));
|
|
123
98
|
};
|
|
124
99
|
|
|
125
100
|
export default InlineEdit;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { InlineSelectProps } from './InlineSelect.types';
|
|
3
|
-
declare const InlineSelect:
|
|
2
|
+
declare const InlineSelect: ({ className, style, dropdownProps, dropdownOverlayStyle, inputStyle, size, disabled, autoFocus, hideIcon, error, input, placeholder, dataSource, initialValue, }: InlineSelectProps) => JSX.Element;
|
|
4
3
|
export default InlineSelect;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import AutosizeInput from 'react-input-autosize';
|
|
3
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
5
4
|
import { toCamelCase } from '@synerise/ds-utils';
|
|
6
5
|
import Icon, { AngleDownS } from '@synerise/ds-icon';
|
|
7
6
|
import Dropdown from '@synerise/ds-dropdown';
|
|
7
|
+
import AutosizeInput from '../autosize/autosize';
|
|
8
8
|
import * as S from './InlineSelect.style';
|
|
9
|
-
import { attachWidthWatcher } from '../utils';
|
|
10
9
|
import SelectDropdown from './SelectDropdown/SelectDropdown';
|
|
11
10
|
|
|
12
11
|
var InlineSelect = function InlineSelect(_ref) {
|
|
@@ -28,45 +27,34 @@ var InlineSelect = function InlineSelect(_ref) {
|
|
|
28
27
|
placeholder = _ref.placeholder,
|
|
29
28
|
dataSource = _ref.dataSource,
|
|
30
29
|
initialValue = _ref.initialValue;
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
}, []);
|
|
34
|
-
var fontStyleWatcher = React.useMemo(function () {
|
|
35
|
-
return React.createRef();
|
|
36
|
-
}, []);
|
|
37
|
-
var updateInputWidth = React.useCallback(function () {
|
|
38
|
-
if (inputRef.current) {
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
inputRef.current.copyInputStyles(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
var autoWidthRef = useRef(null);
|
|
31
|
+
var inputRef = useRef();
|
|
41
32
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
React.useEffect(function () {
|
|
46
|
-
updateInputWidth();
|
|
47
|
-
|
|
48
|
-
if (fontStyleWatcher) {
|
|
49
|
-
attachWidthWatcher(fontStyleWatcher.current, updateInputWidth);
|
|
50
|
-
}
|
|
51
|
-
}, [autoFocus, fontStyleWatcher, inputRef, updateInputWidth]);
|
|
33
|
+
var _useState = useState(initialValue || placeholder || 'option'),
|
|
34
|
+
selectedValue = _useState[0],
|
|
35
|
+
setSelectedValue = _useState[1];
|
|
52
36
|
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
var _useState2 = useState(false),
|
|
38
|
+
opened = _useState2[0],
|
|
39
|
+
setOpened = _useState2[1];
|
|
56
40
|
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
var _useState3 = useState(false),
|
|
42
|
+
pressed = _useState3[0],
|
|
43
|
+
setPressed = _useState3[1];
|
|
60
44
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
setPressed = _React$useState3[1];
|
|
64
|
-
|
|
65
|
-
React.useEffect(function () {
|
|
66
|
-
if ((input == null ? void 0 : input.value) !== selectedValue) {
|
|
45
|
+
useEffect(function () {
|
|
46
|
+
if (input != null && input.value && input.value !== selectedValue) {
|
|
67
47
|
setSelectedValue(input == null ? void 0 : input.value);
|
|
68
48
|
}
|
|
69
|
-
}, [input, selectedValue]);
|
|
49
|
+
}, [input == null ? void 0 : input.value, selectedValue]);
|
|
50
|
+
useEffect(function () {
|
|
51
|
+
if (autoWidthRef.current) {
|
|
52
|
+
inputRef.current = autoWidthRef.current.inputRef.current;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
useEffect(function () {
|
|
56
|
+
autoFocus && inputRef.current && inputRef.current.focus();
|
|
57
|
+
}, [autoFocus, inputRef]);
|
|
70
58
|
return /*#__PURE__*/React.createElement(Dropdown, _extends({
|
|
71
59
|
visible: !disabled && opened,
|
|
72
60
|
onVisibleChange: setOpened,
|
|
@@ -108,24 +96,17 @@ var InlineSelect = function InlineSelect(_ref) {
|
|
|
108
96
|
value: selectedValue || placeholder,
|
|
109
97
|
autoComplete: input.autoComplete,
|
|
110
98
|
placeholderIsMinWidth: false,
|
|
111
|
-
style: inputStyle
|
|
112
|
-
|
|
113
|
-
,
|
|
114
|
-
ref:
|
|
99
|
+
style: inputStyle,
|
|
100
|
+
extraWidth: 2,
|
|
101
|
+
wrapperClassName: "autosize-input",
|
|
102
|
+
ref: autoWidthRef
|
|
115
103
|
}), !hideIcon && /*#__PURE__*/React.createElement(S.IconWrapper, {
|
|
116
104
|
size: size,
|
|
117
105
|
expanded: opened
|
|
118
106
|
}, /*#__PURE__*/React.createElement(Icon, {
|
|
119
107
|
component: /*#__PURE__*/React.createElement(AngleDownS, null),
|
|
120
108
|
size: 24
|
|
121
|
-
}))
|
|
122
|
-
ref: fontStyleWatcher,
|
|
123
|
-
style: {
|
|
124
|
-
position: 'absolute',
|
|
125
|
-
visibility: 'hidden',
|
|
126
|
-
pointerEvents: 'none'
|
|
127
|
-
}
|
|
128
|
-
})));
|
|
109
|
+
}))));
|
|
129
110
|
};
|
|
130
111
|
|
|
131
112
|
export default InlineSelect;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { InputHTMLAttributes, CSSProperties, RefObject } from 'react';
|
|
2
|
+
export type AutosizeInputProps = InputHTMLAttributes<HTMLInputElement> & {
|
|
3
|
+
extraWidth?: number | string;
|
|
4
|
+
minWidth?: number | string;
|
|
5
|
+
onAutosize?: (newWidth: number) => void;
|
|
6
|
+
placeholderIsMinWidth?: boolean;
|
|
7
|
+
value?: string | number;
|
|
8
|
+
wrapperClassName?: string;
|
|
9
|
+
wrapperStyle?: CSSProperties;
|
|
10
|
+
};
|
|
11
|
+
export type AutosizeInputRefType = {
|
|
12
|
+
inputRef: RefObject<HTMLInputElement>;
|
|
13
|
+
sizerRef: RefObject<HTMLDivElement>;
|
|
14
|
+
placeholderSizerRef: RefObject<HTMLDivElement>;
|
|
15
|
+
copyInputStyles: () => void;
|
|
16
|
+
updateInputWidth: () => void;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Automatically sized input field.
|
|
20
|
+
*/
|
|
21
|
+
export declare const AutosizeInput: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & {
|
|
22
|
+
extraWidth?: string | number | undefined;
|
|
23
|
+
minWidth?: string | number | undefined;
|
|
24
|
+
onAutosize?: ((newWidth: number) => void) | undefined;
|
|
25
|
+
placeholderIsMinWidth?: boolean | undefined;
|
|
26
|
+
value?: string | number | undefined;
|
|
27
|
+
wrapperClassName?: string | undefined;
|
|
28
|
+
wrapperStyle?: React.CSSProperties | undefined;
|
|
29
|
+
} & React.RefAttributes<AutosizeInputRefType>>;
|
|
30
|
+
export default AutosizeInput;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var _excluded = ["extraWidth", "wrapperClassName", "wrapperStyle", "onAutosize", "placeholderIsMinWidth", "minWidth"];
|
|
2
|
+
|
|
3
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
|
|
7
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
8
|
+
|
|
9
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
|
|
11
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
+
|
|
13
|
+
import React, { useState, useEffect, useRef, useLayoutEffect, forwardRef, useImperativeHandle } from 'react';
|
|
14
|
+
import { useResizeObserver } from '@synerise/ds-utils';
|
|
15
|
+
var sizerStyle = {
|
|
16
|
+
position: 'absolute',
|
|
17
|
+
top: 0,
|
|
18
|
+
left: 0,
|
|
19
|
+
visibility: 'hidden',
|
|
20
|
+
height: 0,
|
|
21
|
+
overflow: 'scroll',
|
|
22
|
+
whiteSpace: 'pre'
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Automatically sized input field.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export var AutosizeInput = forwardRef(function (_ref, forwardedRef) {
|
|
29
|
+
var _props$value, _props$style$display, _props$style;
|
|
30
|
+
|
|
31
|
+
var _ref$extraWidth = _ref.extraWidth,
|
|
32
|
+
extraWidth = _ref$extraWidth === void 0 ? 16 : _ref$extraWidth,
|
|
33
|
+
wrapperClassName = _ref.wrapperClassName,
|
|
34
|
+
wrapperStyleProp = _ref.wrapperStyle,
|
|
35
|
+
onAutosize = _ref.onAutosize,
|
|
36
|
+
placeholderIsMinWidth = _ref.placeholderIsMinWidth,
|
|
37
|
+
_ref$minWidth = _ref.minWidth,
|
|
38
|
+
minWidth = _ref$minWidth === void 0 ? 0 : _ref$minWidth,
|
|
39
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
40
|
+
|
|
41
|
+
var inputRef = useRef(null);
|
|
42
|
+
var sizerRef = useRef(null);
|
|
43
|
+
var placeholderSizerRef = useRef(null);
|
|
44
|
+
|
|
45
|
+
var _useState = useState(''),
|
|
46
|
+
input = _useState[0],
|
|
47
|
+
setInput = _useState[1];
|
|
48
|
+
|
|
49
|
+
var _useState2 = useState(0),
|
|
50
|
+
inputWidth = _useState2[0],
|
|
51
|
+
setInputWidth = _useState2[1];
|
|
52
|
+
|
|
53
|
+
var _useResizeObserver = useResizeObserver(sizerRef),
|
|
54
|
+
updatedSizerWidth = _useResizeObserver.width;
|
|
55
|
+
|
|
56
|
+
var _useResizeObserver2 = useResizeObserver(placeholderSizerRef),
|
|
57
|
+
updatedPlaceholderWidth = _useResizeObserver2.width;
|
|
58
|
+
|
|
59
|
+
var usedValue = "" + ((_props$value = props.value) != null ? _props$value : input);
|
|
60
|
+
|
|
61
|
+
var handleInput = function handleInput(event) {
|
|
62
|
+
setInput(event.target.value);
|
|
63
|
+
if (props.onChange) props.onChange(event);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
var copyInputStyles = function copyInputStyles() {
|
|
67
|
+
if (inputRef.current) {
|
|
68
|
+
var computedStyle = window.getComputedStyle(inputRef.current);
|
|
69
|
+
|
|
70
|
+
if (sizerRef.current) {
|
|
71
|
+
sizerRef.current.style.fontSize = computedStyle.fontSize;
|
|
72
|
+
sizerRef.current.style.fontFamily = computedStyle.fontFamily;
|
|
73
|
+
sizerRef.current.style.fontWeight = computedStyle.fontWeight;
|
|
74
|
+
sizerRef.current.style.fontStyle = computedStyle.fontStyle;
|
|
75
|
+
sizerRef.current.style.letterSpacing = computedStyle.letterSpacing;
|
|
76
|
+
sizerRef.current.style.textTransform = computedStyle.textTransform;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (placeholderSizerRef.current) {
|
|
80
|
+
placeholderSizerRef.current.style.fontSize = computedStyle.fontSize;
|
|
81
|
+
placeholderSizerRef.current.style.fontFamily = computedStyle.fontFamily;
|
|
82
|
+
placeholderSizerRef.current.style.fontWeight = computedStyle.fontWeight;
|
|
83
|
+
placeholderSizerRef.current.style.fontStyle = computedStyle.fontStyle;
|
|
84
|
+
placeholderSizerRef.current.style.letterSpacing = computedStyle.letterSpacing;
|
|
85
|
+
placeholderSizerRef.current.style.textTransform = computedStyle.textTransform;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
var updateInputWidth = function updateInputWidth() {
|
|
91
|
+
var _sizerRef$current, _placeholderSizerRef$;
|
|
92
|
+
|
|
93
|
+
var sizerWidth = (_sizerRef$current = sizerRef.current) == null ? void 0 : _sizerRef$current.scrollWidth;
|
|
94
|
+
var placeholderWidth = (_placeholderSizerRef$ = placeholderSizerRef.current) == null ? void 0 : _placeholderSizerRef$.scrollWidth;
|
|
95
|
+
|
|
96
|
+
if (sizerWidth && usedValue.length) {
|
|
97
|
+
/* If the input field has content, update the sizer to match its width */
|
|
98
|
+
var width = sizerWidth;
|
|
99
|
+
|
|
100
|
+
if (placeholderIsMinWidth && placeholderWidth && sizerWidth < placeholderWidth && placeholderSizerRef.current) {
|
|
101
|
+
width = placeholderWidth;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (width < +minWidth) {
|
|
105
|
+
width = +minWidth;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (width) {
|
|
109
|
+
setInputWidth(width + +extraWidth);
|
|
110
|
+
if (onAutosize) onAutosize(width);
|
|
111
|
+
}
|
|
112
|
+
} else if (props.placeholder && placeholderWidth) {
|
|
113
|
+
/* If no input value exists, check for placeholder value and update the sizer accordingly */
|
|
114
|
+
setInputWidth(Math.max(+minWidth, placeholderWidth) + +extraWidth);
|
|
115
|
+
if (onAutosize) onAutosize(placeholderWidth);
|
|
116
|
+
} else if (sizerRef.current) {
|
|
117
|
+
/* If no input value or placeholder exists, update the sizer to the width of the "minWidth" + "extraWidth" prop (default is 16) */
|
|
118
|
+
setInputWidth(+minWidth + +extraWidth);
|
|
119
|
+
if (onAutosize) onAutosize(+minWidth);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/* Copy styles of the input field to the sizer, ensuring that the width of the input adjusts accordingly */
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
useLayoutEffect(function () {
|
|
126
|
+
copyInputStyles();
|
|
127
|
+
}, []);
|
|
128
|
+
useEffect(updateInputWidth, [usedValue, props.placeholder, extraWidth, placeholderIsMinWidth, onAutosize, setInputWidth, minWidth, updatedPlaceholderWidth, updatedSizerWidth]);
|
|
129
|
+
useImperativeHandle(forwardedRef, function () {
|
|
130
|
+
return {
|
|
131
|
+
inputRef: inputRef,
|
|
132
|
+
sizerRef: sizerRef,
|
|
133
|
+
placeholderSizerRef: placeholderSizerRef,
|
|
134
|
+
copyInputStyles: copyInputStyles,
|
|
135
|
+
updateInputWidth: updateInputWidth
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
var wrapperStyle = _objectSpread({}, wrapperStyleProp, {
|
|
140
|
+
position: 'relative',
|
|
141
|
+
display: (_props$style$display = (_props$style = props.style) == null ? void 0 : _props$style.display) != null ? _props$style$display : 'inline-block'
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
var inputStyle = _objectSpread({
|
|
145
|
+
boxSizing: 'content-box',
|
|
146
|
+
width: inputWidth
|
|
147
|
+
}, props.style);
|
|
148
|
+
|
|
149
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
150
|
+
className: wrapperClassName,
|
|
151
|
+
style: wrapperStyle,
|
|
152
|
+
"data-testid": "wrapper"
|
|
153
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
154
|
+
style: sizerStyle,
|
|
155
|
+
ref: sizerRef,
|
|
156
|
+
"data-testid": "sizer"
|
|
157
|
+
}, usedValue), /*#__PURE__*/React.createElement("input", _extends({}, props, {
|
|
158
|
+
ref: inputRef,
|
|
159
|
+
value: usedValue,
|
|
160
|
+
style: inputStyle,
|
|
161
|
+
onChange: handleInput,
|
|
162
|
+
"data-testid": "input"
|
|
163
|
+
})), props.placeholder ? /*#__PURE__*/React.createElement("div", {
|
|
164
|
+
ref: placeholderSizerRef,
|
|
165
|
+
style: sizerStyle,
|
|
166
|
+
"data-testid": "placeholder-sizer"
|
|
167
|
+
}, props.placeholder) : null);
|
|
168
|
+
});
|
|
169
|
+
export default AutosizeInput;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-inline-edit",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.104",
|
|
4
4
|
"description": "InlineEdit UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -33,13 +33,14 @@
|
|
|
33
33
|
],
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@synerise/ds-dropdown": "^0.17.
|
|
37
|
-
"@synerise/ds-icon": "^0.60.
|
|
38
|
-
"@synerise/ds-menu": "^0.18.
|
|
39
|
-
"@synerise/ds-scrollbar": "^0.10.
|
|
40
|
-
"@synerise/ds-search": "^0.8.
|
|
41
|
-
"@synerise/ds-tooltip": "^0.14.
|
|
36
|
+
"@synerise/ds-dropdown": "^0.17.104",
|
|
37
|
+
"@synerise/ds-icon": "^0.60.6",
|
|
38
|
+
"@synerise/ds-menu": "^0.18.19",
|
|
39
|
+
"@synerise/ds-scrollbar": "^0.10.1",
|
|
40
|
+
"@synerise/ds-search": "^0.8.86",
|
|
41
|
+
"@synerise/ds-tooltip": "^0.14.24",
|
|
42
42
|
"@synerise/ds-typography": "^0.14.3",
|
|
43
|
+
"@synerise/ds-utils": "^0.26.2",
|
|
43
44
|
"react-input-autosize": "^2.2.2"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
@@ -48,10 +49,9 @@
|
|
|
48
49
|
"styled-components": "5.0.1"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"@synerise/ds-utils": "^0.26.1",
|
|
52
52
|
"@testing-library/jest-dom": "5.1.1",
|
|
53
53
|
"@testing-library/react": "10.0.1",
|
|
54
54
|
"@types/react-input-autosize": "2.2.1"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "84c9ff34c60369cc819ab1d4307373fafaf06462"
|
|
57
57
|
}
|