@synerise/ds-input 1.7.10 → 1.7.12
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 +8 -0
- package/dist/AutosizeInput/AutosizeInput.d.ts +6 -7
- package/dist/AutosizeInput/AutosizeInput.js +39 -116
- package/dist/AutosizeInput/AutosizeInput.types.d.ts +5 -18
- package/dist/AutosizeInput/useAutosizeWidth.d.ts +18 -0
- package/dist/AutosizeInput/useAutosizeWidth.js +145 -0
- package/dist/AutosizeInput/useAutosizeWidth.types.d.ts +29 -0
- package/dist/AutosizeInput/useAutosizeWidth.types.js +1 -0
- package/dist/AutosizeInput/useStretchToFit.d.ts +26 -0
- package/dist/AutosizeInput/useStretchToFit.js +31 -0
- package/dist/Input.d.ts +13 -3
- package/dist/Input.js +170 -81
- package/dist/Input.styles.d.ts +32 -11
- package/dist/Input.styles.js +64 -38
- package/dist/Input.types.d.ts +23 -7
- package/dist/InputGroup.d.ts +1 -1
- package/dist/InputGroup.js +11 -4
- package/dist/InputGroup.styles.d.ts +1 -0
- package/dist/InputGroup.styles.js +9 -2
- package/dist/InputGroup.types.d.ts +22 -3
- package/dist/InputMultivalue/InputMultivalue.styles.js +1 -1
- package/dist/TextArea.d.ts +2 -2
- package/dist/TextArea.js +4 -5
- package/dist/Textarea/Textarea.d.ts +4 -3
- package/dist/Textarea/Textarea.js +33 -4
- package/dist/Textarea/Textarea.styles.js +2 -2
- package/dist/Textarea/Textarea.types.d.ts +13 -8
- package/dist/components/ExpandableWrapper.d.ts +1 -2
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +0 -2
- package/dist/hooks/useElementFocus.d.ts +3 -2
- package/dist/hooks/useInputAddonHeight.d.ts +1 -2
- package/dist/hooks/useInputAddonHeight.js +1 -1
- package/dist/hooks/useTextareaAutosize.d.ts +53 -0
- package/dist/hooks/useTextareaAutosize.js +82 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +8 -3
- package/dist/utils/getCharCount.d.ts +3 -2
- package/package.json +8 -12
- package/dist/assets/style/index-tn0RQdqM.css +0 -0
- package/dist/components/AutosizeWrapper.d.ts +0 -17
- package/dist/components/AutosizeWrapper.js +0 -18
- package/dist/style/index.css +0 -1
package/dist/Input.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useMemo, useRef, useState, useEffect, useCallback } from "react";
|
|
3
3
|
import { v4 } from "uuid";
|
|
4
4
|
import { useMergeRefs } from "@floating-ui/react";
|
|
5
5
|
import FormField from "@synerise/ds-form-field";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import Icon, { CloseS } from "@synerise/ds-icon";
|
|
7
|
+
import { useAutosizeWidth, SIZER_STYLE } from "./AutosizeInput/useAutosizeWidth.js";
|
|
8
|
+
import { useStretchToFit } from "./AutosizeInput/useStretchToFit.js";
|
|
9
|
+
import { NativeInput, OuterWrapper, InputWrapper, InnerAffix, ClearButton, InputGroupRow, Addon } from "./Input.styles.js";
|
|
8
10
|
import { ElementIcons } from "./components/ElementIcons.js";
|
|
9
11
|
import { ExpandableWrapper } from "./components/ExpandableWrapper.js";
|
|
10
|
-
import { AutosizeWrapper } from "./components/AutosizeWrapper.js";
|
|
11
12
|
import { useElementFocus } from "./hooks/useElementFocus.js";
|
|
12
|
-
import { useInputAddonHeight } from "./hooks/useInputAddonHeight.js";
|
|
13
13
|
import { useCounterLimit } from "./hooks/useCounterLimit.js";
|
|
14
14
|
import { getCharCount } from "./utils/getCharCount.js";
|
|
15
15
|
import { default as default2 } from "./InputGroup.js";
|
|
16
16
|
import { default as default3 } from "./InputMultivalue/InputMultivalue.js";
|
|
17
|
-
|
|
18
|
-
const
|
|
17
|
+
const DEFAULT_EXTRA_WIDTH = 2;
|
|
18
|
+
const CLEAR_BASE_OFFSET = 8;
|
|
19
|
+
const ICON_SLOT_WIDTH = 28;
|
|
19
20
|
const Input = forwardRef(({
|
|
20
21
|
className,
|
|
21
22
|
errorText,
|
|
@@ -38,54 +39,136 @@ const Input = forwardRef(({
|
|
|
38
39
|
expandableTooltip,
|
|
39
40
|
renderCustomCounter,
|
|
40
41
|
autoResizeProps,
|
|
41
|
-
|
|
42
|
+
allowClear,
|
|
43
|
+
size,
|
|
44
|
+
innerPrefix,
|
|
45
|
+
// antd affix/border props are intentionally not forwarded to the native
|
|
46
|
+
// input (the DS uses icon1/icon2 + prefixel/suffixel + innerPrefix); kept
|
|
47
|
+
// out of `...inputProps`.
|
|
48
|
+
prefix: _prefix,
|
|
49
|
+
suffix: _suffix,
|
|
50
|
+
bordered: _bordered,
|
|
51
|
+
onPressEnter,
|
|
52
|
+
addonBefore,
|
|
53
|
+
addonAfter,
|
|
54
|
+
...inputProps
|
|
42
55
|
}, forwardedRef) => {
|
|
43
56
|
const id = useMemo(() => v4(), []);
|
|
44
|
-
const charCount = getCharCount(
|
|
57
|
+
const charCount = getCharCount(inputProps.value, counterLimit);
|
|
45
58
|
const expandableTextAreaRef = useRef(null);
|
|
46
59
|
const [expanded, setExpanded] = useState(false);
|
|
47
60
|
const [overflown, setOverflown] = useState(false);
|
|
48
61
|
const scrollLeftRef = useRef(0);
|
|
49
|
-
const hasErrorMessage = Boolean(errorText);
|
|
50
62
|
const paddingDiff = useRef();
|
|
63
|
+
const hasErrorMessage = Boolean(errorText);
|
|
51
64
|
const inputRef = useRef(null);
|
|
52
|
-
const autosizeRef = useRef(null);
|
|
53
65
|
const externalRef = useRef(null);
|
|
54
66
|
const elementRef = useRef(null);
|
|
55
|
-
const
|
|
67
|
+
const beforeAddon = prefixel ?? addonBefore;
|
|
68
|
+
const afterAddon = suffixel ?? addonAfter;
|
|
69
|
+
const {
|
|
70
|
+
value,
|
|
71
|
+
placeholder,
|
|
72
|
+
disabled,
|
|
73
|
+
readOnly
|
|
74
|
+
} = inputProps;
|
|
75
|
+
const hasValue = value !== void 0 && value !== null && `${value}` !== "";
|
|
56
76
|
const iconCount = useMemo(() => {
|
|
57
77
|
return Number(!!icon1) + Number(!!icon2) + Number(!!expandable);
|
|
58
78
|
}, [icon1, icon2, expandable]);
|
|
59
79
|
const handleIconsClick = useElementFocus(inputRef);
|
|
60
|
-
const
|
|
61
|
-
inputAddonHeight
|
|
62
|
-
} = useInputAddonHeight(inputRef);
|
|
80
|
+
const stretchToFit = autoResize && autoResize !== true && Boolean(autoResize.stretchToFit);
|
|
63
81
|
useEffect(() => {
|
|
64
|
-
|
|
65
|
-
externalRef.current = inputRef.current.input;
|
|
66
|
-
}
|
|
82
|
+
externalRef.current = inputRef.current;
|
|
67
83
|
handleInputRef && handleInputRef(externalRef);
|
|
68
84
|
}, [handleInputRef]);
|
|
69
85
|
useEffect(() => {
|
|
70
|
-
if (
|
|
71
|
-
externalRef.current = autosizeRef.current.inputRef.current;
|
|
72
|
-
handleInputRef && handleInputRef(externalRef);
|
|
73
|
-
}
|
|
74
|
-
}, [handleInputRef]);
|
|
75
|
-
useEffect(() => {
|
|
76
|
-
if (inputRef.current?.input) {
|
|
86
|
+
if (inputRef.current) {
|
|
77
87
|
const {
|
|
78
88
|
paddingLeft,
|
|
79
89
|
paddingRight
|
|
80
|
-
} = getComputedStyle(inputRef.current
|
|
90
|
+
} = getComputedStyle(inputRef.current);
|
|
81
91
|
paddingDiff.current = parseFloat(paddingLeft) + parseFloat(paddingRight);
|
|
82
92
|
}
|
|
83
|
-
});
|
|
93
|
+
}, [size, iconCount, autoResize, expandable]);
|
|
84
94
|
useEffect(() => {
|
|
85
|
-
if (!autoResize && expandable && inputRef.current
|
|
86
|
-
setOverflown(inputRef.current.
|
|
95
|
+
if (!autoResize && expandable && inputRef.current) {
|
|
96
|
+
setOverflown(inputRef.current.scrollWidth > inputRef.current.clientWidth);
|
|
87
97
|
}
|
|
88
98
|
}, [autoResize, expandable, expanded]);
|
|
99
|
+
const handleAutosize = useCallback((newWidth) => {
|
|
100
|
+
if (autoResize && expandable && inputRef.current) {
|
|
101
|
+
const minWidth = parseInt(window.getComputedStyle(inputRef.current).minWidth, 10);
|
|
102
|
+
setOverflown(newWidth > minWidth);
|
|
103
|
+
}
|
|
104
|
+
}, [autoResize, expandable]);
|
|
105
|
+
const {
|
|
106
|
+
sizerRef,
|
|
107
|
+
containerRef
|
|
108
|
+
} = useAutosizeWidth({
|
|
109
|
+
value: typeof value === "string" || typeof value === "number" ? value : "",
|
|
110
|
+
placeholder,
|
|
111
|
+
extraWidth: autoResizeProps?.extraWidth ?? DEFAULT_EXTRA_WIDTH,
|
|
112
|
+
placeholderIsMinWidth: autoResizeProps?.placeholderIsMinWidth,
|
|
113
|
+
inputRef,
|
|
114
|
+
onAutosize: handleAutosize
|
|
115
|
+
});
|
|
116
|
+
const mergedInputRef = useMergeRefs([inputRef, containerRef]);
|
|
117
|
+
const handleStretchBefore = useCallback(() => {
|
|
118
|
+
if (inputRef.current) {
|
|
119
|
+
scrollLeftRef.current = inputRef.current.scrollLeft || 0;
|
|
120
|
+
inputRef.current.style.removeProperty("max-width");
|
|
121
|
+
}
|
|
122
|
+
}, []);
|
|
123
|
+
const handleStretchAfter = useCallback(() => {
|
|
124
|
+
if (inputRef.current) {
|
|
125
|
+
inputRef.current.scrollLeft = scrollLeftRef.current;
|
|
126
|
+
}
|
|
127
|
+
}, []);
|
|
128
|
+
const getMaxWidth = useCallback((availableWidth) => availableWidth - (paddingDiff.current ?? 0), []);
|
|
129
|
+
const {
|
|
130
|
+
outerRef
|
|
131
|
+
} = useStretchToFit({
|
|
132
|
+
enabled: !!stretchToFit,
|
|
133
|
+
targetRef: inputRef,
|
|
134
|
+
getMaxWidth,
|
|
135
|
+
onBeforeResize: handleStretchBefore,
|
|
136
|
+
onAfterResize: handleStretchAfter
|
|
137
|
+
});
|
|
138
|
+
const mergedOuterRef = useMergeRefs([elementRef, outerRef, forwardedRef]);
|
|
139
|
+
const handleChange = useCallback((event) => {
|
|
140
|
+
const {
|
|
141
|
+
value: newValue,
|
|
142
|
+
scrollWidth,
|
|
143
|
+
clientWidth
|
|
144
|
+
} = event.currentTarget;
|
|
145
|
+
const isNowOverflown = scrollWidth > clientWidth;
|
|
146
|
+
if (!autoResize && expandable && isNowOverflown !== overflown) {
|
|
147
|
+
setOverflown(isNowOverflown);
|
|
148
|
+
}
|
|
149
|
+
if (counterLimit && newValue.length > counterLimit) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
inputProps.onChange && inputProps.onChange(event);
|
|
153
|
+
}, [inputProps, autoResize, counterLimit, expandable, overflown]);
|
|
154
|
+
const handleKeyDown = useCallback((event) => {
|
|
155
|
+
inputProps.onKeyDown && inputProps.onKeyDown(event);
|
|
156
|
+
if (event.key === "Enter") {
|
|
157
|
+
onPressEnter && onPressEnter(event);
|
|
158
|
+
}
|
|
159
|
+
}, [inputProps, onPressEnter]);
|
|
160
|
+
const handleClear = useCallback(() => {
|
|
161
|
+
const element = inputRef.current;
|
|
162
|
+
if (!element) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const setter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value")?.set;
|
|
166
|
+
setter?.call(element, "");
|
|
167
|
+
element.dispatchEvent(new Event("input", {
|
|
168
|
+
bubbles: true
|
|
169
|
+
}));
|
|
170
|
+
element.focus();
|
|
171
|
+
}, []);
|
|
89
172
|
const handleTextareaChange = (event) => {
|
|
90
173
|
const {
|
|
91
174
|
value: newValue
|
|
@@ -93,19 +176,19 @@ const Input = forwardRef(({
|
|
|
93
176
|
if (counterLimit && newValue.length > counterLimit) {
|
|
94
177
|
return;
|
|
95
178
|
}
|
|
96
|
-
|
|
179
|
+
inputProps.onChange && inputProps.onChange(event);
|
|
97
180
|
};
|
|
98
181
|
const handleExpandableTextareaBlur = (event) => {
|
|
99
182
|
setExpanded(false);
|
|
100
|
-
if (inputRef.current
|
|
101
|
-
inputRef.current.
|
|
102
|
-
inputRef.current.
|
|
183
|
+
if (inputRef.current) {
|
|
184
|
+
inputRef.current.value = event.target.value;
|
|
185
|
+
inputRef.current.focus();
|
|
103
186
|
}
|
|
104
187
|
};
|
|
105
188
|
const handleExpandIconClick = (event) => {
|
|
106
189
|
event.stopPropagation();
|
|
107
190
|
if (inputRef.current && expandableTextAreaRef.current) {
|
|
108
|
-
expandableTextAreaRef.current.value = inputRef.current.
|
|
191
|
+
expandableTextAreaRef.current.value = inputRef.current.value ?? "";
|
|
109
192
|
expandableTextAreaRef.current.focus();
|
|
110
193
|
}
|
|
111
194
|
setExpanded(true);
|
|
@@ -114,60 +197,66 @@ const Input = forwardRef(({
|
|
|
114
197
|
if (expanded) {
|
|
115
198
|
expandableTextAreaRef.current && expandableTextAreaRef.current.focus();
|
|
116
199
|
}
|
|
117
|
-
}, [
|
|
118
|
-
const handleChange = useCallback((event) => {
|
|
119
|
-
const {
|
|
120
|
-
value: newValue,
|
|
121
|
-
scrollWidth,
|
|
122
|
-
clientWidth
|
|
123
|
-
} = event.currentTarget;
|
|
124
|
-
const isNowOverflown = scrollWidth > clientWidth;
|
|
125
|
-
if (!autoResize && expandable && isNowOverflown !== overflown) {
|
|
126
|
-
setOverflown(isNowOverflown);
|
|
127
|
-
}
|
|
128
|
-
if (counterLimit && newValue.length > counterLimit) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
antdInputProps.onChange && antdInputProps.onChange(event);
|
|
132
|
-
}, [antdInputProps, autoResize, counterLimit, expandable, overflown]);
|
|
133
|
-
const stretchToFit = autoResize && autoResize !== true && Boolean(autoResize.stretchToFit);
|
|
134
|
-
const preAutosize = useCallback(() => {
|
|
135
|
-
scrollLeftRef.current = inputRef.current?.input?.scrollLeft || 0;
|
|
136
|
-
inputRef.current?.input && inputRef.current.input.style.removeProperty("max-width");
|
|
137
|
-
}, []);
|
|
138
|
-
const onAutosize = useCallback((newWidth) => {
|
|
139
|
-
const parentRect = elementRef.current && elementRef.current.getBoundingClientRect();
|
|
140
|
-
if (stretchToFit && inputRef.current?.input && parentRect?.width && paddingDiff.current) {
|
|
141
|
-
inputRef.current.input.style.maxWidth = `${parentRect?.width - paddingDiff.current}px`;
|
|
142
|
-
inputRef.current.input.scrollLeft = scrollLeftRef.current;
|
|
143
|
-
}
|
|
144
|
-
if (newWidth !== void 0 && autoResize && inputRef.current?.input && expandable) {
|
|
145
|
-
const style = window.getComputedStyle(inputRef.current.input);
|
|
146
|
-
const minWidth = parseInt(style.minWidth, 10);
|
|
147
|
-
setOverflown(newWidth > minWidth);
|
|
148
|
-
}
|
|
149
|
-
}, [autoResize, expandable, stretchToFit]);
|
|
150
|
-
const handleWrapperResize = useCallback(() => {
|
|
151
|
-
preAutosize();
|
|
152
|
-
onAutosize();
|
|
153
|
-
}, [onAutosize, preAutosize]);
|
|
154
|
-
useResizeObserver(elementRef, handleWrapperResize);
|
|
200
|
+
}, [expanded]);
|
|
155
201
|
const rightSide = useCounterLimit({
|
|
156
202
|
renderCustomCounter,
|
|
157
203
|
counterLimit,
|
|
158
204
|
charCount
|
|
159
205
|
});
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
206
|
+
const showClear = Boolean(allowClear) && hasValue && !disabled && !readOnly;
|
|
207
|
+
const clearOffset = CLEAR_BASE_OFFSET + (iconCount > 0 ? iconCount * ICON_SLOT_WIDTH : 0);
|
|
208
|
+
const inputControl = /* @__PURE__ */ jsx(NativeInput, { autoResize, $size: size, $hasPrefixel: !!beforeAddon, $hasSuffixel: !!afterAddon, $hasInnerPrefix: !!innerPrefix, "data-testid": "input-autosize-input", ...inputProps, error: hasErrorMessage || error, className: hasErrorMessage || error ? "error" : void 0, onChange: handleChange, onKeyDown: handleKeyDown, value, id, ref: mergedInputRef });
|
|
209
|
+
const inputWithAddons = beforeAddon || afterAddon ? /* @__PURE__ */ jsxs(InputGroupRow, { children: [
|
|
210
|
+
beforeAddon && /* @__PURE__ */ jsx(Addon, { className: "ds-input-prefix", $position: "before", $size: size, children: beforeAddon }),
|
|
211
|
+
inputControl,
|
|
212
|
+
afterAddon && /* @__PURE__ */ jsx(Addon, { className: "ds-input-suffix", $position: "after", $size: size, children: afterAddon })
|
|
213
|
+
] }) : inputControl;
|
|
214
|
+
const autoSizedComponent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
215
|
+
innerPrefix && /* @__PURE__ */ jsx(InnerAffix, { children: innerPrefix }),
|
|
216
|
+
inputWithAddons,
|
|
217
|
+
autoResize && /* @__PURE__ */ jsx("span", { ref: sizerRef, style: SIZER_STYLE, "aria-hidden": true }),
|
|
218
|
+
showClear && /* @__PURE__ */ jsx(ClearButton, { type: "button", "aria-label": "clear", $offset: clearOffset, onClick: handleClear, children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(CloseS, {}) }) })
|
|
219
|
+
] });
|
|
220
|
+
return /* @__PURE__ */ jsx(OuterWrapper, { ref: mergedOuterRef, autoResize, className, resetMargin, iconCount, children: /* @__PURE__ */ jsx(FormField, { label, rightSide, id, tooltip, tooltipConfig, description, errorText, children: /* @__PURE__ */ jsxs(InputWrapper, { iconCount, children: [
|
|
221
|
+
/* @__PURE__ */ jsx(ElementIcons, { handleIconsClick, disabled, icon1, icon2, icon1Tooltip, icon2Tooltip, className, type: "input", expandable, overflown, handleExpandIconClick, expandableTooltip }),
|
|
222
|
+
expandable ? /* @__PURE__ */ jsx(ExpandableWrapper, { onChange: handleTextareaChange, onBlur: handleExpandableTextareaBlur, ref: expandableTextAreaRef, value, expanded, children: autoSizedComponent }) : autoSizedComponent
|
|
164
223
|
] }) }) });
|
|
165
224
|
});
|
|
166
|
-
const RawInput = (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
225
|
+
const RawInput = ({
|
|
226
|
+
error,
|
|
227
|
+
size,
|
|
228
|
+
className,
|
|
229
|
+
// FormField / DS-only props that are not valid on a bare native input:
|
|
230
|
+
label,
|
|
231
|
+
description,
|
|
232
|
+
errorText,
|
|
233
|
+
tooltip,
|
|
234
|
+
tooltipConfig,
|
|
235
|
+
counterLimit,
|
|
236
|
+
renderCustomCounter,
|
|
237
|
+
icon1,
|
|
238
|
+
icon1Tooltip,
|
|
239
|
+
icon2,
|
|
240
|
+
icon2Tooltip,
|
|
241
|
+
resetMargin,
|
|
242
|
+
handleInputRef,
|
|
243
|
+
prefixel,
|
|
244
|
+
suffixel,
|
|
245
|
+
autoResize,
|
|
246
|
+
autoResizeProps,
|
|
247
|
+
expandable,
|
|
248
|
+
expandableTooltip,
|
|
249
|
+
// antd affix/group props handled by `Input`, not the raw input:
|
|
250
|
+
allowClear,
|
|
251
|
+
prefix,
|
|
252
|
+
suffix,
|
|
253
|
+
bordered,
|
|
254
|
+
onPressEnter,
|
|
255
|
+
addonBefore,
|
|
256
|
+
addonAfter,
|
|
257
|
+
...rest
|
|
258
|
+
}) => {
|
|
259
|
+
return /* @__PURE__ */ jsx(NativeInput, { ...rest, $size: size, error, className: [className, error && "error"].filter(Boolean).join(" ") || void 0 });
|
|
171
260
|
};
|
|
172
261
|
export {
|
|
173
262
|
Input,
|
package/dist/Input.styles.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { InputProps, InputRef } from 'antd';
|
|
2
|
-
import { SizeType } from 'antd/es/config-provider/SizeContext';
|
|
3
|
-
import { TextAreaProps, TextAreaRef } from 'antd/lib/input/TextArea';
|
|
4
1
|
import { default as React } from 'react';
|
|
5
2
|
import { FlattenSimpleInterpolation } from 'styled-components';
|
|
6
|
-
import { AutoResizeProp } from './Input.types';
|
|
3
|
+
import { AutoResizeProp, InputSize } from './Input.types';
|
|
7
4
|
type AutoSizeConfProps = {
|
|
8
5
|
autoResize?: AutoResizeProp;
|
|
9
6
|
boxSizing?: 'content-box' | 'border-box';
|
|
10
7
|
iconCount?: number;
|
|
11
8
|
};
|
|
12
|
-
export declare function autoresizeConfObjToCss({ autoResize, iconCount, boxSizing, }: AutoSizeConfProps):
|
|
9
|
+
export declare function autoresizeConfObjToCss({ autoResize, iconCount, boxSizing, }: AutoSizeConfProps): "" | FlattenSimpleInterpolation;
|
|
13
10
|
export declare const Wrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
14
11
|
export declare const InputWrapper: import('styled-components').StyledComponent<"div", any, {
|
|
15
12
|
iconCount?: number;
|
|
@@ -24,18 +21,42 @@ export declare const IconsFlexContainer: import('styled-components').StyledCompo
|
|
|
24
21
|
type: string;
|
|
25
22
|
}, never>;
|
|
26
23
|
export declare const IconWrapper: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
27
|
-
|
|
24
|
+
/**
|
|
25
|
+
* DS-native text input — replaces the antd `Input`. State (focus / error /
|
|
26
|
+
* disabled / readOnly) is expressed with native pseudo-classes and theme tokens;
|
|
27
|
+
* no antd component, no `.ant-*` styling selectors.
|
|
28
|
+
*/
|
|
29
|
+
export declare const NativeInput: import('styled-components').StyledComponent<React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
|
|
28
30
|
error?: boolean;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
autoResize?: AutoResizeProp;
|
|
32
|
+
$size?: InputSize;
|
|
33
|
+
$hasPrefixel?: boolean;
|
|
34
|
+
$hasSuffixel?: boolean;
|
|
35
|
+
$hasInnerPrefix?: boolean;
|
|
36
|
+
} & React.RefAttributes<HTMLInputElement>>, any, Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
|
|
31
37
|
error?: boolean;
|
|
32
|
-
readOnly?: boolean;
|
|
33
38
|
autoResize?: AutoResizeProp;
|
|
39
|
+
$size?: InputSize;
|
|
40
|
+
$hasPrefixel?: boolean;
|
|
41
|
+
$hasSuffixel?: boolean;
|
|
42
|
+
$hasInnerPrefix?: boolean;
|
|
43
|
+
} & {
|
|
44
|
+
readOnly?: boolean;
|
|
34
45
|
disabled?: boolean;
|
|
35
46
|
}, never>;
|
|
36
|
-
export declare const
|
|
47
|
+
export declare const InputGroupRow: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
48
|
+
export declare const Addon: import('styled-components').StyledComponent<"div", any, {
|
|
49
|
+
$position: "before" | "after";
|
|
50
|
+
$size?: InputSize;
|
|
51
|
+
}, never>;
|
|
52
|
+
export declare const ClearButton: import('styled-components').StyledComponent<"button", any, {
|
|
53
|
+
$offset: number;
|
|
54
|
+
}, never>;
|
|
55
|
+
/** Inline content rendered inside the input on the left (the `innerPrefix` prop). */
|
|
56
|
+
export declare const InnerAffix: import('styled-components').StyledComponent<"div", any, {}, never>;
|
|
57
|
+
export declare const RawTextArea: import('styled-components').StyledComponent<React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & {
|
|
37
58
|
error?: boolean;
|
|
38
|
-
} & React.RefAttributes<
|
|
59
|
+
} & React.RefAttributes<HTMLTextAreaElement>>, any, {
|
|
39
60
|
error?: boolean;
|
|
40
61
|
}, never>;
|
|
41
62
|
export declare const ExpandableWrapper: import('styled-components').StyledComponent<"div", any, {
|
package/dist/Input.styles.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { Input } from "antd";
|
|
3
2
|
import { forwardRef } from "react";
|
|
4
3
|
import styled, { css } from "styled-components";
|
|
5
4
|
import { TextareaWrapper } from "./Textarea/Textarea.styles.js";
|
|
6
|
-
const {
|
|
7
|
-
TextArea
|
|
8
|
-
} = Input;
|
|
9
5
|
const errorInputStyle = (props) => `
|
|
10
|
-
|
|
6
|
+
&&& {
|
|
11
7
|
border-color: ${props.theme.palette["red-600"]};
|
|
12
8
|
box-shadow: inset 0 0 0 1px ${props.theme.palette["red-600"]};
|
|
13
9
|
background: ${props.theme.palette["red-050"]};
|
|
@@ -41,13 +37,13 @@ const Wrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
|
41
37
|
const InputWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
42
38
|
displayName: "Inputstyles__InputWrapper",
|
|
43
39
|
componentId: "sc-dc57an-1"
|
|
44
|
-
})(["position:relative;&&
|
|
40
|
+
})(["position:relative;&& input{padding-right:", ";&::placeholder{line-height:1.29;}}"], (props) => {
|
|
45
41
|
return `${getIconsWidth(props.iconCount || 0) + INPUT_PADDING}px`;
|
|
46
42
|
});
|
|
47
43
|
const OuterWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
48
44
|
displayName: "Inputstyles__OuterWrapper",
|
|
49
45
|
componentId: "sc-dc57an-2"
|
|
50
|
-
})(["margin:", ";&.active{&&{input{box-shadow:inset 0 0 0 1px ", ";border-color:", ";background-color:", ";}}}input{
|
|
46
|
+
})(["margin:", ";&.active{&&{input{box-shadow:inset 0 0 0 1px ", ";border-color:", ";background-color:", ";}}}input{", "}", ""], (props) => props.resetMargin ? "0" : "0 0 16px 0", (props) => props.theme.palette["blue-600"], (props) => props.theme.palette["blue-600"], (props) => props.theme.palette["blue-050"], (props) => autoresizeConfObjToCss(props), (props) => props.autoResize && `
|
|
51
47
|
${InputWrapper} {
|
|
52
48
|
display: inline-block;
|
|
53
49
|
}`);
|
|
@@ -68,35 +64,61 @@ const IconWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
|
68
64
|
displayName: "Inputstyles__IconWrapper",
|
|
69
65
|
componentId: "sc-dc57an-5"
|
|
70
66
|
})([".icon:hover{svg{fill:", ";cursor:pointer;}}"], (props) => props.theme.palette["blue-600"]);
|
|
71
|
-
const
|
|
67
|
+
const NativeInput = /* @__PURE__ */ styled(forwardRef(({
|
|
72
68
|
error,
|
|
69
|
+
autoResize,
|
|
70
|
+
$size,
|
|
71
|
+
$hasPrefixel,
|
|
72
|
+
$hasSuffixel,
|
|
73
|
+
$hasInnerPrefix,
|
|
73
74
|
...props
|
|
74
|
-
}, ref) => /* @__PURE__ */ jsx(
|
|
75
|
-
displayName: "
|
|
75
|
+
}, ref) => /* @__PURE__ */ jsx("input", { autoComplete: "off", ...props, ref }))).withConfig({
|
|
76
|
+
displayName: "Inputstyles__NativeInput",
|
|
76
77
|
componentId: "sc-dc57an-6"
|
|
77
|
-
})(["", "
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
})(["box-sizing:", ";width:100%;", " margin:0;padding:7px ", "px;", " color:", ";background-color:", ";border:", "px solid ", ";border-radius:3px;font-family:inherit;font-size:13px;outline:0;grid-area:1 / 1;transition:all 0.3s,width 0ms,min-width 0ms,max-width 0ms;", " ", " &::placeholder{color:", ";line-height:1.29;}&:hover:not(:disabled){border-color:", ";}&:focus{box-shadow:inset 0 0 0 1px ", ";border-color:", ";background-color:", ";}&:disabled{cursor:not-allowed;background-color:", ";}", ";", ";", ""], (props) => props.autoResize ? "content-box" : "border-box", (props) => props.autoResize ? `height: ${props.$size === "large" ? "32" : "16"}px;` : `height: ${props.$size === "large" ? "48" : "32"}px;`, INPUT_PADDING, (props) => props.$hasInnerPrefix && "padding-left: 32px;", (props) => props.disabled ? props.theme.palette["grey-400"] : props.theme.palette["grey-700"], (props) => props.theme.palette.white, INPUT_BORDER, (props) => props.theme.palette["grey-300"], (props) => props.$hasPrefixel && "border-top-left-radius: 0; border-bottom-left-radius: 0;", (props) => props.$hasSuffixel && "border-top-right-radius: 0; border-bottom-right-radius: 0;", (props) => props.theme.palette["grey-500"], (props) => props.theme.palette["grey-400"], (props) => props.theme.palette["blue-600"], (props) => props.theme.palette["blue-600"], (props) => props.theme.palette["blue-050"], (props) => props.theme.palette["grey-050"], (props) => props.error ? errorInputStyle(props) : "", (props) => autoresizeConfObjToCss({
|
|
79
|
+
autoResize: props.autoResize
|
|
80
|
+
}), (props) => props.readOnly && `
|
|
81
|
+
&&& {
|
|
82
|
+
&:hover {
|
|
83
|
+
border-color: ${props.theme.palette["grey-300"]};
|
|
84
|
+
}
|
|
85
|
+
&:focus {
|
|
86
|
+
border-color: ${props.theme.palette["grey-300"]};
|
|
87
|
+
box-shadow: none;
|
|
88
|
+
background: ${props.theme.palette.white};
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
`);
|
|
92
|
+
const InputGroupRow = /* @__PURE__ */ styled.div.withConfig({
|
|
93
|
+
displayName: "Inputstyles__InputGroupRow",
|
|
94
|
+
componentId: "sc-dc57an-7"
|
|
95
|
+
})(["display:flex;align-items:stretch;width:100%;"]);
|
|
96
|
+
const Addon = /* @__PURE__ */ styled.div.withConfig({
|
|
97
|
+
displayName: "Inputstyles__Addon",
|
|
98
|
+
componentId: "sc-dc57an-8"
|
|
99
|
+
})(["box-sizing:border-box;height:", "px;display:flex;align-items:center;flex-shrink:0;overflow:hidden;padding:0;white-space:nowrap;color:", ";background-color:", ";border:", "px solid ", ";", ""], (props) => props.$size === "large" ? "48" : "32", (props) => props.theme.palette["grey-700"], (props) => props.theme.palette["grey-050"], INPUT_BORDER, (props) => props.theme.palette["grey-300"], (props) => props.$position === "before" ? "border-right: 0; border-radius: 3px 0 0 3px;" : "border-left: 0; border-radius: 0 3px 3px 0;");
|
|
100
|
+
const ClearButton = /* @__PURE__ */ styled.button.withConfig({
|
|
101
|
+
displayName: "Inputstyles__ClearButton",
|
|
102
|
+
componentId: "sc-dc57an-9"
|
|
103
|
+
})(["position:absolute;top:50%;right:", "px;transform:translateY(-50%);z-index:2;display:flex;align-items:center;justify-content:center;padding:0;border:0;background:transparent;cursor:pointer;color:", ";&:hover{color:", ";}"], (props) => props.$offset, (props) => props.theme.palette["grey-500"], (props) => props.theme.palette["grey-700"]);
|
|
104
|
+
const InnerAffix = /* @__PURE__ */ styled.div.withConfig({
|
|
105
|
+
displayName: "Inputstyles__InnerAffix",
|
|
106
|
+
componentId: "sc-dc57an-10"
|
|
107
|
+
})(["position:absolute;top:50%;left:4px;transform:translateY(-50%);z-index:2;display:flex;align-items:center;"]);
|
|
108
|
+
const RawTextArea = /* @__PURE__ */ styled(forwardRef(({
|
|
91
109
|
error,
|
|
92
110
|
...props
|
|
93
|
-
}, ref) => /* @__PURE__ */ jsx(
|
|
94
|
-
displayName: "
|
|
95
|
-
componentId: "sc-dc57an-
|
|
96
|
-
})(["", "
|
|
111
|
+
}, ref) => /* @__PURE__ */ jsx("textarea", { autoComplete: "off", ...props, ref }))).withConfig({
|
|
112
|
+
displayName: "Inputstyles__RawTextArea",
|
|
113
|
+
componentId: "sc-dc57an-11"
|
|
114
|
+
})(["&&{box-sizing:border-box;width:100%;color:", ";font-family:inherit;font-size:13px;padding:8px 12px;", "}"], (props) => props.theme.palette["grey-700"], (props) => props.error ? `
|
|
115
|
+
box-shadow: inset 0 0 0 1px ${props.theme.palette["red-600"]};
|
|
116
|
+
background: ${props.theme.palette["red-050"]};
|
|
117
|
+
border-color: ${props.theme.palette["red-600"]};
|
|
118
|
+
` : "");
|
|
97
119
|
const ExpandableWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
98
120
|
displayName: "Inputstyles__ExpandableWrapper",
|
|
99
|
-
componentId: "sc-dc57an-
|
|
121
|
+
componentId: "sc-dc57an-12"
|
|
100
122
|
})(["position:relative;overflow:visible;", "{position:absolute;top:0;left:0;right:0;z-index:999;resize:none;max-height:124px;min-height:65px;min-width:282px;", "}"], TextareaWrapper, (props) => {
|
|
101
123
|
if (props.expanded) {
|
|
102
124
|
return css(["pointer-events:initial;display:block;"]);
|
|
@@ -105,36 +127,36 @@ const ExpandableWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
|
105
127
|
});
|
|
106
128
|
const ContentBelow = /* @__PURE__ */ styled.div.withConfig({
|
|
107
129
|
displayName: "Inputstyles__ContentBelow",
|
|
108
|
-
componentId: "sc-dc57an-
|
|
130
|
+
componentId: "sc-dc57an-13"
|
|
109
131
|
})(["margin-top:8px;"]);
|
|
110
132
|
const ErrorText = /* @__PURE__ */ styled.div.withConfig({
|
|
111
133
|
displayName: "Inputstyles__ErrorText",
|
|
112
|
-
componentId: "sc-dc57an-
|
|
134
|
+
componentId: "sc-dc57an-14"
|
|
113
135
|
})(["color:", ";margin-bottom:4px;"], (props) => props.theme.palette["red-600"]);
|
|
114
136
|
const Label = /* @__PURE__ */ styled.label.withConfig({
|
|
115
137
|
displayName: "Inputstyles__Label",
|
|
116
|
-
componentId: "sc-dc57an-
|
|
138
|
+
componentId: "sc-dc57an-15"
|
|
117
139
|
})(["color:", ";font-weight:500;display:block;"], (props) => props.theme.palette["grey-800"]);
|
|
118
140
|
const Counter = /* @__PURE__ */ styled.div.withConfig({
|
|
119
141
|
displayName: "Inputstyles__Counter",
|
|
120
|
-
componentId: "sc-dc57an-
|
|
142
|
+
componentId: "sc-dc57an-16"
|
|
121
143
|
})(["font-weight:500;flex:1 0 auto;text-align:end;color:", ";"], (props) => props.theme.palette["grey-500"]);
|
|
122
144
|
const Description = /* @__PURE__ */ styled.div.withConfig({
|
|
123
145
|
displayName: "Inputstyles__Description",
|
|
124
|
-
componentId: "sc-dc57an-
|
|
146
|
+
componentId: "sc-dc57an-17"
|
|
125
147
|
})(["color:", ";"], (props) => props.theme.palette["grey-600"]);
|
|
126
148
|
const ContentAbove = /* @__PURE__ */ styled.div.withConfig({
|
|
127
149
|
displayName: "Inputstyles__ContentAbove",
|
|
128
|
-
componentId: "sc-dc57an-
|
|
150
|
+
componentId: "sc-dc57an-18"
|
|
129
151
|
})(["display:flex;justify-content:space-between;margin-bottom:8px;min-height:18px;"]);
|
|
130
152
|
const AddonWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
131
153
|
displayName: "Inputstyles__AddonWrapper",
|
|
132
|
-
componentId: "sc-dc57an-
|
|
154
|
+
componentId: "sc-dc57an-19"
|
|
133
155
|
})(["background:", ";display:flex;align-items:center;height:", ";"], (props) => props.theme.palette["grey-050"], (props) => props.height ? `${props.height}px` : "30px");
|
|
134
156
|
export {
|
|
157
|
+
Addon,
|
|
135
158
|
AddonWrapper,
|
|
136
|
-
|
|
137
|
-
AntdTextArea,
|
|
159
|
+
ClearButton,
|
|
138
160
|
ContentAbove,
|
|
139
161
|
ContentBelow,
|
|
140
162
|
Counter,
|
|
@@ -144,9 +166,13 @@ export {
|
|
|
144
166
|
IconWrapper,
|
|
145
167
|
IconsFlexContainer,
|
|
146
168
|
IconsWrapper,
|
|
169
|
+
InnerAffix,
|
|
170
|
+
InputGroupRow,
|
|
147
171
|
InputWrapper,
|
|
148
172
|
Label,
|
|
173
|
+
NativeInput,
|
|
149
174
|
OuterWrapper,
|
|
175
|
+
RawTextArea,
|
|
150
176
|
Wrapper,
|
|
151
177
|
autoresizeConfObjToCss
|
|
152
178
|
};
|
package/dist/Input.types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TextAreaProps as AntdTextAreaProps } from 'antd/lib/input';
|
|
3
|
-
import { ForwardRefExoticComponent, MutableRefObject, ReactElement, ReactNode, RefAttributes } from 'react';
|
|
1
|
+
import { ForwardRefExoticComponent, InputHTMLAttributes, KeyboardEventHandler, MutableRefObject, ReactElement, ReactNode, RefAttributes } from 'react';
|
|
4
2
|
import { StyledComponent } from 'styled-components';
|
|
5
3
|
import { FormFieldCommonProps } from '@synerise/ds-form-field';
|
|
6
4
|
import { AutosizeInputProps } from './AutosizeInput/AutosizeInput.types';
|
|
@@ -9,10 +7,24 @@ export type AutoResizeProp = boolean | {
|
|
|
9
7
|
maxWidth?: string;
|
|
10
8
|
stretchToFit?: boolean;
|
|
11
9
|
};
|
|
10
|
+
export type InputSize = 'small' | 'middle' | 'large';
|
|
12
11
|
/**
|
|
13
|
-
*
|
|
12
|
+
* Native `<input>` props, preserving the subset of the antd `Input` surface that
|
|
13
|
+
* the design system actually forwards. `size`/`prefix` are redefined (the native
|
|
14
|
+
* HTML attrs have different meanings).
|
|
14
15
|
*/
|
|
15
|
-
export type
|
|
16
|
+
export type NativeInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, 'size' | 'prefix'> & {
|
|
17
|
+
size?: InputSize;
|
|
18
|
+
allowClear?: boolean;
|
|
19
|
+
bordered?: boolean;
|
|
20
|
+
/** Inline node rendered inside the input on the left, before the value. */
|
|
21
|
+
innerPrefix?: ReactNode;
|
|
22
|
+
prefix?: ReactNode;
|
|
23
|
+
suffix?: ReactNode;
|
|
24
|
+
onPressEnter?: KeyboardEventHandler<HTMLInputElement>;
|
|
25
|
+
addonBefore?: ReactNode;
|
|
26
|
+
addonAfter?: ReactNode;
|
|
27
|
+
};
|
|
16
28
|
export type BaseProps<RefElementType extends HTMLTextAreaElement | HTMLInputElement = HTMLInputElement> = {
|
|
17
29
|
error?: boolean;
|
|
18
30
|
className?: string;
|
|
@@ -31,9 +43,13 @@ export type BaseProps<RefElementType extends HTMLTextAreaElement | HTMLInputElem
|
|
|
31
43
|
expandable?: boolean;
|
|
32
44
|
expandableTooltip?: ReactNode;
|
|
33
45
|
} & FormFieldCommonProps;
|
|
46
|
+
export type InputProps = BaseProps & NativeInputProps;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated use `InputProps`, `TextareaProps` instead
|
|
49
|
+
*/
|
|
50
|
+
export type Props = BaseProps<HTMLInputElement | HTMLTextAreaElement>;
|
|
34
51
|
/**
|
|
35
52
|
* @deprecated use `InputProps`, `TextareaProps` instead
|
|
36
53
|
*/
|
|
37
|
-
export type EnhancedProps =
|
|
38
|
-
export type InputProps = BaseProps & AntdInputProps;
|
|
54
|
+
export type EnhancedProps = InputProps;
|
|
39
55
|
export type StyledInput<CustomProps extends object = object> = StyledComponent<ForwardRefExoticComponent<InputProps & RefAttributes<HTMLDivElement>>, object, CustomProps, never>;
|
package/dist/InputGroup.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { Props } from './InputGroup.types';
|
|
3
|
-
declare const InputGroup: ({ children, label, errors, description, resetMargin, tooltip, tooltipConfig, ...
|
|
3
|
+
declare const InputGroup: ({ children, label, errorText, errors, description, resetMargin, tooltip, tooltipConfig, compact, growItem, className, style, size: _size, ...rest }: Props) => React.JSX.Element;
|
|
4
4
|
export default InputGroup;
|