@jobber/components 7.14.2 → 7.15.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 (65) hide show
  1. package/dist/Autocomplete/index.cjs +4 -3
  2. package/dist/Autocomplete/index.mjs +3 -2
  3. package/dist/DataList/components/DataListSearch/index.cjs +2 -1
  4. package/dist/DataList/components/DataListSearch/index.mjs +2 -1
  5. package/dist/DataList/index.cjs +2 -1
  6. package/dist/DataList/index.mjs +2 -1
  7. package/dist/DataTable/index.cjs +2 -1
  8. package/dist/DataTable/index.mjs +2 -1
  9. package/dist/DatePicker/index.cjs +0 -1
  10. package/dist/DatePicker/index.mjs +0 -1
  11. package/dist/DatePicker-cjs.js +782 -4
  12. package/dist/DatePicker-es.js +782 -4
  13. package/dist/FormField/index.cjs +14 -13
  14. package/dist/FormField/index.mjs +5 -4
  15. package/dist/FormField-cjs.js +4 -3
  16. package/dist/FormField-es.js +2 -1
  17. package/dist/FormFieldPostFix-cjs.js +2 -237
  18. package/dist/FormFieldPostFix-es.js +3 -228
  19. package/dist/FormFieldWrapper-cjs.js +242 -0
  20. package/dist/FormFieldWrapper-es.js +231 -0
  21. package/dist/InputDate/index.cjs +2 -2
  22. package/dist/InputDate/index.mjs +2 -2
  23. package/dist/InputEmail/index.cjs +2 -1
  24. package/dist/InputEmail/index.mjs +2 -1
  25. package/dist/InputEmail-cjs.js +3 -2
  26. package/dist/InputEmail-es.js +2 -1
  27. package/dist/InputNumber/index.cjs +2 -1
  28. package/dist/InputNumber/index.mjs +2 -1
  29. package/dist/InputPassword/index.cjs +2 -1
  30. package/dist/InputPassword/index.mjs +2 -1
  31. package/dist/InputPhoneNumber/index.cjs +2 -1
  32. package/dist/InputPhoneNumber/index.mjs +2 -1
  33. package/dist/InputPhoneNumber-cjs.js +3 -2
  34. package/dist/InputPhoneNumber-es.js +2 -1
  35. package/dist/InputText/index.cjs +3 -2
  36. package/dist/InputText/index.mjs +2 -1
  37. package/dist/InputTime/InputTime.d.ts +1 -1
  38. package/dist/InputTime/InputTime.types.d.ts +10 -24
  39. package/dist/InputTime/hooks/useInputTimeActions.d.ts +2 -2
  40. package/dist/InputTime/index.cjs +16 -350
  41. package/dist/InputTime/index.d.ts +2 -4
  42. package/dist/InputTime/index.mjs +15 -353
  43. package/dist/InputTime-cjs.js +300 -0
  44. package/dist/InputTime-es.js +298 -0
  45. package/dist/RecurringSelect/index.cjs +2 -1
  46. package/dist/RecurringSelect/index.mjs +2 -1
  47. package/dist/Select/index.cjs +2 -1
  48. package/dist/Select/index.mjs +2 -1
  49. package/dist/Select-cjs.js +3 -2
  50. package/dist/Select-es.js +2 -1
  51. package/dist/Tabs-es.js +1 -1
  52. package/dist/_baseEach-es.js +2 -2
  53. package/dist/_getAllKeys-es.js +1 -1
  54. package/dist/debounce-es.js +1 -1
  55. package/dist/docs/InputTime/InputTime.md +45 -27
  56. package/dist/docs/usage-guidelines/usage-guidelines.md +0 -1
  57. package/dist/index.cjs +13 -13
  58. package/dist/index.mjs +3 -3
  59. package/dist/isTypedArray-es.js +1 -1
  60. package/dist/styles.css +7 -2
  61. package/dist/useScrollToActive-es.js +1 -1
  62. package/package.json +2 -2
  63. package/dist/InputTime/InputTime.rebuilt.d.ts +0 -3
  64. package/dist/omit-cjs.js +0 -783
  65. package/dist/omit-es.js +0 -781
@@ -4,7 +4,7 @@ var InputPhoneNumber = require('../InputPhoneNumber-cjs.js');
4
4
  require('../tslib.es6-cjs.js');
5
5
  require('react');
6
6
  require('classnames');
7
- require('../FormFieldPostFix-cjs.js');
7
+ require('../FormFieldWrapper-cjs.js');
8
8
  require('@jobber/hooks');
9
9
  require('framer-motion');
10
10
  require('@jobber/design');
@@ -15,6 +15,7 @@ require('../Typography-cjs.js');
15
15
  require('../Text-cjs.js');
