@synerise/ds-inline-edit 0.7.4 → 0.7.6

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.7.6](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.7.5...@synerise/ds-inline-edit@0.7.6) (2024-05-16)
7
+
8
+ **Note:** Version bump only for package @synerise/ds-inline-edit
9
+
10
+
11
+
12
+
13
+
14
+ ## [0.7.5](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.7.4...@synerise/ds-inline-edit@0.7.5) (2024-05-10)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **input:** refactored autosize input solution ([449bd86](https://github.com/Synerise/synerise-design/commit/449bd868b8d3b545ac582c556fa0ff607c77f853))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [0.7.4](https://github.com/Synerise/synerise-design/compare/@synerise/ds-inline-edit@0.7.3...@synerise/ds-inline-edit@0.7.4) (2024-05-08)
7
26
 
8
27
  **Note:** Version bump only for package @synerise/ds-inline-edit
@@ -2,7 +2,7 @@ import React, { useCallback, useRef, useState, useEffect } from 'react';
2
2
  import Tooltip from '@synerise/ds-tooltip';
3
3
  import Icon, { EditS } from '@synerise/ds-icon';
4
4
  import { toCamelCase } from '@synerise/ds-utils';
5
- import AutosizeInput from './autosize/autosize';
5
+ import { AutosizeInput } from '@synerise/ds-input';
6
6
  import * as S from './InlineEdit.styles';
7
7
 
