@synerise/ds-input 1.7.11 → 1.7.13

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/CLAUDE.md +309 -0
  3. package/dist/AutosizeInput/AutosizeInput.d.ts +6 -7
  4. package/dist/AutosizeInput/AutosizeInput.js +39 -116
  5. package/dist/AutosizeInput/AutosizeInput.types.d.ts +5 -18
  6. package/dist/AutosizeInput/useAutosizeWidth.d.ts +18 -0
  7. package/dist/AutosizeInput/useAutosizeWidth.js +145 -0
  8. package/dist/AutosizeInput/useAutosizeWidth.types.d.ts +29 -0
  9. package/dist/AutosizeInput/useAutosizeWidth.types.js +1 -0
  10. package/dist/AutosizeInput/useStretchToFit.d.ts +26 -0
  11. package/dist/AutosizeInput/useStretchToFit.js +31 -0
  12. package/dist/Input.d.ts +13 -3
  13. package/dist/Input.js +170 -81
  14. package/dist/Input.styles.d.ts +32 -11
  15. package/dist/Input.styles.js +64 -38
  16. package/dist/Input.types.d.ts +23 -7
  17. package/dist/InputGroup.d.ts +1 -1
  18. package/dist/InputGroup.js +11 -4
  19. package/dist/InputGroup.styles.d.ts +1 -0
  20. package/dist/InputGroup.styles.js +9 -2
  21. package/dist/InputGroup.types.d.ts +22 -3
  22. package/dist/InputMultivalue/InputMultivalue.styles.js +1 -1
  23. package/dist/TextArea.d.ts +2 -2
  24. package/dist/TextArea.js +4 -5
  25. package/dist/Textarea/Textarea.d.ts +4 -3
  26. package/dist/Textarea/Textarea.js +33 -4
  27. package/dist/Textarea/Textarea.styles.js +2 -2
  28. package/dist/Textarea/Textarea.types.d.ts +13 -8
  29. package/dist/components/ExpandableWrapper.d.ts +1 -2
  30. package/dist/components/index.d.ts +0 -1
  31. package/dist/components/index.js +0 -2
  32. package/dist/hooks/useElementFocus.d.ts +3 -2
  33. package/dist/hooks/useInputAddonHeight.d.ts +1 -2
  34. package/dist/hooks/useInputAddonHeight.js +1 -1
  35. package/dist/hooks/useTextareaAutosize.d.ts +53 -0
  36. package/dist/hooks/useTextareaAutosize.js +82 -0
  37. package/dist/index.d.ts +6 -2
  38. package/dist/index.js +8 -3
  39. package/dist/utils/getCharCount.d.ts +3 -2
  40. package/package.json +9 -12
  41. package/dist/assets/style/index-tn0RQdqM.css +0 -0
  42. package/dist/components/AutosizeWrapper.d.ts +0 -17
  43. package/dist/components/AutosizeWrapper.js +0 -18
  44. package/dist/style/index.css +0 -1