16
16
  require('../useFormFieldFocus-cjs.js');
17
17
  require('../InputValidation-cjs.js');
18
+ require('../FormFieldPostFix-cjs.js');
18
19
  require('../Spinner-cjs.js');
19
20
  require('../useAtlantisFormFieldName-cjs.js');
20
21
  require('react-hook-form');
@@ -2,7 +2,7 @@ export { I as InputPhoneNumber } from '../InputPhoneNumber-es.js';
2
2
  import '../tslib.es6-es.js';
3
3
  import 'react';
4
4
  import 'classnames';
5
- import '../FormFieldPostFix-es.js';
5
+ import '../FormFieldWrapper-es.js';
6
6
  import '@jobber/hooks';
7
7
  import 'framer-motion';
8
8
  import '@jobber/design';
@@ -13,6 +13,7 @@ import '../Typography-es.js';
13
13
  import '../Text-es.js';
14
14
  import '../useFormFieldFocus-es.js';
15
15
  import '../InputValidation-es.js';
16
+ import '../FormFieldPostFix-es.js';
16
17
  import '../Spinner-es.js';
17
18
  import '../useAtlantisFormFieldName-es.js';
18
19
  import 'react-hook-form';
@@ -3,6 +3,7 @@
3
3
  var tslib_es6 = require('./tslib.es6-cjs.js');
4
4
  var React = require('react');
5
5
  var classnames = require('classnames');
6
+ var FormFieldWrapper = require('./FormFieldWrapper-cjs.js');
6
7
  var FormFieldPostFix = require('./FormFieldPostFix-cjs.js');
7
8
  var useAtlantisFormFieldName = require('./useAtlantisFormFieldName-cjs.js');
8
9
  require('react-hook-form');
