@jobber/components 4.24.2 → 4.24.3-pre.4

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,15 +1,9 @@
1
- import React from "react";
1
+ /// <reference types="react" />
2
2
  import { XOR } from "ts-xor";
3
3
  import { GroupOption, Option } from "./Option";
4
- import { InputTextRef } from "../InputText";
5
4
  import { FormFieldProps } from "../FormField";
6
5
  type OptionCollection = XOR<Option[], GroupOption[]>;
7
- interface AutocompleteProps extends Pick<FormFieldProps, "invalid" | "name" | "onBlur" | "onFocus" | "prefix" | "size" | "suffix" | "validations"> {
8
- /**
9
- * @deprecated
10
- * Use `ref` instead.
11
- */
12
- readonly inputRef?: FormFieldProps["inputRef"];
6
+ interface AutocompleteProps extends Pick<FormFieldProps, "size" | "onBlur" | "onFocus" | "invalid" | "name" | "validations"> {
13
7
  /**
14
8
  * Initial options to show when user first focuses the Autocomplete
15
9
  */
@@ -46,5 +40,9 @@ interface AutocompleteProps extends Pick<FormFieldProps, "invalid" | "name" | "o
46
40
  */
47
41
  readonly placeholder: string;
48
42
  }
49
- export declare const Autocomplete: React.ForwardRefExoticComponent<AutocompleteProps & React.RefAttributes<InputTextRef>>;
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;
50
48
  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-c66e199a.js');
16
+ var InputText = require('../InputText-e9b345ff.js');
17
17
  require('../Typography-fd6f932a.js');
18
18
  require('@jobber/design');
19
19
  require('../FormField-090113ec.js');
@@ -145,14 +145,16 @@ function useRepositionMenu(attachTo, visible = false) {
145
145
  return Object.assign(Object.assign({}, popper), { menuRef, setMenuRef, targetWidth });
146
146
  }
147
147
 
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"]);
148
+ /**
149
+ * Max statements disabled here to make room for the
150
+ * debounce functions.
151
+ */
152
+ // eslint-disable-next-line max-statements
153
+ function Autocomplete({ initialOptions = [], value, allowFreeForm = true, size = undefined, invalid, debounce: debounceRate = 300, onChange, getOptions, placeholder, onBlur, onFocus, name, validations, }) {
154
+ var _a;
153
155
  const [options, setOptions] = React.useState(initialOptions);
154
156
  const [menuVisible, setMenuVisible] = React.useState(false);
155
- const [inputText, setInputText] = React.useState((_b = value === null || value === void 0 ? void 0 : value.label) !== null && _b !== void 0 ? _b : "");
157
+ const [inputText, setInputText] = React.useState((_a = value === null || value === void 0 ? void 0 : value.label) !== null && _a !== void 0 ? _a : "");
156
158
  const autocompleteRef = React.useRef(null);
157
159
  const delayedSearch = debounce__default["default"](updateSearch, debounceRate);
158
160
  React.useEffect(() => {
@@ -164,7 +166,7 @@ function AutocompleteInternal(_a, ref) {
164
166
  updateInput((_a = value === null || value === void 0 ? void 0 : value.label) !== null && _a !== void 0 ? _a : "");
165
167
  }, [value]);
166
168
  return (React__default["default"].createElement("div", { className: styles.autocomplete, ref: autocompleteRef },
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)),
169
+ React__default["default"].createElement(InputText.InputText, { autocomplete: false, size: size, invalid: invalid, value: inputText, onChange: handleInputChange, placeholder: placeholder, onFocus: handleInputFocus, onBlur: handleInputBlur, name: name, validations: validations }),
168
170
  menuVisible && (React__default["default"].createElement(Menu, { attachTo: autocompleteRef, visible: menuVisible && options.length > 0, options: options, selectedOption: value, onOptionSelect: handleMenuChange }))));
169
171
  function updateInput(newText) {
170
172
  setInputText(newText);
@@ -214,6 +216,5 @@ function mapToOptions(items) {
214
216
  return result;
215
217
  }, []);
216
218
  }
217
- const Autocomplete = React.forwardRef(AutocompleteInternal);
218
219
 
219
220
  exports.Autocomplete = Autocomplete;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var DatePicker = require('../DatePicker-38b0c40b.js');
5
+ var DatePicker = require('../DatePicker-940cdb21.js');
6
6
  require('react');
7
7
  require('classnames');
8
8
  require('react-datepicker');
