@synerise/ds-input 0.19.18 → 0.20.0

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 CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [0.20.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-input@0.19.19...@synerise/ds-input@0.20.0) (2024-03-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * **input:** support autoresize to stretch to parent ([329c866](https://github.com/synerise/synerise-design/commit/329c866cb54921ad1260ae217cb8c471e43b986e))
12
+
13
+
14
+
15
+
16
+
17
+ ## [0.19.19](https://github.com/synerise/synerise-design/compare/@synerise/ds-input@0.19.18...@synerise/ds-input@0.19.19) (2024-02-21)
18
+
19
+ **Note:** Version bump only for package @synerise/ds-input
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.19.18](https://github.com/synerise/synerise-design/compare/@synerise/ds-input@0.19.17...@synerise/ds-input@0.19.18) (2024-02-19)
7
26
 
8
27
  **Note:** Version bump only for package @synerise/ds-input
package/README.md CHANGED
@@ -19,7 +19,7 @@ Input UI Component
19
19
 
20
20
  ## API
21
21
 
22
- #### Input
22
+ ### Input
23
23
 
24
24
  | Property | Description | Type | Default |
25
25
  | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- | --------- |
@@ -46,9 +46,32 @@ Input UI Component
46
46
  | tooltipConfig | Config of tooltip | [TooltipProps](https://design.synerise.com/docs/components/tooltip#api) | - |
47
47
  | type | The type of input, see: [MDN](https://developer.mozilla.org/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types)(use `Input.TextArea` instead of `type="textarea"`) | string | `text` |
48
48
  | value | The input content value | string | |
49
- | autoResize | 'resize' width of the input based on width of the text in input | boolean | `false` |
49
+ | autoResize | 'resize' width of the input based on width of the text in input | AutoResizeProp (see below) | `undefined` |
50
50
 
51
- #### MaskedInput
51
+ #### AutoResizeProp
52
+
53
+ ```
54
+ type AutoResizeProp = `boolean` | {
55
+ minWidth: string;
56
+ maxWidth?: string;
57
+ stretchToFit?: boolean
58
+ };
59
+ ```
60
+
61
+ Setting `stretchToFit: true` will make the field stretch to fit the containing element. The component observes the width of the wrapper and adjusts the maxWidth accordingly.
62
+ **Important** if the Input is within a flex-item then there is necessary CSS that needs to be applied to the flex-item containers in order for the flex-item to grow to fill the allowed space, but at the same time not stretch the flex container (identical issue happens when text-overflow needs to happen inside a flex-item).
63
+
64
+ ```css
65
+ $flexItemSurroundingTheInput {
66
+ min-width: 0;
67
+ flex-grow: 1
68
+ }
69
+ ```
70
+
71
+ See https://css-tricks.com/flexbox-truncated-text/ for more details.
72
+
73
+
74
+ ### MaskedInput
52
75
 
53
76
  Same as Input api with additional props:
54
77
 
@@ -58,7 +81,7 @@ Same as Input api with additional props:
58
81
  | placeholderChar | Customized placeholder character used to fill in editable parts of the pattern. | string | '\_' |
59
82
  | formatCharacters | Customized format character definitions for use in the pattern. | Object (https://github.com/insin/inputmask-core#formatcharacters) | - |
60
83
 
61
- #### InputGroup
84
+ ### InputGroup
62
85
 
63
86
  | Property | Description | Type | Default |
64
87
  | -------- | ------------------------------------------------------------------------------------------------------- | ------- | ------- |
package/dist/Input.js CHANGED
@@ -14,6 +14,7 @@ import React, { cloneElement, useState, useEffect, useRef, useCallback, useMemo
14
14
  import '@synerise/ds-core/dist/js/style';
15
15
  import { v4 as uuid } from 'uuid';
16
16
  import "./style/index.css";
17
+ import { useResizeToFit } from '@synerise/ds-utils';
17
18
  import Tooltip from '@synerise/ds-tooltip/dist/Tooltip';
18
19
  import * as S from './Input.styles';
19
20
  import Label from './Label/Label';
@@ -104,6 +105,50 @@ var enhancedInput = function enhancedInput(WrappedComponent, _ref) {
104
105
  };
105
106
  }, // eslint-disable-next-line react-hooks/exhaustive-deps
106
107
  [antdInputProps, handleChange]);
108
+ var stretchToFit = typeof autoResize === 'object' && Boolean(autoResize.stretchToFit);
109
+ var paddingDiff = useRef();
110
+
111
+ var _useResizeToFit = useResizeToFit({
112
+ onResize: function onResize(width) {
113
+ if (inputRef.current && paddingDiff.current) {
114
+ // @ts-ignore
115
+ inputRef.current.input.style.maxWidth = width - paddingDiff.current + "px";
116
+ }
117
+ },
118
+ autoObserve: true
119
+ }),
120
+ observe = _useResizeToFit.observe,
121
+ disconnect = _useResizeToFit.disconnect,
122
+ elementRef = _useResizeToFit.elementRef;
123
+
124
+ useEffect(function () {
125
+ if (inputRef.current) {
126
+ // @ts-ignore
127
+ var _getComputedStyle = getComputedStyle(inputRef.current.input),
128
+ paddingLeft = _getComputedStyle.paddingLeft,
129
+ paddingRight = _getComputedStyle.paddingRight;
130
+
131
+ paddingDiff.current = parseFloat(paddingLeft) + parseFloat(paddingRight);
132
+ }
133
+ }, [paddingDiff]);
134
+ useEffect(function () {
135
+ if (elementRef.current) {
136
+ if (stretchToFit) {
137
+ observe();
138
+ } else {
139
+ disconnect(); // @ts-ignore
140
+
141
+ if (inputRef.current && inputRef.current.input) {
142
+ // @ts-ignore
143
+ inputRef.current.input.style.removeProperty('max-width');
144
+ }
145
+ }
146
+ }
147
+
148
+ return function () {
149
+ disconnect();
150
+ };
151
+ }, [disconnect, observe, stretchToFit, elementRef]);
107
152
  return /*#__PURE__*/React.createElement(S.OuterWrapper, {
108
153
  autoResize: autoResize,
109
154
  className: className,
@@ -116,6 +161,7 @@ var enhancedInput = function enhancedInput(WrappedComponent, _ref) {
116
161
  }), counterLimit && /*#__PURE__*/React.createElement(S.Counter, {
117
162
  "data-testid": "counter"
118
163
  }, charCount, "/", counterLimit)), /*#__PURE__*/React.createElement(S.InputWrapper, {
164
+ ref: elementRef,
119
165
  icon1: Boolean(icon1),
120
166
  icon2: Boolean(icon2)
121
167
  }, (icon1 || icon2) && /*#__PURE__*/React.createElement(S.IconsWrapper, {
@@ -1,29 +1,28 @@
1
+ import React, { MutableRefObject, ReactNode } from 'react';
1
2
  import BaseAntInput from 'antd/lib/input';
2
3
  import TextArea from 'antd/lib/input/TextArea';
3
- import * as React from 'react';
4
4
  import MaskedInput from 'antd-mask-input';
5
5
  import { SizeType } from 'antd/es/config-provider/SizeContext';
6
+ import type { AutoResizeProp } from './Input.types';
6
7
  export type AutoResizeInputProps = {
7
- autoResize?: boolean | {
8
- minWidth: string;
9
- maxWidth: string;
10
- };
11
- suffixel?: boolean | React.ReactNode;
12
- prefixel?: boolean | React.ReactNode;
13
- icon1?: boolean | React.ReactNode;
14
- icon2?: boolean | React.ReactNode;
8
+ autoResize?: AutoResizeProp;
9
+ suffixel?: ReactNode;
10
+ prefixel?: ReactNode;
11
+ icon1?: ReactNode;
12
+ icon2?: ReactNode;
15
13
  };
14
+ export declare function autoresizeConfObjToCss({ autoResize }: {
15
+ autoResize?: AutoResizeProp;
16
+ }): string;
16
17
  export declare const OuterWrapper: import("styled-components").StyledComponent<"div", any, {
17
18
  resetMargin?: boolean | undefined;
18
- autoResize?: boolean | {
19
- minWidth: string;
20
- maxWidth: string;
21
- } | undefined;
19
+ autoResize?: AutoResizeProp | undefined;
22
20
  }, never>;
23
21
  export declare const Wrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
24
22
  interface InputWrapperProps {
25
23
  icon1: boolean;
26
24
  icon2: boolean;
25
+ ref?: MutableRefObject<HTMLDivElement | null>;
27
26
  }
28
27
  export declare const InputWrapper: import("styled-components").StyledComponent<"div", any, InputWrapperProps, never>;
29
28
  export declare const IconsWrapper: import("styled-components").StyledComponent<"div", any, {
@@ -53,10 +52,7 @@ export declare const AntdTextArea: import("styled-components").StyledComponent<R
53
52
  }, never>;
54
53
  export declare const ContentBelow: import("styled-components").StyledComponent<"div", any, {}, never>;
55
54
  export declare const WrapperAutoResize: import("styled-components").StyledComponent<"div", any, {
56
- autoResize?: boolean | {
57
- minWidth: string;
58
- maxWidth: string;
59
- } | undefined;
55
+ autoResize?: AutoResizeProp | undefined;
60
56
  }, never>;
61
57
  export declare const AutoResize: import("styled-components").StyledComponent<"div", any, AutoResizeInputProps, never>;
62
58
  export declare const ErrorText: import("styled-components").StyledComponent<"div", any, {}, never>;
@@ -6,9 +6,9 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
6
6
 
7
7
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
8
8
 
9
+ import React, { forwardRef } from 'react';
9
10
  import styled, { css } from 'styled-components';
10
11
  import BaseAntInput from 'antd/lib/input';
11
- import * as React from 'react';
12
12
  import MaskedInput from 'antd-mask-input';
13
13
 
14
14
  var errorInputStyle = function errorInputStyle(props) {
@@ -27,17 +27,16 @@ var getPaddingAutoResize = function getPaddingAutoResize(props) {
27
27
  return '0 13px';
28
28
  };
29
29
 
30
- function autoresizeConfObjToCss(_ref) {
30
+ export function autoresizeConfObjToCss(_ref) {
31
31
  var autoResize = _ref.autoResize;
32
32
  if (!autoResize) return '';
33
33
 
34
34
  if (typeof autoResize === 'object') {
35
- return "max-width: " + autoResize.maxWidth + "; min-width: " + autoResize.minWidth;
35
+ return "\n " + (autoResize.maxWidth !== undefined ? "max-width: " + autoResize.maxWidth + ";" : '') + "\n min-width: " + autoResize.minWidth + ";\n ";
36
36
  }
37
37
 
38
38
  return "max-width: 400px; min-width: 150px;";
39
39
  }
40
-
41
40
  export var OuterWrapper = styled.div.withConfig({
42
41
  displayName: "Inputstyles__OuterWrapper",
43
42
  componentId: "dc57an-0"
@@ -88,7 +87,7 @@ export var IconWrapper = styled.div.withConfig({
88
87
  })([".icon:hover{svg{fill:", ";cursor:pointer;}}"], function (props) {
89
88
  return props.theme.palette['blue-600'];
90
89
  });
91
- export var AntdInput = styled(React.forwardRef( // eslint-disable-next-line
90
+ export var AntdInput = styled(forwardRef( // eslint-disable-next-line
92
91
  function (_ref2, ref) {
93
92
  var error = _ref2.error,
94
93
  props = _objectWithoutPropertiesLoose(_ref2, _excluded);
@@ -118,7 +117,7 @@ function (_ref2, ref) {
118
117
  theme = _ref3.theme;
119
118
  return readOnly ? "\n &:hover {\n border-color: " + theme.palette['grey-300'] + ";\n }\n &:focus {\n border-color: " + theme.palette['grey-300'] + ";\n box-shadow: none;\n background: #fff;\n }\n " : '';
120
119
  });
121
- export var AntdMaskedInput = styled(React.forwardRef( // eslint-disable-next-line
120
+ export var AntdMaskedInput = styled(forwardRef( // eslint-disable-next-line
122
121
  function (_ref4, ref) {
123
122
  var error = _ref4.error,
124
123
  mask = _ref4.mask,
@@ -144,7 +143,7 @@ function (_ref4, ref) {
144
143
  }, function (props) {
145
144
  return props.theme.palette['grey-700'];
146
145
  });
147
- export var AntdTextArea = styled(React.forwardRef( // eslint-disable-next-line
146
+ export var AntdTextArea = styled(forwardRef( // eslint-disable-next-line
148
147
  function (_ref5, ref) {
149
148
  var error = _ref5.error,
150
149
  props = _objectWithoutPropertiesLoose(_ref5, _excluded3);
@@ -1,28 +1,30 @@
1
- import * as React from 'react';
1
+ import { ReactNode, ReactElement, MutableRefObject } from 'react';
2
2
  import { InputProps, TextAreaProps } from 'antd/lib/input';
3
3
  import { MaskedInputProps } from 'antd-mask-input/build/main/lib/MaskedInput';
4
- import TooltipExtendedProps from '@synerise/ds-tooltip/dist/Tooltip.types';
5
4
  import { TooltipProps } from 'antd/lib/tooltip';
5
+ import TooltipExtendedProps from '@synerise/ds-tooltip/dist/Tooltip.types';
6
+ export type AutoResizeProp = boolean | {
7
+ minWidth: string;
8
+ maxWidth?: string;
9
+ stretchToFit?: boolean;
10
+ };
6
11
  export interface Props {
7
12
  error?: boolean;
8
13
  className?: string;
9
- tooltip?: React.ReactNode;
14
+ tooltip?: ReactNode;
10
15
  tooltipConfig?: TooltipExtendedProps & TooltipProps;
11
- errorText?: React.ReactNode | string;
12
- label?: React.ReactNode | string;
13
- description?: React.ReactNode | string;
16
+ errorText?: ReactNode;
17
+ label?: ReactNode;
18
+ description?: ReactNode;
14
19
  counterLimit?: number;
15
- icon1?: React.ReactElement;
16
- icon1Tooltip?: React.ReactElement;
17
- icon2?: React.ReactElement;
18
- icon2Tooltip?: React.ReactElement;
20
+ icon1?: ReactElement;
21
+ icon1Tooltip?: ReactElement;
22
+ icon2?: ReactElement;
23
+ icon2Tooltip?: ReactElement;
19
24
  resetMargin?: boolean;
20
- handleInputRef?: (ref: React.MutableRefObject<HTMLInputElement | HTMLTextAreaElement | undefined>) => void;
21
- prefixel?: React.ReactNode;
22
- suffixel?: React.ReactNode;
23
- autoResize?: boolean | {
24
- minWidth: string;
25
- maxWidth: string;
26
- };
25
+ handleInputRef?: (ref: MutableRefObject<HTMLInputElement | HTMLTextAreaElement | undefined>) => void;
26
+ prefixel?: ReactNode;
27
+ suffixel?: ReactNode;
28
+ autoResize?: AutoResizeProp;
27
29
  }
28
30
  export type EnhancedProps = Props & (InputProps | TextAreaProps | MaskedInputProps);
@@ -25,8 +25,10 @@ var InputGroup = function InputGroup(_ref) {
25
25
  tooltip: tooltip
26
26
  })), /*#__PURE__*/React.createElement(Input.Group, antdInputGroupProps, /*#__PURE__*/React.createElement(S.InputGroupWrapper, {
27
27
  compact: antdInputGroupProps.compact
28
- }, Children.map(childrenArray, function (child) {
29
- return /*#__PURE__*/React.createElement(S.InputGroupItem, null, child);
28
+ }, Children.map(childrenArray, function (child, index) {
29
+ return /*#__PURE__*/React.createElement(S.InputGroupItem, {
30
+ className: "ds-input-group-item ds-input-group-item-" + index
31
+ }, child);
30
32
  }))), (errors && errors.length > 0 || description) && /*#__PURE__*/React.createElement(InputStyles.ContentBelow, null, errors && errors.map(function (error) {
31
33
  return /*#__PURE__*/React.createElement(InputStyles.ErrorText, {
32
34
  key: "error"
@@ -6,8 +6,8 @@ export var InputGroupItem = styled.div.withConfig({
6
6
  export var InputGroupWrapper = styled.div.withConfig({
7
7
  displayName: "InputGroupstyles__InputGroupWrapper",
8
8
  componentId: "sc-1cn2cc5-1"
9
- })(["&&&{display:flex;align-items:", ";", "}"], function (props) {
10
- return props.compact ? '' : 'stretch';
9
+ })(["&&&{display:flex;min-width:0;", ";", "}"], function (props) {
10
+ return props.compact ? '' : 'align-items: stretch';
11
11
  }, function (props) {
12
12
  return 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
13
  });
@@ -8,7 +8,7 @@ declare class AutosizeInput extends Component {
8
8
  componentDidMount(): void;
9
9
  componentDidUpdate(prevProps: any, prevState: any): void;
10
10
  componentWillUnmount(): void;
11
- inputRef: (el: any) => void;
11
+ inputRef: (el: any, originalElement: any) => void;
12
12
  placeHolderSizerRef: (el: any) => void;
13
13
  sizerRef: (el: any) => void;
14
14
  copyInputStyles(): void;
@@ -27,7 +27,7 @@ var sizerStyle = {
27
27
  overflow: 'scroll',
28
28
  whiteSpace: 'pre'
29
29
  };
30
- var INPUT_PROPS_BLACKLIST = ['extraWidth', 'injectStyles', 'inputClassName', 'inputRef', 'inputStyle', 'minWidth', 'onAutosize', 'placeholderIsMinWidth', 'autoResize'];
30
+ var INPUT_PROPS_BLACKLIST = ['extraWidth', 'injectStyles', 'inputClassName', 'inputRef', 'inputStyle', 'minWidth', 'onAutosize', 'placeholderIsMinWidth', 'autoResize', 'refPropName'];
31
31
 
32
32
  var cleanInputProps = function cleanInputProps(inputProps) {
33
33
  INPUT_PROPS_BLACKLIST.forEach(function (field) {
@@ -69,11 +69,11 @@ var AutosizeInput = /*#__PURE__*/function (_Component) {
69
69
 
70
70
  _this = _Component.call(this, props) || this;
71
71
 
72
- _defineProperty(_assertThisInitialized(_this), "inputRef", function (el) {
72
+ _defineProperty(_assertThisInitialized(_this), "inputRef", function (el, originalElement) {
73
73
  _this.input = el;
74
74
 
75
75
  if (typeof _this.props.inputRef === 'function') {
76
- _this.props.inputRef(el);
76
+ _this.props.inputRef(el, originalElement);
77
77
  }
78
78
  });
79
79
 
@@ -91,7 +91,7 @@ var AutosizeInput = /*#__PURE__*/function (_Component) {
91
91
  var input = el.previousElementSibling;
92
92
  var ref = transformRef(input);
93
93
 
94
- _this.inputRef(ref);
94
+ _this.inputRef(ref, input);
95
95
 
96
96
  _this.copyInputStyles();
97
97
  });
@@ -218,7 +218,8 @@ var AutosizeInput = /*#__PURE__*/function (_Component) {
218
218
  var inputStyle = _objectSpread({
219
219
  boxSizing: 'content-box',
220
220
  width: this.state.inputWidth + "px",
221
- minHeight: 30 - 12 * 2 + "px"
221
+ minHeight: 30 - 12 * 2 + "px",
222
+ transition: 'width 0s ease 0s'
222
223
  }, this.props.inputStyle);
223
224
 
224
225
  var defaultRenderInput = function defaultRenderInput(props) {
package/dist/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export { default as Label } from './Label/Label';
3
3
  export { Input, TextArea, RawInput, RawTextArea, InputGroup, MaskedInput, InputMultivalue, RawMaskedInput, AutoResize, WrapperAutoResize, } from './Input';
4
4
  export * as InputStyles from './Input.styles';
5
5
  export type { EnhancedProps };
6
- export type { Props as InputProps } from './Input.types';
6
+ export type { Props as InputProps, AutoResizeProp } from './Input.types';
7
7
  export { default as AutosizeInput } from './autosize/autosize';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-input",
3
- "version": "0.19.18",
3
+ "version": "0.20.0",
4
4
  "description": "Input UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -33,11 +33,11 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-icon": "^0.60.1",
37
- "@synerise/ds-scrollbar": "^0.8.1",
38
- "@synerise/ds-tooltip": "^0.14.18",
36
+ "@synerise/ds-icon": "^0.60.3",
37
+ "@synerise/ds-scrollbar": "^0.8.3",
38
+ "@synerise/ds-tooltip": "^0.14.20",
39
39
  "@synerise/ds-typography": "^0.14.3",
40
- "@synerise/ds-utils": "^0.24.25",
40
+ "@synerise/ds-utils": "^0.25.0",
41
41
  "antd-mask-input": "^0.1.13",
42
42
  "csstype": "2.6.9",
43
43
  "uuid": "^8.3.2"
@@ -51,5 +51,5 @@
51
51
  "devDependencies": {
52
52
  "@testing-library/react": "10.0.1"
53
53
  },
54
- "gitHead": "cddb99e7a7cf30926aa46cf772a17d6803ff62cf"
54
+ "gitHead": "6b8da853a2bb4e993d89e9b0b3041216f0c9c976"
55
55
  }