@@ -179,8 +180,8 @@ const InputPhoneNumber = React.forwardRef(function InputPhoneNumberInternal(_a,
179
180
  const descriptionIdentifier = `descriptionUUID--${id}`, descriptionVisible = props.description && !props.inline;
180
181
  const isInvalid = Boolean(props.error || props.invalid);
181
182
  const dataAttrs = filterDataAttributes.filterDataAttributes(props);
182
- return (React.createElement(FormFieldPostFix.FormFieldWrapper, { disabled: props.disabled, size: props.size, inline: props.inline, wrapperRef: wrapperRef, error: (_c = props.error) !== null && _c !== void 0 ? _c : "", invalid: Boolean(props.error || props.invalid), identifier: id, descriptionIdentifier: descriptionIdentifier, description: props.description, clearable: (_d = props.clearable) !== null && _d !== void 0 ? _d : "never", onClear: handleClear, type: "tel", placeholder: props.placeholder, value: formattedValue, prefix: props.prefix, suffix: props.suffix, readonly: props.readOnly, loading: props.loading },
183
- React.createElement("input", Object.assign({ id: id, name: name, type: "tel", ref: inputPhoneNumberRef, className: classnames(FormFieldPostFix.formFieldStyles.input, {
183
+ return (React.createElement(FormFieldWrapper.FormFieldWrapper, { disabled: props.disabled, size: props.size, inline: props.inline, wrapperRef: wrapperRef, error: (_c = props.error) !== null && _c !== void 0 ? _c : "", invalid: Boolean(props.error || props.invalid), identifier: id, descriptionIdentifier: descriptionIdentifier, description: props.description, clearable: (_d = props.clearable) !== null && _d !== void 0 ? _d : "never", onClear: handleClear, type: "tel", placeholder: props.placeholder, value: formattedValue, prefix: props.prefix, suffix: props.suffix, readonly: props.readOnly, loading: props.loading },
184
+ React.createElement("input", Object.assign({ id: id, name: name, type: "tel", ref: inputPhoneNumberRef, className: classnames(FormFieldWrapper.formFieldStyles.input, {
184
185
  [styles.emptyValue]: inputValue.length === 0 && pattern[0] === "(",
185
186
  }), value: formattedValue, disabled: props.disabled, readOnly: props.readOnly, autoFocus: props.autoFocus, autoComplete: props.autoComplete, inputMode: props.inputMode, tabIndex: props.tabIndex, required: props.required, role: props.role, "aria-label": props["aria-label"], "aria-describedby": descriptionVisible ? descriptionIdentifier : props["aria-describedby"], "aria-invalid": isInvalid ? true : undefined, "aria-controls": props["aria-controls"], "aria-expanded": props["aria-expanded"], "aria-activedescendant": props["aria-activedescendant"], "aria-autocomplete": props["aria-autocomplete"], "aria-required": props["aria-required"], onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, onKeyDown: handleKeyDown, onClick: handleClick, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onPointerDown: handlePointerDown, onPointerUp: handlePointerUp }, dataAttrs)),
186
187
  React.createElement(MaskElement, { isMasking: isMasking, formattedValue: formattedValue, placeholderMask: placeholderMask }),
@@ -1,7 +1,8 @@
1
1
  import { _ as __rest } from './tslib.es6-es.js';
2
2
  import React__default, { useState, useMemo, useCallback, useEffect, forwardRef, useId } from 'react';
3
3
  import classnames from 'classnames';
4
- import { c as FormFieldWrapper, g as formFieldStyles, h as FormFieldPostFix } from './FormFieldPostFix-es.js';
4
+ import { c as FormFieldWrapper, g as formFieldStyles } from './FormFieldWrapper-es.js';
5
+ import { F as FormFieldPostFix } from './FormFieldPostFix-es.js';
5
6
  import { u as useAtlantisFormFieldName } from './useAtlantisFormFieldName-es.js';
6
7
  import 'react-hook-form';
7
8
  import './Button-es.js';
@@ -9,6 +9,7 @@ require('react-hook-form');
9
9
  require('framer-motion');
10
10
  require('@jobber/design');
11
11
  require('../Button-cjs.js');
12
+ var FormFieldWrapper = require('../FormFieldWrapper-cjs.js');
12
13
  var FormFieldPostFix = require('../FormFieldPostFix-cjs.js');
13
14
  var useAtlantisFormFieldName = require('../useAtlantisFormFieldName-cjs.js');
14
15
  var mergeRefs = require('../mergeRefs-cjs.js');
@@ -248,10 +249,10 @@ const InputTextSPAR = React.forwardRef(function InputTextInternal(props, inputRe
248
249
  const mergedRef = React.useMemo(() => mergeRefs.mergeRefs([inputRef, inputTextRef]), []);
249
250
  // Shared props for both TextArea and TextInput
250
251
  const commonInputProps = Object.assign({ id,
251
- name, className: FormFieldPostFix.formFieldStyles.input, value: props.value, disabled: props.disabled, readOnly: props.readOnly, autoFocus: props.autoFocus, autoComplete: props.autoComplete, inputMode: props.inputMode, tabIndex: props.tabIndex, maxLength: props.maxLength, required: props.required, role: props.role, "aria-label": props["aria-label"], "aria-describedby": descriptionVisible
252
+ name, className: FormFieldWrapper.formFieldStyles.input, value: props.value, disabled: props.disabled, readOnly: props.readOnly, autoFocus: props.autoFocus, autoComplete: props.autoComplete, inputMode: props.inputMode, tabIndex: props.tabIndex, maxLength: props.maxLength, required: props.required, role: props.role, "aria-label": props["aria-label"], "aria-describedby": descriptionVisible
252
253
  ? descriptionIdentifier
253
254
  : props["aria-describedby"], "aria-invalid": isInvalid ? true : undefined, "aria-controls": props["aria-controls"], "aria-expanded": props["aria-expanded"], "aria-activedescendant": props["aria-activedescendant"], "aria-autocomplete": props["aria-autocomplete"], "aria-required": props["aria-required"], onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, onClick: handleClick, ref: mergedRef }, dataAttrs);
254
- return (React.createElement(FormFieldPostFix.FormFieldWrapper, { disabled: props.disabled, size: props.size, align: props.align, inline: props.inline, name: name, wrapperRef: wrapperRef, error: (_a = props.error) !== null && _a !== void 0 ? _a : "", invalid: Boolean(props.error || props.invalid), identifier: id, descriptionIdentifier: descriptionIdentifier, description: props.description, clearable: (_b = props.clearable) !== null && _b !== void 0 ? _b : "never", onClear: handleClear, type: props.multiline ? "textarea" : "text", placeholder: props.placeholder, value: props.value, prefix: props.prefix, suffix: props.suffix, readonly: props.readOnly, rows: rowRange.min, toolbar: props.toolbar, toolbarVisibility: props.toolbarVisibility, showMiniLabel: props.showMiniLabel },
255
+ return (React.createElement(FormFieldWrapper.FormFieldWrapper, { disabled: props.disabled, size: props.size, align: props.align, inline: props.inline, name: name, wrapperRef: wrapperRef, error: (_a = props.error) !== null && _a !== void 0 ? _a : "", invalid: Boolean(props.error || props.invalid), identifier: id, descriptionIdentifier: descriptionIdentifier, description: props.description, clearable: (_b = props.clearable) !== null && _b !== void 0 ? _b : "never", onClear: handleClear, type: props.multiline ? "textarea" : "text", placeholder: props.placeholder, value: props.value, prefix: props.prefix, suffix: props.suffix, readonly: props.readOnly, rows: rowRange.min, toolbar: props.toolbar, toolbarVisibility: props.toolbarVisibility, showMiniLabel: props.showMiniLabel },
255
256
  React.createElement(React.Fragment, null,
256
257
  props.multiline ? (React.createElement(TextArea, Object.assign({}, commonInputProps, { rows: rowRange.min }))) : (React.createElement(TextInput, Object.assign({}, commonInputProps, { pattern: props.pattern }))),
257
258
  React.createElement(FormFieldPostFix.FormFieldPostFix, { variation: "spinner", visible: (_c = props.loading) !== null && _c !== void 0 ? _c : false }))));
@@ -7,7 +7,8 @@ import 'react-hook-form';
7
7
  import 'framer-motion';
8
8
  import '@jobber/design';
9
9
  import '../Button-es.js';
10
- import { g as formFieldStyles, c as FormFieldWrapper, h as FormFieldPostFix } from '../FormFieldPostFix-es.js';
10
+ import { g as formFieldStyles, c as FormFieldWrapper } from '../FormFieldWrapper-es.js';
11
+ import { F as FormFieldPostFix } from '../FormFieldPostFix-es.js';
11
12
  import { u as useAtlantisFormFieldName } from '../useAtlantisFormFieldName-es.js';
12
13
  import { m as mergeRefs } from '../mergeRefs-es.js';
13
14
  import { f as filterDataAttributes } from '../filterDataAttributes-es.js';
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import type { InputTimeProps } from "./InputTime.types";
3
- export declare function InputTime({ defaultValue, value, onChange, ...params }: InputTimeProps): React.JSX.Element;
3
+ export declare function InputTime({ value, onChange, readOnly, autoComplete, inputRef, step, ...props }: InputTimeProps): React.JSX.Element;
@@ -1,29 +1,7 @@
1
1
  import type { Ref } from "react";
2
- import type { CommonFormFieldProps, FormFieldProps } from "../FormField";
2
+ import type { FormFieldProps } from "../FormField";
3
3
  import type { FocusEvents, HTMLInputBaseProps, KeyboardEvents, MouseEvents, RebuiltInputCommonProps } from "../sharedHelpers/types";
4
- export interface InputTimeProps extends Pick<CommonFormFieldProps, "id" | "align" | "description" | "disabled" | "invalid" | "inline" | "loading" | "name" | "onValidation" | "placeholder" | "size" | "clearable">, Pick<FormFieldProps, "maxLength" | "readonly" | "autocomplete" | "max" | "min" | "onEnter" | "onFocus" | "onBlur" | "inputRef" | "validations"> {
5
- /**
6
- * Intial value of the input. Only use this when you need to prepopulate the
7
- * field with a data that is not controlled by the components state. If a
8
- * state is controlling the value, use the `value` prop instead.
9
- */
10
- readonly defaultValue?: Date;
11
- /**
12
- * Set the component to the given value.
13
- */
14
- readonly value?: Date;
15
- /**
16
- * Function called when user changes input value.
17
- */
18
- onChange?(newValue?: Date): void;
19
- }
20
- /**
21
- * @deprecated Use the v2 InputTime component instead (version={2}).
22
- */
23
- export interface InputTimeLegacyProps extends InputTimeProps {
24
- version?: 1;
25
- }
26
- export interface InputTimeRebuiltProps extends Omit<HTMLInputBaseProps, "maxLength">, FocusEvents<HTMLInputElement>, KeyboardEvents<HTMLInputElement>, MouseEvents<HTMLInputElement>, Omit<RebuiltInputCommonProps, "showMiniLabel">, Pick<InputTimeProps, "value" | "onChange"> {
4
+ export interface InputTimeProps extends Omit<HTMLInputBaseProps, "maxLength">, FocusEvents<HTMLInputElement>, KeyboardEvents<HTMLInputElement>, MouseEvents<HTMLInputElement>, Omit<RebuiltInputCommonProps, "showMiniLabel" | "version">, Pick<InputTimeProps, "value" | "onChange"> {
27
5
  /**
28
6
  * Maximum numerical or date value.
29
7
  */
@@ -45,4 +23,12 @@ export interface InputTimeRebuiltProps extends Omit<HTMLInputBaseProps, "maxLeng
45
23
  * @deprecated Use `onKeyDown` or `onKeyUp` instead.
46
24
  */
47
25
  readonly onEnter?: FormFieldProps["onEnter"];
26
+ /**
27
+ * Set the component to the given value.
28
+ */
29
+ readonly value?: Date;
30
+ /**
31
+ * Function called when user changes input value.
32
+ */
33
+ onChange?(newValue?: Date): void;
48
34
  }
@@ -1,6 +1,6 @@
1
1
  import type { ChangeEvent, FocusEvent, KeyboardEvent, MouseEvent, PointerEvent } from "react";
2
- import type { InputTimeRebuiltProps } from "../InputTime.types";
3
- export interface UseInputTimeActionsProps extends Pick<InputTimeRebuiltProps, "onChange" | "onFocus" | "onBlur" | "onKeyDown" | "onClick" | "onMouseDown" | "onMouseUp" | "onPointerDown" | "onPointerUp"> {
2
+ import type { InputTimeProps } from "../InputTime.types";
3
+ export interface UseInputTimeActionsProps extends Pick<InputTimeProps, "onChange" | "onFocus" | "onBlur" | "onKeyDown" | "onClick" | "onMouseDown" | "onMouseUp" | "onPointerDown" | "onPointerUp"> {
4
4
  readonly value?: Date;
5
5
  readonly readOnly?: boolean;
6
6
  readonly disabled?: boolean;
@@ -1,362 +1,28 @@
1
1
  'use strict';
2
2
 
3
- var React = require('react');
4
- var tslib_es6 = require('../tslib.es6-cjs.js');
5
- var debounce = require('../debounce-cjs.js');
6
- var FormFieldPostFix = require('../FormFieldPostFix-cjs.js');
7
- require('classnames');
8
- require('@jobber/design');
9
- require('react-hook-form');
10
- var mergeRefs = require('../mergeRefs-cjs.js');
11
- require('../Button-cjs.js');
12
- var filterDataAttributes = require('../filterDataAttributes-cjs.js');
13
- var omit = require('../omit-cjs.js');
14
- var FormField = require('../FormField-cjs.js');
15
- require('@jobber/hooks');
16
- require('framer-motion');
3
+ var InputTime = require('../InputTime-cjs.js');
4
+ require('../tslib.es6-cjs.js');
5
+ require('react');
6
+ require('../debounce-cjs.js');
17
7
  require('../_commonjsHelpers-cjs.js');
18
8
  require('../isObjectLike-cjs.js');
19
9
  require('../isSymbol-cjs.js');
10
+ require('../FormFieldWrapper-cjs.js');
11
+ require('@jobber/hooks');
12
+ require('framer-motion');
13
+ require('@jobber/design');
14
+ require('classnames');
15
+ require('../Button-cjs.js');
16
+ require('react-router-dom');
20
17
  require('../Icon-cjs.js');
21
- require('../Text-cjs.js');
22
18
  require('../Typography-cjs.js');
19
+ require('../Text-cjs.js');
23
20
  require('../useFormFieldFocus-cjs.js');
24
21
  require('../InputValidation-cjs.js');
25
- require('../Spinner-cjs.js');
26
- require('react-router-dom');
27
- require('../_getAllKeys-cjs.js');
28
- require('../isTypedArray-cjs.js');
29
- require('../identity-cjs.js');
30
- require('../_getTag-cjs.js');
31
- require('../keysIn-cjs.js');
32
- require('../_baseAssignValue-cjs.js');
33
- require('../_baseFlatten-cjs.js');
34
- require('../_setToString-cjs.js');
35
- require('../useAtlantisFormFieldName-cjs.js');
36
-
37
- const DEBOUNCE_TIME = 300;
38
- function useTimePredict({ value, handleChange }) {
39
- const [IS_12_HOUR_FORMAT, set12HourFormat] = React.useState(false);
40
- const [typedTime, setTypedTime] = React.useState("");
41
- const predictTime = React.useCallback(debounce.debounce(() => {
42
- if (value)
43
- return;
44
- handleChange(predictHours(typedTime, IS_12_HOUR_FORMAT));
45
- }, DEBOUNCE_TIME), [typedTime, value, handleChange, IS_12_HOUR_FORMAT]);
46
- React.useEffect(() => {
47
- set12HourFormat(Boolean(Intl.DateTimeFormat(navigator.language, {
48
- hour: "numeric",
49
- }).resolvedOptions().hour12));
50
- }, []);
51
- /**
52
- * Predict the hour when user types a number
53
- */
54
- React.useEffect(() => {
55
- /**
56
- * Don't try to predict if the user types 0 as the user would almost always
57
- * type another number after 0.
58
- */
59
- if (typedTime && typedTime !== "0") {
60
- predictTime();
61
- if ((IS_12_HOUR_FORMAT && typedTime !== "1") || typedTime.length === 2) {
62
- // Immediately predict the hour
63
- predictTime.flush();
64
- }
65
- }
66
- return predictTime.cancel;
67
- }, [typedTime]);
68
- /**
69
- * Reset typed time when the value changed
70
- */
71
- React.useEffect(() => {
72
- setTypedTime("");
73
- }, [value]);
74
- return {
75
- setTypedTime,
76
- };
77
- }
78
- function predictHours(time, is12HourFormat = false) {
79
- const today = new Date();
80
- const currentHour = today.getHours();
81
- const parsedTime = parseInt(time, 10);
82
- let predictedTime;
83
- if (is12HourFormat) {
84
- predictedTime = predict12Hours(parsedTime, currentHour);
85
- }
86
- else {
87
- predictedTime = predict24Hours(time, parsedTime, currentHour);
88
- }
89
- return formatHour(predictedTime);
90
- }
91
- function predict12Hours(parsedTime, currentHour) {
92
- /**
93
- * We need to predict what the user wants when they type 1 since it could be
94
- * 10, 11, 12, or 1.
95
- *
96
- * If the current hour is over 12PM, we can skip this and go to the next logic.
97
- */
98
- if (parsedTime === 1 && currentHour < 12) {
99
- if (currentHour < 10) {
100
- return 10;
101
- }
102
- else {
103
- return currentHour + 1;
104
- }
105
- }
106
- /**
107
- * Typing 1-5 predicts that the user want that exact hour on the afternoon.
108
- */
109
- if (parsedTime <= 5) {
110
- return parsedTime + 12;
111
- }
112
- /**
113
- * Typing 13-15 predicts that the user want the 2nd number as the minute interval.
114
- */
115
- if (parsedTime > 12 && parsedTime <= 15) {
116
- const timeArray = parsedTime.toString().split("").map(Number); // 13 -> [1, 3]
117
- const convertToHoursAndMinutes = timeArray.map((time, i) => {
118
- if (i === 0)
119
- return time + 12; // 1 -> 13 as 1PM
120
- if (i === 1)
121
- return time * 10; // 3 -> 30 as 30 minutes
122
- });
123
- return Number(convertToHoursAndMinutes.join("")); // [13, 30] -> 1330
124
- }
125
- /**
126
- * Anything after 5 will be predicted to be set as AM.
127
- */
128
- return parsedTime;
129
- }
130
- function predict24Hours(time, parsedTime, currentHour) {
131
- /**
132
- * Typing 1 could be predicted from 10 to 19.
133
- * Typing 01 skips this logic and sets the time to 01:00.
134
- */
135
- if (parsedTime === 1 && time !== "01") {
136
- if (currentHour < 10 || currentHour > 19) {
137
- return 10;
138
- }
139
- else {
140
- return currentHour + 1;
141
- }
142
- }
143
- /**
144
- * Typing 2 could be predicted from 20 to 24.
145
- * Typing 02 skips this logic and sets the time to 02:00.
146
- */
147
- if (parsedTime === 2 && time !== "02") {
148
- if (currentHour < 20) {
149
- return 20;
150
- }
151
- else {
152
- return currentHour + 1;
153
- }
154
- }
155
- /**
156
- * Typing 24 or 00 is set to midnight. This ensures the time doesn't get set
157
- * to 24 as that would be invalid.
158
- */
159
- if (parsedTime === 24 || time === "00") {
160
- return 0;
161
- }
162
- return parsedTime;
163
- }
164
- function formatHour(time) {
165
- if (time > 99) {
166
- const splitTime = time.toString().split("");
167
- if (splitTime.length === 3)
168
- splitTime.unshift("0"); // 130 -> 0130
169
- splitTime.splice(2, 0, ":"); // 0130 -> 01:30
170
- return splitTime.join("");
171
- }
172
- if (time < 10) {
173
- return `0${time}:00`;
174
- }
175
- return `${time}:00`;
176
- }
177
-
178
- function dateToTimeString(date, includeSeconds = false) {
179
- if (!(date instanceof Date)) {
180
- return "";
181
- }
182
- const hours = date.getHours().toString().padStart(2, "0");
183
- const minutes = date.getMinutes().toString().padStart(2, "0");
184
- if (includeSeconds) {
185
- const seconds = date.getSeconds().toString().padStart(2, "0");
186
- return `${hours}:${minutes}:${seconds}`;
187
- }
188
- return `${hours}:${minutes}`;
189
- }
190
- function timeStringToDate(timeString, baseDate) {
191
- try {
192
- const [hours, minutes, seconds = 0] = timeString.split(":").map(Number);
193
- if (isNaN(hours) ||
194
- isNaN(minutes) ||
195
- isNaN(seconds) ||
196
- hours < 0 ||
197
- hours > 24 ||
198
- minutes < 0 ||
199
- minutes > 60 ||
200
- seconds < 0 ||
201
- seconds > 60) {
202
- return undefined;
203
- }
204
- // Try to preserve the Date part of the Date object as long as it is valid
205
- const date = baseDate instanceof Date && !isNaN(baseDate.getTime())
206
- ? new Date(baseDate)
207
- : new Date();
208
- date.setHours(hours, minutes, seconds, 0);
209
- return date;
210
- }
211
- catch (_a) {
212
- return undefined;
213
- }
214
- }
215
-
216
- function useInputTimeActions({ onChange, value, inputRef, onFocus, onBlur, onKeyDown, onClick, onMouseDown, onMouseUp, onPointerDown, onPointerUp, }) {
217
- function handleChangeEvent(event) {
218
- handleChange(event.target.value);
219
- }
220
- function handleChange(newValue) {
221
- onChange === null || onChange === void 0 ? void 0 : onChange(timeStringToDate(newValue, value));
222
- }
223
- function handleBlur(event) {
224
- onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
225
- if (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) {
226
- if (!inputRef.current.checkValidity()) {
227
- inputRef.current.value = "";
228
- inputRef.current.valueAsDate = null;
229
- // Remove validation error. This is mainly needed for Safari
230
- inputRef.current.setCustomValidity("");
231
- }
232
- }
233
- }
234
- function handleClear() {
235
- var _a;
236
- // Clear the value and refocus without triggering blur event
237
- onChange === null || onChange === void 0 ? void 0 : onChange(undefined);
238
- (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
239
- }
240
- function handleFocus(event) {
241
- onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
242
- }
243
- function handleKeyDown(event) {
244
- onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
245
- }
246
- function handleClick(event) {
247
- onClick === null || onClick === void 0 ? void 0 : onClick(event);
248
- }
249
- function handleMouseDown(event) {
250
- onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
251
- }
252
- function handleMouseUp(event) {
253
- onMouseUp === null || onMouseUp === void 0 ? void 0 : onMouseUp(event);
254
- }
255
- function handlePointerDown(event) {
256
- onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown(event);
257
- }
258
- function handlePointerUp(event) {
259
- onPointerUp === null || onPointerUp === void 0 ? void 0 : onPointerUp(event);
260
- }
261
- return {
262
- handleChangeEvent,
263
- handleChange,
264
- handleBlur,
265
- handleClear,
266
- handleFocus,
267
- handleKeyDown,
268
- handleClick,
269
- handleMouseDown,
270
- handleMouseUp,
271
- handlePointerDown,
272
- handlePointerUp,
273
- };
274
- }
275
-
276
- function InputTimeRebuilt(_a) {
277
- var _b;
278
- var { value, onChange, readOnly, autoComplete, inputRef, step = 60 } = _a, props = tslib_es6.__rest(_a, ["value", "onChange", "readOnly", "autoComplete", "inputRef", "step"]);
279
- const { internalRef, mergedRef, wrapperRef } = useInputTimeRefs(inputRef);
280
- const generatedId = React.useId();
281
- const id = props.id || generatedId;
282
- const { handleChangeEvent, handleChange, handleBlur, handleClear, handleFocus, handleKeyDown, handleClick, handleMouseDown, handleMouseUp, handlePointerDown, handlePointerUp, } = useInputTimeActions({
283
- onChange,
284
- value,
285
- readOnly,
286
- disabled: props.disabled,
287
- inputRef: internalRef,
288
- onFocus: props.onFocus,
289
- onBlur: props.onBlur,
290
- onKeyDown: props.onKeyDown,
291
- onClick: props.onClick,
292
- onMouseDown: props.onMouseDown,
293
- onMouseUp: props.onMouseUp,
294
- onPointerDown: props.onPointerDown,
295
- onPointerUp: props.onPointerUp,
296
- });
297
- const { setTypedTime } = useTimePredict({
298
- value,
299
- handleChange,
300
- });
301
- // Kept outside the useInputTimeActions hook to avoid circular dependency via setTypedTime and handleChange
302
- function handleKeyUp(event) {
303
- var _a;
304
- (_a = props.onKeyUp) === null || _a === void 0 ? void 0 : _a.call(props, event);
305
- if (props.disabled || readOnly)
306
- return;
307
- !isNaN(parseInt(event.key, 10)) && setTypedTime(prev => prev + event.key);
308
- }
309
- const dataAttrs = filterDataAttributes.filterDataAttributes(props);
310
- const descriptionIdentifier = `descriptionUUID--${id}`;
311
- const descriptionVisible = props.description && !props.inline;
312
- const isInvalid = Boolean(props.error || props.invalid);
313
- return (React.createElement(FormFieldPostFix.FormFieldWrapper, { disabled: props.disabled, size: props.size, align: props.align, inline: props.inline, name: props.name, error: props.error || "", identifier: id, descriptionIdentifier: descriptionIdentifier, invalid: props.invalid, description: props.description, clearable: (_b = props.clearable) !== null && _b !== void 0 ? _b : "never", onClear: handleClear, type: "time", readonly: readOnly, placeholder: props.placeholder, value: dateToTimeString(value, step % 60 !== 0), wrapperRef: wrapperRef },
314
- React.createElement("input", Object.assign({ ref: mergedRef, type: "time", name: props.name, className: FormFieldPostFix.formFieldStyles.input, id: id, disabled: props.disabled, readOnly: readOnly, autoComplete: autoComplete, autoFocus: props.autoFocus, required: props.required, max: props.max, min: props.min, step: step, value: dateToTimeString(value, step % 60 !== 0), onChange: handleChangeEvent, onBlur: handleBlur, onFocus: handleFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onClick: handleClick, onMouseDown: handleMouseDown, onMouseUp: handleMouseUp, onPointerDown: handlePointerDown, onPointerUp: handlePointerUp, "data-testid": "ATL-InputTime-input", "aria-label": props["aria-label"], "aria-describedby": descriptionVisible ? descriptionIdentifier : props["aria-describedby"], "aria-invalid": isInvalid ? true : undefined, "aria-required": props["aria-required"] }, dataAttrs))));
315
- }
316
- function useInputTimeRefs(inputRef) {
317
- const internalRef = React.useRef(null);
318
- const mergedRef = mergeRefs.mergeRefs([internalRef, inputRef]);
319
- const wrapperRef = React.useRef(null);
320
- return { internalRef, mergedRef, wrapperRef };
321
- }
22
+ require('react-hook-form');
23
+ require('../mergeRefs-cjs.js');
24
+ require('../filterDataAttributes-cjs.js');
322
25
 
323
- function InputTime$1(_a) {
324
- var { defaultValue, value, onChange } = _a, params = tslib_es6.__rest(_a, ["defaultValue", "value", "onChange"]);
325
- const ref = React.useRef(null);
326
- const wrapperRef = React.useRef(null);
327
- const { setTypedTime } = useTimePredict({ value, handleChange });
328
- const fieldProps = omit.omit(Object.assign(Object.assign(Object.assign({ onChange: handleChange }, (defaultValue && { defaultValue: dateToTimeString(defaultValue) })), (!defaultValue && { value: dateToTimeString(value) })), params), ["version"]);
329
- return (React.createElement(FormField.FormField, Object.assign({ inputRef: ref, type: "time" }, fieldProps, { onBlur: handleBlur, onKeyUp: e => {
330
- var _a;
331
- (_a = fieldProps.onKeyUp) === null || _a === void 0 ? void 0 : _a.call(fieldProps, e);
332
- !isNaN(parseInt(e.key, 10)) && setTypedTime(prev => prev + e.key);
333
- }, wrapperRef: wrapperRef })));
334
- function handleChange(newValue) {
335
- onChange === null || onChange === void 0 ? void 0 : onChange(timeStringToDate(newValue, value));
336
- }
337
- function handleBlur() {
338
- var _a;
339
- (_a = params.onBlur) === null || _a === void 0 ? void 0 : _a.call(params);
340
- // Time inputs doesn't clear the typed value when it's invalid. This should
341
- // force it to reset the input value when the typed value is invalid.
342
- if (ref.current) {
343
- if (!ref.current.checkValidity()) {
344
- ref.current.value = "";
345
- }
346
- }
347
- }
348
- }
349
26
 
350
- function isNewInputTimeProps(props) {
351
- return props.version === 2;
352
- }
353
- function InputTime(props) {
354
- if (isNewInputTimeProps(props)) {
355
- return React.createElement(InputTimeRebuilt, Object.assign({}, props));
356
- }
357
- else {
358
- return React.createElement(InputTime$1, Object.assign({}, props));
359
- }
360
- }
361
27
 
362
- exports.InputTime = InputTime;
28
+ exports.InputTime = InputTime.InputTime;
@@ -1,4 +1,2 @@
1
- import React from "react";
2
- import type { InputTimeLegacyProps, InputTimeRebuiltProps } from "./InputTime.types";
3
- export type InputTimeShimProps = InputTimeLegacyProps | InputTimeRebuiltProps;
4
- export declare function InputTime(props: InputTimeShimProps): React.JSX.Element;
1
+ export type { InputTimeProps } from "./InputTime.types";
2
+ export { InputTime } from "./InputTime";