@synerise/ds-autocomplete 0.6.4 → 0.7.1
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 +19 -0
- package/README.md +24 -1
- package/dist/Autocomplete.js +49 -6
- package/dist/Autocomplete.styles.d.ts +2 -10
- package/dist/Autocomplete.styles.js +2 -12
- package/dist/Autocomplete.types.d.ts +3 -4
- package/package.json +4 -4
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.1](https://github.com/Synerise/synerise-design/compare/@synerise/ds-autocomplete@0.7.0...@synerise/ds-autocomplete@0.7.1) (2024-03-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @synerise/ds-autocomplete
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [0.7.0](https://github.com/Synerise/synerise-design/compare/@synerise/ds-autocomplete@0.6.4...@synerise/ds-autocomplete@0.7.0) (2024-03-05)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* **input:** support autoresize to stretch to parent ([329c866](https://github.com/Synerise/synerise-design/commit/329c866cb54921ad1260ae217cb8c471e43b986e))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
## [0.6.4](https://github.com/Synerise/synerise-design/compare/@synerise/ds-autocomplete@0.6.3...@synerise/ds-autocomplete@0.6.4) (2024-02-21)
|
|
7
26
|
|
|
8
27
|
**Note:** Version bump only for package @synerise/ds-autocomplete
|
package/README.md
CHANGED
|
@@ -57,4 +57,27 @@ import Autocomplete from '@synerise/ds-autocomplete'
|
|
|
57
57
|
| errorText | error message, if provided input will be set in error state | string | - |
|
|
58
58
|
| label | input label | string | - |
|
|
59
59
|
| description | input description | string | - |
|
|
60
|
-
| autoResize | 'resize' width of the input based on width of the text in input |
|
|
60
|
+
| autoResize | 'resize' width of the input based on width of the text in input | AutoResizeProp | undefined |
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
#### AutoResizeProp
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
type AutoResizeProp = `boolean` | {
|
|
67
|
+
minWidth: string;
|
|
68
|
+
maxWidth?: string;
|
|
69
|
+
stretchToFit?: boolean
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
**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).
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
$flexItemSurroundingTheInput {
|
|
78
|
+
min-width: 0;
|
|
79
|
+
flex-grow: 1
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
See https://css-tricks.com/flexbox-truncated-text/ for more details.
|
package/dist/Autocomplete.js
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
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); }
|
|
2
2
|
|
|
3
|
+
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; }
|
|
4
|
+
|
|
5
|
+
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; }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
3
9
|
import React, { useRef, useEffect } from 'react';
|
|
4
10
|
import '@synerise/ds-core/dist/js/style';
|
|
5
11
|
import "./style/index.css";
|
|
6
12
|
import AntdAutoComplete from 'antd/lib/auto-complete';
|
|
7
13
|
import { ErrorText, Description, Label } from '@synerise/ds-typography';
|
|
8
14
|
import { AutosizeInput } from '@synerise/ds-input';
|
|
15
|
+
import { useResizeToFit } from '@synerise/ds-utils';
|
|
9
16
|
import * as S from './Autocomplete.styles';
|
|
10
17
|
|
|
11
18
|
var Autocomplete = function Autocomplete(props) {
|
|
@@ -16,9 +23,11 @@ var Autocomplete = function Autocomplete(props) {
|
|
|
16
23
|
disabled = props.disabled,
|
|
17
24
|
error = props.error,
|
|
18
25
|
handleInputRef = props.handleInputRef,
|
|
26
|
+
getPopupContainer = props.getPopupContainer,
|
|
19
27
|
autoResize = props.autoResize,
|
|
20
28
|
readOnly = props.readOnly;
|
|
21
29
|
var inputRef = useRef(undefined);
|
|
30
|
+
var autocompleteInputRef = useRef(null);
|
|
22
31
|
useEffect(function () {
|
|
23
32
|
handleInputRef && handleInputRef(inputRef);
|
|
24
33
|
}, [inputRef, handleInputRef]);
|
|
@@ -34,25 +43,59 @@ var Autocomplete = function Autocomplete(props) {
|
|
|
34
43
|
return el.querySelector('input');
|
|
35
44
|
},
|
|
36
45
|
refPropName: 'inputRef',
|
|
37
|
-
extraWidth:
|
|
46
|
+
extraWidth: 25,
|
|
47
|
+
inputRef: function inputRef(_inputRef, originalInput) {
|
|
48
|
+
autocompleteInputRef.current = originalInput;
|
|
49
|
+
}
|
|
38
50
|
} : {};
|
|
39
|
-
return /*#__PURE__*/React.createElement(Component, _extends({}, autoResize ? {
|
|
51
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, autoResize ? _objectSpread({
|
|
40
52
|
renderInput: AntdAutoComplete,
|
|
41
|
-
autoResize: autoResize
|
|
42
|
-
|
|
43
|
-
} : {}, props, {
|
|
53
|
+
autoResize: autoResize
|
|
54
|
+
}, autosizeProps) : {}, props, {
|
|
44
55
|
// @ts-ignore
|
|
45
56
|
ref: inputRef,
|
|
46
57
|
disabled: readOnly || disabled,
|
|
47
58
|
dropdownClassName: "ds-autocomplete-dropdown ps__child--consume",
|
|
48
|
-
getPopupContainer: getParentNode
|
|
59
|
+
getPopupContainer: getPopupContainer || getParentNode
|
|
49
60
|
}));
|
|
50
61
|
};
|
|
51
62
|
|
|
63
|
+
var stretchToFit = typeof autoResize === 'object' && Boolean(autoResize.stretchToFit);
|
|
64
|
+
|
|
65
|
+
var _useResizeToFit = useResizeToFit({
|
|
66
|
+
onResize: function onResize(width) {
|
|
67
|
+
if (autocompleteInputRef.current) {
|
|
68
|
+
autocompleteInputRef.current.style.maxWidth = width + 5 + "px";
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
autoObserve: true
|
|
72
|
+
}),
|
|
73
|
+
observe = _useResizeToFit.observe,
|
|
74
|
+
disconnect = _useResizeToFit.disconnect,
|
|
75
|
+
elementRef = _useResizeToFit.elementRef;
|
|
76
|
+
|
|
77
|
+
useEffect(function () {
|
|
78
|
+
if (elementRef.current) {
|
|
79
|
+
if (stretchToFit) {
|
|
80
|
+
observe();
|
|
81
|
+
} else {
|
|
82
|
+
disconnect();
|
|
83
|
+
|
|
84
|
+
if (autocompleteInputRef.current) {
|
|
85
|
+
autocompleteInputRef.current.style.removeProperty('max-width');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return function () {
|
|
91
|
+
disconnect();
|
|
92
|
+
};
|
|
93
|
+
}, [disconnect, observe, stretchToFit, elementRef]);
|
|
52
94
|
return /*#__PURE__*/React.createElement(S.AutocompleteWrapper, {
|
|
53
95
|
autoResize: autoResize,
|
|
54
96
|
className: "ds-autocomplete " + (className || '')
|
|
55
97
|
}, label && /*#__PURE__*/React.createElement(S.LabelWrapper, null, /*#__PURE__*/React.createElement(Label, null, label)), /*#__PURE__*/React.createElement(S.ComponentWrapper, {
|
|
98
|
+
ref: elementRef,
|
|
56
99
|
readOnly: readOnly,
|
|
57
100
|
error: !!errorText || error
|
|
58
101
|
}, renderAutoCompleteComponent()), errorText && /*#__PURE__*/React.createElement(S.ErrorWrapper, null, /*#__PURE__*/React.createElement(ErrorText, null, errorText)), description && /*#__PURE__*/React.createElement(S.DescWrapper, null, description && /*#__PURE__*/React.createElement(Description, {
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
+
import { AutoResizeProp } from '@synerise/ds-input';
|
|
1
2
|
export declare const LabelWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
2
3
|
export declare const ErrorWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
4
|
export declare const DescWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
5
|
export declare const LoaderWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
|
-
export type AutoResizeProps = {
|
|
6
|
-
autoResize?: boolean | {
|
|
7
|
-
minWidth: string;
|
|
8
|
-
maxWidth: string;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
6
|
export declare const AutocompleteWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
12
|
-
autoResize?:
|
|
13
|
-
minWidth: string;
|
|
14
|
-
maxWidth: string;
|
|
15
|
-
} | undefined;
|
|
7
|
+
autoResize?: AutoResizeProp | undefined;
|
|
16
8
|
}, never>;
|
|
17
9
|
export declare const ComponentWrapper: import("styled-components").StyledComponent<"div", any, {
|
|
18
10
|
error?: boolean | undefined;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import styled, { css } from 'styled-components';
|
|
2
|
+
import { autoresizeConfObjToCss } from '@synerise/ds-input/dist/Input.styles';
|
|
2
3
|
export var LabelWrapper = styled.div.withConfig({
|
|
3
4
|
displayName: "Autocompletestyles__LabelWrapper",
|
|
4
5
|
componentId: "sc-10de6ms-0"
|
|
@@ -44,17 +45,6 @@ var readonly = function readonly() {
|
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
|
|
47
|
-
function autoresizeConfObjToCss(_ref) {
|
|
48
|
-
var autoResize = _ref.autoResize;
|
|
49
|
-
if (!autoResize) return '';
|
|
50
|
-
|
|
51
|
-
if (typeof autoResize === 'object') {
|
|
52
|
-
return "max-width: " + autoResize.maxWidth + "; min-width: " + autoResize.minWidth;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return "max-width: 400px; min-width: 150px;";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
48
|
export var AutocompleteWrapper = styled.div.withConfig({
|
|
59
49
|
displayName: "Autocompletestyles__AutocompleteWrapper",
|
|
60
50
|
componentId: "sc-10de6ms-4"
|
|
@@ -79,5 +69,5 @@ export var ComponentWrapper = styled.div.withConfig({
|
|
|
79
69
|
return css([".ant-select-selector{&:hover{", "}", "}"], error(), error());
|
|
80
70
|
}
|
|
81
71
|
|
|
82
|
-
return css(["&.ant-select{.ant-input{transition:ease-in-out all 0.3s;&:focus{", " &:hover{", "}}}}"], active(), active());
|
|
72
|
+
return css(["&.ant-select{.ant-select-selector{padding:0 10px;}.ant-input{transition:ease-in-out all 0.3s;&:focus{", " &:hover{", "}}}}"], active(), active());
|
|
83
73
|
});
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { ReactNode, MutableRefObject } from 'react';
|
|
2
2
|
import { AutoCompleteProps as OriginalProps } from 'antd/lib/auto-complete';
|
|
3
3
|
import Select from 'antd/lib/select';
|
|
4
|
+
import type { AutoResizeProp } from '@synerise/ds-input';
|
|
4
5
|
export type OverrideProps = {
|
|
5
6
|
className?: string;
|
|
6
7
|
errorText?: ReactNode | string;
|
|
7
8
|
label?: ReactNode | string;
|
|
8
9
|
description?: ReactNode | string;
|
|
9
10
|
error?: boolean;
|
|
11
|
+
getPopupContainer?: (node: HTMLElement) => HTMLElement;
|
|
10
12
|
readOnly?: boolean;
|
|
11
13
|
handleInputRef?: (ref: MutableRefObject<Select | undefined>) => void;
|
|
12
|
-
autoResize?:
|
|
13
|
-
minWidth: string;
|
|
14
|
-
maxWidth: string;
|
|
15
|
-
};
|
|
14
|
+
autoResize?: AutoResizeProp;
|
|
16
15
|
};
|
|
17
16
|
export type AutocompleteProps = OverrideProps & OriginalProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-autocomplete",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Autocomplete UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "Synerise/synerise-design",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"types": "dist/index.d.ts",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@synerise/ds-input": "^0.
|
|
36
|
+
"@synerise/ds-input": "^0.20.1",
|
|
37
37
|
"@synerise/ds-typography": "^0.14.3"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"styled-components": "5.0.1"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@synerise/ds-utils": "^0.
|
|
46
|
+
"@synerise/ds-utils": "^0.25.0",
|
|
47
47
|
"@testing-library/jest-dom": "5.1.1",
|
|
48
48
|
"@testing-library/react": "10.0.1"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "914ce4be2e0e1fe145edeca838ab04eaa1aec1bf"
|
|
51
51
|
}
|