@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.
Files changed (56) hide show
  1. package/dist/Autocomplete/index.cjs +6 -5
  2. package/dist/Autocomplete/index.mjs +3 -2
  3. package/dist/DataList/components/DataListSearch/index.cjs +1 -0
  4. package/dist/DataList/components/DataListSearch/index.mjs +1 -0
  5. package/dist/DataList/index.cjs +1 -0
  6. package/dist/DataList/index.mjs +1 -0
  7. package/dist/DataTable/index.cjs +2 -14
  8. package/dist/DataTable/index.mjs +2 -14
  9. package/dist/DataTable-cjs.js +3 -3
  10. package/dist/DataTable-es.js +1 -1
  11. package/dist/FormField/index.cjs +14 -13
  12. package/dist/FormField/index.mjs +5 -4
  13. package/dist/FormField-cjs.js +8 -281
  14. package/dist/FormField-es.js +3 -263
  15. package/dist/InputDate/InputDate.d.ts +1 -1
  16. package/dist/InputDate/InputDate.types.d.ts +2 -30
  17. package/dist/InputDate/index.cjs +22 -163
  18. package/dist/InputDate/index.d.ts +2 -4
  19. package/dist/InputDate/index.mjs +21 -166
  20. package/dist/InputDate/useInputDateActivatorActions.d.ts +2 -2
  21. package/dist/InputDate-cjs.js +96 -0
  22. package/dist/InputDate-es.js +94 -0
  23. package/dist/InputEmail/index.cjs +7 -6
  24. package/dist/InputEmail/index.mjs +4 -3
  25. package/dist/InputNumber/index.cjs +1 -0
  26. package/dist/InputNumber/index.mjs +2 -1
  27. package/dist/InputPassword/index.cjs +1 -0
  28. package/dist/InputPassword/index.mjs +1 -0
  29. package/dist/InputPassword-es.js +1 -1
  30. package/dist/InputPhoneNumber/index.cjs +6 -5
  31. package/dist/InputPhoneNumber/index.mjs +2 -1
  32. package/dist/InputText/index.cjs +8 -7
  33. package/dist/InputText/index.mjs +4 -3
  34. package/dist/InputTime/index.cjs +5 -4
  35. package/dist/InputTime/index.mjs +2 -1
  36. package/dist/RecurringSelect/index.cjs +3 -14
  37. package/dist/RecurringSelect/index.mjs +3 -14
  38. package/dist/RecurringSelect-cjs.js +6 -6
  39. package/dist/RecurringSelect-es.js +1 -1
  40. package/dist/Select/Select.d.ts +6 -2
  41. package/dist/Select/Select.types.d.ts +2 -16
  42. package/dist/Select/index.cjs +11 -103
  43. package/dist/Select/index.d.ts +2 -9
  44. package/dist/Select/index.mjs +9 -105
  45. package/dist/Select-cjs.js +78 -0
  46. package/dist/Select-es.js +75 -0
  47. package/dist/docs/InputDate/InputDate.md +31 -19
  48. package/dist/docs/Select/Select.md +69 -33
  49. package/dist/docs/usage-guidelines/usage-guidelines.md +9 -13
  50. package/dist/index.cjs +16 -15
  51. package/dist/index.mjs +4 -3
  52. package/dist/mergeRefs-cjs.js +279 -0
  53. package/dist/mergeRefs-es.js +265 -0
  54. package/package.json +2 -2
  55. package/dist/InputDate/InputDate.rebuilt.d.ts +0 -3
  56. package/dist/Select/Select.rebuilt.d.ts +0 -3
