@jobber/components 7.5.0 → 7.7.0
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 +6 -5
- package/dist/Autocomplete/index.mjs +3 -2
- package/dist/DataList/components/DataListSearch/index.cjs +1 -0
- package/dist/DataList/components/DataListSearch/index.mjs +1 -0
- package/dist/DataList/index.cjs +1 -0
- package/dist/DataList/index.mjs +1 -0
- package/dist/DataTable/index.cjs +2 -14
- package/dist/DataTable/index.mjs +2 -14
- package/dist/DataTable-cjs.js +3 -3
- package/dist/DataTable-es.js +1 -1
- package/dist/FormField/index.cjs +14 -13
- package/dist/FormField/index.mjs +5 -4
- package/dist/FormField-cjs.js +8 -281
- package/dist/FormField-es.js +3 -263
- package/dist/InputDate/InputDate.d.ts +1 -1
- package/dist/InputDate/InputDate.types.d.ts +2 -30
- package/dist/InputDate/index.cjs +22 -163
- package/dist/InputDate/index.d.ts +2 -4
- package/dist/InputDate/index.mjs +21 -166
- package/dist/InputDate/useInputDateActivatorActions.d.ts +2 -2
- package/dist/InputDate-cjs.js +96 -0
- package/dist/InputDate-es.js +94 -0
- package/dist/InputEmail/index.cjs +7 -6
- package/dist/InputEmail/index.mjs +4 -3
- package/dist/InputNumber/index.cjs +1 -0
- package/dist/InputNumber/index.mjs +2 -1
- package/dist/InputPassword/index.cjs +1 -0
- package/dist/InputPassword/index.mjs +1 -0
- package/dist/InputPassword-es.js +1 -1
- package/dist/InputPhoneNumber/index.cjs +6 -5
- package/dist/InputPhoneNumber/index.mjs +2 -1
- package/dist/InputText/index.cjs +8 -7
- package/dist/InputText/index.mjs +4 -3
- package/dist/InputTime/index.cjs +5 -4
- package/dist/InputTime/index.mjs +2 -1
- package/dist/RecurringSelect/index.cjs +3 -14
- package/dist/RecurringSelect/index.mjs +3 -14
- package/dist/RecurringSelect-cjs.js +6 -6
- package/dist/RecurringSelect-es.js +1 -1
- package/dist/Select/Select.d.ts +6 -2
- package/dist/Select/Select.types.d.ts +2 -16
- package/dist/Select/index.cjs +11 -103
- package/dist/Select/index.d.ts +2 -9
- package/dist/Select/index.mjs +9 -105
- package/dist/Select-cjs.js +78 -0
- package/dist/Select-es.js +75 -0
- package/dist/docs/InputDate/InputDate.md +31 -19
- package/dist/docs/Select/Select.md +69 -33
- package/dist/docs/usage-guidelines/usage-guidelines.md +9 -13
- package/dist/index.cjs +16 -15
- package/dist/index.mjs +4 -3
- package/dist/mergeRefs-cjs.js +279 -0
- package/dist/mergeRefs-es.js +265 -0
- package/package.json +2 -2
- package/dist/InputDate/InputDate.rebuilt.d.ts +0 -3
- package/dist/Select/Select.rebuilt.d.ts +0 -3
package/dist/FormField-es.js
CHANGED
|
@@ -1,242 +1,9 @@
|
|
|
1
|
-
import React__default, {
|
|
2
|
-
import {
|
|
3
|
-
import { AnimatePresence, motion } from 'framer-motion';
|
|
4
|
-
import { tokens } from '@jobber/design';
|
|
1
|
+
import React__default, { useEffect, useImperativeHandle, useId, useRef } from 'react';
|
|
2
|
+
import { h as formFieldStyles, m as mergeRefs, c as FormFieldWrapper, i as FormFieldPostFix, u as useAtlantisFormFieldName } from './mergeRefs-es.js';
|
|
5
3
|
import classnames from 'classnames';
|
|
6
|
-
import { B as Button } from './Button-es.js';
|
|
7
|
-
import { I as Icon } from './Icon-es.js';
|
|
8
|
-
import { T as Text } from './Text-es.js';
|
|
9
|
-
import { u as useFormFieldFocus } from './useFormFieldFocus-es.js';
|
|
10
|
-
import { I as InputValidation } from './InputValidation-es.js';
|
|
11
|
-
import { S as Spinner } from './Spinner-es.js';
|
|
12
4
|
import { _ as __rest } from './tslib.es6-es.js';
|
|
13
5
|
import { useFormContext, useForm, useController } from 'react-hook-form';
|
|
14
6
|
|
|
15
|
-
var formFieldStyles = {"container":"YL-mNv-Bl6g-","wrapper":"_8lhbGTQ-hhg-","disabled":"Tz9LK9ABKMk-","horizontalWrapper":"b5mv1x1H7YE-","textarea":"hGr6YW4AeLM-","safari":"QBCWi9GBgMs-","timeInputLabel":"_0pmqVa2zSE4-","miniLabel":"F1t76G6bDKo-","large":"_9tjyT9QUtP8-","text":"QmMiyoAWp-g-","invalid":"XWDSfe6weSY-","small":"Sw5O4I0lMJg-","inline":"SaORbL7SYWY-","center":"ozy2UoT2vsg-","right":"_3TJdT91YD3c-","maxLength":"W6GrMqLy2qk-","inputWrapper":"-LmjnYRU0r0-","childrenWrapper":"yVXYv6hkuOA-","input":"vtSDcuzNr9Q-","emptyPhoneNumber":"MVhuQuzUBUs-","label":"Dgk00tzlODA-","select":"NwQGiWBWIsc-","externalLabel":"Qb8zQ8n-8vc-","postfix":"yTDzs9h1otI-","affixIcon":"m0YpdssD2dY-","suffix":"_-3mMnjSh6ok-","affixLabel":"-Wzcb0pBh5I-","description":"DHX5ijY3xIw-","toolbar":"AL-2brNI7dk-","spinning":"_8Rzv7CcDW80-"};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @internal Reach out to UX Foundations if using this component since it is possible it might change
|
|
19
|
-
*/
|
|
20
|
-
function AffixLabel({ label, variation = "prefix", labelRef, }) {
|
|
21
|
-
const affixLabelClass = classnames(formFieldStyles.affixLabel, {
|
|
22
|
-
[formFieldStyles.suffix]: variation === "suffix",
|
|
23
|
-
});
|
|
24
|
-
if (!label)
|
|
25
|
-
return null;
|
|
26
|
-
return (React__default.createElement("div", { ref: labelRef, className: affixLabelClass }, label));
|
|
27
|
-
}
|
|
28
|
-
function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
|
|
29
|
-
const affixIconClass = classnames(formFieldStyles.affixIcon, {
|
|
30
|
-
[formFieldStyles.suffix]: variation === "suffix",
|
|
31
|
-
});
|
|
32
|
-
const iconSize = size === "small" ? "small" : "base";
|
|
33
|
-
if (!icon)
|
|
34
|
-
return null;
|
|
35
|
-
return (React__default.createElement("div", { className: affixIconClass }, onClick ? (React__default.createElement(Button
|
|
36
|
-
/**
|
|
37
|
-
* We can cast the ariaLabel here as a `Suffix`
|
|
38
|
-
* requires an ariaLabel if there is an action
|
|
39
|
-
*/
|
|
40
|
-
, {
|
|
41
|
-
/**
|
|
42
|
-
* We can cast the ariaLabel here as a `Suffix`
|
|
43
|
-
* requires an ariaLabel if there is an action
|
|
44
|
-
*/
|
|
45
|
-
ariaLabel: ariaLabel, icon: icon, onClick: onClick, variation: "subtle", type: "tertiary", size: iconSize })) : (React__default.createElement(Icon, { name: icon, size: iconSize, color: "greyBlue" }))));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function FormFieldDescription({ id, description, visible = true, }) {
|
|
49
|
-
if (!visible)
|
|
50
|
-
return null;
|
|
51
|
-
const useStringFormat = !description || typeof description === "string";
|
|
52
|
-
return (React__default.createElement("div", { id: id, className: formFieldStyles.description }, useStringFormat ? (React__default.createElement(Text, { size: "small", variation: "subdued" }, description)) : (description)));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var styles = {"clearInput":"YmRTd-KeXv4-","spinning":"B25z9B8I3gs-"};
|
|
56
|
-
|
|
57
|
-
function ClearAction({ onClick, visible, }) {
|
|
58
|
-
if (!visible)
|
|
59
|
-
return null;
|
|
60
|
-
return (React__default.createElement("button", { className: styles.clearInput, onClick: onClick, type: "button", "aria-label": "Clear input", "data-testid": "ATL-FormField-clearButton" },
|
|
61
|
-
React__default.createElement(Icon, { name: "remove", size: "small" })));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function useToolbar(props) {
|
|
65
|
-
const isToolbarVisible = props.toolbar !== undefined &&
|
|
66
|
-
(props.toolbarVisibility === "always" || props.focused);
|
|
67
|
-
const toolbarAnimationEnd = { opacity: 0, height: 0 };
|
|
68
|
-
const toolbarAnimationStart = { opacity: 1, height: "auto" };
|
|
69
|
-
return {
|
|
70
|
-
isToolbarVisible,
|
|
71
|
-
toolbarAnimationEnd,
|
|
72
|
-
toolbarAnimationStart,
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function useIsSafari() {
|
|
77
|
-
return (globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator)
|
|
78
|
-
? /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
|
|
79
|
-
: false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Hook for getting the correct styles for the FormField and its children
|
|
84
|
-
*/
|
|
85
|
-
function useFormFieldWrapperStyles({ size, align, placeholder, value, invalid, error, max, prefixRef, suffixRef, maxLength, type, disabled, inline, showMiniLabel = true, }) {
|
|
86
|
-
const isSafari = useIsSafari();
|
|
87
|
-
const wrapperClasses = classnames(formFieldStyles.wrapper, size && formFieldStyles[size], align && formFieldStyles[align], {
|
|
88
|
-
[formFieldStyles.miniLabel]: (showMiniLabel && placeholder && value !== "") ||
|
|
89
|
-
(placeholder && type === "select") ||
|
|
90
|
-
// Naively assume that if the the type is tel, it is the InputPhoneNumber
|
|
91
|
-
(placeholder && type === "tel"),
|
|
92
|
-
[formFieldStyles.text]: type === "textarea" || type === "text",
|
|
93
|
-
[formFieldStyles.textarea]: type === "textarea",
|
|
94
|
-
[formFieldStyles.safari]: isSafari && type === "textarea",
|
|
95
|
-
[formFieldStyles.select]: type === "select",
|
|
96
|
-
[formFieldStyles.invalid]: invalid !== null && invalid !== void 0 ? invalid : error,
|
|
97
|
-
[formFieldStyles.disabled]: disabled,
|
|
98
|
-
[formFieldStyles.maxLength]: maxLength,
|
|
99
|
-
[formFieldStyles.timeInputLabel]: placeholder && type === "time" && placeholder && value === "",
|
|
100
|
-
});
|
|
101
|
-
const containerClasses = classnames(formFieldStyles.container, {
|
|
102
|
-
[formFieldStyles.inline]: inline,
|
|
103
|
-
});
|
|
104
|
-
const wrapperInlineStyle = {
|
|
105
|
-
["--formField-maxLength"]: maxLength || max,
|
|
106
|
-
};
|
|
107
|
-
const [labelStyle, setLabelStyle] = useState({
|
|
108
|
-
paddingLeft: undefined,
|
|
109
|
-
paddingRight: undefined,
|
|
110
|
-
});
|
|
111
|
-
useEffect(() => {
|
|
112
|
-
var _a, _b;
|
|
113
|
-
setLabelStyle(getAffixPaddding({
|
|
114
|
-
value,
|
|
115
|
-
type,
|
|
116
|
-
prefixWidth: ((_a = prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0,
|
|
117
|
-
suffixWidth: ((_b = suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current) === null || _b === void 0 ? void 0 : _b.offsetWidth) || 0,
|
|
118
|
-
}));
|
|
119
|
-
}, [value]);
|
|
120
|
-
return {
|
|
121
|
-
inputStyle: formFieldStyles.input,
|
|
122
|
-
wrapperClasses,
|
|
123
|
-
containerClasses,
|
|
124
|
-
wrapperInlineStyle,
|
|
125
|
-
labelStyle,
|
|
126
|
-
setLabelStyle,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function getAffixPaddding({ value, type, prefixWidth, suffixWidth, }) {
|
|
130
|
-
const hasValue = value !== "";
|
|
131
|
-
const newPadding = {
|
|
132
|
-
paddingLeft: undefined,
|
|
133
|
-
paddingRight: undefined,
|
|
134
|
-
};
|
|
135
|
-
// Naively assume that if the the type is tel, it is the InputPhoneNumber
|
|
136
|
-
if (type === "tel")
|
|
137
|
-
return newPadding;
|
|
138
|
-
if (prefixWidth && !hasValue) {
|
|
139
|
-
newPadding.paddingLeft = offset(prefixWidth);
|
|
140
|
-
}
|
|
141
|
-
if (suffixWidth && !hasValue) {
|
|
142
|
-
newPadding.paddingRight = offset(suffixWidth);
|
|
143
|
-
}
|
|
144
|
-
function offset(width) {
|
|
145
|
-
return `calc(${width}px + var(--space-smallest)`;
|
|
146
|
-
}
|
|
147
|
-
return newPadding;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function FormFieldWrapper({ align, description, descriptionIdentifier, placeholder, value, children, invalid, error, size, prefix, suffix, max, maxLength, type, disabled, inline, identifier, clearable, onClear, readonly, toolbar, toolbarVisibility = "while-editing", showMiniLabel = true, wrapperRef, }) {
|
|
151
|
-
const prefixRef = useRef(null);
|
|
152
|
-
const suffixRef = useRef(null);
|
|
153
|
-
const { wrapperClasses, containerClasses, wrapperInlineStyle, labelStyle } = useFormFieldWrapperStyles({
|
|
154
|
-
align,
|
|
155
|
-
max,
|
|
156
|
-
maxLength,
|
|
157
|
-
prefixRef,
|
|
158
|
-
suffixRef,
|
|
159
|
-
placeholder,
|
|
160
|
-
value,
|
|
161
|
-
invalid,
|
|
162
|
-
error,
|
|
163
|
-
type,
|
|
164
|
-
disabled,
|
|
165
|
-
inline,
|
|
166
|
-
size,
|
|
167
|
-
showMiniLabel,
|
|
168
|
-
});
|
|
169
|
-
const { focused } = useFormFieldFocus({ wrapperRef });
|
|
170
|
-
const showClear = useShowClear({
|
|
171
|
-
clearable,
|
|
172
|
-
multiline: type === "textarea",
|
|
173
|
-
focused,
|
|
174
|
-
hasValue: Boolean(value),
|
|
175
|
-
disabled,
|
|
176
|
-
readonly,
|
|
177
|
-
});
|
|
178
|
-
const { isToolbarVisible, toolbarAnimationEnd, toolbarAnimationStart } = useToolbar({
|
|
179
|
-
focused,
|
|
180
|
-
toolbar,
|
|
181
|
-
toolbarVisibility,
|
|
182
|
-
});
|
|
183
|
-
return (React__default.createElement("div", { className: containerClasses },
|
|
184
|
-
React__default.createElement("div", { className: wrapperClasses, style: wrapperInlineStyle, "data-testid": "Form-Field-Wrapper", ref: wrapperRef },
|
|
185
|
-
React__default.createElement(FormFieldInputHorizontalWrapper, null,
|
|
186
|
-
React__default.createElement(AffixIcon, Object.assign({}, prefix, { size: size })),
|
|
187
|
-
React__default.createElement(FormFieldInputWrapperStyles, null,
|
|
188
|
-
(showMiniLabel || !value) && (React__default.createElement(FormFieldLabel, { htmlFor: identifier, style: (prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) || (suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current)
|
|
189
|
-
? labelStyle
|
|
190
|
-
: undefined }, placeholder)),
|
|
191
|
-
React__default.createElement(AffixLabel, Object.assign({}, prefix, { labelRef: prefixRef })),
|
|
192
|
-
React__default.createElement(FormFieldWrapperMain, null, children),
|
|
193
|
-
React__default.createElement(AffixLabel, Object.assign({}, suffix, { labelRef: suffixRef, variation: "suffix" }))),
|
|
194
|
-
React__default.createElement(ClearAction, { onClick: onClear, visible: showClear }),
|
|
195
|
-
React__default.createElement(AffixIcon, Object.assign({}, suffix, { variation: "suffix", size: size }))),
|
|
196
|
-
React__default.createElement(FormFieldWrapperToolbar, { toolbarVisibility: toolbarVisibility, isToolbarVisible: isToolbarVisible, toolbarAnimationEnd: toolbarAnimationEnd, toolbarAnimationStart: toolbarAnimationStart, toolbar: toolbar })),
|
|
197
|
-
React__default.createElement(FormFieldDescription, { visible: !!description && !inline, id: descriptionIdentifier, description: description }),
|
|
198
|
-
React__default.createElement(InputValidation, { message: error, visible: !!error && !inline })));
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* @internal Reach out to UX Foundations if using this component since it is possible it might change
|
|
202
|
-
*/
|
|
203
|
-
function FormFieldInputHorizontalWrapper({ children, }) {
|
|
204
|
-
return React__default.createElement("div", { className: formFieldStyles.horizontalWrapper }, children);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* @internal Reach out to UX Foundations if using this component since it is possible it might change
|
|
208
|
-
*/
|
|
209
|
-
function FormFieldInputWrapperStyles({ children, }) {
|
|
210
|
-
return React__default.createElement("div", { className: formFieldStyles.inputWrapper }, children);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* @internal Reach out to UX Foundations if using this component since it is possible it might change
|
|
214
|
-
*/
|
|
215
|
-
function FormFieldWrapperMain({ children, tabIndex = -1, }) {
|
|
216
|
-
return (React__default.createElement("div", { className: formFieldStyles.childrenWrapper, tabIndex: tabIndex }, children));
|
|
217
|
-
}
|
|
218
|
-
function FormFieldLabel({ children, htmlFor, style, external = false, }) {
|
|
219
|
-
if (!children)
|
|
220
|
-
return null;
|
|
221
|
-
return (React__default.createElement("label", { className: external ? formFieldStyles.externalLabel : formFieldStyles.label, htmlFor: htmlFor, style: style }, children));
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* @internal Reach out to UX Foundations if using this component since it is possible it might change
|
|
225
|
-
*/
|
|
226
|
-
function FormFieldWrapperToolbar({ toolbar, isToolbarVisible, toolbarAnimationEnd, toolbarAnimationStart, toolbarVisibility, }) {
|
|
227
|
-
return (React__default.createElement(AnimatePresence, { initial: toolbarVisibility === "always" ? false : true }, isToolbarVisible && (React__default.createElement(motion.div, { key: "toolbar", initial: toolbarAnimationEnd, animate: toolbarAnimationStart, exit: toolbarAnimationEnd, transition: {
|
|
228
|
-
duration: tokens["timing-base"] / 1000,
|
|
229
|
-
ease: "easeInOut",
|
|
230
|
-
}, tabIndex: -1 },
|
|
231
|
-
React__default.createElement("div", { className: formFieldStyles.toolbar, "data-testid": "ATL-InputText-Toolbar" }, toolbar)))));
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function FormFieldPostFix({ variation, visible = true, className, }) {
|
|
235
|
-
if (!visible)
|
|
236
|
-
return null;
|
|
237
|
-
return (React__default.createElement("span", { className: classnames(formFieldStyles.postfix, className) }, variation === "select" ? (React__default.createElement(Icon, { name: "arrowDown" })) : (React__default.createElement(Spinner, { size: "small" }))));
|
|
238
|
-
}
|
|
239
|
-
|
|
240
7
|
/**
|
|
241
8
|
* Combines the actions from the props of the FormField with the actions from react-hook-form. This is used to
|
|
242
9
|
* manage the form state of a field through react-hook-form while providing support for additional callbacks
|
|
@@ -309,33 +76,6 @@ function shouldAddPhoneNumberClass(type, value, pattern) {
|
|
|
309
76
|
return type === "tel" && !value && pattern && pattern[0] === "(";
|
|
310
77
|
}
|
|
311
78
|
|
|
312
|
-
function useAtlantisFormFieldName({ id, nameProp, }) {
|
|
313
|
-
/**
|
|
314
|
-
* Generate a name if one is not supplied, this is the name
|
|
315
|
-
* that will be used for react-hook-form and not neccessarily
|
|
316
|
-
* attached to the DOM
|
|
317
|
-
*/
|
|
318
|
-
const name = nameProp ? nameProp : `generatedName--${id}`;
|
|
319
|
-
return { name };
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Given an array of refs, merge them into a single ref callback.
|
|
324
|
-
* This is useful for cases where you need to pass a multiple refs to a component.
|
|
325
|
-
*/
|
|
326
|
-
function mergeRefs(refs) {
|
|
327
|
-
return value => {
|
|
328
|
-
refs.forEach(ref => {
|
|
329
|
-
if (typeof ref === "function") {
|
|
330
|
-
ref(value);
|
|
331
|
-
}
|
|
332
|
-
else if (ref != null) {
|
|
333
|
-
ref.current = value;
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
|
|
339
79
|
/**
|
|
340
80
|
* Hook used to manage the form state of a field through react-hook-form
|
|
341
81
|
*/
|
|
@@ -458,4 +198,4 @@ function setAutocomplete(autocompleteSetting) {
|
|
|
458
198
|
return autocompleteSetting;
|
|
459
199
|
}
|
|
460
200
|
|
|
461
|
-
export {
|
|
201
|
+
export { FormField as F, useAtlantisFormFieldActions as a, useAtlantisReactHookForm as b, useAtlantisFormField as u };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import type { InputDateProps } from "./InputDate.types";
|
|
3
|
-
export declare
|
|
3
|
+
export declare const InputDate: React.ForwardRefExoticComponent<InputDateProps & React.RefAttributes<HTMLInputElement>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FormFieldProps } from "../FormField";
|
|
2
2
|
import type { FocusEvents, HTMLInputBaseProps, KeyboardEvents, RebuiltInputCommonProps } from "../sharedHelpers/types";
|
|
3
|
-
export interface
|
|
3
|
+
export interface InputDateProps extends Omit<HTMLInputBaseProps, "maxLength">, FocusEvents<HTMLInputElement | HTMLTextAreaElement>, KeyboardEvents<HTMLInputElement | HTMLTextAreaElement>, Omit<RebuiltInputCommonProps, "clearable" | "prefix" | "suffix" | "showMiniLabel" | "version"> {
|
|
4
4
|
/**
|
|
5
5
|
* A Date object value
|
|
6
6
|
* (e.g., `new Date("11/11/2011")`)
|
|
@@ -34,31 +34,3 @@ export interface InputDateRebuiltProps extends Omit<HTMLInputBaseProps, "maxLeng
|
|
|
34
34
|
*/
|
|
35
35
|
readonly emptyValueLabel?: string;
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated Use the v2 InputDate component instead (version={2}).
|
|
39
|
-
*/
|
|
40
|
-
export interface InputDateProps extends Omit<CommonFormFieldProps, "clearable">, Pick<FormFieldProps, "readonly" | "disabled" | "onEnter" | "onFocus" | "inputRef" | "validations" | "placeholder" | "onChange" | "onBlur"> {
|
|
41
|
-
/**
|
|
42
|
-
* A Date object value
|
|
43
|
-
* (e.g., `new Date("11/11/2011")`)
|
|
44
|
-
* */
|
|
45
|
-
readonly value?: Date;
|
|
46
|
-
onChange(newValue: Date): void;
|
|
47
|
-
/**
|
|
48
|
-
* The maximum selectable date.
|
|
49
|
-
*/
|
|
50
|
-
readonly maxDate?: Date;
|
|
51
|
-
/**
|
|
52
|
-
* The minimum selectable date.
|
|
53
|
-
*/
|
|
54
|
-
readonly minDate?: Date;
|
|
55
|
-
/**
|
|
56
|
-
* Whether to show the calendar icon
|
|
57
|
-
* @default true
|
|
58
|
-
*/
|
|
59
|
-
readonly showIcon?: boolean;
|
|
60
|
-
/**
|
|
61
|
-
* Text to display instead of a date value
|
|
62
|
-
*/
|
|
63
|
-
readonly emptyValueLabel?: string;
|
|
64
|
-
}
|
package/dist/InputDate/index.cjs
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
var InputDate = require('../InputDate-cjs.js');
|
|
4
|
+
require('react');
|
|
5
|
+
require('../DatePicker-cjs.js');
|
|
6
6
|
require('classnames');
|
|
7
|
-
require('../
|
|
8
|
-
require('react-
|
|
7
|
+
require('../clsx-cjs.js');
|
|
8
|
+
require('../floating-ui.react-cjs.js');
|
|
9
|
+
require('../index.esm-cjs.js');
|
|
10
|
+
require('react/jsx-runtime');
|
|
11
|
+
require('react-dom');
|
|
12
|
+
require('../floating-ui.react-dom-cjs.js');
|
|
9
13
|
require('@jobber/hooks');
|
|
10
|
-
require('
|
|
11
|
-
require('@jobber/design');
|
|
14
|
+
require('../Typography-cjs.js');
|
|
12
15
|
require('../Button-cjs.js');
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
require('../tslib.es6-cjs.js');
|
|
17
|
+
require('react-router-dom');
|
|
18
|
+
require('../Icon-cjs.js');
|
|
19
|
+
require('@jobber/design');
|
|
20
|
+
require('../omit-cjs.js');
|
|
15
21
|
require('../_commonjsHelpers-cjs.js');
|
|
16
22
|
require('../_getAllKeys-cjs.js');
|
|
17
23
|
require('../isTypedArray-cjs.js');
|
|
@@ -23,165 +29,18 @@ require('../keysIn-cjs.js');
|
|
|
23
29
|
require('../_baseAssignValue-cjs.js');
|
|
24
30
|
require('../_baseFlatten-cjs.js');
|
|
25
31
|
require('../_setToString-cjs.js');
|
|
26
|
-
require('../
|
|
32
|
+
require('../AtlantisContext-cjs.js');
|
|
33
|
+
require('../InputText/index.cjs');
|
|
34
|
+
require('../FormField-cjs.js');
|
|
35
|
+
require('../mergeRefs-cjs.js');
|
|
36
|
+
require('framer-motion');
|
|
27
37
|
require('../Text-cjs.js');
|
|
28
|
-
require('../Typography-cjs.js');
|
|
29
38
|
require('../useFormFieldFocus-cjs.js');
|
|
30
39
|
require('../InputValidation-cjs.js');
|
|
31
40
|
require('../Spinner-cjs.js');
|
|
32
|
-
require('react-
|
|
33
|
-
require('../clsx-cjs.js');
|
|
34
|
-
require('../floating-ui.react-cjs.js');
|
|
35
|
-
require('../index.esm-cjs.js');
|
|
36
|
-
require('react/jsx-runtime');
|
|
37
|
-
require('react-dom');
|
|
38
|
-
require('../floating-ui.react-dom-cjs.js');
|
|
39
|
-
require('../AtlantisContext-cjs.js');
|
|
41
|
+
require('react-hook-form');
|
|
40
42
|
require('../filterDataAttributes-cjs.js');
|
|
41
43
|
|
|
42
|
-
// eslint-disable-next-line import/no-deprecated
|
|
43
|
-
function InputDate$1(inputProps) {
|
|
44
|
-
const formFieldActionsRef = React.useRef(null);
|
|
45
|
-
return (React.createElement(DatePicker.DatePicker, { selected: inputProps.value, onChange: inputProps.onChange, disabled: inputProps.disabled, readonly: inputProps.readonly, fullWidth: !inputProps.inline, minDate: inputProps.minDate, maxDate: inputProps.maxDate, smartAutofocus: false, activator: activatorProps => {
|
|
46
|
-
const { onChange, onClick, value } = activatorProps;
|
|
47
|
-
const newActivatorProps = omit.omit(activatorProps, ["activator"]);
|
|
48
|
-
const [isFocused, setIsFocused] = React.useState(false);
|
|
49
|
-
const suffix = inputProps.showIcon !== false
|
|
50
|
-
? {
|
|
51
|
-
icon: "calendar",
|
|
52
|
-
ariaLabel: "Show calendar",
|
|
53
|
-
onClick: !inputProps.disabled && onClick && onClick,
|
|
54
|
-
}
|
|
55
|
-
: undefined;
|
|
56
|
-
// Set form field to formatted date string immediately, to avoid validations
|
|
57
|
-
// triggering incorrectly when it blurs (to handle the datepicker UI click)
|
|
58
|
-
React.useEffect(() => {
|
|
59
|
-
var _a;
|
|
60
|
-
value && ((_a = formFieldActionsRef.current) === null || _a === void 0 ? void 0 : _a.setValue(value));
|
|
61
|
-
}, [value]);
|
|
62
|
-
const showEmptyValueLabel = !value && !isFocused;
|
|
63
|
-
return (
|
|
64
|
-
// We prevent the picker from opening on focus for keyboard navigation, so to maintain a good UX for mouse users we want to open the picker on click
|
|
65
|
-
React.createElement("div", { onClick: onClick },
|
|
66
|
-
React.createElement(FormField.FormField, Object.assign({}, newActivatorProps, inputProps, { value: showEmptyValueLabel ? inputProps.emptyValueLabel || "" : value, placeholder: inputProps.placeholder, onChange: (_, event) => {
|
|
67
|
-
onChange && onChange(event);
|
|
68
|
-
}, onBlur: () => {
|
|
69
|
-
inputProps.onBlur && inputProps.onBlur();
|
|
70
|
-
activatorProps.onBlur && activatorProps.onBlur();
|
|
71
|
-
setIsFocused(false);
|
|
72
|
-
}, onFocus: () => {
|
|
73
|
-
inputProps.onFocus && inputProps.onFocus();
|
|
74
|
-
activatorProps.onFocus && activatorProps.onFocus();
|
|
75
|
-
setIsFocused(true);
|
|
76
|
-
}, onKeyUp: event => {
|
|
77
|
-
var _a;
|
|
78
|
-
if (inputProps.showIcon === false &&
|
|
79
|
-
event.key === "ArrowDown") {
|
|
80
|
-
(_a = activatorProps.onClick) === null || _a === void 0 ? void 0 : _a.call(activatorProps);
|
|
81
|
-
}
|
|
82
|
-
}, actionsRef: formFieldActionsRef, suffix: suffix }))));
|
|
83
|
-
} }));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function useInputDateActivatorActions({ onChange, onBlur, onFocus, }) {
|
|
87
|
-
const [isFocused, setIsFocused] = React.useState(false);
|
|
88
|
-
function handleChange(_newValue, event) {
|
|
89
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
90
|
-
}
|
|
91
|
-
function handleFocus(event) {
|
|
92
|
-
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
93
|
-
setIsFocused(true);
|
|
94
|
-
}
|
|
95
|
-
function handleBlur(event) {
|
|
96
|
-
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
97
|
-
setIsFocused(false);
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
handleBlur,
|
|
101
|
-
handleChange,
|
|
102
|
-
handleFocus,
|
|
103
|
-
isFocused,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const InputDateRebuilt = React.forwardRef((props, forwardedRef) => {
|
|
108
|
-
const { onChange } = props;
|
|
109
|
-
const isCalendarOpenRef = React.useRef(false);
|
|
110
|
-
const inputFocusedRef = React.useRef(false);
|
|
111
|
-
const compositeFocusedRef = React.useRef(false);
|
|
112
|
-
const lastBlurEventRef = React.useRef(null);
|
|
113
|
-
return (React.createElement(DatePicker.DatePicker, { selected: props.value, onChange: newValue => {
|
|
114
|
-
onChange(newValue);
|
|
115
|
-
}, disabled: props.disabled, readonly: props.readOnly, fullWidth: !props.inline, minDate: props.minDate, maxDate: props.maxDate, smartAutofocus: false, activator: InputDateActivator, onOpenChange: open => {
|
|
116
|
-
var _a;
|
|
117
|
-
isCalendarOpenRef.current = open;
|
|
118
|
-
// When calendar closes, fire onBlur if input is also not focused
|
|
119
|
-
if (!open &&
|
|
120
|
-
!inputFocusedRef.current &&
|
|
121
|
-
compositeFocusedRef.current &&
|
|
122
|
-
lastBlurEventRef.current) {
|
|
123
|
-
compositeFocusedRef.current = false;
|
|
124
|
-
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, lastBlurEventRef.current);
|
|
125
|
-
}
|
|
126
|
-
} }));
|
|
127
|
-
function InputDateActivator(activatorProps) {
|
|
128
|
-
const { onClick, value } = activatorProps;
|
|
129
|
-
const { handleChange, handleFocus, handleBlur, isFocused } = useInputDateActivatorActions({
|
|
130
|
-
onChange: activatorProps.onChange,
|
|
131
|
-
onFocus: event => {
|
|
132
|
-
var _a, _b;
|
|
133
|
-
inputFocusedRef.current = true;
|
|
134
|
-
// Fire parent's onFocus only when the composite component first receives focus
|
|
135
|
-
if (!compositeFocusedRef.current) {
|
|
136
|
-
compositeFocusedRef.current = true;
|
|
137
|
-
(_a = props.onFocus) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
138
|
-
}
|
|
139
|
-
(_b = activatorProps.onFocus) === null || _b === void 0 ? void 0 : _b.call(activatorProps);
|
|
140
|
-
},
|
|
141
|
-
onBlur: event => {
|
|
142
|
-
var _a, _b;
|
|
143
|
-
inputFocusedRef.current = false;
|
|
144
|
-
lastBlurEventRef.current = event;
|
|
145
|
-
// Only fire parent's onBlur if calendar is also closed
|
|
146
|
-
if (!isCalendarOpenRef.current && compositeFocusedRef.current) {
|
|
147
|
-
compositeFocusedRef.current = false;
|
|
148
|
-
(_a = props.onBlur) === null || _a === void 0 ? void 0 : _a.call(props, event);
|
|
149
|
-
}
|
|
150
|
-
(_b = activatorProps.onBlur) === null || _b === void 0 ? void 0 : _b.call(activatorProps);
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
const suffix = props.showIcon !== false
|
|
154
|
-
? {
|
|
155
|
-
icon: "calendar",
|
|
156
|
-
ariaLabel: "Show calendar",
|
|
157
|
-
onClick: !props.disabled && onClick && onClick,
|
|
158
|
-
}
|
|
159
|
-
: undefined;
|
|
160
|
-
const showEmptyValueLabel = !value && !isFocused;
|
|
161
|
-
return (
|
|
162
|
-
// We prevent the picker from opening on focus for keyboard navigation, so to maintain a good UX for mouse users we want to open the picker on click
|
|
163
|
-
React.createElement("div", { onClick: onClick },
|
|
164
|
-
React.createElement(InputText_index.InputText, { "aria-describedby": activatorProps.ariaDescribedBy, "aria-labelledby": activatorProps.ariaLabelledBy, "aria-required": activatorProps.ariaRequired === "true" ? true : false, autoFocus: props.autoFocus, id: activatorProps.id, autoComplete: props.autoComplete, disabled: props.disabled, error: props.error, readOnly: props.readOnly, placeholder: props.placeholder, size: props.size, inline: props.inline, align: props.align, description: props.description, invalid: props.invalid, required: props.required, name: props.name, version: 2, value: showEmptyValueLabel ? props.emptyValueLabel || "" : value || "", ref: forwardedRef, suffix: suffix, onFocus: handleFocus, onBlur: handleBlur, onKeyDown: event => {
|
|
165
|
-
var _a, _b;
|
|
166
|
-
if (props.showIcon === false && event.key === "ArrowDown") {
|
|
167
|
-
(_a = activatorProps.onClick) === null || _a === void 0 ? void 0 : _a.call(activatorProps);
|
|
168
|
-
}
|
|
169
|
-
(_b = props.onKeyDown) === null || _b === void 0 ? void 0 : _b.call(props, event);
|
|
170
|
-
}, onChange: handleChange })));
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
InputDateRebuilt.displayName = "InputDateRebuilt";
|
|
174
44
|
|
|
175
|
-
function isNewInputDateProps(props) {
|
|
176
|
-
return props.version === 2;
|
|
177
|
-
}
|
|
178
|
-
const InputDate = React.forwardRef(function InputDateShim(props, ref) {
|
|
179
|
-
if (isNewInputDateProps(props)) {
|
|
180
|
-
return React.createElement(InputDateRebuilt, Object.assign({}, props, { ref: ref }));
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
return React.createElement(InputDate$1, Object.assign({}, props));
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
45
|
|
|
187
|
-
exports.InputDate = InputDate;
|
|
46
|
+
exports.InputDate = InputDate.InputDate;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type InputDateProps = InputDateLegacyProps | InputDateRebuiltProps;
|
|
4
|
-
export declare const InputDate: React.ForwardRefExoticComponent<InputDateProps & React.RefAttributes<HTMLInputElement>>;
|
|
1
|
+
export type { InputDateProps } from "./InputDate.types";
|
|
2
|
+
export { InputDate } from "./InputDate";
|