@synerise/ds-input 1.7.11 → 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.
Files changed (43) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/AutosizeInput/AutosizeInput.d.ts +6 -7
  3. package/dist/AutosizeInput/AutosizeInput.js +39 -116
  4. package/dist/AutosizeInput/AutosizeInput.types.d.ts +5 -18
  5. package/dist/AutosizeInput/useAutosizeWidth.d.ts +18 -0
  6. package/dist/AutosizeInput/useAutosizeWidth.js +145 -0
  7. package/dist/AutosizeInput/useAutosizeWidth.types.d.ts +29 -0
  8. package/dist/AutosizeInput/useAutosizeWidth.types.js +1 -0
  9. package/dist/AutosizeInput/useStretchToFit.d.ts +26 -0
  10. package/dist/AutosizeInput/useStretchToFit.js +31 -0
  11. package/dist/Input.d.ts +13 -3
  12. package/dist/Input.js +170 -81
  13. package/dist/Input.styles.d.ts +32 -11
  14. package/dist/Input.styles.js +64 -38
  15. package/dist/Input.types.d.ts +23 -7
  16. package/dist/InputGroup.d.ts +1 -1
  17. package/dist/InputGroup.js +11 -4
  18. package/dist/InputGroup.styles.d.ts +1 -0
  19. package/dist/InputGroup.styles.js +9 -2
  20. package/dist/InputGroup.types.d.ts +22 -3
  21. package/dist/InputMultivalue/InputMultivalue.styles.js +1 -1
  22. package/dist/TextArea.d.ts +2 -2
  23. package/dist/TextArea.js +4 -5
  24. package/dist/Textarea/Textarea.d.ts +4 -3
  25. package/dist/Textarea/Textarea.js +33 -4
  26. package/dist/Textarea/Textarea.styles.js +2 -2
  27. package/dist/Textarea/Textarea.types.d.ts +13 -8
  28. package/dist/components/ExpandableWrapper.d.ts +1 -2
  29. package/dist/components/index.d.ts +0 -1
  30. package/dist/components/index.js +0 -2
  31. package/dist/hooks/useElementFocus.d.ts +3 -2
  32. package/dist/hooks/useInputAddonHeight.d.ts +1 -2
  33. package/dist/hooks/useInputAddonHeight.js +1 -1
  34. package/dist/hooks/useTextareaAutosize.d.ts +53 -0
  35. package/dist/hooks/useTextareaAutosize.js +82 -0
  36. package/dist/index.d.ts +6 -2
  37. package/dist/index.js +8 -3
  38. package/dist/utils/getCharCount.d.ts +3 -2
  39. package/package.json +3 -7
  40. package/dist/assets/style/index-tn0RQdqM.css +0 -0
  41. package/dist/components/AutosizeWrapper.d.ts +0 -17
  42. package/dist/components/AutosizeWrapper.js +0 -18
  43. package/dist/style/index.css +0 -1
@@ -1,21 +1,28 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { Input } from "antd";
3
2
  import { Children } from "react";
4
3
  import FormField from "@synerise/ds-form-field";
5
- import { OuterWrapper, ErrorText } from "./Input.styles.js";
4
+ import { ErrorText, OuterWrapper } from "./Input.styles.js";
6
5
  import { InputGroupWrapper, InputGroupItem } from "./InputGroup.styles.js";
7
6
  const InputGroup = ({
8
7
  children,
9
8
  label,
9
+ errorText,
10
10
  errors,
11
11
  description,
12
12
  resetMargin,
13
13
  tooltip,
14
14
  tooltipConfig,
15
- ...antdInputGroupProps
15
+ compact,
16
+ growItem,
17
+ className,
18
+ style,
19
+ // antd `Input.Group` size cascade is no longer applied; size each child input directly.
20
+ size: _size,
21
+ ...rest
16
22
  }) => {
17
23
  const childrenArray = Children.toArray(children);
18
- return /* @__PURE__ */ jsx(OuterWrapper, { className: "ds-input-group-outer-wrapper", resetMargin, children: /* @__PURE__ */ jsx(FormField, { label, tooltip, tooltipConfig, description, errorText: errors && errors.map((error) => /* @__PURE__ */ jsx(ErrorText, { children: error }, error)), children: /* @__PURE__ */ jsx(Input.Group, { ...antdInputGroupProps, children: /* @__PURE__ */ jsx(InputGroupWrapper, { compact: antdInputGroupProps.compact, children: Children.map(childrenArray, (child, index) => /* @__PURE__ */ jsx(InputGroupItem, { className: `ds-input-group-item ds-input-group-item-${index}`, children: child })) }) }) }) });
24
+ const resolvedErrorText = errorText ?? (errors && errors.map((error) => /* @__PURE__ */ jsx(ErrorText, { children: error }, error)));
25
+ return /* @__PURE__ */ jsx(OuterWrapper, { className: "ds-input-group-outer-wrapper", resetMargin, children: /* @__PURE__ */ jsx(FormField, { label, tooltip, tooltipConfig, description, errorText: resolvedErrorText, children: /* @__PURE__ */ jsx(InputGroupWrapper, { compact, $growItem: growItem, className, style, ...rest, children: Children.map(childrenArray, (child, index) => /* @__PURE__ */ jsx(InputGroupItem, { className: `ds-input-group-item ds-input-group-item-${index}`, children: child })) }) }) });
19
26
  };