@@ -0,0 +1,279 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+ var jobberHooks = require('@jobber/hooks');
5
+ var framerMotion = require('framer-motion');
6
+ var design = require('@jobber/design');
7
+ var classnames = require('classnames');
8
+ var Button = require('./Button-cjs.js');
9
+ var Icon = require('./Icon-cjs.js');
10
+ var Text = require('./Text-cjs.js');
11
+ var useFormFieldFocus = require('./useFormFieldFocus-cjs.js');
12
+ var InputValidation = require('./InputValidation-cjs.js');
13
+ var Spinner = require('./Spinner-cjs.js');
14
+
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.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.createElement("div", { className: affixIconClass }, onClick ? (React.createElement(Button.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.createElement(Icon.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.createElement("div", { id: id, className: formFieldStyles.description }, useStringFormat ? (React.createElement(Text.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.createElement("button", { className: styles.clearInput, onClick: onClick, type: "button", "aria-label": "Clear input", "data-testid": "ATL-FormField-clearButton" },
61
+ React.createElement(Icon.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] = React.useState({
108
+ paddingLeft: undefined,
109
+ paddingRight: undefined,
110
+ });
111
+ React.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 = React.useRef(null);
152
+ const suffixRef = React.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.useFormFieldFocus({ wrapperRef });
170
+ const showClear = jobberHooks.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.createElement("div", { className: containerClasses },
184
+ React.createElement("div", { className: wrapperClasses, style: wrapperInlineStyle, "data-testid": "Form-Field-Wrapper", ref: wrapperRef },
185
+ React.createElement(FormFieldInputHorizontalWrapper, null,
186
+ React.createElement(AffixIcon, Object.assign({}, prefix, { size: size })),
187
+ React.createElement(FormFieldInputWrapperStyles, null,
188
+ (showMiniLabel || !value) && (React.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.createElement(AffixLabel, Object.assign({}, prefix, { labelRef: prefixRef })),
192
+ React.createElement(FormFieldWrapperMain, null, children),
193
+ React.createElement(AffixLabel, Object.assign({}, suffix, { labelRef: suffixRef, variation: "suffix" }))),
194
+ React.createElement(ClearAction, { onClick: onClear, visible: showClear }),
195
+ React.createElement(AffixIcon, Object.assign({}, suffix, { variation: "suffix", size: size }))),
196
+ React.createElement(FormFieldWrapperToolbar, { toolbarVisibility: toolbarVisibility, isToolbarVisible: isToolbarVisible, toolbarAnimationEnd: toolbarAnimationEnd, toolbarAnimationStart: toolbarAnimationStart, toolbar: toolbar })),
197
+ React.createElement(FormFieldDescription, { visible: !!description && !inline, id: descriptionIdentifier, description: description }),
198
+ React.createElement(InputValidation.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.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.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.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.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.createElement(framerMotion.AnimatePresence, { initial: toolbarVisibility === "always" ? false : true }, isToolbarVisible && (React.createElement(framerMotion.motion.div, { key: "toolbar", initial: toolbarAnimationEnd, animate: toolbarAnimationStart, exit: toolbarAnimationEnd, transition: {
228
+ duration: design.tokens["timing-base"] / 1000,
229
+ ease: "easeInOut",
230
+ }, tabIndex: -1 },
231
+ React.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.createElement("span", { className: classnames(formFieldStyles.postfix, className) }, variation === "select" ? (React.createElement(Icon.Icon, { name: "arrowDown" })) : (React.createElement(Spinner.Spinner, { size: "small" }))));
238
+ }
239
+
240
+ function useAtlantisFormFieldName({ id, nameProp, }) {
241
+ /**
242
+ * Generate a name if one is not supplied, this is the name
243
+ * that will be used for react-hook-form and not neccessarily
244
+ * attached to the DOM
245
+ */
246
+ const name = nameProp ? nameProp : `generatedName--${id}`;
247
+ return { name };
248
+ }
249
+
250
+ /**
251
+ * Given an array of refs, merge them into a single ref callback.
252
+ * This is useful for cases where you need to pass a multiple refs to a component.
253
+ */
254
+ function mergeRefs(refs) {
255
+ return value => {
256
+ refs.forEach(ref => {
257
+ if (typeof ref === "function") {
258
+ ref(value);
259
+ }
260
+ else if (ref != null) {
261
+ ref.current = value;
262
+ }
263
+ });
264
+ };
265
+ }
266
+
267
+ exports.AffixIcon = AffixIcon;
268
+ exports.AffixLabel = AffixLabel;
269
+ exports.FormFieldInputHorizontalWrapper = FormFieldInputHorizontalWrapper;
270
+ exports.FormFieldInputWrapperStyles = FormFieldInputWrapperStyles;
271
+ exports.FormFieldLabel = FormFieldLabel;
272
+ exports.FormFieldPostFix = FormFieldPostFix;
273
+ exports.FormFieldWrapper = FormFieldWrapper;
274
+ exports.FormFieldWrapperMain = FormFieldWrapperMain;
275
+ exports.FormFieldWrapperToolbar = FormFieldWrapperToolbar;
276
+ exports.formFieldStyles = formFieldStyles;
277
+ exports.mergeRefs = mergeRefs;
278
+ exports.useAtlantisFormFieldName = useAtlantisFormFieldName;
279
+ exports.useFormFieldWrapperStyles = useFormFieldWrapperStyles;
@@ -0,0 +1,265 @@
1
+ import React__default, { useState, useEffect, useRef } from 'react';
2
+ import { useShowClear } from '@jobber/hooks';
3
+ import { AnimatePresence, motion } from 'framer-motion';
4
+ import { tokens } from '@jobber/design';
5
+ 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
+
13
+ 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-"};
14
+
15
+ /**
16
+ * @internal Reach out to UX Foundations if using this component since it is possible it might change
17
+ */
18
+ function AffixLabel({ label, variation = "prefix", labelRef, }) {
19
+ const affixLabelClass = classnames(formFieldStyles.affixLabel, {
20
+ [formFieldStyles.suffix]: variation === "suffix",
21
+ });
22
+ if (!label)
23
+ return null;
24
+ return (React__default.createElement("div", { ref: labelRef, className: affixLabelClass }, label));
25
+ }
26
+ function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
27
+ const affixIconClass = classnames(formFieldStyles.affixIcon, {
28
+ [formFieldStyles.suffix]: variation === "suffix",
29
+ });
30
+ const iconSize = size === "small" ? "small" : "base";
31
+ if (!icon)
32
+ return null;
33
+ return (React__default.createElement("div", { className: affixIconClass }, onClick ? (React__default.createElement(Button
34
+ /**
35
+ * We can cast the ariaLabel here as a `Suffix`
36
+ * requires an ariaLabel if there is an action
37
+ */
38
+ , {
39
+ /**
40
+ * We can cast the ariaLabel here as a `Suffix`
41
+ * requires an ariaLabel if there is an action
42
+ */
43
+ ariaLabel: ariaLabel, icon: icon, onClick: onClick, variation: "subtle", type: "tertiary", size: iconSize })) : (React__default.createElement(Icon, { name: icon, size: iconSize, color: "greyBlue" }))));
44
+ }
45
+
46
+ function FormFieldDescription({ id, description, visible = true, }) {
47
+ if (!visible)
48
+ return null;
49
+ const useStringFormat = !description || typeof description === "string";
50
+ return (React__default.createElement("div", { id: id, className: formFieldStyles.description }, useStringFormat ? (React__default.createElement(Text, { size: "small", variation: "subdued" }, description)) : (description)));
51
+ }
52
+
53
+ var styles = {"clearInput":"YmRTd-KeXv4-","spinning":"B25z9B8I3gs-"};
54
+
55
+ function ClearAction({ onClick, visible, }) {
56
+ if (!visible)
57
+ return null;
58
+ return (React__default.createElement("button", { className: styles.clearInput, onClick: onClick, type: "button", "aria-label": "Clear input", "data-testid": "ATL-FormField-clearButton" },
59
+ React__default.createElement(Icon, { name: "remove", size: "small" })));
60
+ }
61
+
62
+ function useToolbar(props) {
63
+ const isToolbarVisible = props.toolbar !== undefined &&
64
+ (props.toolbarVisibility === "always" || props.focused);
65
+ const toolbarAnimationEnd = { opacity: 0, height: 0 };
66
+ const toolbarAnimationStart = { opacity: 1, height: "auto" };
67
+ return {
68
+ isToolbarVisible,
69
+ toolbarAnimationEnd,
70
+ toolbarAnimationStart,
71
+ };
72
+ }
73
+
74
+ function useIsSafari() {
75
+ return (globalThis === null || globalThis === void 0 ? void 0 : globalThis.navigator)
76
+ ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
77
+ : false;
78
+ }
79
+
80
+ /**
81
+ * Hook for getting the correct styles for the FormField and its children
82
+ */
83
+ function useFormFieldWrapperStyles({ size, align, placeholder, value, invalid, error, max, prefixRef, suffixRef, maxLength, type, disabled, inline, showMiniLabel = true, }) {
84
+ const isSafari = useIsSafari();
85
+ const wrapperClasses = classnames(formFieldStyles.wrapper, size && formFieldStyles[size], align && formFieldStyles[align], {
86
+ [formFieldStyles.miniLabel]: (showMiniLabel && placeholder && value !== "") ||
87
+ (placeholder && type === "select") ||
88
+ // Naively assume that if the the type is tel, it is the InputPhoneNumber
89
+ (placeholder && type === "tel"),
90
+ [formFieldStyles.text]: type === "textarea" || type === "text",
91
+ [formFieldStyles.textarea]: type === "textarea",
92
+ [formFieldStyles.safari]: isSafari && type === "textarea",
93
+ [formFieldStyles.select]: type === "select",
94
+ [formFieldStyles.invalid]: invalid !== null && invalid !== void 0 ? invalid : error,
95
+ [formFieldStyles.disabled]: disabled,
96
+ [formFieldStyles.maxLength]: maxLength,
97
+ [formFieldStyles.timeInputLabel]: placeholder && type === "time" && placeholder && value === "",
98
+ });
99
+ const containerClasses = classnames(formFieldStyles.container, {
100
+ [formFieldStyles.inline]: inline,
101
+ });
102
+ const wrapperInlineStyle = {
103
+ ["--formField-maxLength"]: maxLength || max,
104
+ };
105
+ const [labelStyle, setLabelStyle] = useState({
106
+ paddingLeft: undefined,
107
+ paddingRight: undefined,
108
+ });
109
+ useEffect(() => {
110
+ var _a, _b;
111
+ setLabelStyle(getAffixPaddding({
112
+ value,
113
+ type,
114
+ prefixWidth: ((_a = prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) || 0,
115
+ suffixWidth: ((_b = suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current) === null || _b === void 0 ? void 0 : _b.offsetWidth) || 0,
116
+ }));
117
+ }, [value]);
118
+ return {
119
+ inputStyle: formFieldStyles.input,
120
+ wrapperClasses,
121
+ containerClasses,
122
+ wrapperInlineStyle,
123
+ labelStyle,
124
+ setLabelStyle,
125
+ };
126
+ }
127
+ function getAffixPaddding({ value, type, prefixWidth, suffixWidth, }) {
128
+ const hasValue = value !== "";
129
+ const newPadding = {
130
+ paddingLeft: undefined,
131
+ paddingRight: undefined,
132
+ };
133
+ // Naively assume that if the the type is tel, it is the InputPhoneNumber
134
+ if (type === "tel")
135
+ return newPadding;
136
+ if (prefixWidth && !hasValue) {
137
+ newPadding.paddingLeft = offset(prefixWidth);
138
+ }
139
+ if (suffixWidth && !hasValue) {
140
+ newPadding.paddingRight = offset(suffixWidth);
141
+ }
142
+ function offset(width) {
143
+ return `calc(${width}px + var(--space-smallest)`;
144
+ }
145
+ return newPadding;
146
+ }
147
+
148
+ 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, }) {
149
+ const prefixRef = useRef(null);
150
+ const suffixRef = useRef(null);
151
+ const { wrapperClasses, containerClasses, wrapperInlineStyle, labelStyle } = useFormFieldWrapperStyles({
152
+ align,
153
+ max,
154
+ maxLength,
155
+ prefixRef,
156
+ suffixRef,
157
+ placeholder,
158
+ value,
159
+ invalid,
160
+ error,
161
+ type,
162
+ disabled,
163
+ inline,
164
+ size,
165
+ showMiniLabel,
166
+ });
167
+ const { focused } = useFormFieldFocus({ wrapperRef });
168
+ const showClear = useShowClear({
169
+ clearable,
170
+ multiline: type === "textarea",
171
+ focused,
172
+ hasValue: Boolean(value),
173
+ disabled,
174
+ readonly,
175
+ });
176
+ const { isToolbarVisible, toolbarAnimationEnd, toolbarAnimationStart } = useToolbar({
177
+ focused,
178
+ toolbar,
179
+ toolbarVisibility,
180
+ });
181
+ return (React__default.createElement("div", { className: containerClasses },
182
+ React__default.createElement("div", { className: wrapperClasses, style: wrapperInlineStyle, "data-testid": "Form-Field-Wrapper", ref: wrapperRef },
183
+ React__default.createElement(FormFieldInputHorizontalWrapper, null,
184
+ React__default.createElement(AffixIcon, Object.assign({}, prefix, { size: size })),
185
+ React__default.createElement(FormFieldInputWrapperStyles, null,
186
+ (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)
187
+ ? labelStyle
188
+ : undefined }, placeholder)),
189
+ React__default.createElement(AffixLabel, Object.assign({}, prefix, { labelRef: prefixRef })),
190
+ React__default.createElement(FormFieldWrapperMain, null, children),
191
+ React__default.createElement(AffixLabel, Object.assign({}, suffix, { labelRef: suffixRef, variation: "suffix" }))),
192
+ React__default.createElement(ClearAction, { onClick: onClear, visible: showClear }),
193
+ React__default.createElement(AffixIcon, Object.assign({}, suffix, { variation: "suffix", size: size }))),
194
+ React__default.createElement(FormFieldWrapperToolbar, { toolbarVisibility: toolbarVisibility, isToolbarVisible: isToolbarVisible, toolbarAnimationEnd: toolbarAnimationEnd, toolbarAnimationStart: toolbarAnimationStart, toolbar: toolbar })),
195
+ React__default.createElement(FormFieldDescription, { visible: !!description && !inline, id: descriptionIdentifier, description: description }),
196
+ React__default.createElement(InputValidation, { message: error, visible: !!error && !inline })));
197
+ }
198
+ /**
199
+ * @internal Reach out to UX Foundations if using this component since it is possible it might change
200
+ */
201
+ function FormFieldInputHorizontalWrapper({ children, }) {
202
+ return React__default.createElement("div", { className: formFieldStyles.horizontalWrapper }, children);
203
+ }
204
+ /**
205
+ * @internal Reach out to UX Foundations if using this component since it is possible it might change
206
+ */
207
+ function FormFieldInputWrapperStyles({ children, }) {
208
+ return React__default.createElement("div", { className: formFieldStyles.inputWrapper }, children);
209
+ }
210
+ /**
211
+ * @internal Reach out to UX Foundations if using this component since it is possible it might change
212
+ */
213
+ function FormFieldWrapperMain({ children, tabIndex = -1, }) {
214
+ return (React__default.createElement("div", { className: formFieldStyles.childrenWrapper, tabIndex: tabIndex }, children));
215
+ }
216
+ function FormFieldLabel({ children, htmlFor, style, external = false, }) {
217
+ if (!children)
218
+ return null;
219
+ return (React__default.createElement("label", { className: external ? formFieldStyles.externalLabel : formFieldStyles.label, htmlFor: htmlFor, style: style }, children));
220
+ }
221
+ /**
222
+ * @internal Reach out to UX Foundations if using this component since it is possible it might change
223
+ */
224
+ function FormFieldWrapperToolbar({ toolbar, isToolbarVisible, toolbarAnimationEnd, toolbarAnimationStart, toolbarVisibility, }) {
225
+ 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: {
226
+ duration: tokens["timing-base"] / 1000,
227
+ ease: "easeInOut",
228
+ }, tabIndex: -1 },
229
+ React__default.createElement("div", { className: formFieldStyles.toolbar, "data-testid": "ATL-InputText-Toolbar" }, toolbar)))));
230
+ }
231
+
232
+ function FormFieldPostFix({ variation, visible = true, className, }) {
233
+ if (!visible)
234
+ return null;
235
+ return (React__default.createElement("span", { className: classnames(formFieldStyles.postfix, className) }, variation === "select" ? (React__default.createElement(Icon, { name: "arrowDown" })) : (React__default.createElement(Spinner, { size: "small" }))));
236
+ }
237
+
238
+ function useAtlantisFormFieldName({ id, nameProp, }) {
239
+ /**
240
+ * Generate a name if one is not supplied, this is the name
241
+ * that will be used for react-hook-form and not neccessarily
242
+ * attached to the DOM
243
+ */
244
+ const name = nameProp ? nameProp : `generatedName--${id}`;
245
+ return { name };
246
+ }
247
+
248
+ /**
249
+ * Given an array of refs, merge them into a single ref callback.
250
+ * This is useful for cases where you need to pass a multiple refs to a component.
251
+ */
252
+ function mergeRefs(refs) {
253
+ return value => {
254
+ refs.forEach(ref => {
255
+ if (typeof ref === "function") {
256
+ ref(value);
257
+ }
258
+ else if (ref != null) {
259
+ ref.current = value;
260
+ }
261
+ });
262
+ };
263
+ }
264
+
265
+ export { AffixIcon as A, FormFieldInputHorizontalWrapper as F, FormFieldInputWrapperStyles as a, FormFieldLabel as b, FormFieldWrapper as c, FormFieldWrapperMain as d, FormFieldWrapperToolbar as e, AffixLabel as f, useFormFieldWrapperStyles as g, formFieldStyles as h, FormFieldPostFix as i, mergeRefs as m, useAtlantisFormFieldName as u };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "7.5.0",
3
+ "version": "7.7.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -583,5 +583,5 @@
583
583
  "> 1%",
584
584
  "IE 10"
585
585
  ],
586
- "gitHead": "ef902bb0b1d5c005656294383b02d036d1aa666a"
586
+ "gitHead": "0208a24535b499bdfbf9983264777e5a5d278d36"
587
587
  }
@@ -1,3 +0,0 @@
1
- import React from "react";
2
- import type { InputDateRebuiltProps } from "./InputDate.types";
3
- export declare const InputDateRebuilt: React.ForwardRefExoticComponent<InputDateRebuiltProps & React.RefAttributes<HTMLInputElement>>;
@@ -1,3 +0,0 @@
1
- import React from "react";
2
- import type { SelectRebuiltProps } from "./Select.types";
3
- export declare function SelectRebuilt(props: SelectRebuiltProps): React.JSX.Element;