@synerise/ds-input 0.21.1 → 0.21.3
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 +20 -0
- package/dist/AutosizeInput/AutosizeInput.d.ts +16 -0
- package/dist/AutosizeInput/AutosizeInput.js +176 -0
- package/dist/AutosizeInput/AutosizeInput.types.d.ts +25 -0
- package/dist/AutosizeInput/AutosizeInput.types.js +1 -0
- package/dist/AutosizeInput/utils/calculateInputWidth.d.ts +11 -0
- package/dist/AutosizeInput/utils/calculateInputWidth.js +30 -0
- package/dist/AutosizeInput/utils/index.d.ts +1 -0
- package/dist/AutosizeInput/utils/index.js +1 -0
- package/dist/AutosizeWrapper/AutosizeWrapper.d.ts +17 -0
- package/dist/AutosizeWrapper/AutosizeWrapper.js +25 -0
- package/dist/Input.d.ts +3 -9
- package/dist/Input.js +70 -151
- package/dist/Input.styles.d.ts +5 -8
- package/dist/Input.styles.js +16 -14
- package/dist/Input.types.d.ts +0 -2
- package/dist/InputGroup.js +1 -0
- package/dist/TextArea.d.ts +10 -0
- package/dist/TextArea.js +90 -0
- package/dist/TextArea.types.d.ts +3 -0
- package/dist/TextArea.types.js +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +4 -2
- package/dist/utils/getCharCount.d.ts +1 -1
- package/package.json +6 -6
- package/dist/autosize/autosize.d.ts +0 -23
- package/dist/autosize/autosize.js +0 -258
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
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.21.3](https://github.com/synerise/synerise-design/compare/@synerise/ds-input@0.21.2...@synerise/ds-input@0.21.3) (2024-05-16)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-input
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.21.2](https://github.com/synerise/synerise-design/compare/@synerise/ds-input@0.21.1...@synerise/ds-input@0.21.2) (2024-05-10)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* **date-picker:** added autoResize handling ([f3a759c](https://github.com/synerise/synerise-design/commit/f3a759c2b40664cc2d225cb4eaaefcbbf70321fe))
|
|
20
|
+
* **input:** refactored autosize input solution ([449bd86](https://github.com/synerise/synerise-design/commit/449bd868b8d3b545ac582c556fa0ff607c77f853))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## [0.21.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-input@0.21.0...@synerise/ds-input@0.21.1) (2024-05-08)
|
|
7
27
|
|
|
8
28
|
**Note:** Version bump only for package @synerise/ds-input
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AutosizeInputRefType } from './AutosizeInput.types';
|
|
3
|
+
declare const AutosizeInput: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
|
|
4
|
+
placeholderIsMinWidth?: boolean | undefined;
|
|
5
|
+
wrapperClassName?: string | undefined;
|
|
6
|
+
wrapperStyle?: React.CSSProperties | undefined;
|
|
7
|
+
extraWidth?: string | number | undefined;
|
|
8
|
+
minWidth?: string | number | undefined;
|
|
9
|
+
onAutosize?: ((newWidth: number) => void) | undefined;
|
|
10
|
+
preAutosize?: ((newWidth: number) => void) | undefined;
|
|
11
|
+
transformRef?: ((element: HTMLElement) => HTMLElement) | undefined;
|
|
12
|
+
transformWrapperRef?: ((element: HTMLElement) => HTMLElement) | undefined;
|
|
13
|
+
handleInputRef?: ((element: HTMLInputElement, originalElement: HTMLElement) => HTMLElement) | undefined;
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
} & React.RefAttributes<AutosizeInputRefType>>;
|
|
16
|
+
export default AutosizeInput;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
var _excluded = ["extraWidth", "wrapperClassName", "wrapperStyle", "onAutosize", "preAutosize", "placeholderIsMinWidth", "minWidth", "handleInputRef", "children", "transformWrapperRef", "transformRef"];
|
|
2
|
+
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
import React, { useState, useEffect, useRef, useLayoutEffect, forwardRef, useImperativeHandle, useCallback } from 'react';
|
|
12
|
+
import { useResizeObserver } from '@synerise/ds-utils';
|
|
13
|
+
import { calculateInputWidth } from './utils';
|
|
14
|
+
var sizerStyle = {
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
top: 0,
|
|
17
|
+
left: 0,
|
|
18
|
+
visibility: 'hidden',
|
|
19
|
+
height: 0,
|
|
20
|
+
overflow: 'scroll',
|
|
21
|
+
whiteSpace: 'pre'
|
|
22
|
+
};
|
|
23
|
+
var AutosizeInput = forwardRef(function (_ref, forwardedRef) {
|
|
24
|
+
var _ref2, _props$value, _props$style$display, _props$style;
|
|
25
|
+
|
|
26
|
+
var _ref$extraWidth = _ref.extraWidth,
|
|
27
|
+
extraWidth = _ref$extraWidth === void 0 ? 16 : _ref$extraWidth,
|
|
28
|
+
wrapperClassName = _ref.wrapperClassName,
|
|
29
|
+
wrapperStyleProp = _ref.wrapperStyle,
|
|
30
|
+
onAutosize = _ref.onAutosize,
|
|
31
|
+
preAutosize = _ref.preAutosize,
|
|
32
|
+
placeholderIsMinWidth = _ref.placeholderIsMinWidth,
|
|
33
|
+
_ref$minWidth = _ref.minWidth,
|
|
34
|
+
minWidth = _ref$minWidth === void 0 ? 0 : _ref$minWidth,
|
|
35
|
+
handleInputRef = _ref.handleInputRef,
|
|
36
|
+
children = _ref.children,
|
|
37
|
+
_ref$transformWrapper = _ref.transformWrapperRef,
|
|
38
|
+
transformWrapperRef = _ref$transformWrapper === void 0 ? function (element) {
|
|
39
|
+
return element;
|
|
40
|
+
} : _ref$transformWrapper,
|
|
41
|
+
_ref$transformRef = _ref.transformRef,
|
|
42
|
+
transformRef = _ref$transformRef === void 0 ? function (element) {
|
|
43
|
+
return element;
|
|
44
|
+
} : _ref$transformRef,
|
|
45
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
46
|
+
|
|
47
|
+
var inputRef = useRef(null);
|
|
48
|
+
var inputWrapperRef = useRef(null);
|
|
49
|
+
var sizerRef = useRef(null);
|
|
50
|
+
var placeholderSizerRef = useRef(null);
|
|
51
|
+
var wrapperRef = useRef(null);
|
|
52
|
+
|
|
53
|
+
var _useState = useState(0),
|
|
54
|
+
inputWidth = _useState[0],
|
|
55
|
+
setInputWidth = _useState[1];
|
|
56
|
+
|
|
57
|
+
var _useResizeObserver = useResizeObserver(sizerRef),
|
|
58
|
+
updatedSizerWidth = _useResizeObserver.width;
|
|
59
|
+
|
|
60
|
+
var _useResizeObserver2 = useResizeObserver(placeholderSizerRef),
|
|
61
|
+
updatedPlaceholderWidth = _useResizeObserver2.width;
|
|
62
|
+
|
|
63
|
+
var usedValue = (_ref2 = (_props$value = props.value) != null ? _props$value : props.defaultValue) != null ? _ref2 : '';
|
|
64
|
+
|
|
65
|
+
var copyInputStyles = function copyInputStyles() {
|
|
66
|
+
if (inputRef.current) {
|
|
67
|
+
var computedStyle = window.getComputedStyle(inputRef.current);
|
|
68
|
+
|
|
69
|
+
if (sizerRef.current) {
|
|
70
|
+
sizerRef.current.style.fontSize = computedStyle.fontSize;
|
|
71
|
+
sizerRef.current.style.fontFamily = computedStyle.fontFamily;
|
|
72
|
+
sizerRef.current.style.fontWeight = computedStyle.fontWeight;
|
|
73
|
+
sizerRef.current.style.fontStyle = computedStyle.fontStyle;
|
|
74
|
+
sizerRef.current.style.letterSpacing = computedStyle.letterSpacing;
|
|
75
|
+
sizerRef.current.style.textTransform = computedStyle.textTransform;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (placeholderSizerRef.current) {
|
|
79
|
+
placeholderSizerRef.current.style.fontSize = computedStyle.fontSize;
|
|
80
|
+
placeholderSizerRef.current.style.fontFamily = computedStyle.fontFamily;
|
|
81
|
+
placeholderSizerRef.current.style.fontWeight = computedStyle.fontWeight;
|
|
82
|
+
placeholderSizerRef.current.style.fontStyle = computedStyle.fontStyle;
|
|
83
|
+
placeholderSizerRef.current.style.letterSpacing = computedStyle.letterSpacing;
|
|
84
|
+
placeholderSizerRef.current.style.textTransform = computedStyle.textTransform;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
var resize = useCallback(function (width) {
|
|
90
|
+
preAutosize && preAutosize(width);
|
|
91
|
+
setInputWidth(width + +extraWidth);
|
|
92
|
+
onAutosize && onAutosize(width);
|
|
93
|
+
}, [extraWidth, onAutosize, preAutosize]);
|
|
94
|
+
|
|
95
|
+
var updateInputWidth = function updateInputWidth() {
|
|
96
|
+
var _sizerRef$current, _placeholderSizerRef$;
|
|
97
|
+
|
|
98
|
+
var sizerWidth = (_sizerRef$current = sizerRef.current) == null ? void 0 : _sizerRef$current.scrollWidth;
|
|
99
|
+
var placeholderWidth = (_placeholderSizerRef$ = placeholderSizerRef.current) == null ? void 0 : _placeholderSizerRef$.scrollWidth;
|
|
100
|
+
var calculatedWidth = calculateInputWidth({
|
|
101
|
+
sizerWidth: sizerWidth,
|
|
102
|
+
usedValue: usedValue,
|
|
103
|
+
placeholderIsMinWidth: placeholderIsMinWidth,
|
|
104
|
+
placeholderWidth: placeholderWidth,
|
|
105
|
+
minWidth: +minWidth,
|
|
106
|
+
placeholder: props.placeholder
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
if (sizerWidth && usedValue && calculatedWidth || props.placeholder && placeholderWidth || sizerRef.current) {
|
|
110
|
+
resize(calculatedWidth);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
/* Copy styles of the input field to the sizer, ensuring that the width of the input adjusts accordingly */
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
useLayoutEffect(function () {
|
|
117
|
+
copyInputStyles();
|
|
118
|
+
}, []);
|
|
119
|
+
useEffect(function () {
|
|
120
|
+
if (inputWrapperRef.current) {
|
|
121
|
+
inputWrapperRef.current.style.width = inputWidth + "px";
|
|
122
|
+
}
|
|
123
|
+
}, [inputWidth]);
|
|
124
|
+
useEffect(function () {
|
|
125
|
+
if (sizerRef.current) {
|
|
126
|
+
var sizerSibling = sizerRef.current.nextElementSibling;
|
|
127
|
+
var inputElement = sizerSibling instanceof HTMLElement && transformRef(sizerSibling);
|
|
128
|
+
var inputWrapperElement = sizerSibling instanceof HTMLElement && transformWrapperRef(sizerSibling);
|
|
129
|
+
|
|
130
|
+
if (inputWrapperElement && inputWrapperElement instanceof HTMLElement) {
|
|
131
|
+
inputWrapperRef.current = inputWrapperElement;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (inputElement) {
|
|
135
|
+
if (inputElement && inputElement instanceof HTMLInputElement) {
|
|
136
|
+
inputRef.current = inputElement;
|
|
137
|
+
inputRef.current.style.boxSizing = 'content-box';
|
|
138
|
+
handleInputRef && handleInputRef(inputElement, sizerSibling);
|
|
139
|
+
copyInputStyles();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, [handleInputRef, transformRef, transformWrapperRef]);
|
|
144
|
+
useEffect(updateInputWidth, [usedValue, props.placeholder, extraWidth, placeholderIsMinWidth, onAutosize, setInputWidth, minWidth, updatedPlaceholderWidth, updatedSizerWidth, preAutosize, resize]);
|
|
145
|
+
useImperativeHandle(forwardedRef, function () {
|
|
146
|
+
return {
|
|
147
|
+
inputRef: inputRef,
|
|
148
|
+
sizerRef: sizerRef,
|
|
149
|
+
wrapperRef: wrapperRef,
|
|
150
|
+
placeholderSizerRef: placeholderSizerRef,
|
|
151
|
+
copyInputStyles: copyInputStyles,
|
|
152
|
+
updateInputWidth: updateInputWidth
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
var wrapperStyle = _objectSpread({}, wrapperStyleProp, {
|
|
157
|
+
position: 'relative',
|
|
158
|
+
display: (_props$style$display = (_props$style = props.style) == null ? void 0 : _props$style.display) != null ? _props$style$display : 'inline-block'
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
162
|
+
ref: wrapperRef,
|
|
163
|
+
className: wrapperClassName,
|
|
164
|
+
style: wrapperStyle,
|
|
165
|
+
"data-testid": "wrapper"
|
|
166
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
167
|
+
style: sizerStyle,
|
|
168
|
+
ref: sizerRef,
|
|
169
|
+
"data-testid": "sizer"
|
|
170
|
+
}, usedValue), children, props.placeholder ? /*#__PURE__*/React.createElement("div", {
|
|
171
|
+
ref: placeholderSizerRef,
|
|
172
|
+
style: sizerStyle,
|
|
173
|
+
"data-testid": "placeholder-sizer"
|
|
174
|
+
}, props.placeholder) : null);
|
|
175
|
+
});
|
|
176
|
+
export default AutosizeInput;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { InputHTMLAttributes, CSSProperties, RefObject, MutableRefObject, ReactNode } from 'react';
|
|
2
|
+
export type AutosizeInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'size'> & {
|
|
3
|
+
placeholderIsMinWidth?: boolean;
|
|
4
|
+
wrapperClassName?: string;
|
|
5
|
+
wrapperStyle?: CSSProperties;
|
|
6
|
+
extraWidth?: number | string;
|
|
7
|
+
minWidth?: number | string;
|
|
8
|
+
onAutosize?: (newWidth: number) => void;
|
|
9
|
+
preAutosize?: (newWidth: number) => void;
|
|
10
|
+
transformRef?: (element: HTMLElement) => HTMLElement;
|
|
11
|
+
transformWrapperRef?: (element: HTMLElement) => HTMLElement;
|
|
12
|
+
handleInputRef?: (element: HTMLInputElement, originalElement: HTMLElement) => HTMLElement;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
export type AutosizeWrapperProps = AutosizeInputProps & {
|
|
16
|
+
autoResize?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type AutosizeInputRefType = {
|
|
19
|
+
inputRef: MutableRefObject<HTMLInputElement | null>;
|
|
20
|
+
sizerRef: RefObject<HTMLDivElement>;
|
|
21
|
+
wrapperRef: RefObject<HTMLDivElement>;
|
|
22
|
+
placeholderSizerRef: RefObject<HTMLDivElement>;
|
|
23
|
+
copyInputStyles: () => void;
|
|
24
|
+
updateInputWidth: () => void;
|
|
25
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AutosizeInputProps } from 'AutosizeInput/AutosizeInput.types';
|
|
2
|
+
type CalculateWidthProps = {
|
|
3
|
+
sizerWidth?: number;
|
|
4
|
+
usedValue?: AutosizeInputProps['value'];
|
|
5
|
+
placeholderIsMinWidth?: AutosizeInputProps['placeholderIsMinWidth'];
|
|
6
|
+
placeholderWidth?: number | null;
|
|
7
|
+
minWidth?: number;
|
|
8
|
+
placeholder?: AutosizeInputProps['placeholder'];
|
|
9
|
+
};
|
|
10
|
+
declare const calculateInputWidth: ({ sizerWidth, usedValue, placeholderIsMinWidth, placeholderWidth, minWidth, placeholder, }: CalculateWidthProps) => number;
|
|
11
|
+
export default calculateInputWidth;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var calculateInputWidth = function calculateInputWidth(_ref) {
|
|
2
|
+
var sizerWidth = _ref.sizerWidth,
|
|
3
|
+
usedValue = _ref.usedValue,
|
|
4
|
+
placeholderIsMinWidth = _ref.placeholderIsMinWidth,
|
|
5
|
+
placeholderWidth = _ref.placeholderWidth,
|
|
6
|
+
minWidth = _ref.minWidth,
|
|
7
|
+
placeholder = _ref.placeholder;
|
|
8
|
+
var width = 0;
|
|
9
|
+
|
|
10
|
+
if (sizerWidth && usedValue) {
|
|
11
|
+
/* If the input field has content, update the sizer to match its width */
|
|
12
|
+
width = sizerWidth;
|
|
13
|
+
|
|
14
|
+
if (placeholderIsMinWidth && placeholderWidth && sizerWidth < placeholderWidth) {
|
|
15
|
+
width = placeholderWidth;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (minWidth !== undefined && width < minWidth) {
|
|
19
|
+
width = minWidth;
|
|
20
|
+
}
|
|
21
|
+
} else if (placeholder && placeholderWidth) {
|
|
22
|
+
width = placeholderWidth;
|
|
23
|
+
} else {
|
|
24
|
+
width = minWidth || 0;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return width;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default calculateInputWidth;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as calculateInputWidth } from './calculateInputWidth';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as calculateInputWidth } from './calculateInputWidth';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { AutosizeInputRefType } from '../AutosizeInput/AutosizeInput.types';
|
|
3
|
+
export declare const AutosizeWrapper: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
|
|
4
|
+
placeholderIsMinWidth?: boolean | undefined;
|
|
5
|
+
wrapperClassName?: string | undefined;
|
|
6
|
+
wrapperStyle?: React.CSSProperties | undefined;
|
|
7
|
+
extraWidth?: string | number | undefined;
|
|
8
|
+
minWidth?: string | number | undefined;
|
|
9
|
+
onAutosize?: ((newWidth: number) => void) | undefined;
|
|
10
|
+
preAutosize?: ((newWidth: number) => void) | undefined;
|
|
11
|
+
transformRef?: ((element: HTMLElement) => HTMLElement) | undefined;
|
|
12
|
+
transformWrapperRef?: ((element: HTMLElement) => HTMLElement) | undefined;
|
|
13
|
+
handleInputRef?: ((element: HTMLInputElement, originalElement: HTMLElement) => HTMLElement) | undefined;
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
} & {
|
|
16
|
+
autoResize?: boolean | undefined;
|
|
17
|
+
} & React.RefAttributes<AutosizeInputRefType>>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var _excluded = ["autoResize", "extraWidth", "children"];
|
|
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 _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; }
|
|
6
|
+
|
|
7
|
+
import React, { forwardRef } from 'react';
|
|
8
|
+
import AutosizeInput from '../AutosizeInput/AutosizeInput';
|
|
9
|
+
var AUTOSIZE_EXTRA_WIDTH = 2;
|
|
10
|
+
export var AutosizeWrapper = forwardRef(function (_ref, ref) {
|
|
11
|
+
var autoResize = _ref.autoResize,
|
|
12
|
+
_ref$extraWidth = _ref.extraWidth,
|
|
13
|
+
extraWidth = _ref$extraWidth === void 0 ? AUTOSIZE_EXTRA_WIDTH : _ref$extraWidth,
|
|
14
|
+
children = _ref.children,
|
|
15
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
|
|
17
|
+
if (autoResize) {
|
|
18
|
+
return /*#__PURE__*/React.createElement(AutosizeInput, _extends({
|
|
19
|
+
ref: ref,
|
|
20
|
+
extraWidth: extraWidth
|
|
21
|
+
}, props), children);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
25
|
+
});
|
package/dist/Input.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { StyledComponent } from 'styled-components';
|
|
3
3
|
import { InputProps as AntdInputProps } from 'antd/lib/input';
|
|
4
4
|
import AntdMaskedInput from 'antd-mask-input';
|
|
5
5
|
import '@synerise/ds-core/dist/js/style';
|
|
6
6
|
import './style/index.less';
|
|
7
|
-
import { BaseProps, InputProps as DSInputProps
|
|
7
|
+
import { BaseProps, InputProps as DSInputProps } from './Input.types';
|
|
8
8
|
export declare const Input: React.ComponentType<BaseProps<HTMLInputElement> & AntdInputProps>;
|
|
9
9
|
export declare const MaskedInput: React.ComponentType<BaseProps<HTMLInputElement> & AntdInputProps & {
|
|
10
10
|
mask: string;
|
|
@@ -12,7 +12,6 @@ export declare const MaskedInput: React.ComponentType<BaseProps<HTMLInputElement
|
|
|
12
12
|
placeholderChar?: string | undefined;
|
|
13
13
|
value?: string | undefined;
|
|
14
14
|
}>;
|
|
15
|
-
export declare const TextArea: ({ className, errorText, label, description, counterLimit, tooltip, tooltipConfig, icon1, icon1Tooltip, autoResize, icon2, icon2Tooltip, resetMargin, handleInputRef, prefixel, suffixel, error, ...antdTextareaProps }: TextareaProps) => JSX.Element;
|
|
16
15
|
export declare const RawMaskedInput: StyledComponent<React.ForwardRefExoticComponent<AntdInputProps & {
|
|
17
16
|
mask: string;
|
|
18
17
|
formatCharacters?: object | undefined;
|
|
@@ -23,13 +22,8 @@ export declare const RawMaskedInput: StyledComponent<React.ForwardRefExoticCompo
|
|
|
23
22
|
} & React.RefAttributes<AntdMaskedInput>>, any, {
|
|
24
23
|
error?: boolean | undefined;
|
|
25
24
|
}, never>;
|
|
25
|
+
export declare const RawInput: (props: DSInputProps) => JSX.Element;
|
|
26
26
|
export { default as InputGroup } from './InputGroup';
|
|
27
|
-
export declare const RawInput: (props: DSInputProps) => ReactElement;
|
|
28
|
-
export declare const RawTextArea: StyledComponent<React.ForwardRefExoticComponent<{
|
|
29
|
-
error?: boolean | undefined;
|
|
30
|
-
} & React.RefAttributes<import("antd/lib/input/TextArea").default>>, any, {
|
|
31
|
-
error?: boolean | undefined;
|
|
32
|
-
}, never>;
|
|
33
27
|
export { default as InputMultivalue } from './InputMultivalue/InputMultivalue';
|
|
34
28
|
export declare const AutoResize: any;
|
|
35
29
|
export declare const WrapperAutoResize: any;
|
package/dist/Input.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var _excluded = ["className", "errorText", "label", "description", "counterLimit", "tooltip", "tooltipConfig", "icon1", "icon1Tooltip", "autoResize", "icon2", "icon2Tooltip", "resetMargin", "handleInputRef", "prefixel", "suffixel", "error"]
|
|
2
|
-
_excluded2 = ["className", "errorText", "label", "description", "counterLimit", "tooltip", "tooltipConfig", "icon1", "icon1Tooltip", "autoResize", "icon2", "icon2Tooltip", "resetMargin", "handleInputRef", "prefixel", "suffixel", "error"];
|
|
1
|
+
var _excluded = ["className", "errorText", "label", "description", "counterLimit", "tooltip", "tooltipConfig", "icon1", "icon1Tooltip", "autoResize", "icon2", "icon2Tooltip", "resetMargin", "handleInputRef", "prefixel", "suffixel", "error"];
|
|
3
2
|
|
|
4
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); }
|
|
5
4
|
|
|
@@ -8,14 +7,13 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
8
7
|
import React, { useEffect, useRef, useCallback, useMemo } from 'react';
|
|
9
8
|
import { v4 as uuid } from 'uuid';
|
|
10
9
|
import '@synerise/ds-core/dist/js/style';
|
|
10
|
+
import { useResizeObserver } from '@synerise/ds-utils';
|
|
11
11
|
import "./style/index.css";
|
|
12
|
-
import { useResizeToFit } from '@synerise/ds-utils';
|
|
13
12
|
import * as S from './Input.styles';
|
|
14
13
|
import { ContentAboveElement, ContentBelowElement, ElementIcons } from './components';
|
|
15
|
-
import Textarea from './Textarea/Textarea';
|
|
16
|
-
import AutosizeInput from './autosize/autosize';
|
|
17
14
|
import { useInputAddonHeight, useElementFocus } from './hooks';
|
|
18
15
|
import { getCharCount } from './utils';
|
|
16
|
+
import { AutosizeWrapper } from './AutosizeWrapper/AutosizeWrapper';
|
|
19
17
|
var VERTICAL_BORDER_OFFSET = 2;
|
|
20
18
|
|
|
21
19
|
var createInputComponent = function createInputComponent(WrappedComponent) {
|
|
@@ -43,96 +41,66 @@ var createInputComponent = function createInputComponent(WrappedComponent) {
|
|
|
43
41
|
return uuid();
|
|
44
42
|
}, []);
|
|
45
43
|
var charCount = getCharCount(antdInputProps.value, counterLimit);
|
|
46
|
-
var
|
|
44
|
+
var scrollLeftRef = useRef(0);
|
|
47
45
|
var hasErrorMessage = Boolean(errorText);
|
|
46
|
+
var paddingDiff = useRef();
|
|
48
47
|
var inputRef = useRef(null);
|
|
48
|
+
var autosizeRef = useRef(null);
|
|
49
49
|
var externalRef = useRef(null);
|
|
50
|
+
var elementRef = useRef(null);
|
|
50
51
|
var handleIconsClick = useElementFocus(inputRef);
|
|
51
52
|
|
|
52
53
|
var _useInputAddonHeight = useInputAddonHeight(inputRef),
|
|
53
54
|
inputAddonHeight = _useInputAddonHeight.inputAddonHeight;
|
|
54
55
|
|
|
56
|
+
useResizeObserver(elementRef);
|
|
55
57
|
useEffect(function () {
|
|
56
|
-
if (inputRef
|
|
58
|
+
if (inputRef.current) {
|
|
57
59
|
externalRef.current = inputRef.current.input;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
handleInputRef && handleInputRef(externalRef);
|
|
61
|
-
}, [
|
|
63
|
+
}, [handleInputRef]);
|
|
64
|
+
useEffect(function () {
|
|
65
|
+
if (autosizeRef.current) {
|
|
66
|
+
externalRef.current = autosizeRef.current.inputRef.current;
|
|
67
|
+
handleInputRef && handleInputRef(externalRef);
|
|
68
|
+
}
|
|
69
|
+
}, [handleInputRef]);
|
|
70
|
+
useEffect(function () {
|
|
71
|
+
if (inputRef.current) {
|
|
72
|
+
var _getComputedStyle2 = getComputedStyle(inputRef.current.input),
|
|
73
|
+
paddingLeft = _getComputedStyle2.paddingLeft,
|
|
74
|
+
paddingRight = _getComputedStyle2.paddingRight;
|
|
75
|
+
|
|
76
|
+
paddingDiff.current = parseFloat(paddingLeft) + parseFloat(paddingRight);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
62
79
|
var handleChange = useCallback(function (e) {
|
|
63
80
|
var newValue = e.currentTarget.value;
|
|
64
81
|
if (counterLimit && newValue.length > counterLimit) return;
|
|
65
82
|
antdInputProps.onChange && antdInputProps.onChange(e);
|
|
66
83
|
}, [antdInputProps, counterLimit]);
|
|
84
|
+
var stretchToFit = autoResize && autoResize !== true && Boolean(autoResize.stretchToFit);
|
|
67
85
|
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
renderInput: WrappedComponent,
|
|
71
|
-
autoResize: autoResize
|
|
72
|
-
} : {}, {
|
|
73
|
-
className: hasErrorMessage || error ? 'error' : undefined,
|
|
74
|
-
addonBefore: !!prefixel && /*#__PURE__*/React.createElement(S.AddonWrapper, {
|
|
75
|
-
className: "ds-input-prefix",
|
|
76
|
-
height: inputAddonHeight - VERTICAL_BORDER_OFFSET
|
|
77
|
-
}, prefixel),
|
|
78
|
-
addonAfter: !!suffixel && /*#__PURE__*/React.createElement(S.AddonWrapper, {
|
|
79
|
-
className: "ds-input-suffix",
|
|
80
|
-
height: inputAddonHeight - VERTICAL_BORDER_OFFSET
|
|
81
|
-
}, suffixel),
|
|
82
|
-
error: hasErrorMessage || error,
|
|
83
|
-
onChange: handleChange,
|
|
84
|
-
value: antdInputProps.value,
|
|
85
|
-
id: id,
|
|
86
|
-
ref: inputRef,
|
|
87
|
-
autoComplete: "off"
|
|
88
|
-
}));
|
|
89
|
-
};
|
|
86
|
+
var preAutosize = function preAutosize() {
|
|
87
|
+
var _inputRef$current;
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
scrollLeftRef.current = ((_inputRef$current = inputRef.current) == null ? void 0 : _inputRef$current.input.scrollLeft) || 0;
|
|
90
|
+
inputRef.current && inputRef.current.input.style.removeProperty('max-width');
|
|
91
|
+
};
|
|
93
92
|
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
if (inputRef.current && paddingDiff.current) {
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
inputRef.current.input.style.maxWidth = width - paddingDiff.current + "px";
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
autoObserve: true
|
|
102
|
-
}),
|
|
103
|
-
observe = _useResizeToFit.observe,
|
|
104
|
-
disconnect = _useResizeToFit.disconnect,
|
|
105
|
-
elementRef = _useResizeToFit.elementRef;
|
|
93
|
+
var onAutosize = function onAutosize() {
|
|
94
|
+
var parentRect = elementRef.current && elementRef.current.getBoundingClientRect();
|
|
106
95
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
var _getComputedStyle2 = getComputedStyle(inputRef.current.input),
|
|
111
|
-
paddingLeft = _getComputedStyle2.paddingLeft,
|
|
112
|
-
paddingRight = _getComputedStyle2.paddingRight;
|
|
113
|
-
|
|
114
|
-
paddingDiff.current = parseFloat(paddingLeft) + parseFloat(paddingRight);
|
|
115
|
-
}
|
|
116
|
-
}, [paddingDiff]);
|
|
117
|
-
useEffect(function () {
|
|
118
|
-
if (elementRef.current) {
|
|
119
|
-
if (stretchToFit) {
|
|
120
|
-
observe();
|
|
121
|
-
} else {
|
|
122
|
-
disconnect(); // @ts-ignore
|
|
123
|
-
|
|
124
|
-
if (inputRef.current && inputRef.current.input) {
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
inputRef.current.input.style.removeProperty('max-width');
|
|
127
|
-
}
|
|
128
|
-
}
|
|
96
|
+
if (stretchToFit && inputRef.current && parentRect != null && parentRect.width && paddingDiff.current) {
|
|
97
|
+
inputRef.current.input.style.maxWidth = (parentRect == null ? void 0 : parentRect.width) - paddingDiff.current + "px";
|
|
98
|
+
inputRef.current.input.scrollLeft = scrollLeftRef.current;
|
|
129
99
|
}
|
|
100
|
+
};
|
|
130
101
|
|
|
131
|
-
return function () {
|
|
132
|
-
disconnect();
|
|
133
|
-
};
|
|
134
|
-
}, [disconnect, observe, stretchToFit, elementRef]);
|
|
135
102
|
return /*#__PURE__*/React.createElement(S.OuterWrapper, {
|
|
103
|
+
ref: elementRef,
|
|
136
104
|
autoResize: autoResize,
|
|
137
105
|
className: className,
|
|
138
106
|
resetMargin: resetMargin
|
|
@@ -144,7 +112,6 @@ var createInputComponent = function createInputComponent(WrappedComponent) {
|
|
|
144
112
|
tooltipConfig: tooltipConfig,
|
|
145
113
|
charCount: charCount
|
|
146
114
|
}), /*#__PURE__*/React.createElement(S.InputWrapper, {
|
|
147
|
-
ref: elementRef,
|
|
148
115
|
icon1: Boolean(icon1),
|
|
149
116
|
icon2: Boolean(icon2)
|
|
150
117
|
}, /*#__PURE__*/React.createElement(ElementIcons, {
|
|
@@ -156,7 +123,33 @@ var createInputComponent = function createInputComponent(WrappedComponent) {
|
|
|
156
123
|
icon2Tooltip: icon2Tooltip,
|
|
157
124
|
className: className,
|
|
158
125
|
type: "input"
|
|
159
|
-
}),
|
|
126
|
+
}), /*#__PURE__*/React.createElement(AutosizeWrapper, {
|
|
127
|
+
preAutosize: preAutosize,
|
|
128
|
+
onAutosize: onAutosize,
|
|
129
|
+
value: antdInputProps.value,
|
|
130
|
+
autoResize: !!autoResize
|
|
131
|
+
}, /*#__PURE__*/React.createElement(WrappedComponent, _extends({
|
|
132
|
+
style: {
|
|
133
|
+
minHeight: '6px'
|
|
134
|
+
},
|
|
135
|
+
autoResize: autoResize
|
|
136
|
+
}, antdInputProps, {
|
|
137
|
+
className: hasErrorMessage || error ? 'error' : undefined,
|
|
138
|
+
addonBefore: !!prefixel && /*#__PURE__*/React.createElement(S.AddonWrapper, {
|
|
139
|
+
className: "ds-input-prefix",
|
|
140
|
+
height: inputAddonHeight - VERTICAL_BORDER_OFFSET
|
|
141
|
+
}, prefixel),
|
|
142
|
+
addonAfter: !!suffixel && /*#__PURE__*/React.createElement(S.AddonWrapper, {
|
|
143
|
+
className: "ds-input-suffix",
|
|
144
|
+
height: inputAddonHeight - VERTICAL_BORDER_OFFSET
|
|
145
|
+
}, suffixel),
|
|
146
|
+
error: hasErrorMessage || error,
|
|
147
|
+
onChange: handleChange,
|
|
148
|
+
value: antdInputProps.value,
|
|
149
|
+
autoComplete: "off",
|
|
150
|
+
id: id,
|
|
151
|
+
ref: inputRef
|
|
152
|
+
})))), /*#__PURE__*/React.createElement(ContentBelowElement, {
|
|
160
153
|
description: description,
|
|
161
154
|
errorText: errorText
|
|
162
155
|
}));
|
|
@@ -165,90 +158,16 @@ var createInputComponent = function createInputComponent(WrappedComponent) {
|
|
|
165
158
|
|
|
166
159
|
export var Input = createInputComponent(S.AntdInput);
|
|
167
160
|
export var MaskedInput = createInputComponent(S.AntdMaskedInput);
|
|
168
|
-
export var TextArea = function TextArea(_ref2) {
|
|
169
|
-
var className = _ref2.className,
|
|
170
|
-
errorText = _ref2.errorText,
|
|
171
|
-
label = _ref2.label,
|
|
172
|
-
description = _ref2.description,
|
|
173
|
-
counterLimit = _ref2.counterLimit,
|
|
174
|
-
tooltip = _ref2.tooltip,
|
|
175
|
-
tooltipConfig = _ref2.tooltipConfig,
|
|
176
|
-
icon1 = _ref2.icon1,
|
|
177
|
-
icon1Tooltip = _ref2.icon1Tooltip,
|
|
178
|
-
autoResize = _ref2.autoResize,
|
|
179
|
-
icon2 = _ref2.icon2,
|
|
180
|
-
icon2Tooltip = _ref2.icon2Tooltip,
|
|
181
|
-
resetMargin = _ref2.resetMargin,
|
|
182
|
-
handleInputRef = _ref2.handleInputRef,
|
|
183
|
-
prefixel = _ref2.prefixel,
|
|
184
|
-
suffixel = _ref2.suffixel,
|
|
185
|
-
error = _ref2.error,
|
|
186
|
-
antdTextareaProps = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
187
|
-
|
|
188
|
-
var id = useMemo(function () {
|
|
189
|
-
return uuid();
|
|
190
|
-
}, []);
|
|
191
|
-
var charCount = getCharCount(antdTextareaProps.value, counterLimit);
|
|
192
|
-
var hasErrorMessage = Boolean(errorText);
|
|
193
|
-
var ref = useRef(null);
|
|
194
|
-
var handleIconsClick = useElementFocus(ref);
|
|
195
|
-
useEffect(function () {
|
|
196
|
-
handleInputRef && handleInputRef(ref);
|
|
197
|
-
}, [ref, handleInputRef]);
|
|
198
|
-
var handleChange = useCallback(function (e) {
|
|
199
|
-
var newValue = e.currentTarget.value;
|
|
200
|
-
|
|
201
|
-
if (counterLimit && newValue.length > counterLimit) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
antdTextareaProps.onChange && antdTextareaProps.onChange(e);
|
|
206
|
-
}, [antdTextareaProps, counterLimit]);
|
|
207
|
-
return /*#__PURE__*/React.createElement(S.OuterWrapper, {
|
|
208
|
-
autoResize: autoResize,
|
|
209
|
-
className: className,
|
|
210
|
-
resetMargin: resetMargin
|
|
211
|
-
}, /*#__PURE__*/React.createElement(ContentAboveElement, {
|
|
212
|
-
label: label,
|
|
213
|
-
counterLimit: counterLimit,
|
|
214
|
-
id: id,
|
|
215
|
-
tooltip: tooltip,
|
|
216
|
-
tooltipConfig: tooltipConfig,
|
|
217
|
-
charCount: charCount
|
|
218
|
-
}), /*#__PURE__*/React.createElement(S.InputWrapper, {
|
|
219
|
-
icon1: Boolean(icon1),
|
|
220
|
-
icon2: Boolean(icon2)
|
|
221
|
-
}, /*#__PURE__*/React.createElement(ElementIcons, {
|
|
222
|
-
handleIconsClick: handleIconsClick,
|
|
223
|
-
disabled: antdTextareaProps.disabled,
|
|
224
|
-
icon1Tooltip: icon1Tooltip,
|
|
225
|
-
icon1: icon1,
|
|
226
|
-
icon2: icon2,
|
|
227
|
-
icon2Tooltip: icon2Tooltip,
|
|
228
|
-
className: className,
|
|
229
|
-
type: "textArea"
|
|
230
|
-
}), /*#__PURE__*/React.createElement(Textarea, _extends({}, antdTextareaProps, {
|
|
231
|
-
className: hasErrorMessage || error ? 'error' : undefined,
|
|
232
|
-
error: hasErrorMessage || error,
|
|
233
|
-
onChange: handleChange,
|
|
234
|
-
value: antdTextareaProps.value,
|
|
235
|
-
id: id // ref={ref}
|
|
236
|
-
,
|
|
237
|
-
autoComplete: "off"
|
|
238
|
-
}))), /*#__PURE__*/React.createElement(ContentBelowElement, {
|
|
239
|
-
description: description,
|
|
240
|
-
errorText: errorText
|
|
241
|
-
}));
|
|
242
|
-
};
|
|
243
161
|
export var RawMaskedInput = S.AntdMaskedInput;
|
|
244
|
-
export { default as InputGroup } from './InputGroup';
|
|
245
162
|
export var RawInput = function RawInput(props) {
|
|
246
163
|
var error = props.error;
|
|
247
164
|
return /*#__PURE__*/React.createElement(S.AntdInput, _extends({
|
|
248
165
|
className: error ? 'error' : ''
|
|
249
166
|
}, props));
|
|
250
167
|
};
|
|
251
|
-
export
|
|
252
|
-
export { default as InputMultivalue } from './InputMultivalue/InputMultivalue';
|
|
253
|
-
|
|
168
|
+
export { default as InputGroup } from './InputGroup';
|
|
169
|
+
export { default as InputMultivalue } from './InputMultivalue/InputMultivalue'; // @deprecated
|
|
170
|
+
|
|
171
|
+
export var AutoResize = Object.assign(S.AutoResize); // @deprecated
|
|
172
|
+
|
|
254
173
|
export var WrapperAutoResize = Object.assign(S.WrapperAutoResize);
|
package/dist/Input.styles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
import BaseAntInput, { InputProps } from 'antd/lib/input';
|
|
3
3
|
import TextArea from 'antd/lib/input/TextArea';
|
|
4
4
|
import MaskedInput from 'antd-mask-input';
|
|
@@ -14,17 +14,15 @@ export type AutoResizeInputProps = {
|
|
|
14
14
|
export declare function autoresizeConfObjToCss({ autoResize }: {
|
|
15
15
|
autoResize?: AutoResizeProp;
|
|
16
16
|
}): string;
|
|
17
|
+
export declare const InputWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
18
|
+
icon1: boolean;
|
|
19
|
+
icon2: boolean;
|
|
20
|
+
}, never>;
|
|
17
21
|
export declare const OuterWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
18
22
|
resetMargin?: boolean | undefined;
|
|
19
23
|
autoResize?: AutoResizeProp | undefined;
|
|
20
24
|
}, never>;
|
|
21
25
|
export declare const Wrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
22
|
-
interface InputWrapperProps {
|
|
23
|
-
icon1: boolean;
|
|
24
|
-
icon2: boolean;
|
|
25
|
-
ref?: MutableRefObject<HTMLDivElement | null>;
|
|
26
|
-
}
|
|
27
|
-
export declare const InputWrapper: import("styled-components").StyledComponent<"div", any, InputWrapperProps, never>;
|
|
28
26
|
export declare const IconsWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
29
27
|
disabled?: boolean | undefined;
|
|
30
28
|
}, never>;
|
|
@@ -67,4 +65,3 @@ export declare const ContentAbove: import("styled-components").StyledComponent<"
|
|
|
67
65
|
export declare const AddonWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
68
66
|
height: number;
|
|
69
67
|
}, never>;
|
|
70
|
-
export {};
|
package/dist/Input.styles.js
CHANGED
|
@@ -32,15 +32,23 @@ export function autoresizeConfObjToCss(_ref) {
|
|
|
32
32
|
if (!autoResize) return '';
|
|
33
33
|
|
|
34
34
|
if (typeof autoResize === 'object') {
|
|
35
|
-
return "\n " + (autoResize.maxWidth
|
|
35
|
+
return "\n " + (autoResize.maxWidth ? "max-width: " + autoResize.maxWidth + ";" : '') + "\n min-width: " + autoResize.minWidth + ";\n ";
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
return "max-width: 400px; min-width: 150px;";
|
|
39
39
|
}
|
|
40
|
+
export var InputWrapper = styled.div.withConfig({
|
|
41
|
+
displayName: "Inputstyles__InputWrapper",
|
|
42
|
+
componentId: "dc57an-0"
|
|
43
|
+
})(["position:relative;&& .ant-input{padding-right:", ";&::placeholder{line-height:1.29;}}.ant-input-group-addon{height:100%;}"], function (props) {
|
|
44
|
+
if (props.icon1 && props.icon2) return '64px;';
|
|
45
|
+
if (props.icon1 || props.icon2) return '36px;';
|
|
46
|
+
return '12px';
|
|
47
|
+
});
|
|
40
48
|
export var OuterWrapper = styled.div.withConfig({
|
|
41
49
|
displayName: "Inputstyles__OuterWrapper",
|
|
42
|
-
componentId: "dc57an-
|
|
43
|
-
})(["margin:", ";&.active{&&{input{box-shadow:inset 0 0 0 1px ", ";border-color:", ";background-color:", ";}}}input{", "}"], function (props) {
|
|
50
|
+
componentId: "dc57an-1"
|
|
51
|
+
})(["margin:", ";&.active{&&{input{box-shadow:inset 0 0 0 1px ", ";border-color:", ";background-color:", ";}}}input{", "}", "{", "}"], function (props) {
|
|
44
52
|
return props.resetMargin ? '0' : '0 0 16px 0';
|
|
45
53
|
}, function (props) {
|
|
46
54
|
return props.theme.palette['blue-600'];
|
|
@@ -50,19 +58,13 @@ export var OuterWrapper = styled.div.withConfig({
|
|
|
50
58
|
return props.theme.palette['blue-050'];
|
|
51
59
|
}, function (props) {
|
|
52
60
|
return autoresizeConfObjToCss(props);
|
|
61
|
+
}, InputWrapper, function (props) {
|
|
62
|
+
return props.autoResize && "\n display: inline-block;\n ";
|
|
53
63
|
});
|
|
54
64
|
export var Wrapper = styled.div.withConfig({
|
|
55
65
|
displayName: "Inputstyles__Wrapper",
|
|
56
|
-
componentId: "dc57an-1"
|
|
57
|
-
})(["margin-bottom:24px;"]);
|
|
58
|
-
export var InputWrapper = styled.div.withConfig({
|
|
59
|
-
displayName: "Inputstyles__InputWrapper",
|
|
60
66
|
componentId: "dc57an-2"
|
|
61
|
-
})(["
|
|
62
|
-
if (props.icon1 && props.icon2) return '64px;';
|
|
63
|
-
if (props.icon1 || props.icon2) return '36px;';
|
|
64
|
-
return '12px';
|
|
65
|
-
});
|
|
67
|
+
})(["margin-bottom:24px;"]);
|
|
66
68
|
export var IconsWrapper = styled.div.withConfig({
|
|
67
69
|
displayName: "Inputstyles__IconsWrapper",
|
|
68
70
|
componentId: "dc57an-3"
|
|
@@ -100,7 +102,7 @@ function (_ref2, ref) {
|
|
|
100
102
|
})).withConfig({
|
|
101
103
|
displayName: "Inputstyles__AntdInput",
|
|
102
104
|
componentId: "dc57an-6"
|
|
103
|
-
})(["", ";&&&{min-height:32px;grid-area:1 / 1;color:", ";z-index:1;&::placeholder{color:", ";}&::-moz-placeholder{line-height:", ";}.ds-input-prefix{border-top-left-radius:3px;border-bottom-left-radius:3px;}.ds-input-suffix{border-top-right-radius:3px;border-bottom-right-radius:3px;}", "}"], function (props) {
|
|
105
|
+
})(["", ";&&&{min-height:32px;transition:all 0.3s,width 0ms,min-width 0ms,max-width 0ms;grid-area:1 / 1;color:", ";z-index:1;&::placeholder{color:", ";}&::-moz-placeholder{line-height:", ";}.ds-input-prefix{border-top-left-radius:3px;border-bottom-left-radius:3px;}.ds-input-suffix{border-top-right-radius:3px;border-bottom-right-radius:3px;}", "}"], function (props) {
|
|
104
106
|
return props.error ? errorInputStyle(props) : '';
|
|
105
107
|
}, function (props) {
|
|
106
108
|
return props.theme.palette['grey-700'];
|
|
@@ -133,7 +135,7 @@ function (_ref4, ref) {
|
|
|
133
135
|
}, function (props) {
|
|
134
136
|
return props.theme.palette['grey-700'];
|
|
135
137
|
});
|
|
136
|
-
export var AntdTextArea = styled(forwardRef( // eslint-disable-next-line
|
|
138
|
+
export var AntdTextArea = styled(forwardRef( // eslint-disable-next-line handle-callback-err
|
|
137
139
|
function (_ref5, ref) {
|
|
138
140
|
var error = _ref5.error,
|
|
139
141
|
props = _objectWithoutPropertiesLoose(_ref5, _excluded3);
|
package/dist/Input.types.d.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { InputProps as AntdInputProps, TextAreaProps as AntdTextAreaProps } from
|
|
|
3
3
|
import { MaskedInputProps as AntdMaskedInputProps } from 'antd-mask-input/build/main/lib/MaskedInput';
|
|
4
4
|
import { TooltipProps } from 'antd/lib/tooltip';
|
|
5
5
|
import TooltipExtendedProps from '@synerise/ds-tooltip/dist/Tooltip.types';
|
|
6
|
-
import { TextAreaProps } from './Textarea/Textarea.types';
|
|
7
6
|
export type AutoResizeProp = boolean | {
|
|
8
7
|
minWidth: string;
|
|
9
8
|
maxWidth?: string;
|
|
@@ -33,5 +32,4 @@ export interface BaseProps<RefElementType extends HTMLTextAreaElement | HTMLInpu
|
|
|
33
32
|
*/
|
|
34
33
|
export type EnhancedProps = BaseProps<HTMLInputElement | HTMLTextAreaElement> & (AntdInputProps | AntdTextAreaProps | AntdMaskedInputProps);
|
|
35
34
|
export type InputProps = BaseProps & AntdInputProps;
|
|
36
|
-
export type TextareaProps = BaseProps<HTMLTextAreaElement> & TextAreaProps;
|
|
37
35
|
export type MaskedInputProps = BaseProps & AntdMaskedInputProps;
|
package/dist/InputGroup.js
CHANGED
|
@@ -19,6 +19,7 @@ var InputGroup = function InputGroup(_ref) {
|
|
|
19
19
|
|
|
20
20
|
var childrenArray = Children.toArray(children);
|
|
21
21
|
return /*#__PURE__*/React.createElement(InputStyles.OuterWrapper, {
|
|
22
|
+
className: "ds-input-group-outer-wrapper",
|
|
22
23
|
resetMargin: resetMargin
|
|
23
24
|
}, label && /*#__PURE__*/React.createElement(InputStyles.ContentAbove, null, /*#__PURE__*/React.createElement(Label, {
|
|
24
25
|
label: label,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import '@synerise/ds-core/dist/js/style';
|
|
3
|
+
import './style/index.less';
|
|
4
|
+
import { TextareaProps } from './TextArea.types';
|
|
5
|
+
export declare const TextArea: ({ className, errorText, label, description, counterLimit, tooltip, tooltipConfig, icon1, icon1Tooltip, autoResize, icon2, icon2Tooltip, resetMargin, handleInputRef, prefixel, suffixel, error, ...antdTextareaProps }: TextareaProps) => JSX.Element;
|
|
6
|
+
export declare const RawTextArea: import("styled-components").StyledComponent<React.ForwardRefExoticComponent<{
|
|
7
|
+
error?: boolean | undefined;
|
|
8
|
+
} & React.RefAttributes<import("antd/lib/input/TextArea").default>>, any, {
|
|
9
|
+
error?: boolean | undefined;
|
|
10
|
+
}, never>;
|
package/dist/TextArea.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var _excluded = ["className", "errorText", "label", "description", "counterLimit", "tooltip", "tooltipConfig", "icon1", "icon1Tooltip", "autoResize", "icon2", "icon2Tooltip", "resetMargin", "handleInputRef", "prefixel", "suffixel", "error"];
|
|
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 _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; }
|
|
6
|
+
|
|
7
|
+
import React, { useEffect, useRef, useCallback, useMemo } from 'react';
|
|
8
|
+
import { v4 as uuid } from 'uuid';
|
|
9
|
+
import '@synerise/ds-core/dist/js/style';
|
|
10
|
+
import "./style/index.css";
|
|
11
|
+
import * as S from './Input.styles';
|
|
12
|
+
import { ContentAboveElement, ContentBelowElement, ElementIcons } from './components';
|
|
13
|
+
import Textarea from './Textarea/Textarea';
|
|
14
|
+
import { useElementFocus } from './hooks';
|
|
15
|
+
import { getCharCount } from './utils';
|
|
16
|
+
export var TextArea = function TextArea(_ref) {
|
|
17
|
+
var className = _ref.className,
|
|
18
|
+
errorText = _ref.errorText,
|
|
19
|
+
label = _ref.label,
|
|
20
|
+
description = _ref.description,
|
|
21
|
+
counterLimit = _ref.counterLimit,
|
|
22
|
+
tooltip = _ref.tooltip,
|
|
23
|
+
tooltipConfig = _ref.tooltipConfig,
|
|
24
|
+
icon1 = _ref.icon1,
|
|
25
|
+
icon1Tooltip = _ref.icon1Tooltip,
|
|
26
|
+
autoResize = _ref.autoResize,
|
|
27
|
+
icon2 = _ref.icon2,
|
|
28
|
+
icon2Tooltip = _ref.icon2Tooltip,
|
|
29
|
+
resetMargin = _ref.resetMargin,
|
|
30
|
+
handleInputRef = _ref.handleInputRef,
|
|
31
|
+
prefixel = _ref.prefixel,
|
|
32
|
+
suffixel = _ref.suffixel,
|
|
33
|
+
error = _ref.error,
|
|
34
|
+
antdTextareaProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
35
|
+
|
|
36
|
+
var id = useMemo(function () {
|
|
37
|
+
return uuid();
|
|
38
|
+
}, []);
|
|
39
|
+
var charCount = getCharCount(antdTextareaProps.value, counterLimit);
|
|
40
|
+
var hasErrorMessage = Boolean(errorText);
|
|
41
|
+
var ref = useRef(null);
|
|
42
|
+
var handleIconsClick = useElementFocus(ref);
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
handleInputRef && handleInputRef(ref);
|
|
45
|
+
}, [ref, handleInputRef]);
|
|
46
|
+
var handleChange = useCallback(function (e) {
|
|
47
|
+
var newValue = e.currentTarget.value;
|
|
48
|
+
|
|
49
|
+
if (counterLimit && newValue.length > counterLimit) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
antdTextareaProps.onChange && antdTextareaProps.onChange(e);
|
|
54
|
+
}, [antdTextareaProps, counterLimit]);
|
|
55
|
+
return /*#__PURE__*/React.createElement(S.OuterWrapper, {
|
|
56
|
+
autoResize: autoResize,
|
|
57
|
+
className: className,
|
|
58
|
+
resetMargin: resetMargin
|
|
59
|
+
}, /*#__PURE__*/React.createElement(ContentAboveElement, {
|
|
60
|
+
label: label,
|
|
61
|
+
counterLimit: counterLimit,
|
|
62
|
+
id: id,
|
|
63
|
+
tooltip: tooltip,
|
|
64
|
+
tooltipConfig: tooltipConfig,
|
|
65
|
+
charCount: charCount
|
|
66
|
+
}), /*#__PURE__*/React.createElement(S.InputWrapper, {
|
|
67
|
+
icon1: Boolean(icon1),
|
|
68
|
+
icon2: Boolean(icon2)
|
|
69
|
+
}, /*#__PURE__*/React.createElement(ElementIcons, {
|
|
70
|
+
handleIconsClick: handleIconsClick,
|
|
71
|
+
disabled: antdTextareaProps.disabled,
|
|
72
|
+
icon1Tooltip: icon1Tooltip,
|
|
73
|
+
icon1: icon1,
|
|
74
|
+
icon2: icon2,
|
|
75
|
+
icon2Tooltip: icon2Tooltip,
|
|
76
|
+
className: className,
|
|
77
|
+
type: "textArea"
|
|
78
|
+
}), /*#__PURE__*/React.createElement(Textarea, _extends({}, antdTextareaProps, {
|
|
79
|
+
className: hasErrorMessage || error ? 'error' : undefined,
|
|
80
|
+
error: hasErrorMessage || error,
|
|
81
|
+
onChange: handleChange,
|
|
82
|
+
value: antdTextareaProps.value,
|
|
83
|
+
id: id,
|
|
84
|
+
autoComplete: "off"
|
|
85
|
+
}))), /*#__PURE__*/React.createElement(ContentBelowElement, {
|
|
86
|
+
description: description,
|
|
87
|
+
errorText: errorText
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
export var RawTextArea = S.AntdTextArea;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export { default as Label } from './Label/Label';
|
|
2
|
-
export { Input,
|
|
2
|
+
export { Input, RawInput, InputGroup, MaskedInput, InputMultivalue, RawMaskedInput, AutoResize, WrapperAutoResize, } from './Input';
|
|
3
|
+
export { TextArea, RawTextArea } from './TextArea';
|
|
4
|
+
export type { TextareaProps } from './TextArea.types';
|
|
3
5
|
export * as InputStyles from './Input.styles';
|
|
4
|
-
export type { BaseProps, EnhancedProps, InputProps,
|
|
5
|
-
export { default as AutosizeInput } from './
|
|
6
|
+
export type { BaseProps, EnhancedProps, InputProps, MaskedInputProps, AutoResizeProp } from './Input.types';
|
|
7
|
+
export { default as AutosizeInput } from './AutosizeInput/AutosizeInput';
|
|
8
|
+
export type { AutosizeInputProps, AutosizeWrapperProps, AutosizeInputRefType, } from './AutosizeInput/AutosizeInput.types';
|
|
9
|
+
export { AutosizeWrapper } from './AutosizeWrapper/AutosizeWrapper';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as Label } from './Label/Label';
|
|
2
|
-
export { Input,
|
|
2
|
+
export { Input, RawInput, InputGroup, MaskedInput, InputMultivalue, RawMaskedInput, AutoResize, WrapperAutoResize } from './Input';
|
|
3
|
+
export { TextArea, RawTextArea } from './TextArea';
|
|
3
4
|
import * as _InputStyles from './Input.styles';
|
|
4
5
|
export { _InputStyles as InputStyles };
|
|
5
|
-
export { default as AutosizeInput } from './
|
|
6
|
+
export { default as AutosizeInput } from './AutosizeInput/AutosizeInput';
|
|
7
|
+
export { AutosizeWrapper } from './AutosizeWrapper/AutosizeWrapper';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { InputProps as AntdInputProps } from 'antd/lib/input';
|
|
2
|
-
import { TextareaProps } from '../
|
|
2
|
+
import { TextareaProps } from '../TextArea.types';
|
|
3
3
|
export declare const getCharCount: (value?: AntdInputProps['value'] | TextareaProps['value'], limit?: number) => number | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-input",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.3",
|
|
4
4
|
"description": "Input UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "synerise/synerise-design",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
],
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@synerise/ds-icon": "^0.
|
|
37
|
-
"@synerise/ds-scrollbar": "^0.10.
|
|
38
|
-
"@synerise/ds-tooltip": "^0.14.
|
|
36
|
+
"@synerise/ds-icon": "^0.61.0",
|
|
37
|
+
"@synerise/ds-scrollbar": "^0.10.5",
|
|
38
|
+
"@synerise/ds-tooltip": "^0.14.28",
|
|
39
39
|
"@synerise/ds-typography": "^0.15.0",
|
|
40
|
-
"@synerise/ds-utils": "^0.26.
|
|
40
|
+
"@synerise/ds-utils": "^0.26.6",
|
|
41
41
|
"antd-mask-input": "^0.1.13",
|
|
42
42
|
"csstype": "2.6.9",
|
|
43
43
|
"uuid": "^8.3.2"
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"@testing-library/react": "10.0.1",
|
|
53
53
|
"@testing-library/user-event": "10.3.1"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "fc089bbf34c691a313b3fa648851d7831a23e3d0"
|
|
56
56
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Component } from 'react';
|
|
2
|
-
declare class AutosizeInput extends Component {
|
|
3
|
-
static getDerivedStateFromProps(props: any, state: any): {
|
|
4
|
-
inputId: any;
|
|
5
|
-
prevId: any;
|
|
6
|
-
} | null;
|
|
7
|
-
constructor(props: any);
|
|
8
|
-
componentDidMount(): void;
|
|
9
|
-
componentDidUpdate(prevProps: any, prevState: any): void;
|
|
10
|
-
componentWillUnmount(): void;
|
|
11
|
-
inputRef: (el: any, originalElement: any) => void;
|
|
12
|
-
placeHolderSizerRef: (el: any) => void;
|
|
13
|
-
sizerRef: (el: any) => void;
|
|
14
|
-
copyInputStyles(): void;
|
|
15
|
-
updateInputWidth(): void;
|
|
16
|
-
getInput(): any;
|
|
17
|
-
focus(): void;
|
|
18
|
-
blur(): void;
|
|
19
|
-
select(): void;
|
|
20
|
-
renderStyles(): JSX.Element | null;
|
|
21
|
-
render(): JSX.Element;
|
|
22
|
-
}
|
|
23
|
-
export default AutosizeInput;
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
var _excluded = ["renderInput"];
|
|
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 _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; }
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
15
|
-
// @ts-nocheck
|
|
16
|
-
|
|
17
|
-
/* eslint-disable */
|
|
18
|
-
import React, { Component } from 'react';
|
|
19
|
-
var sizerStyle = {
|
|
20
|
-
position: 'absolute',
|
|
21
|
-
top: 0,
|
|
22
|
-
left: 0,
|
|
23
|
-
visibility: 'hidden',
|
|
24
|
-
height: 0,
|
|
25
|
-
overflow: 'scroll',
|
|
26
|
-
whiteSpace: 'pre'
|
|
27
|
-
};
|
|
28
|
-
var INPUT_PROPS_BLACKLIST = ['extraWidth', 'injectStyles', 'inputClassName', 'inputRef', 'inputStyle', 'minWidth', 'onAutosize', 'placeholderIsMinWidth', 'autoResize', 'refPropName'];
|
|
29
|
-
|
|
30
|
-
var cleanInputProps = function cleanInputProps(inputProps) {
|
|
31
|
-
INPUT_PROPS_BLACKLIST.forEach(function (field) {
|
|
32
|
-
return delete inputProps[field];
|
|
33
|
-
});
|
|
34
|
-
return inputProps;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
var copyStyles = function copyStyles(styles, node) {
|
|
38
|
-
node.style.fontSize = styles.fontSize;
|
|
39
|
-
node.style.fontFamily = styles.fontFamily;
|
|
40
|
-
node.style.fontWeight = styles.fontWeight;
|
|
41
|
-
node.style.fontStyle = styles.fontStyle;
|
|
42
|
-
node.style.letterSpacing = styles.letterSpacing;
|
|
43
|
-
node.style.textTransform = styles.textTransform;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
var isIE = typeof window !== 'undefined' && window.navigator ? /MSIE |Trident\/|Edge\//.test(window.navigator.userAgent) : false;
|
|
47
|
-
|
|
48
|
-
var generateId = function generateId() {
|
|
49
|
-
// we only need an auto-generated ID for stylesheet injection, which is only
|
|
50
|
-
// used for IE. so if the browser is not IE, this should return undefined.
|
|
51
|
-
return isIE ? '_' + Math.random().toString(36).substr(2, 12) : undefined;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
var AutosizeInput = /*#__PURE__*/function (_Component) {
|
|
55
|
-
function AutosizeInput(props) {
|
|
56
|
-
var _this;
|
|
57
|
-
|
|
58
|
-
_this = _Component.call(this, props) || this;
|
|
59
|
-
|
|
60
|
-
_defineProperty(_this, "inputRef", function (el, originalElement) {
|
|
61
|
-
_this.input = el;
|
|
62
|
-
|
|
63
|
-
if (typeof _this.props.inputRef === 'function') {
|
|
64
|
-
_this.props.inputRef(el, originalElement);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
_defineProperty(_this, "placeHolderSizerRef", function (el) {
|
|
69
|
-
_this.placeHolderSizer = el;
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
_defineProperty(_this, "sizerRef", function (el) {
|
|
73
|
-
var _this$props$transform = _this.props.transformRef,
|
|
74
|
-
transformRef = _this$props$transform === void 0 ? function (el) {
|
|
75
|
-
return el;
|
|
76
|
-
} : _this$props$transform;
|
|
77
|
-
_this.sizer = el;
|
|
78
|
-
if (!el) return;
|
|
79
|
-
var input = el.previousElementSibling;
|
|
80
|
-
var ref = transformRef(input);
|
|
81
|
-
|
|
82
|
-
_this.inputRef(ref, input);
|
|
83
|
-
|
|
84
|
-
_this.copyInputStyles();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
_this.state = {
|
|
88
|
-
inputWidth: props.minWidth,
|
|
89
|
-
inputId: props.id || generateId(),
|
|
90
|
-
prevId: props.id
|
|
91
|
-
};
|
|
92
|
-
return _this;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
_inheritsLoose(AutosizeInput, _Component);
|
|
96
|
-
|
|
97
|
-
AutosizeInput.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
|
|
98
|
-
var id = props.id;
|
|
99
|
-
return id !== state.prevId ? {
|
|
100
|
-
inputId: id || generateId(),
|
|
101
|
-
prevId: id
|
|
102
|
-
} : null;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
var _proto = AutosizeInput.prototype;
|
|
106
|
-
|
|
107
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
108
|
-
this.mounted = true;
|
|
109
|
-
this.copyInputStyles();
|
|
110
|
-
this.updateInputWidth();
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
114
|
-
if (prevState.inputWidth !== this.state.inputWidth) {
|
|
115
|
-
if (typeof this.props.onAutosize === 'function') {
|
|
116
|
-
this.props.onAutosize(this.state.inputWidth);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
this.updateInputWidth();
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
124
|
-
this.mounted = false;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
_proto.copyInputStyles = function copyInputStyles() {
|
|
128
|
-
if (!this.mounted || !window.getComputedStyle) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
var inputStyles = this.input && this.input instanceof HTMLElement && window.getComputedStyle(this.input);
|
|
133
|
-
|
|
134
|
-
if (!inputStyles) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
copyStyles(inputStyles, this.sizer);
|
|
139
|
-
|
|
140
|
-
if (this.placeHolderSizer) {
|
|
141
|
-
copyStyles(inputStyles, this.placeHolderSizer);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
_proto.updateInputWidth = function updateInputWidth() {
|
|
146
|
-
if (!this.mounted || !this.sizer || typeof this.sizer.scrollWidth === 'undefined') {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
var newInputWidth;
|
|
151
|
-
|
|
152
|
-
if (this.props.placeholder && (!this.props.value || this.props.value && this.props.placeholderIsMinWidth)) {
|
|
153
|
-
newInputWidth = Math.max(this.sizer.scrollWidth, this.placeHolderSizer.scrollWidth) + 2;
|
|
154
|
-
} else {
|
|
155
|
-
newInputWidth = this.sizer.scrollWidth + 2;
|
|
156
|
-
} // add extraWidth to the detected width. for number types, this defaults to 16 to allow for the stepper UI
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
var extraWidth = this.props.type === 'number' && this.props.extraWidth === undefined ? 16 : parseInt(this.props.extraWidth) || 0;
|
|
160
|
-
newInputWidth += extraWidth;
|
|
161
|
-
|
|
162
|
-
if (newInputWidth < this.props.minWidth) {
|
|
163
|
-
newInputWidth = this.props.minWidth;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (newInputWidth !== this.state.inputWidth) {
|
|
167
|
-
this.setState({
|
|
168
|
-
inputWidth: newInputWidth
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
_proto.getInput = function getInput() {
|
|
174
|
-
return this.input;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
_proto.focus = function focus() {
|
|
178
|
-
this.input.focus();
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
_proto.blur = function blur() {
|
|
182
|
-
this.input.blur();
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
_proto.select = function select() {
|
|
186
|
-
this.input.select();
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
_proto.renderStyles = function renderStyles() {
|
|
190
|
-
// this method injects styles to hide IE's clear indicator, which messes
|
|
191
|
-
// with input size detection. the stylesheet is only injected when the
|
|
192
|
-
// browser is IE, and can also be disabled by the `injectStyles` prop.
|
|
193
|
-
var injectStyles = this.props.injectStyles;
|
|
194
|
-
return isIE && injectStyles ? /*#__PURE__*/React.createElement("style", {
|
|
195
|
-
dangerouslySetInnerHTML: {
|
|
196
|
-
__html: "input#" + this.state.inputId + "::-ms-clear {display: none;}"
|
|
197
|
-
}
|
|
198
|
-
}) : null;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
_proto.render = function render() {
|
|
202
|
-
var _this$props$refPropNa, _ref;
|
|
203
|
-
|
|
204
|
-
var sizerValue = [this.props.defaultValue, this.props.value, ''].reduce(function (previousValue, currentValue) {
|
|
205
|
-
if (previousValue !== null && previousValue !== undefined) {
|
|
206
|
-
return previousValue;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return currentValue;
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
var wrapperStyle = _objectSpread({}, this.props.style);
|
|
213
|
-
|
|
214
|
-
if (!wrapperStyle.display) wrapperStyle.display = 'inline-block';
|
|
215
|
-
|
|
216
|
-
var inputStyle = _objectSpread({
|
|
217
|
-
boxSizing: 'content-box',
|
|
218
|
-
width: this.state.inputWidth + "px",
|
|
219
|
-
minHeight: 30 - 12 * 2 + "px",
|
|
220
|
-
transition: 'width 0s ease 0s'
|
|
221
|
-
}, this.props.inputStyle);
|
|
222
|
-
|
|
223
|
-
var defaultRenderInput = function defaultRenderInput(props) {
|
|
224
|
-
return /*#__PURE__*/React.createElement("input", props);
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
var _this$props = this.props,
|
|
228
|
-
_this$props$renderInp = _this$props.renderInput,
|
|
229
|
-
RenderInput = _this$props$renderInp === void 0 ? defaultRenderInput : _this$props$renderInp,
|
|
230
|
-
inputProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
231
|
-
|
|
232
|
-
cleanInputProps(inputProps);
|
|
233
|
-
inputProps.className = this.props.inputClassName;
|
|
234
|
-
inputProps.id = this.state.inputId;
|
|
235
|
-
inputProps.style = inputStyle;
|
|
236
|
-
this.copyInputStyles();
|
|
237
|
-
var name = (_this$props$refPropNa = this.props.refPropName) != null ? _this$props$refPropNa : 'ref';
|
|
238
|
-
var input = /*#__PURE__*/React.createElement(RenderInput, _extends({
|
|
239
|
-
"data-testid": "autosize-input"
|
|
240
|
-
}, inputProps, (_ref = {}, _ref[name] = this.inputRef, _ref)));
|
|
241
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
242
|
-
className: this.props.className,
|
|
243
|
-
style: wrapperStyle
|
|
244
|
-
}, this.renderStyles(), input, /*#__PURE__*/React.createElement("div", {
|
|
245
|
-
"data-testid": "autosize-sizer",
|
|
246
|
-
ref: this.sizerRef,
|
|
247
|
-
style: sizerStyle
|
|
248
|
-
}, sizerValue), this.props.placeholder ? /*#__PURE__*/React.createElement("div", {
|
|
249
|
-
"data-testid": "autosize-placeholder",
|
|
250
|
-
ref: this.placeHolderSizerRef,
|
|
251
|
-
style: sizerStyle
|
|
252
|
-
}, this.props.placeholder) : null);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
return AutosizeInput;
|
|
256
|
-
}(Component);
|
|
257
|
-
|
|
258
|
-
export default AutosizeInput;
|