@jobber/components 4.23.67-quick-use-.1 → 4.24.1-autocomple.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.
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import React from "react";
|
|
2
2
|
import { XOR } from "ts-xor";
|
|
3
3
|
import { GroupOption, Option } from "./Option";
|
|
4
|
+
import { InputTextRef } from "../InputText";
|
|
4
5
|
import { FormFieldProps } from "../FormField";
|
|
5
6
|
type OptionCollection = XOR<Option[], GroupOption[]>;
|
|
6
|
-
interface AutocompleteProps extends Pick<FormFieldProps, "
|
|
7
|
+
interface AutocompleteProps extends Pick<FormFieldProps, "inputRef" | "invalid" | "name" | "onBlur" | "onFocus" | "prefix" | "size" | "suffix" | "validations"> {
|
|
7
8
|
/**
|
|
8
9
|
* Initial options to show when user first focuses the Autocomplete
|
|
9
10
|
*/
|
|
@@ -40,9 +41,5 @@ interface AutocompleteProps extends Pick<FormFieldProps, "size" | "onBlur" | "on
|
|
|
40
41
|
*/
|
|
41
42
|
readonly placeholder: string;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
* Max statements disabled here to make room for the
|
|
45
|
-
* debounce functions.
|
|
46
|
-
*/
|
|
47
|
-
export declare function Autocomplete({ initialOptions, value, allowFreeForm, size, invalid, debounce: debounceRate, onChange, getOptions, placeholder, onBlur, onFocus, name, validations, }: AutocompleteProps): JSX.Element;
|
|
44
|
+
export declare const Autocomplete: React.ForwardRefExoticComponent<AutocompleteProps & React.RefAttributes<InputTextRef>>;
|
|
48
45
|
export {};
|
|
@@ -13,7 +13,7 @@ var reactPopper = require('react-popper');
|
|
|
13
13
|
var Text = require('../Text-e7ed0974.js');
|
|
14
14
|
var Icon = require('../Icon-405a216c.js');
|
|
15
15
|
var Heading = require('../Heading-a1191b15.js');
|
|
16
|
-
var InputText = require('../InputText-
|
|
16
|
+
var InputText = require('../InputText-c2a7f236.js');
|
|
17
17
|
require('../Typography-fd6f932a.js');
|
|
18
18
|
require('@jobber/design');
|
|
19
19
|
require('../FormField-090113ec.js');
|
|
@@ -145,16 +145,14 @@ function useRepositionMenu(attachTo, visible = false) {
|
|
|
145
145
|
return Object.assign(Object.assign({}, popper), { menuRef, setMenuRef, targetWidth });
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
function Autocomplete({ initialOptions = [], value, allowFreeForm = true, size = undefined, invalid, debounce: debounceRate = 300, onChange, getOptions, placeholder, onBlur, onFocus, name, validations, }) {
|
|
154
|
-
var _a;
|
|
148
|
+
// Max statements increased to make room for the debounce functions
|
|
149
|
+
/* eslint max-statements: ["error", 14] */
|
|
150
|
+
function AutocompleteInternal(_a, ref) {
|
|
151
|
+
var _b;
|
|
152
|
+
var { initialOptions = [], value, allowFreeForm = true, size = undefined, debounce: debounceRate = 300, onChange, getOptions, placeholder, onBlur, onFocus, validations } = _a, inputProps = tslib_es6.__rest(_a, ["initialOptions", "value", "allowFreeForm", "size", "debounce", "onChange", "getOptions", "placeholder", "onBlur", "onFocus", "validations"]);
|
|
155
153
|
const [options, setOptions] = React.useState(initialOptions);
|
|
156
154
|
const [menuVisible, setMenuVisible] = React.useState(false);
|
|
157
|
-
const [inputText, setInputText] = React.useState((
|
|
155
|
+
const [inputText, setInputText] = React.useState((_b = value === null || value === void 0 ? void 0 : value.label) !== null && _b !== void 0 ? _b : "");
|
|
158
156
|
const autocompleteRef = React.useRef(null);
|
|
159
157
|
const delayedSearch = debounce__default["default"](updateSearch, debounceRate);
|
|
160
158
|
React.useEffect(() => {
|
|
@@ -166,7 +164,7 @@ function Autocomplete({ initialOptions = [], value, allowFreeForm = true, size =
|
|
|
166
164
|
updateInput((_a = value === null || value === void 0 ? void 0 : value.label) !== null && _a !== void 0 ? _a : "");
|
|
167
165
|
}, [value]);
|
|
168
166
|
return (React__default["default"].createElement("div", { className: styles.autocomplete, ref: autocompleteRef },
|
|
169
|
-
React__default["default"].createElement(InputText.InputText, { autocomplete: false, size: size,
|
|
167
|
+
React__default["default"].createElement(InputText.InputText, Object.assign({ ref: ref, autocomplete: false, size: size, value: inputText, onChange: handleInputChange, placeholder: placeholder, onFocus: handleInputFocus, onBlur: handleInputBlur, validations: validations }, inputProps)),
|
|
170
168
|
menuVisible && (React__default["default"].createElement(Menu, { attachTo: autocompleteRef, visible: menuVisible && options.length > 0, options: options, selectedOption: value, onOptionSelect: handleMenuChange }))));
|
|
171
169
|
function updateInput(newText) {
|
|
172
170
|
setInputText(newText);
|
|
@@ -216,5 +214,6 @@ function mapToOptions(items) {
|
|
|
216
214
|
return result;
|
|
217
215
|
}, []);
|
|
218
216
|
}
|
|
217
|
+
const Autocomplete = React.forwardRef(AutocompleteInternal);
|
|
219
218
|
|
|
220
219
|
exports.Autocomplete = Autocomplete;
|
|
@@ -7,6 +7,11 @@ export interface InputTextRef {
|
|
|
7
7
|
insert(text: string): void;
|
|
8
8
|
blur(): void;
|
|
9
9
|
focus(): void;
|
|
10
|
+
scrollIntoView({ behavior, block, inline, }: {
|
|
11
|
+
behavior?: ScrollBehavior;
|
|
12
|
+
block?: ScrollLogicalPosition;
|
|
13
|
+
inline?: ScrollLogicalPosition;
|
|
14
|
+
}): void;
|
|
10
15
|
}
|
|
11
16
|
export declare const InputText: React.ForwardRefExoticComponent<({
|
|
12
17
|
readonly multiline: true;
|
package/dist/InputText/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var InputText = require('../InputText-
|
|
5
|
+
var InputText = require('../InputText-c2a7f236.js');
|
|
6
6
|
require('react');
|
|
7
7
|
require('../FormField-090113ec.js');
|
|
8
8
|
require('../tslib.es6-5b8768b7.js');
|
|
@@ -8,8 +8,8 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
8
8
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
9
9
|
|
|
10
10
|
function InputTextInternal(props, ref) {
|
|
11
|
-
const inputRef = React.
|
|
12
|
-
const actionsRef = React.
|
|
11
|
+
const inputRef = React.useRef(null);
|
|
12
|
+
const actionsRef = React.useRef(null);
|
|
13
13
|
const rowRange = getRowRange();
|
|
14
14
|
React.useImperativeHandle(ref, () => ({
|
|
15
15
|
insert: (text) => {
|
|
@@ -27,6 +27,12 @@ function InputTextInternal(props, ref) {
|
|
|
27
27
|
input.focus();
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
|
+
scrollIntoView: ({ behavior, block, inline }) => {
|
|
31
|
+
const input = inputRef.current;
|
|
32
|
+
if (input) {
|
|
33
|
+
input.scrollIntoView({ behavior, block, inline });
|
|
34
|
+
}
|
|
35
|
+
},
|
|
30
36
|
}));
|
|
31
37
|
React.useLayoutEffect(() => {
|
|
32
38
|
if (inputRef && inputRef.current instanceof HTMLTextAreaElement) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.24.1-autocomple.1+06412fec",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@jobber/design": "^0.44.4",
|
|
23
23
|
"@jobber/formatters": "^0.2.2",
|
|
24
|
-
"@jobber/hooks": "^2.1.
|
|
24
|
+
"@jobber/hooks": "^2.1.5",
|
|
25
25
|
"@popperjs/core": "^2.0.6",
|
|
26
26
|
"@std-proposal/temporal": "0.0.1",
|
|
27
27
|
"@tanstack/react-table": "8.5.13",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"> 1%",
|
|
84
84
|
"IE 10"
|
|
85
85
|
],
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "06412fec17ffca111043706527b356b04cacdb66"
|
|
87
87
|
}
|