@@ -68,6 +68,7 @@ function useFocusOnSelectedDate() {
68
68
  function DatePicker({ onChange, onMonthChange, activator, inline, selected, readonly = false, disabled = false, fullWidth = false, smartAutofocus = true, maxDate, minDate, highlightDates, }) {
69
69
  const { ref, focusOnSelectedDate } = useFocusOnSelectedDate();
70
70
  const [open, setOpen] = React.useState(false);
71
+ const { datePickerRef } = useDatePickerFocus(ref, open, inline);
71
72
  const wrapperClassName = classnames__default["default"](styles.datePickerWrapper, {
72
73
  // react-datepicker uses this class name to not close the date picker when
73
74
  // the activator is clicked
@@ -87,7 +88,7 @@ function DatePicker({ onChange, onMonthChange, activator, inline, selected, read
87
88
  React.useEffect(focusOnSelectedDate, [open]);
88
89
  }
89
90
  return (React__default["default"].createElement("div", { className: wrapperClassName, ref: ref },
90
- React__default["default"].createElement(ReactDatePicker__default["default"], { calendarClassName: datePickerClassNames, showPopperArrow: false, selected: selected, inline: inline, disabled: disabled, readOnly: readonly, onChange: handleChange, maxDate: maxDate, minDate: minDate, useWeekdaysShort: true, customInput: React__default["default"].createElement(DatePickerActivator, { activator: activator, fullWidth: fullWidth }), renderCustomHeader: props => React__default["default"].createElement(DatePickerCustomHeader, Object.assign({}, props)), onCalendarOpen: handleCalendarOpen, onCalendarClose: handleCalendarClose, dateFormat: ["P", "PP", "PPP", "MMM dd yyyy", "MMMM dd yyyy"], highlightDates: highlightDates, onMonthChange: onMonthChange })));
91
+ React__default["default"].createElement(ReactDatePicker__default["default"], { calendarClassName: datePickerClassNames, showPopperArrow: false, selected: selected, inline: inline, disabled: disabled, readOnly: readonly, enableTabLoop: false, onChange: handleChange, maxDate: maxDate, minDate: minDate, ref: datePickerRef, useWeekdaysShort: true, customInput: React__default["default"].createElement(DatePickerActivator, { activator: activator, fullWidth: fullWidth }), renderCustomHeader: props => React__default["default"].createElement(DatePickerCustomHeader, Object.assign({}, props)), onCalendarOpen: handleCalendarOpen, onCalendarClose: handleCalendarClose, dateFormat: ["P", "PP", "PPP", "MMM dd yyyy", "MMMM dd yyyy"], highlightDates: highlightDates, onMonthChange: onMonthChange })));
91
92
  /**
92
93
  * The onChange callback on ReactDatePicker returns a Date and an Event, but
93
94
  * the onChange in our interface only provides the Date. Simplifying the code
@@ -106,5 +107,31 @@ function DatePicker({ onChange, onMonthChange, activator, inline, selected, read
106
107
  setOpen(false);
107
108
  }
108
109
  }
110
+ function useDatePickerFocus(ref, open, inline) {
111
+ const datePickerRef = React.useRef(null);
112
+ const handleTabbing = (event) => {
113
+ setTimeout(() => {
114
+ var _a;
115
+ if (event.key === "Tab" &&
116
+ ref.current &&
117
+ !ref.current.contains(document.activeElement)) {
118
+ (_a = datePickerRef.current) === null || _a === void 0 ? void 0 : _a.setOpen(false);
119
+ }
120
+ }, 0);
121
+ };
122
+ React.useEffect(() => {
123
+ var _a;
124
+ if (!inline && open) {
125
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.addEventListener("keydown", handleTabbing);
126
+ }
127
+ return () => {
128
+ var _a;
129
+ (_a = ref.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("keydown", handleTabbing);
130
+ };
131
+ }, [open, ref, inline, handleTabbing]);
132
+ return {
133
+ datePickerRef,
134
+ };
135
+ }
109
136
 
110
137
  exports.DatePicker = DatePicker;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var omit = require('lodash/omit');
6
6
  var React = require('react');
7
7
  var FormField = require('../FormField-090113ec.js');
8
- var DatePicker = require('../DatePicker-38b0c40b.js');
8
+ var DatePicker = require('../DatePicker-940cdb21.js');
9
9
  require('../tslib.es6-5b8768b7.js');
10
10
  require('uuid');
11
11
  require('react-hook-form');
@@ -7,7 +7,6 @@ export interface InputTextRef {
7
7
  insert(text: string): void;
8
8
  blur(): void;
9
9
  focus(): void;
10
- scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
11
10
  }
12
11
  export declare const InputText: React.ForwardRefExoticComponent<({
13
12
  readonly multiline: true;
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var InputText = require('../InputText-c66e199a.js');
5
+ var InputText = require('../InputText-e9b345ff.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.useRef(null);
12
- const actionsRef = React.useRef(null);
11
+ const inputRef = React.createRef();
12
+ const actionsRef = React.createRef();
13
13
  const rowRange = getRowRange();
14
14
  React.useImperativeHandle(ref, () => ({
15
15
  insert: (text) => {
@@ -27,12 +27,6 @@ function InputTextInternal(props, ref) {
27
27
  input.focus();
28
28
  }
29
29
  },
30
- scrollIntoView: arg => {
31
- const input = inputRef.current;
32
- if (input) {
33
- input.scrollIntoView(arg);
34
- }
35
- },
36
30
  }));
37
31
  React.useLayoutEffect(() => {
38
32
  if (inputRef && inputRef.current instanceof HTMLTextAreaElement) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "4.24.2",
3
+ "version": "4.24.3-pre.4+f00e5e03",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@jobber/design": "^0.44.4",
23
- "@jobber/formatters": "*",
23
+ "@jobber/formatters": "^0.2.2",
24
24
  "@jobber/hooks": "^2.1.5",
25
25
  "@popperjs/core": "^2.0.6",
26
26
  "@std-proposal/temporal": "0.0.1",
@@ -83,5 +83,5 @@
83
83
  "> 1%",
84
84
  "IE 10"
85
85
  ],
86
- "gitHead": "2a7429f445c7d4af80b9706b05796d62bc810bc9"
86
+ "gitHead": "f00e5e03b772ed91cc48ebe14a664cb4ee6116a1"
87
87
  }