@@ -0,0 +1,145 @@
1
+ import { useRef, useCallback, useLayoutEffect, useEffect } from "react";
2
+ import calculateInputWidth from "./utils/calculateInputWidth.js";
3
+ const SIZER_STYLE = {
4
+ position: "absolute",
5
+ top: 0,
6
+ left: 0,
7
+ height: 0,
8
+ visibility: "hidden",
9
+ overflow: "scroll",
10
+ whiteSpace: "pre",
11
+ font: "inherit",
12
+ letterSpacing: "inherit",
13
+ textTransform: "inherit",
14
+ fontFeatureSettings: "inherit",
15
+ fontVariantNumeric: "inherit"
16
+ };
17
+ const FONT_CSS_PROPS = [
18
+ "fontSize",
19
+ "fontFamily",
20
+ "fontWeight",
21
+ "fontFeatureSettings",
22
+ // Mirror tabular/proportional figures onto the sizer — otherwise an input using
23
+ // `font-variant-numeric: tabular-nums` renders tabular but is measured proportional,
24
+ // clipping the value or leaving a gap.
25
+ "fontVariantNumeric",
26
+ "fontStyle",
27
+ "letterSpacing",
28
+ "fontStretch",
29
+ "textTransform"
30
+ ];
31
+ const useAutosizeWidth = ({
32
+ value,
33
+ placeholder,
34
+ minWidth = 0,
35
+ extraWidth = 0,
36
+ placeholderIsMinWidth,
37
+ inputRef,
38
+ onAutosize
39
+ }) => {
40
+ const sizerRef = useRef(null);
41
+ const containerRef = useRef(null);
42
+ const copyFont = useCallback(() => {
43
+ const sizer = sizerRef.current;
44
+ const input = inputRef?.current;
45
+ if (!sizer || !input) {
46
+ return;
47
+ }
48
+ const computedStyle = window.getComputedStyle(input);
49
+ FONT_CSS_PROPS.forEach((cssProperty) => {
50
+ sizer.style[cssProperty] = computedStyle[cssProperty];
51
+ });
52
+ }, [inputRef]);
53
+ const measure = useCallback(() => {
54
+ const sizer = sizerRef.current;
55
+ const container = containerRef.current;
56
+ if (!sizer || !container) {
57
+ return;
58
+ }
59
+ const content = value === void 0 || value === null ? "" : String(value);
60
+ sizer.textContent = content;
61
+ const contentWidth = sizer.scrollWidth;
62
+ let placeholderWidth;
63
+ if (placeholder) {
64
+ sizer.textContent = placeholder;
65
+ placeholderWidth = sizer.scrollWidth;
66
+ sizer.textContent = content;
67
+ }
68
+ const computedWidth = calculateInputWidth({
69
+ sizerWidth: contentWidth,
70
+ hasValue: content.length > 0,
71
+ placeholderIsMinWidth,
72
+ placeholderWidth,
73
+ minWidth: +minWidth,
74
+ placeholder
75
+ });
76
+ const finalWidth = computedWidth + +extraWidth;
77
+ if (parseFloat(container.style.width) !== finalWidth) {
78
+ container.style.width = `${finalWidth}px`;
79
+ onAutosize && onAutosize(computedWidth);
80
+ }
81
+ }, [value, placeholder, placeholderIsMinWidth, minWidth, extraWidth, onAutosize]);
82
+ useLayoutEffect(() => {
83
+ copyFont();
84
+ }, [copyFont]);
85
+ useLayoutEffect(() => {
86
+ measure();
87
+ }, [measure]);
88
+ const measureRef = useRef(measure);
89
+ const copyFontRef = useRef(copyFont);
90
+ useLayoutEffect(() => {
91
+ measureRef.current = measure;
92
+ copyFontRef.current = copyFont;
93
+ });
94
+ useEffect(() => {
95
+ const sizer = sizerRef.current;
96
+ if (!sizer || typeof ResizeObserver === "undefined") {
97
+ return void 0;
98
+ }
99
+ let frame = 0;
100
+ const hasRaf = typeof window.requestAnimationFrame === "function";
101
+ const observer = new ResizeObserver(() => {
102
+ if (hasRaf) {
103
+ window.cancelAnimationFrame(frame);
104
+ frame = window.requestAnimationFrame(() => measureRef.current());
105
+ } else {
106
+ measureRef.current();
107
+ }
108
+ });
109
+ observer.observe(sizer);
110
+ return () => {
111
+ observer.disconnect();
112
+ if (hasRaf) {
113
+ window.cancelAnimationFrame(frame);
114
+ }
115
+ };
116
+ }, []);
117
+ useEffect(() => {
118
+ const fontSet = typeof document !== "undefined" ? document.fonts : void 0;
119
+ if (!fontSet) {
120
+ return void 0;
121
+ }
122
+ const remeasure = () => {
123
+ copyFontRef.current();
124
+ measureRef.current();
125
+ };
126
+ fontSet.ready.then(remeasure).catch(() => void 0);
127
+ fontSet.addEventListener("loadingdone", remeasure);
128
+ return () => {
129
+ fontSet.removeEventListener("loadingdone", remeasure);
130
+ };
131
+ }, []);
132
+ const recalculate = useCallback(() => {
133
+ copyFont();
134
+ measure();
135
+ }, [copyFont, measure]);
136
+ return {
137
+ sizerRef,
138
+ containerRef,
139
+ recalculate
140
+ };
141
+ };
142
+ export {
143
+ SIZER_STYLE,
144
+ useAutosizeWidth
145
+ };
@@ -0,0 +1,29 @@
1
+ import { RefObject } from 'react';
2
+ export type UseAutosizeWidthParams = {
3
+ /** Current input value — drives the measured content width. */
4
+ value?: string | number;
5
+ /** Placeholder text — used as the measured width when there is no value. */
6
+ placeholder?: string;
7
+ /** Lower bound (px) applied to the computed content width. */
8
+ minWidth?: number | string;
9
+ /** Extra px added to the computed width (padding / affordances / icons). */
10
+ extraWidth?: number | string;
11
+ /** When true, the placeholder width is used as a minimum width. */
12
+ placeholderIsMinWidth?: boolean;
13
+ /**
14
+ * Optional ref to the styled input. When provided, its resolved font is
15
+ * copied to the hidden sizer once on mount so measurement matches exactly,
16
+ * even when the font is declared on the input rather than an ancestor.
17
+ */
18
+ inputRef?: RefObject<HTMLElement | null>;
19
+ /** Fired with the computed content width (excl. extraWidth) whenever it changes. */
20
+ onAutosize?: (width: number) => void;
21
+ };
22
+ export type UseAutosizeWidthResult<C extends HTMLElement = HTMLDivElement> = {
23
+ /** Attach to a single hidden, empty `<span>` styled with `SIZER_STYLE`. */
24
+ sizerRef: RefObject<HTMLSpanElement>;
25
+ /** Attach to the inline-block wrapper whose width the hook sets imperatively. */
26
+ containerRef: RefObject<C>;
27
+ /** Force a re-measure (e.g. after a web font loads or layout changes). */
28
+ recalculate: () => void;
29
+ };
@@ -0,0 +1,26 @@
1
+ import { RefObject } from 'react';
2
+ export type UseStretchToFitParams = {
3
+ /** When false the observer is disconnected and no max-width is applied. */
4
+ enabled: boolean;
5
+ /** Element whose `max-width` is clamped to the available width. */
6
+ targetRef: RefObject<HTMLElement | null>;
7
+ /**
8
+ * Maps the measured available width to the max-width to apply. Defaults to
9
+ * identity; consumers tweak it for their own padding/affordances
10
+ * (e.g. `(w) => w - paddingDiff` for Input, `(w) => w + 1` for Autocomplete).
11
+ */
12
+ getMaxWidth?: (availableWidth: number) => number;
13
+ /** Runs before the max-width is applied (e.g. capture scroll position). */
14
+ onBeforeResize?: () => void;
15
+ /** Runs after the max-width is applied (e.g. restore scroll position). */
16
+ onAfterResize?: () => void;
17
+ };
18
+ /**
19
+ * Centralises the (previously triplicated) "stretch the autosize input to fill
20
+ * its container" behaviour. Attach the returned `outerRef` to the bounding
21
+ * element; its width is observed via `useResizeToFit` (no state churn) and the
22
+ * `targetRef` element's `max-width` is updated on resize.
23
+ */
24
+ export declare const useStretchToFit: <T extends HTMLElement = HTMLDivElement>({ enabled, targetRef, getMaxWidth, onBeforeResize, onAfterResize, }: UseStretchToFitParams) => {
25
+ outerRef: RefObject<T>;
26
+ };
@@ -0,0 +1,31 @@
1
+ import { useCallback } from "react";
2
+ import { useResizeToFit } from "@synerise/ds-utils";
3
+ const useStretchToFit = ({
4
+ enabled,
5
+ targetRef,
6
+ getMaxWidth = (availableWidth) => availableWidth,
7
+ onBeforeResize,
8
+ onAfterResize
9
+ }) => {
10
+ const handleResize = useCallback((availableWidth) => {
11
+ const target = targetRef.current;
12
+ if (!enabled || !target) {
13
+ return;
14
+ }
15
+ onBeforeResize && onBeforeResize();
16
+ target.style.maxWidth = `${getMaxWidth(availableWidth)}px`;
17
+ onAfterResize && onAfterResize();
18
+ }, [enabled, targetRef, getMaxWidth, onBeforeResize, onAfterResize]);
19
+ const {
20
+ elementRef: outerRef
21
+ } = useResizeToFit({
22
+ onResize: handleResize,
23
+ autoObserve: enabled
24
+ });
25
+ return {
26
+ outerRef
27
+ };
28
+ };
29
+ export {
30
+ useStretchToFit
31
+ };
package/dist/Input.d.ts CHANGED
@@ -14,10 +14,20 @@ export declare const Input: React.ForwardRefExoticComponent<{
14
14
  prefixel?: React.ReactNode;
15
15
  suffixel?: React.ReactNode;
16
16
  autoResize?: import('./Input.types').AutoResizeProp;
17
- autoResizeProps?: Partial<Pick<import('./AutosizeInput/AutosizeInput.types').AutosizeInputProps, "placeholderIsMinWidth" | "wrapperClassName" | "wrapperStyle" | "extraWidth">>;
17
+ autoResizeProps?: Partial<Pick<import('.').AutosizeInputProps, "placeholderIsMinWidth" | "wrapperClassName" | "wrapperStyle" | "extraWidth">>;
18
18
  expandable?: boolean;
19
19
  expandableTooltip?: React.ReactNode;
20
- } & Omit<import('@synerise/ds-form-field').ContentAboveProps, "id" | "rightSide"> & import('@synerise/ds-form-field').ContentBelowProps & import('antd').InputProps & React.RefAttributes<HTMLDivElement>>;
21
- export declare const RawInput: (props: InputProps) => React.JSX.Element;
20
+ } & Omit<import('@synerise/ds-form-field').ContentAboveProps, "id" | "rightSide"> & import('@synerise/ds-form-field').ContentBelowProps & Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "prefix"> & {
21
+ size?: import('./Input.types').InputSize;
22
+ allowClear?: boolean;
23
+ bordered?: boolean;
24
+ innerPrefix?: React.ReactNode;
25
+ prefix?: React.ReactNode;
26
+ suffix?: React.ReactNode;
27
+ onPressEnter?: React.KeyboardEventHandler<HTMLInputElement>;
28
+ addonBefore?: React.ReactNode;
29
+ addonAfter?: React.ReactNode;
30
+ } & React.RefAttributes<HTMLDivElement>>;
31
+ export declare const RawInput: ({ error, size, className, label, description, errorText, tooltip, tooltipConfig, counterLimit, renderCustomCounter, icon1, icon1Tooltip, icon2, icon2Tooltip, resetMargin, handleInputRef, prefixel, suffixel, autoResize, autoResizeProps, expandable, expandableTooltip, allowClear, prefix, suffix, bordered, onPressEnter, addonBefore, addonAfter, ...rest }: InputProps) => React.JSX.Element;
22
32
  export { default as InputGroup } from './InputGroup';