8
8
  var InlineEdit = function InlineEdit(_ref) {
@@ -16,13 +16,7 @@ var InlineEdit = function InlineEdit(_ref) {
16
16
  tooltipTitle = _ref.tooltipTitle,
17
17
  error = _ref.error,
18
18
  input = _ref.input;
19
- var autoWidthRef = useRef(null);
20
- var inputRef = useRef();
21
- useEffect(function () {
22
- if (autoWidthRef.current) {
23
- inputRef.current = autoWidthRef.current.inputRef.current;
24
- }
25
- });
19
+ var inputRef = useRef(null);
26
20
 
27
21
  var _useState = useState(),
28
22
  scrolled = _useState[0],
@@ -68,6 +62,13 @@ var InlineEdit = function InlineEdit(_ref) {
68
62
  error: error,
69
63
  scrolled: scrolled
70
64
  }, /*#__PURE__*/React.createElement(AutosizeInput, {
65
+ extraWidth: 2,
66
+ value: input.value || '',
67
+ placeholderIsMinWidth: false,
68
+ wrapperClassName: "autosize-input"
69
+ }, /*#__PURE__*/React.createElement("input", {
70
+ itemRef: "",
71
+ onScroll: handleScroll,
71
72
  id: input.name ? toCamelCase(input.name) : 'id',
72
73
  className: "autosize-input",
73
74
  placeholder: input.placeholder,
@@ -75,17 +76,13 @@ var InlineEdit = function InlineEdit(_ref) {
75
76
  onKeyPress: handleKeyPress,
76
77
  disabled: disabled,
77
78
  name: input.name,
78
- extraWidth: 2,
79
- readOnly: input.readOnly,
80
- value: input.value || '',
81
79
  onChange: handleChange,
82
80
  onBlur: handleBlur,
81
+ readOnly: input.readOnly,
82
+ value: input.value || '',
83
83
  autoComplete: input.autoComplete,
84
- placeholderIsMinWidth: false,
85
- onScroll: handleScroll,
86
- wrapperClassName: "autosize-input",
87
- ref: autoWidthRef
88
- }), !hideIcon && /*#__PURE__*/React.createElement(Tooltip, {
84
+ ref: inputRef
85
+ })), !hideIcon && /*#__PURE__*/React.createElement(Tooltip, {
89
86
  "data-testid": "inline-edit-icon",
90
87
  title: tooltipTitle
91
88
  }, /*#__PURE__*/React.createElement(S.IconWrapper, {
@@ -1,3 +1,3 @@
1
1
  import { InlineSelectProps } from './InlineSelect.types';
2
- declare const InlineSelect: ({ className, style, dropdownProps, dropdownOverlayStyle, inputStyle, size, disabled, autoFocus, hideIcon, error, input, placeholder, dataSource, initialValue, }: InlineSelectProps) => JSX.Element;
2
+ declare const InlineSelect: ({ className, style, expanded, dropdownProps, dropdownOverlayStyle, inputStyle, size, disabled, autoFocus, hideIcon, error, input, placeholder, dataSource, initialValue, }: InlineSelectProps) => JSX.Element;
3
3
  export default InlineSelect;
@@ -4,13 +4,14 @@ import React, { useRef, useState, useEffect } from 'react';
4
4
  import { toCamelCase } from '@synerise/ds-utils';
5
5
  import Icon, { AngleDownS } from '@synerise/ds-icon';
6
6
  import Dropdown from '@synerise/ds-dropdown';
7
- import AutosizeInput from '../autosize/autosize';
7
+ import { AutosizeInput } from '@synerise/ds-input';
8
8
  import * as S from './InlineSelect.style';
9
9
  import SelectDropdown from './SelectDropdown/SelectDropdown';
10
10
 
11
11
  var InlineSelect = function InlineSelect(_ref) {
12
12
  var className = _ref.className,
13
13
  style = _ref.style,
14
+ expanded = _ref.expanded,
14
15
  _ref$dropdownProps = _ref.dropdownProps,
15
16
  dropdownProps = _ref$dropdownProps === void 0 ? {} : _ref$dropdownProps,
16
17
  _ref$dropdownOverlayS = _ref.dropdownOverlayStyle,
@@ -27,37 +28,31 @@ var InlineSelect = function InlineSelect(_ref) {
27
28
  placeholder = _ref.placeholder,
28
29
  dataSource = _ref.dataSource,
29
30
  initialValue = _ref.initialValue;
30
- var autoWidthRef = useRef(null);
31
- var inputRef = useRef();
31
+ var inputRef = useRef(null);
32
32
 
33
33
  var _useState = useState(initialValue || placeholder || 'option'),
34
34
  selectedValue = _useState[0],
35
35
  setSelectedValue = _useState[1];
36
36
 
37
- var _useState2 = useState(false),
38
- opened = _useState2[0],
39
- setOpened = _useState2[1];
37
+ var _useState2 = useState(Boolean(expanded)),
38
+ isOpened = _useState2[0],
39
+ setIsOpened = _useState2[1];
40
40
 
41
41
  var _useState3 = useState(false),
42
- pressed = _useState3[0],
43
- setPressed = _useState3[1];
42
+ isPressed = _useState3[0],
43
+ setIsPressed = _useState3[1];
44
44
 
45
45
  useEffect(function () {
46
46
  if (input != null && input.value && input.value !== selectedValue) {
47
47
  setSelectedValue(input == null ? void 0 : input.value);
48
48
  }
49
49
  }, [input == null ? void 0 : input.value, selectedValue]);
50
- useEffect(function () {
51
- if (autoWidthRef.current) {
52
- inputRef.current = autoWidthRef.current.inputRef.current;
53
- }
54
- });
55
50
  useEffect(function () {
56
51
  autoFocus && inputRef.current && inputRef.current.focus();
57
52
  }, [autoFocus, inputRef]);
58
53
  return /*#__PURE__*/React.createElement(Dropdown, _extends({
59
- visible: !disabled && opened,
60
- onVisibleChange: setOpened,
54
+ visible: !disabled && isOpened,
55
+ onVisibleChange: setIsOpened,
61
56
  placement: "bottomRight",
62
57
  disabled: disabled,
63
58
  overlay: /*#__PURE__*/React.createElement(SelectDropdown, {
@@ -66,7 +61,7 @@ var InlineSelect = function InlineSelect(_ref) {
66
61
  return setSelectedValue(item.text);
67
62
  },
68
63
  closeDropdown: function closeDropdown() {
69
- return setOpened(false);
64
+ return setIsOpened(false);
70
65
  },
71
66
  style: dropdownOverlayStyle
72
67
  }),
@@ -79,30 +74,33 @@ var InlineSelect = function InlineSelect(_ref) {
79
74
  error: error,
80
75
  tabIndex: 0,
81
76
  onMouseDown: function onMouseDown() {
82
- return setPressed(true);
77
+ return setIsPressed(true);
83
78
  },
84
79
  onMouseUp: function onMouseUp() {
85
- return setPressed(false);
80
+ return setIsPressed(false);
86
81
  },
87
- pressed: pressed,
88
- dropdownOpened: opened
82
+ pressed: isPressed,
83
+ dropdownOpened: isOpened
89
84
  }, /*#__PURE__*/React.createElement(AutosizeInput, {
85
+ value: selectedValue || placeholder,
86
+ placeholderIsMinWidth: false,
87
+ extraWidth: 2,
88
+ wrapperClassName: "autosize-input"
89
+ }, /*#__PURE__*/React.createElement("input", {
90
+ ref: inputRef,
91
+ style: inputStyle,
90
92
  id: input.name ? toCamelCase(input.name) : 'id',
91
93
  className: "autosize-input",
92
- placeholder: input.placeholder,
94
+ placeholder: placeholder,
93
95
  maxLength: input.maxLength,
94
96
  disabled: disabled,
95
97
  name: input.name,
98
+ readOnly: input.readOnly,
96
99
  value: selectedValue || placeholder,
97
- autoComplete: input.autoComplete,
98
- placeholderIsMinWidth: false,
99
- style: inputStyle,
100
- extraWidth: 2,
101
- wrapperClassName: "autosize-input",
102
- ref: autoWidthRef
103
- }), !hideIcon && /*#__PURE__*/React.createElement(S.IconWrapper, {
100
+ autoComplete: "off"
101
+ })), !hideIcon && /*#__PURE__*/React.createElement(S.IconWrapper, {
104
102
  size: size,
105
- expanded: opened
103
+ expanded: isOpened
106
104
  }, /*#__PURE__*/React.createElement(Icon, {
107
105
  component: /*#__PURE__*/React.createElement(AngleDownS, null),
108
106
  size: 24
@@ -1,22 +1,22 @@
1
- import * as React from 'react';
1
+ import type { CSSProperties } from 'react';
2
2
  import { MenuItemProps } from '@synerise/ds-menu/dist/Elements/Item/MenuItem.types';
3
3
  import { DropdownProps } from '@synerise/ds-dropdown/dist/Dropdown';
4
4
  import { InputProps } from '../InlineEdit.types';
5
- export interface InlineSelectProps {
5
+ export type InlineSelectProps = {
6
6
  size?: 'normal' | 'small';
7
7
  tooltipTitle?: string;
8
8
  className?: string;
9
9
  disabled?: boolean;
10
- input: Partial<InputProps>;
11
- style?: React.CSSProperties;
12
- dropdownOverlayStyle?: React.CSSProperties;
13
- inputStyle?: React.CSSProperties;
10
+ input: Partial<Omit<InputProps, 'placeholder'>>;
11
+ style?: CSSProperties;
12
+ dropdownOverlayStyle?: CSSProperties;
13
+ inputStyle?: CSSProperties;
14
14
  dropdownProps?: Partial<DropdownProps>;
15
15
  autoFocus?: boolean;
16
16
  error?: boolean;
17
17
  hideIcon?: boolean;
18
- expanded: boolean;
18
+ expanded?: boolean;
19
19
  initialValue?: string;
20
20
  placeholder?: string;
21
21
  dataSource: MenuItemProps[];
22
- }
22
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-inline-edit",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "description": "InlineEdit UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -33,15 +33,15 @@
33
33
  ],
34
34
  "types": "dist/index.d.ts",
35
35
  "dependencies": {
36
- "@synerise/ds-dropdown": "^0.17.108",
37
- "@synerise/ds-icon": "^0.60.8",
38
- "@synerise/ds-menu": "^0.18.21",
39
- "@synerise/ds-scrollbar": "^0.10.3",
40
- "@synerise/ds-search": "^0.8.89",
41
- "@synerise/ds-tooltip": "^0.14.26",
36
+ "@synerise/ds-dropdown": "^0.17.110",
37
+ "@synerise/ds-icon": "^0.61.0",
38
+ "@synerise/ds-input": "^0.21.3",
39
+ "@synerise/ds-menu": "^0.18.23",
40
+ "@synerise/ds-scrollbar": "^0.10.5",
41
+ "@synerise/ds-search": "^0.8.91",
42
+ "@synerise/ds-tooltip": "^0.14.28",
42
43
  "@synerise/ds-typography": "^0.15.0",
43
- "@synerise/ds-utils": "^0.26.4",
44
- "react-input-autosize": "^2.2.2"
44
+ "@synerise/ds-utils": "^0.26.6"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@synerise/ds-core": "*",
@@ -50,8 +50,7 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@testing-library/jest-dom": "5.1.1",
53
- "@testing-library/react": "10.0.1",
54
- "@types/react-input-autosize": "2.2.1"
53
+ "@testing-library/react": "10.0.1"
55
54
  },
56
- "gitHead": "1ad18b4b850f614943cd940a6b509d215ec025c7"
55
+ "gitHead": "fc089bbf34c691a313b3fa648851d7831a23e3d0"
57
56
  }
@@ -1,30 +0,0 @@
1
- import React, { InputHTMLAttributes, CSSProperties, RefObject } from 'react';
2
- export type AutosizeInputProps = InputHTMLAttributes<HTMLInputElement> & {
3
- extraWidth?: number | string;
4
- minWidth?: number | string;
5
- onAutosize?: (newWidth: number) => void;
6
- placeholderIsMinWidth?: boolean;
7
- value?: string | number;
8
- wrapperClassName?: string;
9
- wrapperStyle?: CSSProperties;
10
- };
11
- export type AutosizeInputRefType = {
12
- inputRef: RefObject<HTMLInputElement>;
13
- sizerRef: RefObject<HTMLDivElement>;
14
- placeholderSizerRef: RefObject<HTMLDivElement>;
15
- copyInputStyles: () => void;
16
- updateInputWidth: () => void;
17
- };
18
- /**
19
- * Automatically sized input field.
20
- */
21
- export declare const AutosizeInput: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & {
22
- extraWidth?: string | number | undefined;
23
- minWidth?: string | number | undefined;
24
- onAutosize?: ((newWidth: number) => void) | undefined;
25
- placeholderIsMinWidth?: boolean | undefined;
26
- value?: string | number | undefined;
27
- wrapperClassName?: string | undefined;
28
- wrapperStyle?: React.CSSProperties | undefined;
29
- } & React.RefAttributes<AutosizeInputRefType>>;
30
- export default AutosizeInput;
@@ -1,169 +0,0 @@
1
- var _excluded = ["extraWidth", "wrapperClassName", "wrapperStyle", "onAutosize", "placeholderIsMinWidth", "minWidth"];
2
-
3
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
-
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
6
-
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
-
9
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
-
11
- 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; }
12
-
13
- import React, { useState, useEffect, useRef, useLayoutEffect, forwardRef, useImperativeHandle } from 'react';
14
- import { useResizeObserver } from '@synerise/ds-utils';
15
- var sizerStyle = {
16
- position: 'absolute',
17
- top: 0,
18
- left: 0,
19
- visibility: 'hidden',
20
- height: 0,
21
- overflow: 'scroll',
22
- whiteSpace: 'pre'
23
- };
24
- /**
25
- * Automatically sized input field.
26
- */
27
-
28
- export var AutosizeInput = forwardRef(function (_ref, forwardedRef) {
29
- var _props$value, _props$style$display, _props$style;
30
-
31
- var _ref$extraWidth = _ref.extraWidth,
32
- extraWidth = _ref$extraWidth === void 0 ? 16 : _ref$extraWidth,
33
- wrapperClassName = _ref.wrapperClassName,
34
- wrapperStyleProp = _ref.wrapperStyle,
35
- onAutosize = _ref.onAutosize,
36
- placeholderIsMinWidth = _ref.placeholderIsMinWidth,
37
- _ref$minWidth = _ref.minWidth,
38
- minWidth = _ref$minWidth === void 0 ? 0 : _ref$minWidth,
39
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
40
-
41
- var inputRef = useRef(null);
42
- var sizerRef = useRef(null);
43
- var placeholderSizerRef = useRef(null);
44
-
45
- var _useState = useState(''),
46
- input = _useState[0],
47
- setInput = _useState[1];
48
-
49
- var _useState2 = useState(0),
50
- inputWidth = _useState2[0],
51
- setInputWidth = _useState2[1];
52
-
53
- var _useResizeObserver = useResizeObserver(sizerRef),
54
- updatedSizerWidth = _useResizeObserver.width;
55
-
56
- var _useResizeObserver2 = useResizeObserver(placeholderSizerRef),
57
- updatedPlaceholderWidth = _useResizeObserver2.width;
58
-
59
- var usedValue = "" + ((_props$value = props.value) != null ? _props$value : input);
60
-
61
- var handleInput = function handleInput(event) {
62
- setInput(event.target.value);
63
- if (props.onChange) props.onChange(event);
64
- };
65
-
66
- var copyInputStyles = function copyInputStyles() {
67
- if (inputRef.current) {
68
- var computedStyle = window.getComputedStyle(inputRef.current);
69
-
70
- if (sizerRef.current) {
71
- sizerRef.current.style.fontSize = computedStyle.fontSize;
72
- sizerRef.current.style.fontFamily = computedStyle.fontFamily;
73
- sizerRef.current.style.fontWeight = computedStyle.fontWeight;
74
- sizerRef.current.style.fontStyle = computedStyle.fontStyle;
75
- sizerRef.current.style.letterSpacing = computedStyle.letterSpacing;
76
- sizerRef.current.style.textTransform = computedStyle.textTransform;
77
- }
78
-
79
- if (placeholderSizerRef.current) {
80
- placeholderSizerRef.current.style.fontSize = computedStyle.fontSize;
81
- placeholderSizerRef.current.style.fontFamily = computedStyle.fontFamily;
82
- placeholderSizerRef.current.style.fontWeight = computedStyle.fontWeight;
83
- placeholderSizerRef.current.style.fontStyle = computedStyle.fontStyle;
84
- placeholderSizerRef.current.style.letterSpacing = computedStyle.letterSpacing;
85
- placeholderSizerRef.current.style.textTransform = computedStyle.textTransform;
86
- }
87
- }
88
- };
89
-
90
- var updateInputWidth = function updateInputWidth() {
91
- var _sizerRef$current, _placeholderSizerRef$;
92
-
93
- var sizerWidth = (_sizerRef$current = sizerRef.current) == null ? void 0 : _sizerRef$current.scrollWidth;
94
- var placeholderWidth = (_placeholderSizerRef$ = placeholderSizerRef.current) == null ? void 0 : _placeholderSizerRef$.scrollWidth;
95
-
96
- if (sizerWidth && usedValue.length) {
97
- /* If the input field has content, update the sizer to match its width */
98
- var width = sizerWidth;
99
-
100
- if (placeholderIsMinWidth && placeholderWidth && sizerWidth < placeholderWidth && placeholderSizerRef.current) {
101
- width = placeholderWidth;
102
- }
103
-
104
- if (width < +minWidth) {
105
- width = +minWidth;
106
- }
107
-
108
- if (width) {
109
- setInputWidth(width + +extraWidth);
110
- if (onAutosize) onAutosize(width);
111
- }
112
- } else if (props.placeholder && placeholderWidth) {
113
- /* If no input value exists, check for placeholder value and update the sizer accordingly */
114
- setInputWidth(Math.max(+minWidth, placeholderWidth) + +extraWidth);
115
- if (onAutosize) onAutosize(placeholderWidth);
116
- } else if (sizerRef.current) {
117
- /* If no input value or placeholder exists, update the sizer to the width of the "minWidth" + "extraWidth" prop (default is 16) */
118
- setInputWidth(+minWidth + +extraWidth);
119
- if (onAutosize) onAutosize(+minWidth);
120
- }
121
- };
122
- /* Copy styles of the input field to the sizer, ensuring that the width of the input adjusts accordingly */
123
-
124
-
125
- useLayoutEffect(function () {
126
- copyInputStyles();
127
- }, []);
128
- useEffect(updateInputWidth, [usedValue, props.placeholder, extraWidth, placeholderIsMinWidth, onAutosize, setInputWidth, minWidth, updatedPlaceholderWidth, updatedSizerWidth]);
129
- useImperativeHandle(forwardedRef, function () {
130
- return {
131
- inputRef: inputRef,
132
- sizerRef: sizerRef,
133
- placeholderSizerRef: placeholderSizerRef,
134
- copyInputStyles: copyInputStyles,
135
- updateInputWidth: updateInputWidth
136
- };
137
- });
138
-
139
- var wrapperStyle = _objectSpread({}, wrapperStyleProp, {
140
- position: 'relative',
141
- display: (_props$style$display = (_props$style = props.style) == null ? void 0 : _props$style.display) != null ? _props$style$display : 'inline-block'
142
- });
143
-
144
- var inputStyle = _objectSpread({
145
- boxSizing: 'content-box',
146
- width: inputWidth
147
- }, props.style);
148
-
149
- return /*#__PURE__*/React.createElement("div", {
150
- className: wrapperClassName,
151
- style: wrapperStyle,
152
- "data-testid": "wrapper"
153
- }, /*#__PURE__*/React.createElement("div", {
154
- style: sizerStyle,
155
- ref: sizerRef,
156
- "data-testid": "sizer"
157
- }, usedValue), /*#__PURE__*/React.createElement("input", _extends({}, props, {
158
- ref: inputRef,
159
- value: usedValue,
160
- style: inputStyle,
161
- onChange: handleInput,
162
- "data-testid": "input"
163
- })), props.placeholder ? /*#__PURE__*/React.createElement("div", {
164
- ref: placeholderSizerRef,
165
- style: sizerStyle,
166
- "data-testid": "placeholder-sizer"
167
- }, props.placeholder) : null);
168
- });
169
- export default AutosizeInput;