@jobber/components 6.5.2 → 6.5.4-MIKEpull--7b61b13.30
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/dist/Autocomplete/index.cjs +1 -1
- package/dist/Autocomplete/index.mjs +1 -1
- package/dist/DataList/components/DataListSearch/index.cjs +2 -2
- package/dist/DataList/components/DataListSearch/index.mjs +2 -2
- package/dist/DataTable/index.cjs +1 -1
- package/dist/DataTable/index.mjs +1 -1
- package/dist/FormField/FormFieldAffix.d.ts +2 -2
- package/dist/FormField/FormFieldDescription.d.ts +3 -2
- package/dist/FormField/FormFieldPostFix.d.ts +2 -1
- package/dist/FormField/FormFieldTypes.d.ts +5 -0
- package/dist/FormField/FormFieldWrapper.d.ts +28 -3
- package/dist/FormField/components/ClearAction.d.ts +3 -1
- package/dist/FormField/hooks/useAtlantisFormField.d.ts +91 -0
- package/dist/FormField/hooks/useAtlantisFormFieldActions.d.ts +22 -0
- package/dist/FormField/hooks/useAtlantisFormFieldName.d.ts +6 -0
- package/dist/FormField/hooks/useAtlantisReactHookForm.d.ts +19 -0
- package/dist/FormField/hooks/useFormFieldWrapperStyles.d.ts +29 -0
- package/dist/FormField/index.cjs +9 -3
- package/dist/FormField/index.d.ts +6 -0
- package/dist/FormField/index.mjs +4 -4
- package/dist/FormField-cjs.js +264 -121
- package/dist/FormField-es.js +260 -123
- package/dist/InputDate/index.cjs +2 -2
- package/dist/InputDate/index.mjs +2 -2
- package/dist/InputDate-cjs.js +6 -0
- package/dist/InputDate-es.js +7 -1
- package/dist/InputEmail/index.cjs +3 -3
- package/dist/InputEmail/index.mjs +3 -3
- package/dist/InputEmail-cjs.js +6 -0
- package/dist/InputEmail-es.js +7 -1
- package/dist/InputNumber/index.cjs +3 -3
- package/dist/InputNumber/index.mjs +3 -3
- package/dist/InputNumber-cjs.js +6 -0
- package/dist/InputNumber-es.js +7 -1
- package/dist/InputPassword/index.cjs +3 -3
- package/dist/InputPassword/index.mjs +3 -3
- package/dist/InputPassword-cjs.js +6 -0
- package/dist/InputPassword-es.js +7 -1
- package/dist/InputPhoneNumber/index.cjs +1 -1
- package/dist/InputPhoneNumber/index.mjs +1 -1
- package/dist/InputPhoneNumber-cjs.js +4 -0
- package/dist/InputPhoneNumber-es.js +5 -1
- package/dist/InputText/InputText.d.ts +2 -0
- package/dist/InputText/index.cjs +3 -3
- package/dist/InputText/index.mjs +3 -3
- package/dist/InputText-cjs.js +6 -0
- package/dist/InputText-es.js +7 -1
- package/dist/InputTime/index.cjs +2 -2
- package/dist/InputTime/index.mjs +2 -2
- package/dist/InputTime-cjs.js +5 -0
- package/dist/InputTime-es.js +6 -1
- package/dist/InputValidation/InputValidation.d.ts +2 -1
- package/dist/InputValidation-cjs.js +3 -1
- package/dist/InputValidation-es.js +3 -1
- package/dist/Option-cjs.js +6 -0
- package/dist/Option-es.js +7 -1
- package/dist/RecurringSelect/index.cjs +2 -2
- package/dist/RecurringSelect/index.mjs +2 -2
- package/dist/Select/index.cjs +3 -3
- package/dist/Select/index.mjs +3 -3
- package/dist/index.cjs +6 -0
- package/dist/index.mjs +1 -1
- package/dist/utils/meta/meta.json +2 -1
- package/package.json +2 -2
package/dist/FormField-es.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, { useRef, useState, useEffect, useId, useImperativeHandle } from 'react';
|
|
3
|
-
import { useFormContext, useForm, useController } from 'react-hook-form';
|
|
4
|
-
import classnames from 'classnames';
|
|
1
|
+
import React, { useState, useEffect, useRef, useImperativeHandle, useId } from 'react';
|
|
5
2
|
import { AnimatePresence, motion } from 'framer-motion';
|
|
6
3
|
import { tokens } from '@jobber/design';
|
|
4
|
+
import classnames from 'classnames';
|
|
7
5
|
import { B as Button } from './Button-es.js';
|
|
8
6
|
import { I as Icon } from './Icon-es.js';
|
|
9
7
|
import { T as Text } from './Text-es.js';
|
|
10
8
|
import { u as useFormFieldFocus } from './useFormFieldFocus-es.js';
|
|
11
9
|
import { I as InputValidation } from './InputValidation-es.js';
|
|
12
10
|
import { S as Spinner } from './Spinner-es.js';
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
import { _ as __rest } from './tslib.es6-es.js';
|
|
12
|
+
import { useFormContext, useForm, useController } from 'react-hook-form';
|
|
15
13
|
|
|
16
14
|
var useShowClear$1 = {};
|
|
17
15
|
|
|
@@ -33,10 +31,14 @@ function useShowClear({ clearable, multiline, focused, hasValue, disabled = fals
|
|
|
33
31
|
}
|
|
34
32
|
}
|
|
35
33
|
|
|
34
|
+
var styles$1 = {"container":"YL-mNv-Bl6g-","wrapper":"_8lhbGTQ-hhg-","horizontalWrapper":"b5mv1x1H7YE-","textarea":"hGr6YW4AeLM-","safari":"QBCWi9GBgMs-","timeInputLabel":"_0pmqVa2zSE4-","miniLabel":"F1t76G6bDKo-","large":"_9tjyT9QUtP8-","text":"QmMiyoAWp-g-","invalid":"XWDSfe6weSY-","disabled":"Tz9LK9ABKMk-","small":"Sw5O4I0lMJg-","inline":"SaORbL7SYWY-","center":"ozy2UoT2vsg-","right":"_3TJdT91YD3c-","maxLength":"W6GrMqLy2qk-","inputWrapper":"-LmjnYRU0r0-","childrenWrapper":"yVXYv6hkuOA-","input":"vtSDcuzNr9Q-","label":"Dgk00tzlODA-","select":"NwQGiWBWIsc-","postfix":"yTDzs9h1otI-","affixIcon":"m0YpdssD2dY-","suffix":"_-3mMnjSh6ok-","hasAction":"OLE9N3Uem4o-","affixLabel":"-Wzcb0pBh5I-","description":"DHX5ijY3xIw-","toolbar":"AL-2brNI7dk-","spinning":"_8Rzv7CcDW80-"};
|
|
35
|
+
|
|
36
36
|
function AffixLabel({ label, variation = "prefix", labelRef, }) {
|
|
37
37
|
const affixLabelClass = classnames(styles$1.affixLabel, {
|
|
38
38
|
[styles$1.suffix]: variation === "suffix",
|
|
39
39
|
});
|
|
40
|
+
if (!label)
|
|
41
|
+
return null;
|
|
40
42
|
return (React.createElement("div", { ref: labelRef, className: affixLabelClass }, label));
|
|
41
43
|
}
|
|
42
44
|
function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
|
|
@@ -46,7 +48,7 @@ function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
|
|
|
46
48
|
});
|
|
47
49
|
const iconSize = size === "small" ? "small" : "base";
|
|
48
50
|
if (!icon)
|
|
49
|
-
return
|
|
51
|
+
return null;
|
|
50
52
|
return (React.createElement("div", { className: affixIconClass }, onClick ? (React.createElement(Button
|
|
51
53
|
/**
|
|
52
54
|
* We can cast the ariaLabel here as a `Suffix`
|
|
@@ -60,14 +62,18 @@ function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
|
|
|
60
62
|
ariaLabel: ariaLabel, icon: icon, onClick: onClick, variation: "subtle", type: "tertiary", size: iconSize })) : (React.createElement(Icon, { name: icon, size: iconSize, color: "greyBlue" }))));
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
function FormFieldDescription({ id, description, }) {
|
|
65
|
+
function FormFieldDescription({ id, description, visible = true, }) {
|
|
66
|
+
if (!visible)
|
|
67
|
+
return null;
|
|
64
68
|
return (React.createElement("div", { id: id, className: styles$1.description },
|
|
65
69
|
React.createElement(Text, { size: "small", variation: "subdued" }, description)));
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
var styles = {"clearInput":"YmRTd-KeXv4-","spinning":"B25z9B8I3gs-"};
|
|
69
73
|
|
|
70
|
-
function ClearAction({ onClick }) {
|
|
74
|
+
function ClearAction({ onClick, visible, }) {
|
|
75
|
+
if (!visible)
|
|
76
|
+
return null;
|
|
71
77
|
return (React.createElement("button", { className: styles.clearInput, onClick: onClick, type: "button", "aria-label": "Clear input" },
|
|
72
78
|
React.createElement(Icon, { name: "remove", size: "small" })));
|
|
73
79
|
}
|
|
@@ -90,8 +96,10 @@ function useIsSafari() {
|
|
|
90
96
|
: false;
|
|
91
97
|
}
|
|
92
98
|
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Hook for getting the correct styles for the FormField and its children
|
|
101
|
+
*/
|
|
102
|
+
function useFormFieldWrapperStyles({ size, align, placeholder, value, invalid, error, max, prefixRef, suffixRef, maxLength, type, disabled, inline, }) {
|
|
95
103
|
const isSafari = useIsSafari();
|
|
96
104
|
const wrapperClasses = classnames(styles$1.wrapper, size && styles$1[size], align && styles$1[align], {
|
|
97
105
|
[styles$1.miniLabel]: (placeholder && value !== "") ||
|
|
@@ -113,15 +121,67 @@ function FormFieldWrapper({ align, description, descriptionIdentifier, placehold
|
|
|
113
121
|
const wrapperInlineStyle = {
|
|
114
122
|
["--formField-maxLength"]: maxLength || max,
|
|
115
123
|
};
|
|
116
|
-
const prefixRef = useRef();
|
|
117
|
-
const suffixRef = useRef();
|
|
118
124
|
const [labelStyle, setLabelStyle] = useState({
|
|
119
125
|
paddingLeft: undefined,
|
|
120
126
|
paddingRight: undefined,
|
|
121
127
|
});
|
|
122
128
|
useEffect(() => {
|
|
123
|
-
|
|
129
|
+
var _a, _b;
|
|
130
|
+
setLabelStyle(getAffixPaddding({
|
|
131
|
+
value,
|
|
132
|
+
type,
|
|
133
|
+
prefixWidth: ((_a = prefixRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0,
|
|
134
|
+
suffixWidth: ((_b = suffixRef.current) === null || _b === void 0 ? void 0 : _b.offsetWidth) || 0,
|
|
135
|
+
}));
|
|
124
136
|
}, [value]);
|
|
137
|
+
return {
|
|
138
|
+
inputStyle: styles$1.input,
|
|
139
|
+
wrapperClasses,
|
|
140
|
+
containerClasses,
|
|
141
|
+
wrapperInlineStyle,
|
|
142
|
+
labelStyle,
|
|
143
|
+
setLabelStyle,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function getAffixPaddding({ value, type, prefixWidth, suffixWidth, }) {
|
|
147
|
+
const hasValue = value !== "";
|
|
148
|
+
const newPadding = {
|
|
149
|
+
paddingLeft: undefined,
|
|
150
|
+
paddingRight: undefined,
|
|
151
|
+
};
|
|
152
|
+
// Naively assume that if the the type is tel, it is the InputPhoneNumber
|
|
153
|
+
if (type === "tel")
|
|
154
|
+
return newPadding;
|
|
155
|
+
if (prefixWidth && !hasValue) {
|
|
156
|
+
newPadding.paddingLeft = offset(prefixWidth);
|
|
157
|
+
}
|
|
158
|
+
if (suffixWidth && !hasValue) {
|
|
159
|
+
newPadding.paddingRight = offset(suffixWidth);
|
|
160
|
+
}
|
|
161
|
+
function offset(width) {
|
|
162
|
+
return `calc(${width}px + var(--space-smallest)`;
|
|
163
|
+
}
|
|
164
|
+
return newPadding;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function FormFieldWrapper({ align, description, descriptionIdentifier, placeholder, value, children, invalid, error, size, prefix, suffix, max, maxLength, type, disabled, inline, identifier, clearable, onClear, toolbar, toolbarVisibility = "while-editing", wrapperRef, }) {
|
|
168
|
+
const prefixRef = useRef();
|
|
169
|
+
const suffixRef = useRef();
|
|
170
|
+
const { wrapperClasses, containerClasses, wrapperInlineStyle, labelStyle } = useFormFieldWrapperStyles({
|
|
171
|
+
align,
|
|
172
|
+
max,
|
|
173
|
+
maxLength,
|
|
174
|
+
prefixRef,
|
|
175
|
+
suffixRef,
|
|
176
|
+
placeholder,
|
|
177
|
+
value,
|
|
178
|
+
invalid,
|
|
179
|
+
error,
|
|
180
|
+
type,
|
|
181
|
+
disabled,
|
|
182
|
+
inline,
|
|
183
|
+
size,
|
|
184
|
+
});
|
|
125
185
|
const { focused } = useFormFieldFocus({ wrapperRef });
|
|
126
186
|
const showClear = useShowClear_2({
|
|
127
187
|
clearable,
|
|
@@ -137,50 +197,124 @@ function FormFieldWrapper({ align, description, descriptionIdentifier, placehold
|
|
|
137
197
|
});
|
|
138
198
|
return (React.createElement("div", { className: containerClasses },
|
|
139
199
|
React.createElement("div", { className: wrapperClasses, style: wrapperInlineStyle, "data-testid": "Form-Field-Wrapper", ref: wrapperRef },
|
|
140
|
-
React.createElement(
|
|
141
|
-
|
|
142
|
-
React.createElement(
|
|
143
|
-
|
|
200
|
+
React.createElement(FormFieldInputHorizontalWrapper, null,
|
|
201
|
+
React.createElement(AffixIcon, Object.assign({}, prefix, { size: size })),
|
|
202
|
+
React.createElement(FormFieldInputWrapperStyles, null,
|
|
203
|
+
React.createElement(FormFieldLabel, { placeholder: placeholder, identifier: identifier, style: (prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) || (suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current)
|
|
144
204
|
? labelStyle
|
|
145
|
-
: undefined }
|
|
146
|
-
|
|
147
|
-
React.createElement(
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
React.createElement(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
205
|
+
: undefined }),
|
|
206
|
+
React.createElement(AffixLabel, Object.assign({}, prefix, { labelRef: prefixRef })),
|
|
207
|
+
React.createElement(FormFieldWrapperMain, null, children),
|
|
208
|
+
React.createElement(AffixLabel, Object.assign({}, suffix, { labelRef: suffixRef, variation: "suffix" }))),
|
|
209
|
+
React.createElement(ClearAction, { onClick: onClear, visible: showClear }),
|
|
210
|
+
React.createElement(AffixIcon, Object.assign({}, suffix, { variation: "suffix", size: size }))),
|
|
211
|
+
React.createElement(FormFieldWrapperToolbar, { toolbarVisibility: toolbarVisibility, isToolbarVisible: isToolbarVisible, toolbarAnimationEnd: toolbarAnimationEnd, toolbarAnimationStart: toolbarAnimationStart, toolbar: toolbar })),
|
|
212
|
+
React.createElement(FormFieldDescription, { visible: !!description && !inline, id: descriptionIdentifier, description: description }),
|
|
213
|
+
React.createElement(InputValidation, { message: error, visible: !!error && !inline })));
|
|
214
|
+
}
|
|
215
|
+
function FormFieldInputHorizontalWrapper({ children, }) {
|
|
216
|
+
return React.createElement("div", { className: styles$1.horizontalWrapper }, children);
|
|
217
|
+
}
|
|
218
|
+
function FormFieldInputWrapperStyles({ children, }) {
|
|
219
|
+
return React.createElement("div", { className: styles$1.inputWrapper }, children);
|
|
220
|
+
}
|
|
221
|
+
function FormFieldWrapperMain({ children, tabIndex = -1, }) {
|
|
222
|
+
return (React.createElement("div", { className: styles$1.childrenWrapper, tabIndex: tabIndex }, children));
|
|
223
|
+
}
|
|
224
|
+
function FormFieldLabel({ placeholder, identifier, style, }) {
|
|
225
|
+
if (!placeholder)
|
|
226
|
+
return null;
|
|
227
|
+
return (React.createElement("label", { className: styles$1.label, htmlFor: identifier, style: style }, placeholder));
|
|
228
|
+
}
|
|
229
|
+
function FormFieldWrapperToolbar({ toolbar, isToolbarVisible, toolbarAnimationEnd, toolbarAnimationStart, toolbarVisibility, }) {
|
|
230
|
+
return (React.createElement(AnimatePresence, { initial: toolbarVisibility === "always" ? false : true }, isToolbarVisible && (React.createElement(motion.div, { key: "toolbar", initial: toolbarAnimationEnd, animate: toolbarAnimationStart, exit: toolbarAnimationEnd, transition: {
|
|
231
|
+
duration: tokens["timing-base"] / 1000,
|
|
232
|
+
ease: "easeInOut",
|
|
233
|
+
}, tabIndex: -1 },
|
|
234
|
+
React.createElement("div", { className: styles$1.toolbar, "data-testid": "ATL-InputText-Toolbar" }, toolbar)))));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function FormFieldPostFix({ variation, visible = true, }) {
|
|
238
|
+
if (!visible)
|
|
239
|
+
return null;
|
|
240
|
+
return (React.createElement("span", { className: styles$1.postfix }, variation === "select" ? (React.createElement(Icon, { name: "arrowDown" })) : (React.createElement(Spinner, { size: "small" }))));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Combines the actions from the props of the FormField with the actions from react-hook-form. This is used to
|
|
245
|
+
* manage the form state of a field through react-hook-form while providing support for additional callbacks
|
|
246
|
+
*/
|
|
247
|
+
function useAtlantisFormFieldActions({ name, onChange, inputRef, onControllerChange, onControllerBlur, onEnter, readonly, type, setValue, onFocus, onBlur, onValidation, }) {
|
|
248
|
+
function handleClear() {
|
|
249
|
+
var _a;
|
|
250
|
+
handleBlur();
|
|
251
|
+
setValue(name, "", { shouldValidate: true });
|
|
252
|
+
onChange && onChange("");
|
|
253
|
+
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
254
|
+
}
|
|
255
|
+
function handleChange(event) {
|
|
256
|
+
let newValue;
|
|
257
|
+
newValue = event.currentTarget.value;
|
|
258
|
+
if (type === "number" && newValue.length > 0) {
|
|
259
|
+
newValue = parseFloat(newValue);
|
|
174
260
|
}
|
|
175
|
-
|
|
176
|
-
|
|
261
|
+
onChange && onChange(newValue, event);
|
|
262
|
+
onControllerChange(event);
|
|
263
|
+
}
|
|
264
|
+
function handleKeyDown(event) {
|
|
265
|
+
if (!onEnter)
|
|
266
|
+
return;
|
|
267
|
+
if (event.key !== "Enter")
|
|
268
|
+
return;
|
|
269
|
+
if (event.shiftKey || event.ctrlKey)
|
|
270
|
+
return;
|
|
271
|
+
event.preventDefault();
|
|
272
|
+
onEnter && onEnter(event);
|
|
273
|
+
}
|
|
274
|
+
function handleFocus(event) {
|
|
275
|
+
const target = event.currentTarget;
|
|
276
|
+
if (target.select) {
|
|
277
|
+
setTimeout(() => readonly && target.select());
|
|
177
278
|
}
|
|
178
|
-
|
|
279
|
+
onFocus && onFocus();
|
|
280
|
+
}
|
|
281
|
+
function handleBlur() {
|
|
282
|
+
onBlur && onBlur();
|
|
283
|
+
onControllerBlur();
|
|
284
|
+
}
|
|
285
|
+
function handleValidation(message) {
|
|
286
|
+
onValidation && onValidation(message);
|
|
179
287
|
}
|
|
288
|
+
return {
|
|
289
|
+
handleClear,
|
|
290
|
+
handleChange,
|
|
291
|
+
handleKeyDown,
|
|
292
|
+
handleFocus,
|
|
293
|
+
handleBlur,
|
|
294
|
+
handleValidation,
|
|
295
|
+
};
|
|
180
296
|
}
|
|
181
297
|
|
|
182
|
-
|
|
183
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Provides the props for the html fields rendered by the FormField component
|
|
300
|
+
*/
|
|
301
|
+
function useAtlantisFormField({ id, nameProp, name, useControllerField: useControllerField, description, disabled, readonly, keyboard, autofocus, handleChange, handleBlur, handleFocus, inline, validations, handleKeyDown, handleValidation, errorMessage, }) {
|
|
302
|
+
const descriptionIdentifier = `descriptionUUID--${id}`;
|
|
303
|
+
const fieldProps = Object.assign(Object.assign(Object.assign({}, useControllerField), { id, className: styles$1.input, name: (validations || nameProp) && name, disabled: disabled, readOnly: readonly, inputMode: keyboard, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, autoFocus: autofocus }), (description &&
|
|
304
|
+
!inline && { "aria-describedby": descriptionIdentifier }));
|
|
305
|
+
const textFieldProps = Object.assign(Object.assign({}, fieldProps), { autoFocus: autofocus, onKeyDown: handleKeyDown });
|
|
306
|
+
useEffect(() => handleValidation(errorMessage), [errorMessage]);
|
|
307
|
+
return { textFieldProps, fieldProps, descriptionIdentifier };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function useAtlantisFormFieldName({ id, nameProp, }) {
|
|
311
|
+
/**
|
|
312
|
+
* Generate a name if one is not supplied, this is the name
|
|
313
|
+
* that will be used for react-hook-form and not neccessarily
|
|
314
|
+
* attached to the DOM
|
|
315
|
+
*/
|
|
316
|
+
const name = nameProp ? nameProp : `generatedName--${id}`;
|
|
317
|
+
return { name };
|
|
184
318
|
}
|
|
185
319
|
|
|
186
320
|
/**
|
|
@@ -200,50 +334,93 @@ function mergeRefs(refs) {
|
|
|
200
334
|
};
|
|
201
335
|
}
|
|
202
336
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const id = useId();
|
|
208
|
-
return React.createElement(FormFieldInternal, Object.assign({}, props, { id: id }));
|
|
209
|
-
}
|
|
210
|
-
// eslint-disable-next-line max-statements
|
|
211
|
-
function FormFieldInternal(props) {
|
|
337
|
+
/**
|
|
338
|
+
* Hook used to manage the form state of a field through react-hook-form
|
|
339
|
+
*/
|
|
340
|
+
function useAtlantisReactForm({ actionsRef, name, defaultValue, value, validations, inputRef, }) {
|
|
212
341
|
var _a;
|
|
213
|
-
const { actionsRef, autocomplete = true, children, defaultValue, description, disabled, id, inputRef, inline, keyboard, max, maxLength, min, name: nameProp, readonly, rows, loading, type = "text", validations, value, onChange, onEnter, onFocus, onBlur, onValidation, onKeyUp, clearable = "never", autofocus, } = props;
|
|
214
342
|
const formContext = useFormContext();
|
|
215
343
|
// If there isn't a Form Context being provided, get a form for this field.
|
|
216
344
|
const { control, setValue, watch } = formContext !== null && formContext !== void 0 ? formContext : useForm({ mode: "onTouched" });
|
|
217
|
-
const descriptionIdentifier = `descriptionUUID--${id}`;
|
|
218
|
-
/**
|
|
219
|
-
* Generate a name if one is not supplied, this is the name
|
|
220
|
-
* that will be used for react-hook-form and not neccessarily
|
|
221
|
-
* attached to the DOM
|
|
222
|
-
*/
|
|
223
|
-
const name = nameProp ? nameProp : `generatedName--${id}`;
|
|
224
|
-
useEffect(() => {
|
|
225
|
-
if (value != undefined) {
|
|
226
|
-
setValue(name, value);
|
|
227
|
-
}
|
|
228
|
-
}, [value, watch(name)]);
|
|
229
345
|
useImperativeHandle(actionsRef, () => ({
|
|
230
346
|
setValue: newValue => {
|
|
231
347
|
setValue(name, newValue, { shouldValidate: true });
|
|
232
348
|
},
|
|
233
349
|
}));
|
|
234
|
-
const
|
|
350
|
+
const { field, fieldState: { error }, } = useController({
|
|
235
351
|
name,
|
|
236
352
|
control,
|
|
237
353
|
rules: validations,
|
|
238
354
|
defaultValue: (_a = value !== null && value !== void 0 ? value : defaultValue) !== null && _a !== void 0 ? _a : "",
|
|
239
|
-
})
|
|
240
|
-
const
|
|
241
|
-
useEffect(() =>
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
355
|
+
});
|
|
356
|
+
const { onChange, onBlur, ref: fieldRef } = field, useControllerField = __rest(field, ["onChange", "onBlur", "ref"]);
|
|
357
|
+
useEffect(() => {
|
|
358
|
+
if (value != undefined) {
|
|
359
|
+
setValue(name, value);
|
|
360
|
+
}
|
|
361
|
+
}, [value, watch(name)]);
|
|
245
362
|
const inputRefs = mergeRefs([inputRef, fieldRef]);
|
|
246
|
-
return
|
|
363
|
+
return {
|
|
364
|
+
inputRefs,
|
|
365
|
+
useControllerField,
|
|
366
|
+
setValue,
|
|
367
|
+
errorMessage: (error === null || error === void 0 ? void 0 : error.message) || "",
|
|
368
|
+
onControllerChange: onChange,
|
|
369
|
+
onControllerBlur: onBlur,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function FormField(props) {
|
|
374
|
+
// Warning: do not move useId into FormFieldInternal. This must be here to avoid
|
|
375
|
+
// a problem where useId isn't stable across multiple StrictMode renders.
|
|
376
|
+
// https://github.com/facebook/react/issues/27103
|
|
377
|
+
const id = useId();
|
|
378
|
+
return React.createElement(FormFieldInternal, Object.assign({}, props, { id: id }));
|
|
379
|
+
}
|
|
380
|
+
function FormFieldInternal(props) {
|
|
381
|
+
const { actionsRef, autocomplete = true, children, defaultValue, description, disabled, id, inputRef, inline, keyboard, max, maxLength, min, name: nameProp, readonly, rows, loading, type = "text", validations, value, onChange, onEnter, onFocus, onBlur, onValidation, onKeyUp, clearable = "never", autofocus, } = props;
|
|
382
|
+
const { name } = useAtlantisFormFieldName({ id, nameProp });
|
|
383
|
+
const { errorMessage, inputRefs, useControllerField, setValue, onControllerBlur, onControllerChange, } = useAtlantisReactForm({
|
|
384
|
+
actionsRef,
|
|
385
|
+
name,
|
|
386
|
+
defaultValue,
|
|
387
|
+
value,
|
|
388
|
+
validations,
|
|
389
|
+
inputRef,
|
|
390
|
+
});
|
|
391
|
+
const { handleValidation, handleBlur, handleChange, handleClear, handleFocus, handleKeyDown, } = useAtlantisFormFieldActions({
|
|
392
|
+
onChange,
|
|
393
|
+
onEnter,
|
|
394
|
+
readonly,
|
|
395
|
+
type,
|
|
396
|
+
onFocus,
|
|
397
|
+
setValue,
|
|
398
|
+
onBlur,
|
|
399
|
+
onValidation,
|
|
400
|
+
onControllerBlur,
|
|
401
|
+
onControllerChange,
|
|
402
|
+
name,
|
|
403
|
+
});
|
|
404
|
+
const { textFieldProps, fieldProps, descriptionIdentifier } = useAtlantisFormField({
|
|
405
|
+
id,
|
|
406
|
+
useControllerField,
|
|
407
|
+
name,
|
|
408
|
+
nameProp,
|
|
409
|
+
description,
|
|
410
|
+
validations: !!validations,
|
|
411
|
+
disabled,
|
|
412
|
+
readonly,
|
|
413
|
+
keyboard,
|
|
414
|
+
autofocus,
|
|
415
|
+
handleChange,
|
|
416
|
+
handleBlur,
|
|
417
|
+
handleFocus,
|
|
418
|
+
inline,
|
|
419
|
+
errorMessage,
|
|
420
|
+
handleValidation,
|
|
421
|
+
handleKeyDown,
|
|
422
|
+
});
|
|
423
|
+
return (React.createElement(FormFieldWrapper, Object.assign({}, props, { value: useControllerField.value, error: errorMessage, identifier: id, descriptionIdentifier: descriptionIdentifier, clearable: clearable, onClear: handleClear }), renderField()));
|
|
247
424
|
function renderField() {
|
|
248
425
|
switch (type) {
|
|
249
426
|
case "select":
|
|
@@ -259,46 +436,6 @@ function FormFieldInternal(props) {
|
|
|
259
436
|
children));
|
|
260
437
|
}
|
|
261
438
|
}
|
|
262
|
-
function handleClear() {
|
|
263
|
-
var _a;
|
|
264
|
-
handleBlur();
|
|
265
|
-
setValue(name, "", { shouldValidate: true });
|
|
266
|
-
onChange && onChange("");
|
|
267
|
-
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
268
|
-
}
|
|
269
|
-
function handleChange(event) {
|
|
270
|
-
let newValue;
|
|
271
|
-
newValue = event.currentTarget.value;
|
|
272
|
-
if (type === "number" && newValue.length > 0) {
|
|
273
|
-
newValue = parseFloat(newValue);
|
|
274
|
-
}
|
|
275
|
-
onChange && onChange(newValue, event);
|
|
276
|
-
onControllerChange(event);
|
|
277
|
-
}
|
|
278
|
-
function handleKeyDown(event) {
|
|
279
|
-
if (!onEnter)
|
|
280
|
-
return;
|
|
281
|
-
if (event.key !== "Enter")
|
|
282
|
-
return;
|
|
283
|
-
if (event.shiftKey || event.ctrlKey)
|
|
284
|
-
return;
|
|
285
|
-
event.preventDefault();
|
|
286
|
-
onEnter && onEnter(event);
|
|
287
|
-
}
|
|
288
|
-
function handleFocus(event) {
|
|
289
|
-
const target = event.currentTarget;
|
|
290
|
-
if (target.select) {
|
|
291
|
-
setTimeout(() => readonly && target.select());
|
|
292
|
-
}
|
|
293
|
-
onFocus && onFocus();
|
|
294
|
-
}
|
|
295
|
-
function handleBlur() {
|
|
296
|
-
onBlur && onBlur();
|
|
297
|
-
onControllerBlur();
|
|
298
|
-
}
|
|
299
|
-
function handleValidation(message) {
|
|
300
|
-
onValidation && onValidation(message);
|
|
301
|
-
}
|
|
302
439
|
}
|
|
303
440
|
function setAutocomplete(autocompleteSetting) {
|
|
304
441
|
if (autocompleteSetting === true) {
|
|
@@ -310,4 +447,4 @@ function setAutocomplete(autocompleteSetting) {
|
|
|
310
447
|
return autocompleteSetting;
|
|
311
448
|
}
|
|
312
449
|
|
|
313
|
-
export {
|
|
450
|
+
export { FormFieldWrapper as F, useAtlantisFormFieldActions as a, useAtlantisFormFieldName as b, useAtlantisReactForm as c, useFormFieldWrapperStyles as d, FormField as e, useAtlantisFormField as u };
|
package/dist/InputDate/index.cjs
CHANGED
|
@@ -26,13 +26,13 @@ require('../_baseFlatten-cjs.js');
|
|
|
26
26
|
require('../_setToString-cjs.js');
|
|
27
27
|
require('../AtlantisContext-cjs.js');
|
|
28
28
|
require('../FormField-cjs.js');
|
|
29
|
-
require('../tslib.es6-cjs.js');
|
|
30
|
-
require('react-hook-form');
|
|
31
29
|
require('framer-motion');
|
|
32
30
|
require('../Text-cjs.js');
|
|
33
31
|
require('../useFormFieldFocus-cjs.js');
|
|
34
32
|
require('../InputValidation-cjs.js');
|
|
35
33
|
require('../Spinner-cjs.js');
|
|
34
|
+
require('../tslib.es6-cjs.js');
|
|
35
|
+
require('react-hook-form');
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
|
package/dist/InputDate/index.mjs
CHANGED
|
@@ -24,10 +24,10 @@ import '../_baseFlatten-es.js';
|
|
|
24
24
|
import '../_setToString-es.js';
|
|
25
25
|
import '../AtlantisContext-es.js';
|
|
26
26
|
import '../FormField-es.js';
|
|
27
|
-
import '../tslib.es6-es.js';
|
|
28
|
-
import 'react-hook-form';
|
|
29
27
|
import 'framer-motion';
|
|
30
28
|
import '../Text-es.js';
|
|
31
29
|
import '../useFormFieldFocus-es.js';
|
|
32
30
|
import '../InputValidation-es.js';
|
|
33
31
|
import '../Spinner-es.js';
|
|
32
|
+
import '../tslib.es6-es.js';
|
|
33
|
+
import 'react-hook-form';
|
package/dist/InputDate-cjs.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
var DatePicker = require('./DatePicker-cjs.js');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
var FormField = require('./FormField-cjs.js');
|
|
6
|
+
require('./tslib.es6-cjs.js');
|
|
7
|
+
require('react-hook-form');
|
|
8
|
+
require('framer-motion');
|
|
9
|
+
require('@jobber/design');
|
|
10
|
+
require('classnames');
|
|
11
|
+
require('react-router-dom');
|
|
6
12
|
|
|
7
13
|
function InputDate(inputProps) {
|
|
8
14
|
const formFieldActionsRef = React.useRef(null);
|
package/dist/InputDate-es.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { D as DatePicker, o as omit } from './DatePicker-es.js';
|
|
2
2
|
import React, { useRef, useState, useEffect } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { e as FormField } from './FormField-es.js';
|
|
4
|
+
import './tslib.es6-es.js';
|
|
5
|
+
import 'react-hook-form';
|
|
6
|
+
import 'framer-motion';
|
|
7
|
+
import '@jobber/design';
|
|
8
|
+
import 'classnames';
|
|
9
|
+
import 'react-router-dom';
|
|
4
10
|
|
|
5
11
|
function InputDate(inputProps) {
|
|
6
12
|
const formFieldActionsRef = useRef(null);
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
var InputEmail = require('../InputEmail-cjs.js');
|
|
4
4
|
require('react');
|
|
5
5
|
require('../FormField-cjs.js');
|
|
6
|
-
require('../tslib.es6-cjs.js');
|
|
7
|
-
require('react-hook-form');
|
|
8
|
-
require('classnames');
|
|
9
6
|
require('framer-motion');
|
|
10
7
|
require('@jobber/design');
|
|
8
|
+
require('classnames');
|
|
11
9
|
require('../Button-cjs.js');
|
|
12
10
|
require('react-router-dom');
|
|
13
11
|
require('../Icon-cjs.js');
|
|
@@ -16,6 +14,8 @@ require('../Text-cjs.js');
|
|
|
16
14
|
require('../useFormFieldFocus-cjs.js');
|
|
17
15
|
require('../InputValidation-cjs.js');
|
|
18
16
|
require('../Spinner-cjs.js');
|
|
17
|
+
require('../tslib.es6-cjs.js');
|
|
18
|
+
require('react-hook-form');
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
export { I as InputEmail, v as validationMessage } from '../InputEmail-es.js';
|
|
2
2
|
import 'react';
|
|
3
3
|
import '../FormField-es.js';
|
|
4
|
-
import '../tslib.es6-es.js';
|
|
5
|
-
import 'react-hook-form';
|
|
6
|
-
import 'classnames';
|
|
7
4
|
import 'framer-motion';
|
|
8
5
|
import '@jobber/design';
|
|
6
|
+
import 'classnames';
|
|
9
7
|
import '../Button-es.js';
|
|
10
8
|
import 'react-router-dom';
|
|
11
9
|
import '../Icon-es.js';
|
|
@@ -14,3 +12,5 @@ import '../Text-es.js';
|
|
|
14
12
|
import '../useFormFieldFocus-es.js';
|
|
15
13
|
import '../InputValidation-es.js';
|
|
16
14
|
import '../Spinner-es.js';
|
|
15
|
+
import '../tslib.es6-es.js';
|
|
16
|
+
import 'react-hook-form';
|
package/dist/InputEmail-cjs.js
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
4
|
var FormField = require('./FormField-cjs.js');
|
|
5
|
+
require('./tslib.es6-cjs.js');
|
|
6
|
+
require('react-hook-form');
|
|
7
|
+
require('framer-motion');
|
|
8
|
+
require('@jobber/design');
|
|
9
|
+
require('classnames');
|
|
10
|
+
require('react-router-dom');
|
|
5
11
|
|
|
6
12
|
const validationMessage = "Please enter a valid email";
|
|
7
13
|
function InputEmail(props) {
|
package/dist/InputEmail-es.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { e as FormField } from './FormField-es.js';
|
|
3
|
+
import './tslib.es6-es.js';
|
|
4
|
+
import 'react-hook-form';
|
|
5
|
+
import 'framer-motion';
|
|
6
|
+
import '@jobber/design';
|
|
7
|
+
import 'classnames';
|
|
8
|
+
import 'react-router-dom';
|
|
3
9
|
|
|
4
10
|
const validationMessage = "Please enter a valid email";
|
|
5
11
|
function InputEmail(props) {
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
var InputNumber = require('../InputNumber-cjs.js');
|
|
4
4
|
require('react');
|
|
5
5
|
require('../FormField-cjs.js');
|
|
6
|
-
require('../tslib.es6-cjs.js');
|
|
7
|
-
require('react-hook-form');
|
|
8
|
-
require('classnames');
|
|
9
6
|
require('framer-motion');
|
|
10
7
|
require('@jobber/design');
|
|
8
|
+
require('classnames');
|
|
11
9
|
require('../Button-cjs.js');
|
|
12
10
|
require('react-router-dom');
|
|
13
11
|
require('../Icon-cjs.js');
|
|
@@ -16,6 +14,8 @@ require('../Text-cjs.js');
|
|
|
16
14
|
require('../useFormFieldFocus-cjs.js');
|
|
17
15
|
require('../InputValidation-cjs.js');
|
|
18
16
|
require('../Spinner-cjs.js');
|
|
17
|
+
require('../tslib.es6-cjs.js');
|
|
18
|
+
require('react-hook-form');
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|