23
33
  export { default as InputMultivalue } from './InputMultivalue/InputMultivalue';
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 { useResizeObserver } from "@synerise/ds-utils";
7
- import { AntdInput, AddonWrapper, OuterWrapper, InputWrapper } from "./Input.styles.js";
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
- import "./style/index.css";
18
- const VERTICAL_BORDER_OFFSET = 2;
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
- ...antdInputProps
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(antdInputProps.value, counterLimit);
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 mergedRef = useMergeRefs([elementRef, forwardedRef]);
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
- if (inputRef.current) {
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 (autosizeRef.current) {
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.input);
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?.input) {
86
- setOverflown(inputRef.current.input.scrollWidth > inputRef.current.input.clientWidth);
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
- antdInputProps.onChange && antdInputProps.onChange(event);
179
+ inputProps.onChange && inputProps.onChange(event);
97
180
  };
98
181
  const handleExpandableTextareaBlur = (event) => {
99
182
  setExpanded(false);
100
- if (inputRef.current?.input) {
101
- inputRef.current.input.value = event.target.value;
102
- inputRef.current.input.focus();
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.input?.value;
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
- }, [expandableTextAreaRef, expanded]);
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 autoSizedComponent = /* @__PURE__ */ jsx(AutosizeWrapper, { ...autoResizeProps, preAutosize, onAutosize, value: antdInputProps.value, autoResize: !!autoResize, placeholder: antdInputProps.placeholder, children: /* @__PURE__ */ jsx(AntdInput, { autoResize, "data-testid": "input-autosize-input", ...antdInputProps, className: hasErrorMessage || error ? "error" : void 0, addonBefore: !!prefixel && /* @__PURE__ */ jsx(AddonWrapper, { className: "ds-input-prefix", height: inputAddonHeight - VERTICAL_BORDER_OFFSET, children: prefixel }), addonAfter: !!suffixel && /* @__PURE__ */ jsx(AddonWrapper, { className: "ds-input-suffix", height: inputAddonHeight - VERTICAL_BORDER_OFFSET, children: suffixel }), error: hasErrorMessage || error, onChange: handleChange, value: antdInputProps.value, autoComplete: "off", id, ref: inputRef }) });
161
- return /* @__PURE__ */ jsx(OuterWrapper, { ref: mergedRef, autoResize, className, resetMargin, iconCount, children: /* @__PURE__ */ jsx(FormField, { label, rightSide, id, tooltip, tooltipConfig, description, errorText, children: /* @__PURE__ */ jsxs(InputWrapper, { iconCount, children: [
162
- /* @__PURE__ */ jsx(ElementIcons, { handleIconsClick, disabled: antdInputProps.disabled, icon1, icon2, icon1Tooltip, icon2Tooltip, className, type: "input", expandable, overflown, handleExpandIconClick, expandableTooltip }),
163
- expandable ? /* @__PURE__ */ jsx(ExpandableWrapper, { onChange: handleTextareaChange, onBlur: handleExpandableTextareaBlur, ref: expandableTextAreaRef, value: antdInputProps.value, expanded, children: autoSizedComponent }) : autoSizedComponent
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 = (props) => {
167
- const {
168
- error
169
- } = props;
170
- return /* @__PURE__ */ jsx(AntdInput, { className: error ? "error" : "", ...props });
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,
@@ -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): FlattenSimpleInterpolation | "";
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
- export declare const AntdInput: import('styled-components').StyledComponent<React.ForwardRefExoticComponent<InputProps & {
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
- size?: SizeType;
30
- } & React.RefAttributes<InputRef>>, any, {
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 AntdTextArea: import('styled-components').StyledComponent<React.ForwardRefExoticComponent<TextAreaProps & {
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<TextAreaRef>>, any, {
59
+ } & React.RefAttributes<HTMLTextAreaElement>>, any, {
39
60
  error?: boolean;
40
61
  }, never>;
41
62
  export declare const ExpandableWrapper: import('styled-components').StyledComponent<"div", any, {