20
27
  export {
21
28
  InputGroup as default
@@ -1,4 +1,5 @@
1
1
  export declare const InputGroupItem: import('styled-components').StyledComponent<"div", any, {}, never>;
2
2
  export declare const InputGroupWrapper: import('styled-components').StyledComponent<"div", any, {
3
3
  compact?: boolean;
4
+ $growItem?: "first" | "last";
4
5
  }, never>;
@@ -2,11 +2,18 @@ import styled, { css } from "styled-components";
2
2
  const InputGroupItem = /* @__PURE__ */ styled.div.withConfig({
3
3
  displayName: "InputGroupstyles__InputGroupItem",
4
4
  componentId: "sc-1cn2cc5-0"
5
- })([""]);
5
+ })(["min-width:0;"]);
6
+ const CONTROLS = ["input", "textarea", "button", ".ds-input-number", ".ant-select-selector", ".ds-button"];
7
+ const controlsUnder = (itemSelector) => CONTROLS.map((control) => `${itemSelector} ${control}`).join(", ");
8
+ const notLastControls = controlsUnder(`${InputGroupItem}:not(:only-child):not(:last-child)`);
9
+ const lastControls = controlsUnder(`${InputGroupItem}:not(:only-child):last-child`);
6
10
  const InputGroupWrapper = /* @__PURE__ */ styled.div.withConfig({
7
11
  displayName: "InputGroupstyles__InputGroupWrapper",
8
12
  componentId: "sc-1cn2cc5-1"
9
- })(["&&&{", "{.ds-select-container{margin-bottom:0;}}.ant-input.ant-input{float:none;}display:flex;min-width:0;", ";", "}"], InputGroupItem, (props) => props.compact ? "" : "align-items: stretch", (props) => props.compact ? css(["", "{&:only-child{flex-grow:1;}&:not(:only-child){&:not(:last-child){margin-right:-1px;.ant-input,.ant-input-number,.ant-select-selector{border-top-right-radius:0px;border-bottom-right-radius:0px;}}&:last-child{.ant-input,.ant-input-number,.ant-select-selector{border-top-left-radius:0px;border-bottom-left-radius:0px;}flex:auto;}}"], InputGroupItem) : css(["", ":last-child{flex-grow:1;}", ":not(:last-child){margin-right:12px;}"], InputGroupItem, InputGroupItem));
13
+ })(["&&&{display:flex;min-width:0;", " ", " .ds-select-container{margin-bottom:0;}", "}"], (props) => props.compact ? "" : "align-items: stretch;", InputGroupItem, (props) => {
14
+ const growChild = props.$growItem === "first" ? "first-child" : "last-child";
15
+ return props.compact ? css(["", ":only-child{flex-grow:1;}", ":not(:only-child):not(:last-child){margin-right:-1px;}", ":not(:only-child):", "{flex:auto;}", ":not(:only-child):not(:", ") .ds-input-number{width:90px;}", "{border-top-right-radius:0;border-bottom-right-radius:0;}", "{border-top-left-radius:0;border-bottom-left-radius:0;}"], InputGroupItem, InputGroupItem, InputGroupItem, growChild, InputGroupItem, growChild, notLastControls, lastControls) : css(["", ":", "{flex-grow:1;}", ":not(:last-child){margin-right:12px;}"], InputGroupItem, growChild, InputGroupItem);
16
+ });
10
17
  export {
11
18
  InputGroupItem,
12
19
  InputGroupWrapper
@@ -1,6 +1,25 @@
1
- import { GroupProps } from 'antd/es/input';
1
+ import { CSSProperties, ReactNode } from 'react';
2
2
  import { FormFieldCommonProps } from '@synerise/ds-form-field';
3
- export type Props = GroupProps & {
3
+ export type InputGroupSize = 'large' | 'default' | 'small';
4
+ export type Props = {
5
+ compact?: boolean;
6
+ size?: InputGroupSize;
7
+ className?: string;
8
+ style?: CSSProperties;
9
+ children?: ReactNode;
10
+ /**
11
+ * Which group item stretches to fill the row (the others keep their natural
12
+ * width). Defaults to `'last'` — the trailing control grows, so a fixed-width
13
+ * leading control (e.g. a Select) sits left and the input fills the rest. Use
14
+ * `'first'` for the flipped layout: the leading control stretches while a
15
+ * fixed-width trailing control (e.g. a ColorPicker) stays compact on the right.
16
+ */
17
+ growItem?: 'first' | 'last';
18
+ /**
19
+ * @deprecated Use `errorText` (from `FormFieldCommonProps`) instead. This
20
+ * antd-proprietary array of error strings is kept only for backward
21
+ * compatibility and is ignored when `errorText` is provided.
22
+ */
4
23
  errors?: string[];
5
24
  resetMargin?: boolean;
6
- } & Omit<FormFieldCommonProps, 'errorText'>;
25
+ } & FormFieldCommonProps;
@@ -1,6 +1,6 @@
1
1
  import styled, { css } from "styled-components";
2
2
  const errorInputStyle = (props) => `
3
- &&, .ant-input {
3
+ && {
4
4
  border-color: ${props.theme.palette["red-600"]};
5
5
  box-shadow: inset 0 0 0 2px ${props.theme.palette["red-600"]};
6
6
  background: ${props.theme.palette["red-050"]};
@@ -1,8 +1,8 @@
1
1
  import { default as React } from 'react';
2
2
  import { TextareaProps } from './TextArea.types';
3
3
  export declare const TextArea: ({ className, errorText, label, description, counterLimit, tooltip, tooltipConfig, icon1, icon1Tooltip, icon2, icon2Tooltip, resetMargin, handleInputRef, prefixel, suffixel, error, renderCustomCounter, ...antdTextareaProps }: TextareaProps) => React.JSX.Element;
4
- export declare const RawTextArea: import('styled-components').StyledComponent<React.ForwardRefExoticComponent<import('antd/lib/input').TextAreaProps & {
4
+ export declare const RawTextArea: import('styled-components').StyledComponent<React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & {
5
5
  error?: boolean;
6
- } & React.RefAttributes<import('antd/lib/input/TextArea').TextAreaRef>>, any, {
6
+ } & React.RefAttributes<HTMLTextAreaElement>>, any, {
7
7
  error?: boolean;
8
8
  }, never>;
package/dist/TextArea.js CHANGED
@@ -2,13 +2,12 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useMemo, useRef, useEffect, useCallback } from "react";
3
3
  import { v4 } from "uuid";
4
4
  import FormField from "@synerise/ds-form-field";
5
- import { AntdTextArea, OuterWrapper, InputWrapper } from "./Input.styles.js";
6
- import { RawTextArea as RawTextArea$1 } from "./Textarea/Textarea.js";
5
+ import { RawTextArea as RawTextArea$1, OuterWrapper, InputWrapper } from "./Input.styles.js";
6
+ import { RawTextArea as RawTextArea$2 } from "./Textarea/Textarea.js";
7
7
  import { ElementIcons } from "./components/ElementIcons.js";
8
8
  import { useElementFocus } from "./hooks/useElementFocus.js";
9
9
  import { useCounterLimit } from "./hooks/useCounterLimit.js";
10
10
  import { getCharCount } from "./utils/getCharCount.js";
11
- import "./style/index.css";
12
11
  const TextArea = ({
13
12
  className,
14
13
  errorText,
@@ -53,10 +52,10 @@ const TextArea = ({
53
52
  });
54
53
  return /* @__PURE__ */ jsx(OuterWrapper, { className, resetMargin, children: /* @__PURE__ */ jsx(FormField, { label, rightSide, id, tooltip, tooltipConfig, description, errorText, children: /* @__PURE__ */ jsxs(InputWrapper, { children: [
55
54
  /* @__PURE__ */ jsx(ElementIcons, { handleIconsClick, disabled: antdTextareaProps.disabled, icon1Tooltip, icon1, icon2, icon2Tooltip, className, type: "textArea" }),
56
- /* @__PURE__ */ jsx(RawTextArea$1, { ...antdTextareaProps, className: hasErrorMessage || error ? "error" : void 0, error: hasErrorMessage || error, onChange: handleChange, value: antdTextareaProps.value, id, autoComplete: "off" })
55
+ /* @__PURE__ */ jsx(RawTextArea$2, { ...antdTextareaProps, className: hasErrorMessage || error ? "error" : void 0, error: hasErrorMessage || error, onChange: handleChange, value: antdTextareaProps.value, id, autoComplete: "off" })
57
56
  ] }) }) });
58
57
  };
59
- const RawTextArea = AntdTextArea;
58
+ const RawTextArea = RawTextArea$1;
60
59
  export {
61
60
  RawTextArea,
62
61
  TextArea
@@ -1,9 +1,10 @@
1
- import { TextAreaRef } from 'antd/lib/input/TextArea';
2
1
  import { default as React } from 'react';
3
- export declare const RawTextArea: React.ForwardRefExoticComponent<import('antd/lib/input/TextArea').TextAreaProps & {
2
+ import { AutoSizeType } from './Textarea.types';
3
+ export declare const RawTextArea: React.ForwardRefExoticComponent<React.TextareaHTMLAttributes<HTMLTextAreaElement> & {
4
+ autoSize?: AutoSizeType;
4
5
  error?: boolean;
5
6
  errorText?: string | React.ReactNode;
6
7
  wrapperStyle?: React.CSSProperties;
7
8
  resize?: import('csstype').ResizeProperty;
8
- } & React.RefAttributes<TextAreaRef>>;
9
+ } & React.RefAttributes<HTMLTextAreaElement>>;
9
10
  export default RawTextArea;
@@ -1,25 +1,54 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- import { forwardRef, useState } from "react";
2
+ import { forwardRef, useState, useRef } from "react";
3
+ import { useMergeRefs } from "@floating-ui/react";
3
4
  import Scrollbar from "@synerise/ds-scrollbar";
4
- import { AntdTextArea } from "../Input.styles.js";
5
+ import { RawTextArea as RawTextArea$1 } from "../Input.styles.js";
6
+ import { useTextareaAutosize } from "../hooks/useTextareaAutosize.js";
5
7
  import { TextareaWrapper } from "./Textarea.styles.js";
8
+ const resolveRows = (autoSize) => typeof autoSize === "object" ? autoSize : void 0;
6
9
  const RawTextArea = forwardRef(({
7
10
  disabled,
8
11
  error,
12
+ errorText,
9
13
  rows = 4,
10
14
  wrapperStyle,
11
15
  onBlur,
12
16
  onFocus,
17
+ onChange,
13
18
  resize,
14
19
  autoSize,
15
20
  readOnly,
21
+ value,
16
22
  ...props
17
23
  }, ref) => {
18
24
  const [focus, setFocus] = useState(false);
25
+ const [viewportHeight, setViewportHeight] = useState(null);
26
+ const innerRef = useRef(null);
27
+ const mergedRef = useMergeRefs([innerRef, ref]);
28
+ const rowsConfig = resolveRows(autoSize);
29
+ const resize_ = useTextareaAutosize({
30
+ ref: innerRef,
31
+ value,
32
+ minRows: rowsConfig?.minRows,
33
+ maxRows: rowsConfig?.maxRows,
34
+ enabled: Boolean(autoSize),
35
+ onViewportHeight: setViewportHeight
36
+ });
37
+ const handleChange = (event) => {
38
+ onChange && onChange(event);
39
+ if (autoSize) {
40
+ resize_();
41
+ }
42
+ };
19
43
  return /* @__PURE__ */ jsx(TextareaWrapper, { className: "ds-textarea", isDisabled: Boolean(disabled), isFocused: focus, isReadOnly: readOnly, hasError: Boolean(error), resize, style: {
20
- height: autoSize ? "auto" : `${rows * 17}px`,
44
+ // In autoSize mode the wrapper is the fixed/max-height viewport the
45
+ // ds-Scrollbar scrolls: the hook reports the clamped viewport height
46
+ // (definite px so the inner `.ps` `height: 100%` resolves) while the
47
+ // textarea grows to its full content height behind it. Falls back to
48
+ // `auto` until the first measurement lands.
49
+ height: autoSize ? viewportHeight !== null ? `${viewportHeight}px` : "auto" : `${rows * 17}px`,
21
50
  ...wrapperStyle
22
- }, children: /* @__PURE__ */ jsx(Scrollbar, { absolute: true, classes: "textarea-scrollbar", children: /* @__PURE__ */ jsx(AntdTextArea, { autoSize, ...props, ref, disabled, readOnly, onFocus: (e) => {
51
+ }, children: /* @__PURE__ */ jsx(Scrollbar, { absolute: true, classes: "textarea-scrollbar", children: /* @__PURE__ */ jsx(RawTextArea$1, { ...props, value, ref: mergedRef, error, disabled, readOnly, onChange: handleChange, onFocus: (e) => {
23
52
  onFocus && onFocus(e);
24
53
  setFocus(true);
25
54
  }, onBlur: (e) => {
@@ -2,7 +2,7 @@ import styled, { css } from "styled-components";
2
2
  const TextareaWrapper = /* @__PURE__ */ styled.div.withConfig({
3
3
  displayName: "Textareastyles__TextareaWrapper",
4
4
  componentId: "sc-23480t-0"
5
- })(["position:relative;overflow:hidden;resize:", ";border-radius:3px;transition:background-color 0.3s ease-in-out,border 0.3s ease-in-out,box-shadow 0.3s ease-in-out;", " .scrollbar-container{height:100%;top:1px;bottom:0;right:1px;.ps__rail-y,.ps__thumb-x,.ps__rail-x{height:calc(100% - 1px);max-height:9px;}& > .textarea-scrollbar{&,& > div{height:calc(100% - 2px);}}}&&&{textarea{position:relative;min-height:100%;resize:none;background:transparent;border:0;box-shadow:none;outline:0;word-wrap:break-word;overflow-wrap:break-word;font-variant-numeric:normal;::placeholder,::-webkit-input-placeholder{line-height:1.38;}:-ms-input-placeholder{line-height:1.38;}}.ant-input-textarea{height:100%;}}"], (props) => props.resize ? props.resize : "vertical", (props) => {
5
+ })(["position:relative;overflow:hidden;resize:", ";border-radius:3px;transition:background-color 0.3s ease-in-out,border 0.3s ease-in-out,box-shadow 0.3s ease-in-out;", " .scrollbar-container{height:100%;top:1px;bottom:0;right:1px;.ps__rail-y,.ps__thumb-x,.ps__rail-x{height:calc(100% - 1px);max-height:9px;}& > .textarea-scrollbar{&,& > div{height:calc(100% - 2px);}}}&&&{textarea{position:relative;min-height:100%;resize:none;background:transparent;border:0;box-shadow:none;outline:0;word-wrap:break-word;overflow-wrap:break-word;font-family:inherit;font-size:13px;font-variant-numeric:normal;&::placeholder,&::-webkit-input-placeholder{color:", ";line-height:1.38;}&:-ms-input-placeholder{color:", ";line-height:1.38;}}}"], (props) => props.resize ? props.resize : "vertical", (props) => {
6
6
  if (props.isReadOnly) {
7
7
  return css(["border:1px solid ", ";background-color:", ";"], props.theme.palette["grey-300"], props.theme.palette["grey-050"]);
8
8
  }
@@ -16,7 +16,7 @@ const TextareaWrapper = /* @__PURE__ */ styled.div.withConfig({
16
16
  return css(["background-color:", ";box-shadow:inset 0 0 0 1px ", ";border:1px solid ", ";"], props.theme.palette["red-050"], props.theme.palette["red-600"], props.theme.palette["red-600"]);
17
17
  }
18
18
  return css(["border:1px solid #dbe0e3;background-color:#fff;"]);
19
- });
19
+ }, (props) => props.theme.palette["grey-500"], (props) => props.theme.palette["grey-500"]);
20
20
  export {
21
21
  TextareaWrapper
22
22
  };
@@ -1,13 +1,18 @@
1
- import { TextAreaProps as AntdTextAreaProps } from 'antd/lib/input';
2
1
  import { ResizeProperty } from 'csstype';
3
- import { default as React } from 'react';
2
+ import { CSSProperties, ReactNode, TextareaHTMLAttributes } from 'react';
3
+ export type AutoSizeType = boolean | {
4
+ minRows?: number;
5
+ maxRows?: number;
6
+ };
7
+ export type RawTextAreaProps = TextareaHTMLAttributes<HTMLTextAreaElement> & {
8
+ /** Auto-grow height to fit content. `true` grows freely; object bounds it by rows. */
9
+ autoSize?: AutoSizeType;
10
+ error?: boolean;
11
+ errorText?: string | ReactNode;
12
+ wrapperStyle?: CSSProperties;
13
+ resize?: ResizeProperty;
14
+ };
4
15
  /**
5
16
  * @deprecated Use RawTextAreaProps instead.
6
17
  */
7
18
  export type TextAreaProps = RawTextAreaProps;
8
- export type RawTextAreaProps = AntdTextAreaProps & {
9
- error?: boolean;
10
- errorText?: string | React.ReactNode;
11
- wrapperStyle?: React.CSSProperties;
12
- resize?: ResizeProperty;
13
- };
@@ -1,4 +1,3 @@
1
- import { TextAreaRef } from 'antd/lib/input/TextArea';
2
1
  import { default as React, ChangeEvent, FocusEvent, ReactNode } from 'react';
3
2
  import { InputProps } from '../Input.types';
4
3
  export declare const ExpandableWrapper: React.ForwardRefExoticComponent<Pick<InputProps, "value"> & {
@@ -6,4 +5,4 @@ export declare const ExpandableWrapper: React.ForwardRefExoticComponent<Pick<Inp
6
5
  expanded: boolean;
7
6
  onChange: (Event: ChangeEvent<HTMLInputElement> & ChangeEvent<HTMLTextAreaElement>) => void;
8
7
  onBlur: (event: FocusEvent<HTMLTextAreaElement>) => void;
9
- } & React.RefAttributes<TextAreaRef>>;
8
+ } & React.RefAttributes<HTMLTextAreaElement>>;
@@ -1,3 +1,2 @@
1
1
  export { ElementIcons } from './ElementIcons';
2
2
  export { ExpandableWrapper } from './ExpandableWrapper';
3
- export { AutosizeWrapper } from './AutosizeWrapper';
@@ -1,8 +1,6 @@
1
1
  import { ElementIcons } from "./ElementIcons.js";
2
2
  import { ExpandableWrapper } from "./ExpandableWrapper.js";
3
- import { AutosizeWrapper } from "./AutosizeWrapper.js";
4
3
  export {
5
- AutosizeWrapper,
6
4
  ElementIcons,
7
5
  ExpandableWrapper
8
6
  };
@@ -1,3 +1,4 @@
1
- import { InputRef } from 'antd';
2
1
  import { MutableRefObject } from 'react';
3
- export declare const useElementFocus: (ref: MutableRefObject<HTMLInputElement | HTMLTextAreaElement | InputRef | null>) => () => void;
2
+ export declare const useElementFocus: <T extends {
3
+ focus: () => void;
4
+ }>(ref: MutableRefObject<T | null>) => () => void;
@@ -1,5 +1,4 @@
1
- import { InputRef } from 'antd';
2
1
  import { MutableRefObject } from 'react';
3
- export declare const useInputAddonHeight: (inputRef: MutableRefObject<InputRef | null>) => {
2
+ export declare const useInputAddonHeight: (inputRef: MutableRefObject<HTMLInputElement | null>) => {
4
3
  inputAddonHeight: number;
5
4
  };
@@ -2,7 +2,7 @@ import { useState, useEffect } from "react";
2
2
  const useInputAddonHeight = (inputRef) => {
3
3
  const [inputAddonHeight, setInputAddonHeight] = useState(0);
4
4
  useEffect(() => {
5
- inputRef.current && inputRef.current.input?.offsetHeight && setInputAddonHeight(inputRef.current.input?.offsetHeight);
5
+ inputRef.current?.offsetHeight && setInputAddonHeight(inputRef.current.offsetHeight);
6
6
  }, [inputRef]);
7
7
  return {
8
8
  inputAddonHeight
@@ -0,0 +1,53 @@
1
+ import { RefObject } from 'react';
2
+ type TextareaMetrics = {
3
+ /** `scrollHeight` of the textarea (content + vertical padding, border excluded). */
4
+ scrollHeight: number;
5
+ verticalPadding: number;
6
+ verticalBorder: number;
7
+ isBorderBox: boolean;
8
+ /** Floor for the textarea's own height (box px). */
9
+ minHeightPx?: number;
10
+ /** Cap for the scroll viewport (box px); the textarea itself is never capped. */
11
+ maxHeightPx?: number;
12
+ };
13
+ /**
14
+ * Pure height calculation extracted from the hook so the sizing logic is
15
+ * unit-testable without a layout engine. Returns two heights:
16
+ *
17
+ * - `contentHeight` — the textarea's own height. It always tracks the full
18
+ * content (floored at `minHeightPx`) and is **never capped**, so the textarea
19
+ * never scrolls itself; the ds-Scrollbar wrapping it owns the scrolling.
20
+ * - `viewportHeight` — the height for the scroll viewport (the wrapper). It
21
+ * tracks the content but is capped at `maxHeightPx`, so once the content
22
+ * exceeds the cap the textarea overflows the viewport and PerfectScrollbar
23
+ * takes over.
24
+ */
25
+ export declare const computeTextareaHeight: ({ scrollHeight, verticalPadding, verticalBorder, isBorderBox, minHeightPx, maxHeightPx, }: TextareaMetrics) => {
26
+ contentHeight: number;
27
+ viewportHeight: number;
28
+ };
29
+ type UseTextareaAutosizeParams = {
30
+ ref: RefObject<HTMLTextAreaElement | null>;
31
+ /** Re-measure whenever this changes (typically the controlled value). */
32
+ value?: unknown;
33
+ minRows?: number;
34
+ maxRows?: number;
35
+ /** When false the textarea keeps its CSS height (no auto-sizing). */
36
+ enabled?: boolean;
37
+ /**
38
+ * Reports the scroll viewport height (clamped by `minRows`/`maxRows`) so the
39
+ * wrapper can be sized as a definite-height viewport for the ds-Scrollbar.
40
+ */
41
+ onViewportHeight?: (height: number) => void;
42
+ };
43
+ /**
44
+ * Grows a `<textarea>` to fit its content between `minRows` and `maxRows`,
45
+ * replacing antd's `autoSize={{ minRows, maxRows }}`. The textarea is sized to
46
+ * its full content height with `overflow: hidden` (it never scrolls itself);
47
+ * the clamped viewport height is reported via `onViewportHeight` so the wrapping
48
+ * ds-Scrollbar handles the scrolling once the content exceeds `maxRows`.
49
+ * Measures synchronously in `useLayoutEffect` (before paint) and re-measures on
50
+ * window resize.
51
+ */
52
+ export declare const useTextareaAutosize: ({ ref, value, minRows, maxRows, enabled, onViewportHeight, }: UseTextareaAutosizeParams) => () => void;
53
+ export {};
@@ -0,0 +1,82 @@
1
+ import { useCallback, useLayoutEffect, useEffect } from "react";
2
+ const computeTextareaHeight = ({
3
+ scrollHeight,
4
+ verticalPadding,
5
+ verticalBorder,
6
+ isBorderBox,
7
+ minHeightPx,
8
+ maxHeightPx
9
+ }) => {
10
+ const naturalHeight = isBorderBox ? scrollHeight + verticalBorder : scrollHeight - verticalPadding;
11
+ let contentHeight = naturalHeight;
12
+ if (minHeightPx !== void 0) {
13
+ contentHeight = Math.max(contentHeight, minHeightPx);
14
+ }
15
+ let viewportHeight = contentHeight;
16
+ if (maxHeightPx !== void 0) {
17
+ viewportHeight = Math.min(viewportHeight, maxHeightPx);
18
+ }
19
+ return {
20
+ contentHeight: Math.round(contentHeight),
21
+ viewportHeight: Math.round(viewportHeight)
22
+ };
23
+ };
24
+ const useTextareaAutosize = ({
25
+ ref,
26
+ value,
27
+ minRows,
28
+ maxRows,
29
+ enabled = true,
30
+ onViewportHeight
31
+ }) => {
32
+ const resize = useCallback(() => {
33
+ const element = ref.current;
34
+ if (!element || !enabled) {
35
+ return;
36
+ }
37
+ const style = window.getComputedStyle(element);
38
+ const verticalPadding = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
39
+ const verticalBorder = (parseFloat(style.borderTopWidth) || 0) + (parseFloat(style.borderBottomWidth) || 0);
40
+ let lineHeight = parseFloat(style.lineHeight);
41
+ if (Number.isNaN(lineHeight)) {
42
+ lineHeight = (parseFloat(style.fontSize) || 16) * 1.2;
43
+ }
44
+ const isBorderBox = style.boxSizing === "border-box";
45
+ const rowsToHeight = (rows) => isBorderBox ? rows * lineHeight + verticalPadding + verticalBorder : rows * lineHeight;
46
+ const previousHeight = element.style.height;
47
+ element.style.height = "auto";
48
+ const {
49
+ scrollHeight
50
+ } = element;
51
+ element.style.height = previousHeight;
52
+ const {
53
+ contentHeight,
54
+ viewportHeight
55
+ } = computeTextareaHeight({
56
+ scrollHeight,
57
+ verticalPadding,
58
+ verticalBorder,
59
+ isBorderBox,
60
+ minHeightPx: minRows !== void 0 ? rowsToHeight(minRows) : void 0,
61
+ maxHeightPx: maxRows !== void 0 ? rowsToHeight(maxRows) : void 0
62
+ });
63
+ element.style.height = `${contentHeight}px`;
64
+ element.style.overflowY = "hidden";
65
+ onViewportHeight && onViewportHeight(viewportHeight);
66
+ }, [ref, minRows, maxRows, enabled, onViewportHeight]);
67
+ useLayoutEffect(() => {
68
+ resize();
69
+ }, [resize, value]);
70
+ useEffect(() => {
71
+ if (!enabled) {
72
+ return void 0;
73
+ }
74
+ window.addEventListener("resize", resize);
75
+ return () => window.removeEventListener("resize", resize);
76
+ }, [resize, enabled]);
77
+ return resize;
78
+ };
79
+ export {
80
+ computeTextareaHeight,
81
+ useTextareaAutosize
82
+ };
package/dist/index.d.ts CHANGED
@@ -11,7 +11,11 @@ export type { InputMultivalueProps } from './InputMultivalue/InputMultivalue.typ
11
11
  export * as InputStyles from './Input.styles';
12
12
  export type { BaseProps, EnhancedProps, InputProps, AutoResizeProp, StyledInput, } from './Input.types';
13
13
  export { default as AutosizeInput } from './AutosizeInput/AutosizeInput';
14
- export type { AutosizeInputProps, AutosizeWrapperProps, AutosizeInputRefType, } from './AutosizeInput/AutosizeInput.types';
15
- export { AutosizeWrapper } from './components/AutosizeWrapper';
14
+ export type { AutosizeInputProps } from './AutosizeInput/AutosizeInput.types';
15
+ export { useAutosizeWidth, SIZER_STYLE, } from './AutosizeInput/useAutosizeWidth';
16
+ export type { UseAutosizeWidthParams, UseAutosizeWidthResult, } from './AutosizeInput/useAutosizeWidth.types';
17
+ export { useStretchToFit } from './AutosizeInput/useStretchToFit';
18
+ export type { UseStretchToFitParams } from './AutosizeInput/useStretchToFit';
19
+ export { autoresizeConfObjToCss } from './Input.styles';
16
20
  export { PasswordInput } from './PasswordInput';
17
21
  export type { PasswordInputProps, PasswordInputTexts, } from './PasswordInput.types';
package/dist/index.js CHANGED
@@ -3,14 +3,15 @@ import { Input, RawInput } from "./Input.js";
3
3
  import { RawTextArea, TextArea } from "./TextArea.js";
4
4
  import { RawTextArea as RawTextArea2 } from "./Textarea/Textarea.js";
5
5
  import * as Input_styles from "./Input.styles.js";
6
+ import { autoresizeConfObjToCss } from "./Input.styles.js";
6
7
  import { default as default2 } from "./AutosizeInput/AutosizeInput.js";
7
- import { AutosizeWrapper } from "./components/AutosizeWrapper.js";
8
+ import { SIZER_STYLE, useAutosizeWidth } from "./AutosizeInput/useAutosizeWidth.js";
9
+ import { useStretchToFit } from "./AutosizeInput/useStretchToFit.js";
8
10
  import { PasswordInput } from "./PasswordInput.js";
9
11
  import { default as default3 } from "./InputGroup.js";
10
12
  import { default as default4 } from "./InputMultivalue/InputMultivalue.js";
11
13
  export {
12
14
  default2 as AutosizeInput,
13
- AutosizeWrapper,
14
15
  RawTextArea2 as DSRawTextArea,
15
16
  Input,
16
17
  default3 as InputGroup,
@@ -20,5 +21,9 @@ export {
20
21
  PasswordInput,
21
22
  RawInput,
22
23
  RawTextArea,
23
- TextArea
24
+ SIZER_STYLE,
25
+ TextArea,
26
+ autoresizeConfObjToCss,
27
+ useAutosizeWidth,
28
+ useStretchToFit
24
29
  };
@@ -1,3 +1,4 @@
1
- import { InputProps as AntdInputProps } from 'antd';
2
1
  import { TextareaProps } from '../TextArea.types';
3
- export declare const getCharCount: (value?: AntdInputProps["value"] | TextareaProps["value"], limit?: number) => number;
2
+ type InputValue = string | number | readonly string[];
3
+ export declare const getCharCount: (value?: InputValue | TextareaProps["value"], limit?: number) => number;
4
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-input",
3
- "version": "1.7.11",
3
+ "version": "1.7.12",
4
4
  "description": "Input UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -35,10 +35,7 @@
35
35
  "check:circular-dependencies": "madge --circular --extensions ts,tsx,js,jsx --ts-config tsconfig.json src/ --exclude '/dist/'",
36
36
  "upgrade:ds": "ncu -f \"@synerise/ds-*\" -u"
37
37
  },
38
- "sideEffects": [
39
- "dist/style/*",
40
- "*.less"
41
- ],
38
+ "sideEffects": false,
42
39
  "types": "dist/index.d.ts",
43
40
  "dependencies": {
44
41
  "@floating-ui/react": "^0.27.16",
@@ -56,11 +53,10 @@
56
53
  },
57
54
  "peerDependencies": {
58
55
  "@synerise/ds-core": "*",
59
- "antd": "4.24.16",
60
56
  "react": ">=16.9.0 <= 18.3.1",
61
57
  "react-intl": ">= 3.12.0 <= 6.8",
62
58
  "styled-components": "^5.3.3",
63
59
  "vitest": "4"
64
60
  },
65
- "gitHead": "d8c64070f58f14e3fb1bfbcbf00d1e3b8fd51eb8"
61
+ "gitHead": "5c90008871be36fb52553a2ed3a633acf5db5b3b"
66
62
  }
File without changes
@@ -1,17 +0,0 @@
1
- import { default as React } from 'react';
2
- import { AutosizeInputRefType } from '../AutosizeInput/AutosizeInput.types';
3
- export declare const AutosizeWrapper: React.ForwardRefExoticComponent<Omit<React.InputHTMLAttributes<HTMLInputElement>, "size"> & {
4
- placeholderIsMinWidth?: boolean;
5
- wrapperClassName?: string;
6
- wrapperStyle?: React.CSSProperties;
7
- extraWidth?: number | string;
8
- minWidth?: number | string;
9
- onAutosize?: (newWidth: number) => void;
10
- preAutosize?: (newWidth: number) => void;
11
- transformRef?: (element: HTMLElement) => HTMLElement;
12
- transformWrapperRef?: (element: HTMLElement) => HTMLElement;
13
- handleInputRef?: (element: HTMLInputElement, originalElement: HTMLElement) => HTMLElement;
14
- children: React.ReactNode;
15
- } & {
16
- autoResize?: boolean;
17
- } & React.RefAttributes<AutosizeInputRefType>>;
@@ -1,18 +0,0 @@
1
- import { jsx, Fragment } from "react/jsx-runtime";
2
- import { forwardRef } from "react";
3
- import AutosizeInput from "../AutosizeInput/AutosizeInput.js";
4
- const AUTOSIZE_EXTRA_WIDTH = 2;
5
- const AutosizeWrapper = forwardRef(({
6
- autoResize,
7
- extraWidth = AUTOSIZE_EXTRA_WIDTH,
8
- children,
9
- ...props
10
- }, ref) => {
11
- if (autoResize) {
12
- return /* @__PURE__ */ jsx(AutosizeInput, { ref, extraWidth, ...props, children });
13
- }
14
- return /* @__PURE__ */ jsx(Fragment, { children });
15
- });
16
- export {
17
- AutosizeWrapper
18
- };