@jobber/components 8.6.0 → 8.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/dist/Autocomplete/index.cjs +1 -2
- package/dist/Autocomplete/index.mjs +1 -2
- package/dist/Autocomplete-cjs.js +1 -3
- package/dist/Autocomplete-es.js +1 -3
- package/dist/DataList/components/DataListSearch/index.cjs +1 -2
- package/dist/DataList/components/DataListSearch/index.mjs +1 -2
- package/dist/DataList/index.cjs +1 -2
- package/dist/DataList/index.mjs +1 -2
- package/dist/DataTable/index.cjs +1 -2
- package/dist/DataTable/index.mjs +1 -2
- package/dist/FormField/FormFieldTypes.d.ts +1 -10
- package/dist/FormField/index.cjs +4 -13
- package/dist/FormField/index.d.ts +0 -4
- package/dist/FormField/index.mjs +4 -9
- package/dist/InputDate/index.cjs +1 -2
- package/dist/InputDate/index.mjs +1 -2
- package/dist/InputEmail/index.cjs +0 -1
- package/dist/InputEmail/index.mjs +0 -1
- package/dist/InputEmail-cjs.js +1 -3
- package/dist/InputEmail-es.js +1 -3
- package/dist/InputPhoneNumber/InputMask.d.ts +0 -38
- package/dist/InputPhoneNumber/InputPhoneNumber.types.d.ts +1 -2
- package/dist/InputPhoneNumber/index.cjs +1 -2
- package/dist/InputPhoneNumber/index.mjs +1 -2
- package/dist/InputPhoneNumber-cjs.js +11 -12
- package/dist/InputPhoneNumber-es.js +11 -12
- package/dist/InputText/index.cjs +1 -2
- package/dist/InputText/index.mjs +1 -2
- package/dist/InputText-cjs.js +3 -5
- package/dist/InputText-es.js +3 -5
- package/dist/InputTime/index.cjs +0 -1
- package/dist/InputTime/index.mjs +0 -1
- package/dist/InputTime-cjs.js +1 -2
- package/dist/InputTime-es.js +1 -2
- package/dist/Select/index.cjs +1 -2
- package/dist/Select/index.mjs +1 -2
- package/dist/Select-cjs.js +3 -5
- package/dist/Select-es.js +3 -5
- package/dist/docs/Button/Button.md +1 -1
- package/dist/docs/errors/errors.md +1 -1
- package/dist/docs/index.md +0 -3
- package/dist/index.cjs +2 -12
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.mjs +2 -6
- package/dist/prebuildCssEntry.d.ts +13 -0
- package/dist/useAtlantisFormFieldName-cjs.js +3 -3
- package/dist/useAtlantisFormFieldName-es.js +3 -3
- package/dist/utils/meta/meta.json +0 -3
- package/package.json +3 -15
- package/rollup.config.mjs +15 -17
- package/Form.d.ts +0 -1
- package/Form.js +0 -17
- package/InputPassword.d.ts +0 -1
- package/InputPassword.js +0 -17
- package/dist/Form/Form.d.ts +0 -18
- package/dist/Form/index.cjs +0 -10
- package/dist/Form/index.d.ts +0 -1
- package/dist/Form/index.mjs +0 -4
- package/dist/Form-cjs.js +0 -43
- package/dist/Form-es.js +0 -41
- package/dist/FormField/FormField.d.ts +0 -3
- package/dist/FormField/hooks/useAtlantisFormField.d.ts +0 -91
- package/dist/FormField/hooks/useAtlantisFormFieldActions.d.ts +0 -22
- package/dist/FormField/hooks/useAtlantisReactHookForm.d.ts +0 -20
- package/dist/FormField-cjs.js +0 -209
- package/dist/FormField-es.js +0 -204
- package/dist/InputPassword/InputPassword.d.ts +0 -13
- package/dist/InputPassword/index.cjs +0 -27
- package/dist/InputPassword/index.d.ts +0 -1
- package/dist/InputPassword/index.mjs +0 -21
- package/dist/InputPassword-cjs.js +0 -28
- package/dist/InputPassword-es.js +0 -26
- package/dist/docs/Form/Form.md +0 -106
- package/dist/docs/FormField/FormField.md +0 -92
- package/dist/docs/InputPassword/InputPassword.md +0 -51
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import type { ChangeEvent, FocusEvent, KeyboardEvent } from "react";
|
|
2
|
-
import type { UseControllerReturn } from "react-hook-form";
|
|
3
|
-
import type { FormFieldProps, KeyBoardTypes } from "../FormFieldTypes";
|
|
4
|
-
export interface useAtlantisFormFieldProps extends Pick<FormFieldProps, "description" | "disabled" | "readonly" | "inline" | "autofocus" | "pattern" | "type" | "value"> {
|
|
5
|
-
/**
|
|
6
|
-
* The html id for the field
|
|
7
|
-
*/
|
|
8
|
-
readonly id: string;
|
|
9
|
-
/**
|
|
10
|
-
* The name for the html input field if one if provided by consumers of the component
|
|
11
|
-
*/
|
|
12
|
-
readonly nameProp?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The auto-generated name for the html input field if a nameProp is not provided
|
|
15
|
-
*/
|
|
16
|
-
readonly name: string;
|
|
17
|
-
/**
|
|
18
|
-
* The ref used to access the FieldActions of the field
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* The field returned from react-hook-form's useController
|
|
22
|
-
*/
|
|
23
|
-
readonly useControllerField: Omit<UseControllerReturn["field"], "ref" | "onChange" | "onBlur">;
|
|
24
|
-
/**
|
|
25
|
-
* The keyboard type for the field. This is used to provide hints to the browser about the type of keyboard to display on mobile devices
|
|
26
|
-
*/
|
|
27
|
-
readonly keyboard?: KeyBoardTypes;
|
|
28
|
-
/**
|
|
29
|
-
* The error message for the field
|
|
30
|
-
*/
|
|
31
|
-
readonly errorMessage: string;
|
|
32
|
-
/**
|
|
33
|
-
* Determines if the field has validations
|
|
34
|
-
*/
|
|
35
|
-
readonly validations: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Callback for when the field value changes
|
|
38
|
-
*/
|
|
39
|
-
handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
40
|
-
/**
|
|
41
|
-
* Callback for when the field loses focus
|
|
42
|
-
*/
|
|
43
|
-
handleBlur: () => void;
|
|
44
|
-
/**
|
|
45
|
-
* Callback for when the field gains focus
|
|
46
|
-
*/
|
|
47
|
-
handleFocus: (event: FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
48
|
-
/**
|
|
49
|
-
* Callback for when keydown event is triggered on the field
|
|
50
|
-
*/
|
|
51
|
-
handleKeyDown: (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
52
|
-
/**
|
|
53
|
-
* Callback that exposes the error message when the field is validated
|
|
54
|
-
*/
|
|
55
|
-
handleValidation: (message: string) => void;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Provides the props for the html fields rendered by the FormField component
|
|
59
|
-
*/
|
|
60
|
-
export declare function useAtlantisFormField({ id, nameProp, name, useControllerField: useControllerField, description, disabled, readonly, keyboard, autofocus, pattern, type, value, handleChange, handleBlur, handleFocus, inline, validations, handleKeyDown, handleValidation, errorMessage, }: useAtlantisFormFieldProps): {
|
|
61
|
-
textFieldProps: {
|
|
62
|
-
autoFocus: boolean | undefined;
|
|
63
|
-
onKeyDown: (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
64
|
-
"aria-describedby"?: string | undefined;
|
|
65
|
-
id: string;
|
|
66
|
-
className: string;
|
|
67
|
-
name: string | undefined;
|
|
68
|
-
disabled: boolean | undefined;
|
|
69
|
-
readOnly: boolean | undefined;
|
|
70
|
-
inputMode: KeyBoardTypes | undefined;
|
|
71
|
-
onChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
72
|
-
onBlur: () => void;
|
|
73
|
-
onFocus: (event: FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
74
|
-
value: any;
|
|
75
|
-
};
|
|
76
|
-
fieldProps: {
|
|
77
|
-
"aria-describedby"?: string | undefined;
|
|
78
|
-
id: string;
|
|
79
|
-
className: string;
|
|
80
|
-
name: string | undefined;
|
|
81
|
-
disabled: boolean | undefined;
|
|
82
|
-
readOnly: boolean | undefined;
|
|
83
|
-
inputMode: KeyBoardTypes | undefined;
|
|
84
|
-
onChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
85
|
-
onBlur: () => void;
|
|
86
|
-
onFocus: (event: FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
87
|
-
autoFocus: boolean | undefined;
|
|
88
|
-
value: any;
|
|
89
|
-
};
|
|
90
|
-
descriptionIdentifier: string;
|
|
91
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { ChangeEvent, FocusEvent, KeyboardEvent } from "react";
|
|
2
|
-
import type { FieldValues, UseFormSetValue } from "react-hook-form";
|
|
3
|
-
import type { FormFieldProps, FormFieldTypes } from "../FormFieldTypes";
|
|
4
|
-
export interface useAtlantisFormFieldActionsProps extends Pick<FormFieldProps, "onChange" | "inputRef" | "onEnter" | "readonly" | "onFocus" | "onBlur" | "onValidation" | "onEnter"> {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
readonly onControllerChange: (...event: unknown[]) => void;
|
|
7
|
-
readonly onControllerBlur: () => void;
|
|
8
|
-
readonly type: FormFieldTypes;
|
|
9
|
-
readonly setValue: UseFormSetValue<FieldValues>;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Combines the actions from the props of the FormField with the actions from react-hook-form. This is used to
|
|
13
|
-
* manage the form state of a field through react-hook-form while providing support for additional callbacks
|
|
14
|
-
*/
|
|
15
|
-
export declare function useAtlantisFormFieldActions({ name, onChange, inputRef, onControllerChange, onControllerBlur, onEnter, readonly, type, setValue, onFocus, onBlur, onValidation, }: useAtlantisFormFieldActionsProps): {
|
|
16
|
-
handleClear: () => void;
|
|
17
|
-
handleChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
18
|
-
handleKeyDown: (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
19
|
-
handleFocus: (event: FocusEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>) => void;
|
|
20
|
-
handleBlur: () => void;
|
|
21
|
-
handleValidation: (message: string) => void;
|
|
22
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { FormFieldProps } from "../FormFieldTypes";
|
|
2
|
-
interface useAtlantisReactHookFormProps extends Pick<FormFieldProps, "actionsRef" | "defaultValue" | "value" | "validations" | "inputRef"> {
|
|
3
|
-
name: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* Hook used to manage the form state of a field through react-hook-form
|
|
7
|
-
*/
|
|
8
|
-
export declare function useAtlantisReactHookForm({ actionsRef, name, defaultValue, value, validations, inputRef, }: useAtlantisReactHookFormProps): {
|
|
9
|
-
inputRefs: import("react").RefCallback<any>;
|
|
10
|
-
useControllerField: {
|
|
11
|
-
value: any;
|
|
12
|
-
disabled?: boolean;
|
|
13
|
-
name: string;
|
|
14
|
-
};
|
|
15
|
-
setValue: import("react-hook-form").UseFormSetValue<import("react-hook-form").FieldValues>;
|
|
16
|
-
errorMessage: string;
|
|
17
|
-
onControllerChange: (...event: any[]) => void;
|
|
18
|
-
onControllerBlur: import("react-hook-form").Noop;
|
|
19
|
-
};
|
|
20
|
-
export {};
|
package/dist/FormField-cjs.js
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var FormFieldWrapper = require('./FormFieldWrapper-cjs.js');
|
|
5
|
-
var FormFieldPostFix = require('./FormFieldPostFix-cjs.js');
|
|
6
|
-
var classnames = require('classnames');
|
|
7
|
-
var useAtlantisFormFieldName = require('./useAtlantisFormFieldName-cjs.js');
|
|
8
|
-
var tslib_es6 = require('./tslib.es6-cjs.js');
|
|
9
|
-
var reactHookForm = require('react-hook-form');
|
|
10
|
-
var mergeRefs = require('./mergeRefs-cjs.js');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Combines the actions from the props of the FormField with the actions from react-hook-form. This is used to
|
|
14
|
-
* manage the form state of a field through react-hook-form while providing support for additional callbacks
|
|
15
|
-
*/
|
|
16
|
-
function useAtlantisFormFieldActions({ name, onChange, inputRef, onControllerChange, onControllerBlur, onEnter, readonly, type, setValue, onFocus, onBlur, onValidation, }) {
|
|
17
|
-
function handleClear() {
|
|
18
|
-
var _a;
|
|
19
|
-
handleBlur();
|
|
20
|
-
setValue(name, "", { shouldValidate: true });
|
|
21
|
-
onChange && onChange("");
|
|
22
|
-
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
23
|
-
}
|
|
24
|
-
function handleChange(event) {
|
|
25
|
-
let newValue;
|
|
26
|
-
newValue = event.currentTarget.value;
|
|
27
|
-
if (type === "number" && newValue.length > 0) {
|
|
28
|
-
newValue = parseFloat(newValue);
|
|
29
|
-
}
|
|
30
|
-
onChange && onChange(newValue, event);
|
|
31
|
-
onControllerChange(event);
|
|
32
|
-
}
|
|
33
|
-
function handleKeyDown(event) {
|
|
34
|
-
if (!onEnter)
|
|
35
|
-
return;
|
|
36
|
-
if (event.key !== "Enter")
|
|
37
|
-
return;
|
|
38
|
-
if (event.shiftKey || event.ctrlKey)
|
|
39
|
-
return;
|
|
40
|
-
event.preventDefault();
|
|
41
|
-
onEnter && onEnter(event);
|
|
42
|
-
}
|
|
43
|
-
function handleFocus(event) {
|
|
44
|
-
const target = event.currentTarget;
|
|
45
|
-
if (target.select) {
|
|
46
|
-
setTimeout(() => readonly && target.select());
|
|
47
|
-
}
|
|
48
|
-
onFocus && onFocus();
|
|
49
|
-
}
|
|
50
|
-
function handleBlur() {
|
|
51
|
-
onBlur && onBlur();
|
|
52
|
-
onControllerBlur();
|
|
53
|
-
}
|
|
54
|
-
function handleValidation(message) {
|
|
55
|
-
onValidation && onValidation(message);
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
handleClear,
|
|
59
|
-
handleChange,
|
|
60
|
-
handleKeyDown,
|
|
61
|
-
handleFocus,
|
|
62
|
-
handleBlur,
|
|
63
|
-
handleValidation,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Provides the props for the html fields rendered by the FormField component
|
|
69
|
-
*/
|
|
70
|
-
function useAtlantisFormField({ id, nameProp, name, useControllerField: useControllerField, description, disabled, readonly, keyboard, autofocus, pattern, type, value, handleChange, handleBlur, handleFocus, inline, validations, handleKeyDown, handleValidation, errorMessage, }) {
|
|
71
|
-
const descriptionIdentifier = `descriptionUUID--${id}`;
|
|
72
|
-
const fieldProps = Object.assign(Object.assign(Object.assign({}, useControllerField), { id, className: classnames(FormFieldWrapper.formFieldStyles.input, {
|
|
73
|
-
[FormFieldWrapper.formFieldStyles.emptyPhoneNumber]: shouldAddPhoneNumberClass(type, value, pattern),
|
|
74
|
-
}), name: (validations || nameProp) && name, disabled: disabled, readOnly: readonly, inputMode: keyboard, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, autoFocus: autofocus }), (description &&
|
|
75
|
-
!inline && { "aria-describedby": descriptionIdentifier }));
|
|
76
|
-
const textFieldProps = Object.assign(Object.assign({}, fieldProps), { autoFocus: autofocus, onKeyDown: handleKeyDown });
|
|
77
|
-
React.useEffect(() => handleValidation(errorMessage), [errorMessage]);
|
|
78
|
-
return { textFieldProps, fieldProps, descriptionIdentifier };
|
|
79
|
-
}
|
|
80
|
-
function shouldAddPhoneNumberClass(type, value, pattern) {
|
|
81
|
-
return type === "tel" && !value && pattern && pattern[0] === "(";
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Hook used to manage the form state of a field through react-hook-form
|
|
86
|
-
*/
|
|
87
|
-
function useAtlantisReactHookForm({ actionsRef, name, defaultValue, value, validations, inputRef, }) {
|
|
88
|
-
var _a;
|
|
89
|
-
const formContext = reactHookForm.useFormContext();
|
|
90
|
-
// If there isn't a Form Context being provided, get a form for this field.
|
|
91
|
-
const { control, setValue, watch } = formContext !== null && formContext !== void 0 ? formContext : reactHookForm.useForm({ mode: "onTouched" });
|
|
92
|
-
React.useImperativeHandle(actionsRef, () => ({
|
|
93
|
-
setValue: newValue => {
|
|
94
|
-
setValue(name, newValue, { shouldValidate: true });
|
|
95
|
-
},
|
|
96
|
-
}));
|
|
97
|
-
const { field, fieldState: { error }, } = reactHookForm.useController({
|
|
98
|
-
name,
|
|
99
|
-
control,
|
|
100
|
-
rules: validations,
|
|
101
|
-
defaultValue: (_a = value !== null && value !== void 0 ? value : defaultValue) !== null && _a !== void 0 ? _a : "",
|
|
102
|
-
});
|
|
103
|
-
const { onChange, onBlur, ref: fieldRef } = field, useControllerField = tslib_es6.__rest(field, ["onChange", "onBlur", "ref"]);
|
|
104
|
-
React.useEffect(() => {
|
|
105
|
-
if (value != undefined) {
|
|
106
|
-
setValue(name, value);
|
|
107
|
-
}
|
|
108
|
-
}, [value, watch(name)]);
|
|
109
|
-
const inputRefs = mergeRefs.mergeRefs([inputRef, fieldRef]);
|
|
110
|
-
return {
|
|
111
|
-
inputRefs,
|
|
112
|
-
useControllerField,
|
|
113
|
-
setValue,
|
|
114
|
-
errorMessage: (error === null || error === void 0 ? void 0 : error.message) || "",
|
|
115
|
-
onControllerChange: onChange,
|
|
116
|
-
onControllerBlur: onBlur,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function FormField(props) {
|
|
121
|
-
// Warning: do not move useId into FormFieldInternal. This must be here to avoid
|
|
122
|
-
// a problem where useId isn't stable across multiple StrictMode renders.
|
|
123
|
-
// https://github.com/facebook/react/issues/27103
|
|
124
|
-
const generatedId = React.useId();
|
|
125
|
-
const id = props.id || generatedId;
|
|
126
|
-
return React.createElement(FormFieldInternal, Object.assign({}, props, { id: id }));
|
|
127
|
-
}
|
|
128
|
-
function FormFieldInternal(props) {
|
|
129
|
-
var _a;
|
|
130
|
-
const { actionsRef, autocomplete = true, children, defaultValue, description, disabled, id, inputRef, inline, keyboard, max, maxLength, min, name: nameProp, pattern, readonly, rows, loading, type = "text", validations, value, onChange, onEnter, onFocus, onBlur, onValidation, onKeyUp, clearable = "never", autofocus, } = props;
|
|
131
|
-
const { name } = useAtlantisFormFieldName.useAtlantisFormFieldName({ id, nameProp });
|
|
132
|
-
const { errorMessage, inputRefs, useControllerField, setValue, onControllerBlur, onControllerChange, } = useAtlantisReactHookForm({
|
|
133
|
-
actionsRef,
|
|
134
|
-
name,
|
|
135
|
-
defaultValue,
|
|
136
|
-
value,
|
|
137
|
-
validations,
|
|
138
|
-
inputRef,
|
|
139
|
-
});
|
|
140
|
-
const { handleValidation, handleBlur, handleChange, handleClear, handleFocus, handleKeyDown, } = useAtlantisFormFieldActions({
|
|
141
|
-
inputRef,
|
|
142
|
-
onChange,
|
|
143
|
-
onEnter,
|
|
144
|
-
readonly,
|
|
145
|
-
type,
|
|
146
|
-
onFocus,
|
|
147
|
-
setValue,
|
|
148
|
-
onBlur,
|
|
149
|
-
onValidation,
|
|
150
|
-
onControllerBlur,
|
|
151
|
-
onControllerChange,
|
|
152
|
-
name,
|
|
153
|
-
});
|
|
154
|
-
const { textFieldProps, fieldProps, descriptionIdentifier } = useAtlantisFormField({
|
|
155
|
-
id,
|
|
156
|
-
useControllerField,
|
|
157
|
-
name,
|
|
158
|
-
nameProp,
|
|
159
|
-
description,
|
|
160
|
-
validations: !!validations,
|
|
161
|
-
disabled,
|
|
162
|
-
readonly,
|
|
163
|
-
keyboard,
|
|
164
|
-
autofocus,
|
|
165
|
-
value,
|
|
166
|
-
type,
|
|
167
|
-
pattern,
|
|
168
|
-
handleChange,
|
|
169
|
-
handleBlur,
|
|
170
|
-
handleFocus,
|
|
171
|
-
inline,
|
|
172
|
-
errorMessage,
|
|
173
|
-
handleValidation,
|
|
174
|
-
handleKeyDown,
|
|
175
|
-
});
|
|
176
|
-
// Ensure focus tracking works by providing a wrapperRef when none is passed
|
|
177
|
-
const internalWrapperRef = React.useRef(null);
|
|
178
|
-
const wrapperRef = (_a = props.wrapperRef) !== null && _a !== void 0 ? _a : internalWrapperRef;
|
|
179
|
-
return (React.createElement(FormFieldWrapper.FormFieldWrapper, Object.assign({}, props, { value: useControllerField.value, error: errorMessage, identifier: id, descriptionIdentifier: descriptionIdentifier, clearable: clearable, onClear: handleClear, wrapperRef: wrapperRef }), renderField()));
|
|
180
|
-
function renderField() {
|
|
181
|
-
switch (type) {
|
|
182
|
-
case "select":
|
|
183
|
-
return (React.createElement(React.Fragment, null,
|
|
184
|
-
React.createElement("select", Object.assign({}, fieldProps), children),
|
|
185
|
-
React.createElement(FormFieldPostFix.FormFieldPostFix, { variation: "select" })));
|
|
186
|
-
case "textarea":
|
|
187
|
-
return React.createElement("textarea", Object.assign({}, textFieldProps, { rows: rows, ref: inputRefs }));
|
|
188
|
-
default:
|
|
189
|
-
return (React.createElement(React.Fragment, null,
|
|
190
|
-
React.createElement("input", Object.assign({}, textFieldProps, { autoComplete: setAutocomplete(autocomplete), type: type, maxLength: maxLength, max: max, min: min, ref: inputRefs, onKeyUp: onKeyUp })),
|
|
191
|
-
loading && React.createElement(FormFieldPostFix.FormFieldPostFix, { variation: "spinner" }),
|
|
192
|
-
children));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
function setAutocomplete(autocompleteSetting) {
|
|
197
|
-
if (autocompleteSetting === true) {
|
|
198
|
-
return undefined;
|
|
199
|
-
}
|
|
200
|
-
else if (autocompleteSetting === false) {
|
|
201
|
-
return "off";
|
|
202
|
-
}
|
|
203
|
-
return autocompleteSetting;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
exports.FormField = FormField;
|
|
207
|
-
exports.useAtlantisFormField = useAtlantisFormField;
|
|
208
|
-
exports.useAtlantisFormFieldActions = useAtlantisFormFieldActions;
|
|
209
|
-
exports.useAtlantisReactHookForm = useAtlantisReactHookForm;
|
package/dist/FormField-es.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import React__default, { useEffect, useImperativeHandle, useId, useRef } from 'react';
|
|
2
|
-
import { g as formFieldStyles, c as FormFieldWrapper } from './FormFieldWrapper-es.js';
|
|
3
|
-
import { F as FormFieldPostFix } from './FormFieldPostFix-es.js';
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
import { u as useAtlantisFormFieldName } from './useAtlantisFormFieldName-es.js';
|
|
6
|
-
import { _ as __rest } from './tslib.es6-es.js';
|
|
7
|
-
import { useFormContext, useForm, useController } from 'react-hook-form';
|
|
8
|
-
import { m as mergeRefs } from './mergeRefs-es.js';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Combines the actions from the props of the FormField with the actions from react-hook-form. This is used to
|
|
12
|
-
* manage the form state of a field through react-hook-form while providing support for additional callbacks
|
|
13
|
-
*/
|
|
14
|
-
function useAtlantisFormFieldActions({ name, onChange, inputRef, onControllerChange, onControllerBlur, onEnter, readonly, type, setValue, onFocus, onBlur, onValidation, }) {
|
|
15
|
-
function handleClear() {
|
|
16
|
-
var _a;
|
|
17
|
-
handleBlur();
|
|
18
|
-
setValue(name, "", { shouldValidate: true });
|
|
19
|
-
onChange && onChange("");
|
|
20
|
-
(_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
21
|
-
}
|
|
22
|
-
function handleChange(event) {
|
|
23
|
-
let newValue;
|
|
24
|
-
newValue = event.currentTarget.value;
|
|
25
|
-
if (type === "number" && newValue.length > 0) {
|
|
26
|
-
newValue = parseFloat(newValue);
|
|
27
|
-
}
|
|
28
|
-
onChange && onChange(newValue, event);
|
|
29
|
-
onControllerChange(event);
|
|
30
|
-
}
|
|
31
|
-
function handleKeyDown(event) {
|
|
32
|
-
if (!onEnter)
|
|
33
|
-
return;
|
|
34
|
-
if (event.key !== "Enter")
|
|
35
|
-
return;
|
|
36
|
-
if (event.shiftKey || event.ctrlKey)
|
|
37
|
-
return;
|
|
38
|
-
event.preventDefault();
|
|
39
|
-
onEnter && onEnter(event);
|
|
40
|
-
}
|
|
41
|
-
function handleFocus(event) {
|
|
42
|
-
const target = event.currentTarget;
|
|
43
|
-
if (target.select) {
|
|
44
|
-
setTimeout(() => readonly && target.select());
|
|
45
|
-
}
|
|
46
|
-
onFocus && onFocus();
|
|
47
|
-
}
|
|
48
|
-
function handleBlur() {
|
|
49
|
-
onBlur && onBlur();
|
|
50
|
-
onControllerBlur();
|
|
51
|
-
}
|
|
52
|
-
function handleValidation(message) {
|
|
53
|
-
onValidation && onValidation(message);
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
handleClear,
|
|
57
|
-
handleChange,
|
|
58
|
-
handleKeyDown,
|
|
59
|
-
handleFocus,
|
|
60
|
-
handleBlur,
|
|
61
|
-
handleValidation,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Provides the props for the html fields rendered by the FormField component
|
|
67
|
-
*/
|
|
68
|
-
function useAtlantisFormField({ id, nameProp, name, useControllerField: useControllerField, description, disabled, readonly, keyboard, autofocus, pattern, type, value, handleChange, handleBlur, handleFocus, inline, validations, handleKeyDown, handleValidation, errorMessage, }) {
|
|
69
|
-
const descriptionIdentifier = `descriptionUUID--${id}`;
|
|
70
|
-
const fieldProps = Object.assign(Object.assign(Object.assign({}, useControllerField), { id, className: classnames(formFieldStyles.input, {
|
|
71
|
-
[formFieldStyles.emptyPhoneNumber]: shouldAddPhoneNumberClass(type, value, pattern),
|
|
72
|
-
}), name: (validations || nameProp) && name, disabled: disabled, readOnly: readonly, inputMode: keyboard, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, autoFocus: autofocus }), (description &&
|
|
73
|
-
!inline && { "aria-describedby": descriptionIdentifier }));
|
|
74
|
-
const textFieldProps = Object.assign(Object.assign({}, fieldProps), { autoFocus: autofocus, onKeyDown: handleKeyDown });
|
|
75
|
-
useEffect(() => handleValidation(errorMessage), [errorMessage]);
|
|
76
|
-
return { textFieldProps, fieldProps, descriptionIdentifier };
|
|
77
|
-
}
|
|
78
|
-
function shouldAddPhoneNumberClass(type, value, pattern) {
|
|
79
|
-
return type === "tel" && !value && pattern && pattern[0] === "(";
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Hook used to manage the form state of a field through react-hook-form
|
|
84
|
-
*/
|
|
85
|
-
function useAtlantisReactHookForm({ actionsRef, name, defaultValue, value, validations, inputRef, }) {
|
|
86
|
-
var _a;
|
|
87
|
-
const formContext = useFormContext();
|
|
88
|
-
// If there isn't a Form Context being provided, get a form for this field.
|
|
89
|
-
const { control, setValue, watch } = formContext !== null && formContext !== void 0 ? formContext : useForm({ mode: "onTouched" });
|
|
90
|
-
useImperativeHandle(actionsRef, () => ({
|
|
91
|
-
setValue: newValue => {
|
|
92
|
-
setValue(name, newValue, { shouldValidate: true });
|
|
93
|
-
},
|
|
94
|
-
}));
|
|
95
|
-
const { field, fieldState: { error }, } = useController({
|
|
96
|
-
name,
|
|
97
|
-
control,
|
|
98
|
-
rules: validations,
|
|
99
|
-
defaultValue: (_a = value !== null && value !== void 0 ? value : defaultValue) !== null && _a !== void 0 ? _a : "",
|
|
100
|
-
});
|
|
101
|
-
const { onChange, onBlur, ref: fieldRef } = field, useControllerField = __rest(field, ["onChange", "onBlur", "ref"]);
|
|
102
|
-
useEffect(() => {
|
|
103
|
-
if (value != undefined) {
|
|
104
|
-
setValue(name, value);
|
|
105
|
-
}
|
|
106
|
-
}, [value, watch(name)]);
|
|
107
|
-
const inputRefs = mergeRefs([inputRef, fieldRef]);
|
|
108
|
-
return {
|
|
109
|
-
inputRefs,
|
|
110
|
-
useControllerField,
|
|
111
|
-
setValue,
|
|
112
|
-
errorMessage: (error === null || error === void 0 ? void 0 : error.message) || "",
|
|
113
|
-
onControllerChange: onChange,
|
|
114
|
-
onControllerBlur: onBlur,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function FormField(props) {
|
|
119
|
-
// Warning: do not move useId into FormFieldInternal. This must be here to avoid
|
|
120
|
-
// a problem where useId isn't stable across multiple StrictMode renders.
|
|
121
|
-
// https://github.com/facebook/react/issues/27103
|
|
122
|
-
const generatedId = useId();
|
|
123
|
-
const id = props.id || generatedId;
|
|
124
|
-
return React__default.createElement(FormFieldInternal, Object.assign({}, props, { id: id }));
|
|
125
|
-
}
|
|
126
|
-
function FormFieldInternal(props) {
|
|
127
|
-
var _a;
|
|
128
|
-
const { actionsRef, autocomplete = true, children, defaultValue, description, disabled, id, inputRef, inline, keyboard, max, maxLength, min, name: nameProp, pattern, readonly, rows, loading, type = "text", validations, value, onChange, onEnter, onFocus, onBlur, onValidation, onKeyUp, clearable = "never", autofocus, } = props;
|
|
129
|
-
const { name } = useAtlantisFormFieldName({ id, nameProp });
|
|
130
|
-
const { errorMessage, inputRefs, useControllerField, setValue, onControllerBlur, onControllerChange, } = useAtlantisReactHookForm({
|
|
131
|
-
actionsRef,
|
|
132
|
-
name,
|
|
133
|
-
defaultValue,
|
|
134
|
-
value,
|
|
135
|
-
validations,
|
|
136
|
-
inputRef,
|
|
137
|
-
});
|
|
138
|
-
const { handleValidation, handleBlur, handleChange, handleClear, handleFocus, handleKeyDown, } = useAtlantisFormFieldActions({
|
|
139
|
-
inputRef,
|
|
140
|
-
onChange,
|
|
141
|
-
onEnter,
|
|
142
|
-
readonly,
|
|
143
|
-
type,
|
|
144
|
-
onFocus,
|
|
145
|
-
setValue,
|
|
146
|
-
onBlur,
|
|
147
|
-
onValidation,
|
|
148
|
-
onControllerBlur,
|
|
149
|
-
onControllerChange,
|
|
150
|
-
name,
|
|
151
|
-
});
|
|
152
|
-
const { textFieldProps, fieldProps, descriptionIdentifier } = useAtlantisFormField({
|
|
153
|
-
id,
|
|
154
|
-
useControllerField,
|
|
155
|
-
name,
|
|
156
|
-
nameProp,
|
|
157
|
-
description,
|
|
158
|
-
validations: !!validations,
|
|
159
|
-
disabled,
|
|
160
|
-
readonly,
|
|
161
|
-
keyboard,
|
|
162
|
-
autofocus,
|
|
163
|
-
value,
|
|
164
|
-
type,
|
|
165
|
-
pattern,
|
|
166
|
-
handleChange,
|
|
167
|
-
handleBlur,
|
|
168
|
-
handleFocus,
|
|
169
|
-
inline,
|
|
170
|
-
errorMessage,
|
|
171
|
-
handleValidation,
|
|
172
|
-
handleKeyDown,
|
|
173
|
-
});
|
|
174
|
-
// Ensure focus tracking works by providing a wrapperRef when none is passed
|
|
175
|
-
const internalWrapperRef = useRef(null);
|
|
176
|
-
const wrapperRef = (_a = props.wrapperRef) !== null && _a !== void 0 ? _a : internalWrapperRef;
|
|
177
|
-
return (React__default.createElement(FormFieldWrapper, Object.assign({}, props, { value: useControllerField.value, error: errorMessage, identifier: id, descriptionIdentifier: descriptionIdentifier, clearable: clearable, onClear: handleClear, wrapperRef: wrapperRef }), renderField()));
|
|
178
|
-
function renderField() {
|
|
179
|
-
switch (type) {
|
|
180
|
-
case "select":
|
|
181
|
-
return (React__default.createElement(React__default.Fragment, null,
|
|
182
|
-
React__default.createElement("select", Object.assign({}, fieldProps), children),
|
|
183
|
-
React__default.createElement(FormFieldPostFix, { variation: "select" })));
|
|
184
|
-
case "textarea":
|
|
185
|
-
return React__default.createElement("textarea", Object.assign({}, textFieldProps, { rows: rows, ref: inputRefs }));
|
|
186
|
-
default:
|
|
187
|
-
return (React__default.createElement(React__default.Fragment, null,
|
|
188
|
-
React__default.createElement("input", Object.assign({}, textFieldProps, { autoComplete: setAutocomplete(autocomplete), type: type, maxLength: maxLength, max: max, min: min, ref: inputRefs, onKeyUp: onKeyUp })),
|
|
189
|
-
loading && React__default.createElement(FormFieldPostFix, { variation: "spinner" }),
|
|
190
|
-
children));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
function setAutocomplete(autocompleteSetting) {
|
|
195
|
-
if (autocompleteSetting === true) {
|
|
196
|
-
return undefined;
|
|
197
|
-
}
|
|
198
|
-
else if (autocompleteSetting === false) {
|
|
199
|
-
return "off";
|
|
200
|
-
}
|
|
201
|
-
return autocompleteSetting;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export { FormField as F, useAtlantisFormFieldActions as a, useAtlantisReactHookForm as b, useAtlantisFormField as u };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { CommonFormFieldProps, FormFieldProps } from "../FormField";
|
|
3
|
-
interface InputPasswordProps extends CommonFormFieldProps, Pick<FormFieldProps, "autocomplete" | "onEnter" | "onFocus" | "onBlur" | "inputRef" | "validations" | "defaultValue"> {
|
|
4
|
-
readonly value?: string;
|
|
5
|
-
onChange?(newValue: string): void;
|
|
6
|
-
/**
|
|
7
|
-
* Display toggle to change the visibility of the password input
|
|
8
|
-
* @default false
|
|
9
|
-
*/
|
|
10
|
-
readonly hasVisibility?: boolean;
|
|
11
|
-
}
|
|
12
|
-
export declare function InputPassword(props: InputPasswordProps): React.JSX.Element;
|
|
13
|
-
export {};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var InputPassword = require('../InputPassword-cjs.js');
|
|
4
|
-
require('react');
|
|
5
|
-
require('../FormField-cjs.js');
|
|
6
|
-
require('../FormFieldWrapper-cjs.js');
|
|
7
|
-
require('@jobber/hooks');
|
|
8
|
-
require('framer-motion');
|
|
9
|
-
require('@jobber/design');
|
|
10
|
-
require('classnames');
|
|
11
|
-
require('../Button-cjs.js');
|
|
12
|
-
require('../tslib.es6-cjs.js');
|
|
13
|
-
require('react-router-dom');
|
|
14
|
-
require('../Icon-cjs.js');
|
|
15
|
-
require('../Typography-cjs.js');
|
|
16
|
-
require('../Text-cjs.js');
|
|
17
|
-
require('../useFormFieldFocus-cjs.js');
|
|
18
|
-
require('../InputValidation-cjs.js');
|
|
19
|
-
require('../FormFieldPostFix-cjs.js');
|
|
20
|
-
require('../Spinner-cjs.js');
|
|
21
|
-
require('../useAtlantisFormFieldName-cjs.js');
|
|
22
|
-
require('react-hook-form');
|
|
23
|
-
require('../mergeRefs-cjs.js');
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
exports.InputPassword = InputPassword.InputPassword;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { InputPassword } from "./InputPassword";
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export { I as InputPassword } from '../InputPassword-es.js';
|
|
2
|
-
import 'react';
|
|
3
|
-
import '../FormField-es.js';
|
|
4
|
-
import '../FormFieldWrapper-es.js';
|
|
5
|
-
import '@jobber/hooks';
|
|
6
|
-
import 'framer-motion';
|
|
7
|
-
import '@jobber/design';
|
|
8
|
-
import 'classnames';
|
|
9
|
-
import '../Button-es.js';
|
|
10
|
-
import '../tslib.es6-es.js';
|
|
11
|
-
import 'react-router-dom';
|
|
12
|
-
import '../Icon-es.js';
|
|
13
|
-
import '../Typography-es.js';
|
|
14
|
-
import '../Text-es.js';
|
|
15
|
-
import '../useFormFieldFocus-es.js';
|
|
16
|
-
import '../InputValidation-es.js';
|
|
17
|
-
import '../FormFieldPostFix-es.js';
|
|
18
|
-
import '../Spinner-es.js';
|
|
19
|
-
import '../useAtlantisFormFieldName-es.js';
|
|
20
|
-
import 'react-hook-form';
|
|
21
|
-
import '../mergeRefs-es.js';
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
var FormField = require('./FormField-cjs.js');
|
|
5
|
-
require('classnames');
|
|
6
|
-
require('./tslib.es6-cjs.js');
|
|
7
|
-
require('react-hook-form');
|
|
8
|
-
require('@jobber/hooks');
|
|
9
|
-
require('framer-motion');
|
|
10
|
-
require('@jobber/design');
|
|
11
|
-
require('./Button-cjs.js');
|
|
12
|
-
|
|
13
|
-
function InputPassword(props) {
|
|
14
|
-
const { hasVisibility = false } = props;
|
|
15
|
-
const [visible, setVisibility] = React.useState(false);
|
|
16
|
-
return (React.createElement(FormField.FormField, Object.assign({}, props, (hasVisibility && {
|
|
17
|
-
suffix: {
|
|
18
|
-
ariaLabel: visible ? "Hide password" : "Show password",
|
|
19
|
-
icon: visible ? "eye" : "eyeCrossed",
|
|
20
|
-
onClick: () => setVisibility(!visible),
|
|
21
|
-
},
|
|
22
|
-
}), { type: visible ? "text" : "password", onChange: handleChange })));
|
|
23
|
-
function handleChange(newValue) {
|
|
24
|
-
props.onChange && props.onChange(newValue);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
exports.InputPassword = InputPassword;
|
package/dist/InputPassword-es.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import React__default, { useState } from 'react';
|
|
2
|
-
import { F as FormField } from './FormField-es.js';
|
|
3
|
-
import 'classnames';
|
|
4
|
-
import './tslib.es6-es.js';
|
|
5
|
-
import 'react-hook-form';
|
|
6
|
-
import '@jobber/hooks';
|
|
7
|
-
import 'framer-motion';
|
|
8
|
-
import '@jobber/design';
|
|
9
|
-
import './Button-es.js';
|
|
10
|
-
|
|
11
|
-
function InputPassword(props) {
|
|
12
|
-
const { hasVisibility = false } = props;
|
|
13
|
-
const [visible, setVisibility] = useState(false);
|
|
14
|
-
return (React__default.createElement(FormField, Object.assign({}, props, (hasVisibility && {
|
|
15
|
-
suffix: {
|
|
16
|
-
ariaLabel: visible ? "Hide password" : "Show password",
|
|
17
|
-
icon: visible ? "eye" : "eyeCrossed",
|
|
18
|
-
onClick: () => setVisibility(!visible),
|
|
19
|
-
},
|
|
20
|
-
}), { type: visible ? "text" : "password", onChange: handleChange })));
|
|
21
|
-
function handleChange(newValue) {
|
|
22
|
-
props.onChange && props.onChange(newValue);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export { InputPassword as I };
|