@jobber/components 4.67.5 → 4.68.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.
Binary file
Binary file
Binary file
@@ -74,6 +74,14 @@ export interface CommonFormFieldProps {
74
74
  * Set the component to the given value.
75
75
  */
76
76
  readonly value?: string | number | Date;
77
+ /**
78
+ * Add a clear action on the input that clears the value.
79
+ *
80
+ * You should always use `while-editing` if you want the input to be
81
+ * clearable. if the input value isn't editable (i.e. `InputTime`) you can
82
+ * set it to `always`.
83
+ */
84
+ readonly clearable?: "never" | "always";
77
85
  }
78
86
  export interface FormFieldProps extends CommonFormFieldProps {
79
87
  actionsRef?: RefObject<FieldActionsRef>;
@@ -4,6 +4,8 @@ interface FormFieldWrapperProps extends FormFieldProps {
4
4
  readonly error: string;
5
5
  readonly identifier: string;
6
6
  readonly descriptionIdentifier: string;
7
+ readonly clearable: "never" | "always";
8
+ readonly onClear: () => void;
7
9
  }
8
- export declare function FormFieldWrapper({ align, description, descriptionIdentifier, placeholder, value, children, invalid, error, size, prefix, suffix, max, maxLength, type, disabled, inline, identifier, }: PropsWithChildren<FormFieldWrapperProps>): JSX.Element;
10
+ export declare function FormFieldWrapper({ align, description, descriptionIdentifier, placeholder, value, children, invalid, error, size, prefix, suffix, max, maxLength, type, disabled, inline, identifier, clearable, onClear, }: PropsWithChildren<FormFieldWrapperProps>): JSX.Element;
9
11
  export {};
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ interface ClearActionProps {
3
+ /**
4
+ * Click handler
5
+ */
6
+ readonly onClick: () => void;
7
+ }
8
+ export declare function ClearAction({ onClick }: ClearActionProps): JSX.Element;
9
+ export {};
Binary file
Binary file
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { CommonFormFieldProps, FormFieldProps } from "../FormField";
3
- interface InputDateProps extends CommonFormFieldProps, Pick<FormFieldProps, "readonly" | "disabled" | "onEnter" | "onFocus" | "inputRef" | "validations" | "placeholder" | "onChange" | "onBlur"> {
3
+ interface InputDateProps extends Omit<CommonFormFieldProps, "clearable">, Pick<FormFieldProps, "readonly" | "disabled" | "onEnter" | "onFocus" | "inputRef" | "validations" | "placeholder" | "onChange" | "onBlur"> {
4
4
  /**
5
5
  * A Date object value
6
6
  * (e.g., `new Date("11/11/2011")`)
Binary file
Binary file
Binary file
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
- var FormField = require('./FormField-dfc061ca.js');
4
+ var FormField = require('./FormField-181efe29.js');
5
5
 
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
Binary file
Binary file
@@ -24,6 +24,7 @@ export declare const InputText: React.ForwardRefExoticComponent<({
24
24
  readonly placeholder?: string | undefined;
25
25
  readonly size?: "large" | "small" | undefined;
26
26
  readonly value?: string | number | Date | undefined;
27
+ readonly clearable?: "always" | "never" | undefined;
27
28
  onFocus?: (() => void) | undefined;
28
29
  onBlur?: (() => void) | undefined;
29
30
  readonly defaultValue?: string | Date | undefined;
@@ -61,6 +62,7 @@ export declare const InputText: React.ForwardRefExoticComponent<({
61
62
  readonly placeholder?: string | undefined;
62
63
  readonly size?: "large" | "small" | undefined;
63
64
  readonly value?: string | number | Date | undefined;
65
+ readonly clearable?: "always" | "never" | undefined;
64
66
  onFocus?: (() => void) | undefined;
65
67
  onBlur?: (() => void) | undefined;
66
68
  readonly defaultValue?: string | Date | undefined;
Binary file
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
- var FormField = require('./FormField-dfc061ca.js');
4
+ var FormField = require('./FormField-181efe29.js');
5
5
 
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
@@ -1,6 +1,6 @@
1
1
  import { CivilTime } from "@std-proposal/temporal";
2
2
  import { CommonFormFieldProps, FormFieldProps } from "../FormField";
3
- export interface InputTimeProps extends Pick<CommonFormFieldProps, "align" | "description" | "disabled" | "invalid" | "inline" | "loading" | "name" | "onValidation" | "placeholder" | "size">, Pick<FormFieldProps, "maxLength" | "readonly" | "autocomplete" | "max" | "min" | "onEnter" | "onFocus" | "onBlur" | "inputRef" | "validations"> {
3
+ export interface InputTimeProps extends Pick<CommonFormFieldProps, "align" | "description" | "disabled" | "invalid" | "inline" | "loading" | "name" | "onValidation" | "placeholder" | "size" | "clearable">, Pick<FormFieldProps, "maxLength" | "readonly" | "autocomplete" | "max" | "min" | "onEnter" | "onFocus" | "onBlur" | "inputRef" | "validations"> {
4
4
  /**
5
5
  * Intial value of the input. Only use this when you need to prepopulate the
6
6
  * field with a data that is not controlled by the components state. If a
Binary file
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
- var FormField = require('./FormField-dfc061ca.js');
4
+ var FormField = require('./FormField-181efe29.js');
5
5
 
6
6
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
7
7
 
Binary file
Binary file
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var React = require('react');
6
6
  var styleInject_es = require('../style-inject.es-9d2f5f4e.js');
7
7
  var classnames = require('classnames');
8
- var formatters = require('@jobber/formatters');
8
+ var require$$3 = require('@jobber/formatters');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
@@ -39,7 +39,7 @@ function CellNumeric({ value }) {
39
39
  }
40
40
 
41
41
  function CellCurrency({ value, currency = undefined, }) {
42
- return React__default["default"].createElement(CellNumeric, { value: formatters.formatCurrency(value, currency) });
42
+ return React__default["default"].createElement(CellNumeric, { value: require$$3.formatCurrency(value, currency) });
43
43
  }
44
44
 
45
45
  function Header({ children }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "4.67.5",
3
+ "version": "4.68.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -83,5 +83,5 @@
83
83
  "> 1%",
84
84
  "IE 10"
85
85
  ],
86
- "gitHead": "d1601e0aca701bd676121e2e4fe47b9f04726d13"
86
+ "gitHead": "4ce40fd6dfd535e44a99fb37415b4a06e4c21ea2"
87
87
  }
@@ -1,227 +0,0 @@
1
- 'use strict';
2
-
3
- var tslib_es6 = require('./tslib.es6-5b8768b7.js');
4
- var React = require('react');
5
- var uuid = require('uuid');
6
- var reactHookForm = require('react-hook-form');
7
- var styleInject_es = require('./style-inject.es-9d2f5f4e.js');
8
- var classnames = require('classnames');
9
- var Button = require('./Button-163a0641.js');
10
- var Icon = require('./Icon-405a216c.js');
11
- var Text = require('./Text-4a2bc89f.js');
12
- var InputValidation = require('./InputValidation-179f0926.js');
13
- var Spinner = require('./Spinner-9d8fc7ff.js');
14
-
15
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
16
-
17
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
18
- var classnames__default = /*#__PURE__*/_interopDefaultLegacy(classnames);
19
-
20
- var css_248z = ":root {\n /**\n * These `--public-field` properties are used in other components such\n * as InputGroup, therefore they must stay on :root\n **/\n --public-field--top-left-radius: var(--radius-base);\n --public-field--top-right-radius: var(--radius-base);\n --public-field--bottom-left-radius: var(--radius-base);\n --public-field--bottom-right-radius: var(--radius-base);\n}\n\n.geR7qBhrMfk- {\n width: 100%;\n}\n\n/**\n * Wrapper\n **/\n\n.nPGhTEEzsoU- {\n --field--placeholder-color: var(--color-greyBlue--light);\n --field--placeholder-offset: 50%;\n --field--placeholder-transform: -50%;\n\n --field--textAlign: left;\n\n --field--height: var(--space-largest);\n\n --field--padding-top: calc(var(--space-base) - var(--space-smallest));\n --field--padding-bottom: calc(var(--space-base) - var(--space-smallest));\n --field--padding-left: var(--space-base);\n --field--padding-right: var(--space-base);\n\n --field--value-color: var(--color-heading);\n --field--value-lineHeight: calc(var(--base-unit) * 1.25);\n\n --field--border-color: var(--color-border);\n --field--background-color: var(--color-surface);\n\n --field--base-elevation: var(--elevation-base);\n --field--label-elevation: calc(var(--field--base-elevation) + 1);\n --field--postfix-elevation: calc(var(--field--base-elevation) - 1);\n --field--postfix-action-elevation: calc(var(--field--base-elevation) + 2);\n\n display: -ms-flexbox;\n\n display: flex;\n width: 100%;\n height: calc(16px * 3);\n height: var(--field--height);\n border: calc(16px / 16) solid rgb(217, 223, 225);\n border: var(--border-base) solid var(--field--border-color);\n border-radius: calc(16px / 8);\n border-radius: var(--radius-base);\n border-top-right-radius: calc(16px / 8);\n border-top-right-radius: var(--public-field--top-right-radius);\n border-bottom-right-radius: calc(16px / 8);\n border-bottom-right-radius: var(--public-field--bottom-right-radius);\n border-bottom-left-radius: calc(16px / 8);\n border-bottom-left-radius: var(--public-field--bottom-left-radius);\n border-top-left-radius: calc(16px / 8);\n border-top-left-radius: var(--public-field--top-left-radius);\n color: rgb(1, 41, 57);\n color: var(--field--value-color);\n font-size: calc((16px * 1) * 0.875);\n font-size: calc(calc(16px * 1) * 0.875);\n font-size: var(--typography--fontSize-base);\n background-color: rgba(255, 255, 255, 1);\n background-color: var(--field--background-color);\n}\n\n.nPGhTEEzsoU- * {\n box-sizing: border-box;\n}\n\n.nPGhTEEzsoU-:focus-within {\n position: relative;\n z-index: var(--field--base-elevation);\n box-shadow: 0px 0px 0px calc(16px / 8) rgba(255, 255, 255, 1),\n 0px 0px 0px calc(16px / 4) rgb(147, 161, 169);\n box-shadow: var(--shadow-focus);\n}\n\n.YhserUiOeFE-:not(:focus-within) input {\n color: var(--field--background-color);\n -webkit-text-fill-color: var(--field--background-color);\n}\n\n.YhserUiOeFE-:focus-within,\n.UIZq8hTmJVU- {\n --field--placeholder-color: var(--color-text--secondary);\n --field--placeholder-offset: var(--space-smallest);\n --field--placeholder-transform: 0;\n --field--padding-top: calc(var(--space-base) + var(--space-smaller));\n --field--padding-bottom: var(--space-small);\n}\n\n.YhserUiOeFE-.Ku8sWS0mLew-:focus-within,\n.UIZq8hTmJVU-.Ku8sWS0mLew- {\n --field--padding-top: calc(var(--space-large) + var(--space-smaller));\n}\n\n.nPGhTEEzsoU-.mgPacJ6Z71Y- {\n --field--placeholder-offset: 0;\n --field--placeholder-transform: 0;\n height: auto;\n min-height: auto;\n}\n\n.gJ-15M615eY-,\n.gJ-15M615eY-:focus-within {\n --field--border-color: var(--color-critical);\n position: relative;\n}\n\n._1rsTLm5GwcM- {\n --field--placeholder-color: var(--color-disabled);\n --field--value-color: var(--color-disabled);\n --field--background-color: var(--color-surface--background);\n --field--border-color: var(--color-disabled--secondary);\n}\n\n/* override iOS default styling for disabled input */\n\n._1rsTLm5GwcM- :disabled {\n -webkit-text-fill-color: var(--field--value-color);\n opacity: 1;\n}\n\n.o8D-H-lKfDk- {\n --field--padding-left: calc(var(--space-base) - var(--space-smaller));\n --field--padding-right: calc(var(--space-base) - var(--space-smaller));\n --field--padding-top: var(--space-small);\n --field--padding-bottom: var(--space-small);\n --field--height: calc(var(--space-larger) + var(--space-smaller));\n}\n\n.Ku8sWS0mLew- {\n --field--padding-left: var(--space-large);\n --field--padding-right: var(--space-large);\n --field--height: calc(var(--space-extravagant));\n}\n\n._5Hu2F3cBvng- {\n display: inline-block;\n width: auto;\n}\n\n.s1WLQs6ffD8- {\n --field--textAlign: center;\n}\n\n.a2r4QheWYIA- {\n --field--textAlign: right;\n}\n\n/**\n * The custom property --formField-maxLength is getting defined inside the\n * component.\n */\n\n.KdAnXK1gClo- {\n width: calc(\n (16px * var(--formField-maxLength)) + var(--field--padding-left) +\n var(--field--padding-right)\n );\n width: calc(\n (var(--base-unit) * var(--formField-maxLength)) + var(--field--padding-left) +\n var(--field--padding-right)\n );\n}\n\n/**\n * Input Wrapper\n **/\n\n.iQFhpFYnz-8- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex: 1;\n flex: 1;\n position: relative;\n /* Ensure input stays with the rest of the element stack */\n z-index: 0;\n z-index: var(--elevation-default);\n}\n\n.Yo2Wi9dpa-Y- {\n position: relative;\n -ms-flex: 1;\n flex: 1;\n}\n\n/**\n * Input\n **/\n\n.LSHPV7PwOTg- {\n position: relative;\n z-index: var(--field--base-elevation);\n width: 100%;\n height: 100%;\n padding-top: var(--field--padding-top);\n padding-bottom: var(--field--padding-bottom);\n padding-left: var(--field--padding-left);\n padding-right: var(--field--padding-right);\n border: none;\n border-radius: 0;\n color: inherit;\n font-family: inherit;\n font-size: inherit;\n line-height: var(--field--value-lineHeight);\n text-align: var(--field--textAlign);\n background: transparent;\n -webkit-appearance: none;\n appearance: none;\n}\n\n.LSHPV7PwOTg-:focus {\n outline: none;\n}\n\n.mgPacJ6Z71Y- .LSHPV7PwOTg- {\n resize: vertical;\n}\n\n.i31GQXcMz54- .LSHPV7PwOTg- {\n z-index: var(--field--label-elevation);\n}\n\n.LSHPV7PwOTg-:-webkit-autofill,\n.LSHPV7PwOTg-:-webkit-autofill:hover,\n.LSHPV7PwOTg-:-webkit-autofill:focus,\n.LSHPV7PwOTg-:-webkit-autofill:active {\n -webkit-box-shadow: 0 0 0 30px rgba(255, 255, 255, 1) inset !important;\n -webkit-box-shadow: 0 0 0 30px var(--color-surface) inset !important;\n}\n\n/**\n * Label\n **/\n\n._3xREbTN5pPg- {\n position: absolute;\n top: var(--field--placeholder-offset);\n z-index: var(--field--label-elevation);\n width: 100%;\n padding-left: var(--field--padding-left);\n padding-right: var(--field--padding-right);\n overflow: hidden;\n color: var(--field--placeholder-color);\n line-height: var(--field--value-lineHeight);\n text-align: var(--field--textAlign);\n text-overflow: ellipsis;\n white-space: nowrap;\n pointer-events: none;\n -webkit-transform: translateY(var(--field--placeholder-transform));\n transform: translateY(var(--field--placeholder-transform));\n transition: all 100ms;\n transition: all var(--timing-quick);\n}\n\n.mgPacJ6Z71Y- ._3xREbTN5pPg- {\n /* Changes the width so that the scrollbar on the textarea doesn't get cut off */\n width: calc(100% - var(--field--padding-right));\n padding-top: var(--field--padding-top);\n /* Remove padding on right to make use of the entire width */\n padding-right: 0;\n -webkit-transform: translateY(--field--placeholder-transform);\n transform: translateY(--field--placeholder-transform);\n}\n\n.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-:focus-within ._3xREbTN5pPg- {\n font-size: calc((16px * 1) * 0.75);\n font-size: calc(calc(16px * 1) * 0.75);\n font-size: var(--typography--fontSize-small);\n}\n\n.mgPacJ6Z71Y-.UIZq8hTmJVU- ._3xREbTN5pPg- {\n padding-top: calc(16px / 8);\n padding-top: var(--space-smallest);\n background-color: var(--field--background-color);\n}\n\n.o8D-H-lKfDk-.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-.o8D-H-lKfDk-.UIZq8hTmJVU-:focus-within ._3xREbTN5pPg- {\n display: none;\n}\n\n/**This is valid cascading order **/\n\n/* stylelint-disable-next-line no-descending-specificity */\n\n.Ku8sWS0mLew-.UIZq8hTmJVU- ._3xREbTN5pPg-,\n.YhserUiOeFE-.Ku8sWS0mLew-.UIZq8hTmJVU-:focus-within ._3xREbTN5pPg- {\n padding-top: calc(16px / 2);\n padding-top: var(--space-small);\n}\n\n/**\n * Postfix\n **/\n\n.VtnAk1HYMMk- {\n position: absolute;\n top: 50%;\n right: calc(16px * 1);\n right: var(--space-base);\n z-index: var(--field--postfix-elevation);\n -webkit-transform: translateY(-50%);\n transform: translateY(-50%);\n}\n\n/**\n * Affix\n **/\n\n.uPLklxvtfJw- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-align: center;\n align-items: center;\n -ms-flex-pack: center;\n justify-content: center;\n margin: 0 calc(var(--field--padding-left) * -1) 0 0;\n padding: 0 var(--field--padding-right) 0 var(--field--padding-left);\n}\n\n@supports (aspect-ratio: 1/1) {\n .uPLklxvtfJw- {\n /*\n * disabling property-no-unknown here as this is a real property\n * that stylelint just doesn't know about. We may be able to remove\n * this when we update our stylelint to not care about IE11.\n */\n /* stylelint-disable-next-line property-no-unknown */\n aspect-ratio: 1/1;\n padding: 0;\n }\n}\n\n.uPLklxvtfJw-.pYqqDvv57JE- {\n margin: 0 0 0 calc(var(--field--padding-right) * -1);\n}\n\n.uPLklxvtfJw-.eI44oQpuVlk- {\n position: relative;\n z-index: var(--field--postfix-action-elevation);\n}\n\n.jO8P2iSHilM- {\n display: -ms-flexbox;\n display: flex;\n margin: 0 calc((var(--field--padding-left) - calc(16px / 8)) * -1) 0 0;\n margin: 0 calc((var(--field--padding-left) - var(--space-smallest)) * -1) 0 0;\n padding: 0 0 0 var(--field--padding-left);\n line-height: var(--field--value-lineHeight);\n -ms-flex-align: center;\n align-items: center;\n -ms-flex: 0 0 auto;\n flex: 0 0 auto;\n}\n\n.jO8P2iSHilM-.pYqqDvv57JE- {\n margin: 0 0 0 calc((var(--field--padding-left) - calc(16px / 8)) * -1);\n margin: 0 0 0 calc((var(--field--padding-left) - var(--space-smallest)) * -1);\n padding: 0 var(--field--padding-left) 0 0;\n}\n\n.UIZq8hTmJVU-:not(.o8D-H-lKfDk-) .jO8P2iSHilM- {\n padding-top: var(--field--padding-top);\n padding-bottom: var(--field--padding-bottom);\n}\n\n._2GfgzNnLOSI- {\n margin-top: calc(16px / 4);\n margin-top: var(--space-smaller);\n}\n";
21
- var styles = {"container":"geR7qBhrMfk-","wrapper":"nPGhTEEzsoU-","timeInputLabel":"YhserUiOeFE-","miniLabel":"UIZq8hTmJVU-","large":"Ku8sWS0mLew-","textarea":"mgPacJ6Z71Y-","invalid":"gJ-15M615eY-","disabled":"_1rsTLm5GwcM-","small":"o8D-H-lKfDk-","inline":"_5Hu2F3cBvng-","center":"s1WLQs6ffD8-","right":"a2r4QheWYIA-","maxLength":"KdAnXK1gClo-","inputWrapper":"iQFhpFYnz-8-","childrenWrapper":"Yo2Wi9dpa-Y-","input":"LSHPV7PwOTg-","select":"i31GQXcMz54-","label":"_3xREbTN5pPg-","postfix":"VtnAk1HYMMk-","affixIcon":"uPLklxvtfJw-","suffix":"pYqqDvv57JE-","hasAction":"eI44oQpuVlk-","affixLabel":"jO8P2iSHilM-","description":"_2GfgzNnLOSI-"};
22
- styleInject_es.styleInject(css_248z);
23
-
24
- function AffixLabel({ label, variation = "prefix", labelRef, }) {
25
- const affixLabelClass = classnames__default["default"](styles.affixLabel, {
26
- [styles.suffix]: variation === "suffix",
27
- });
28
- return (React__default["default"].createElement("div", { ref: labelRef, className: affixLabelClass }, label));
29
- }
30
- function AffixIcon({ icon, onClick, ariaLabel, variation = "prefix", size, }) {
31
- const affixIconClass = classnames__default["default"](styles.affixIcon, {
32
- [styles.suffix]: variation === "suffix",
33
- [styles.hasAction]: onClick,
34
- });
35
- const iconSize = size === "small" ? "small" : "base";
36
- if (!icon)
37
- return React__default["default"].createElement(React__default["default"].Fragment, null);
38
- return (React__default["default"].createElement("div", { className: affixIconClass }, onClick ? (React__default["default"].createElement(Button.Button
39
- /**
40
- * We can cast the ariaLabel here as a `Suffix`
41
- * requires an ariaLabel if there is an action
42
- */
43
- , {
44
- /**
45
- * We can cast the ariaLabel here as a `Suffix`
46
- * requires an ariaLabel if there is an action
47
- */
48
- ariaLabel: ariaLabel, icon: icon, onClick: onClick, variation: "subtle", type: "tertiary", size: iconSize })) : (React__default["default"].createElement(Icon.Icon, { name: icon, size: iconSize, color: "greyBlue" }))));
49
- }
50
-
51
- function FormFieldDescription({ id, description, }) {
52
- return (React__default["default"].createElement("div", { id: id, className: styles.description },
53
- React__default["default"].createElement(Text.Text, { size: "small", variation: "subdued" }, description)));
54
- }
55
-
56
- function FormFieldWrapper({ align, description, descriptionIdentifier, placeholder, value, children, invalid, error, size, prefix, suffix, max, maxLength, type, disabled, inline, identifier, }) {
57
- const wrapperClasses = classnames__default["default"](styles.wrapper, size && styles[size], align && styles[align], {
58
- [styles.miniLabel]: (placeholder && value !== "") ||
59
- (placeholder && type === "select") ||
60
- // Naively assume that if the the type is tel, it is the InputPhoneNumber
61
- (placeholder && type === "tel"),
62
- [styles.textarea]: type === "textarea",
63
- [styles.select]: type === "select",
64
- [styles.invalid]: invalid !== null && invalid !== void 0 ? invalid : error,
65
- [styles.disabled]: disabled,
66
- [styles.maxLength]: maxLength,
67
- [styles.timeInputLabel]: placeholder && type === "time" && placeholder && value === "",
68
- });
69
- const containerClasses = classnames__default["default"](styles.container, {
70
- [styles.inline]: inline,
71
- });
72
- const wrapperInlineStyle = {
73
- ["--formField-maxLength"]: maxLength || max,
74
- };
75
- const prefixRef = React.useRef();
76
- const suffixRef = React.useRef();
77
- const [labelStyle, setLabelStyle] = React.useState({
78
- paddingLeft: undefined,
79
- paddingRight: undefined,
80
- });
81
- React.useEffect(() => {
82
- setLabelStyle(getAffixPaddding);
83
- }, [value]);
84
- return (React__default["default"].createElement("div", { className: containerClasses },
85
- React__default["default"].createElement("div", { className: wrapperClasses, style: wrapperInlineStyle, "data-testid": "Form-Field-Wrapper" },
86
- (prefix === null || prefix === void 0 ? void 0 : prefix.icon) && React__default["default"].createElement(AffixIcon, Object.assign({}, prefix, { size: size })),
87
- React__default["default"].createElement("div", { className: styles.inputWrapper },
88
- placeholder && (React__default["default"].createElement("label", { className: styles.label, htmlFor: identifier, style: (prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) || (suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current)
89
- ? labelStyle
90
- : undefined }, placeholder)),
91
- (prefix === null || prefix === void 0 ? void 0 : prefix.label) && React__default["default"].createElement(AffixLabel, Object.assign({}, prefix, { labelRef: prefixRef })),
92
- React__default["default"].createElement("div", { className: styles.childrenWrapper }, children),
93
- (suffix === null || suffix === void 0 ? void 0 : suffix.label) && (React__default["default"].createElement(AffixLabel, Object.assign({}, suffix, { labelRef: suffixRef, variation: "suffix" })))),
94
- (suffix === null || suffix === void 0 ? void 0 : suffix.icon) && (React__default["default"].createElement(AffixIcon, Object.assign({}, suffix, { variation: "suffix", size: size })))),
95
- description && !inline && (React__default["default"].createElement(FormFieldDescription, { id: descriptionIdentifier, description: description })),
96
- error && !inline && React__default["default"].createElement(InputValidation.InputValidation, { message: error })));
97
- function getAffixPaddding() {
98
- const hasValue = value !== "";
99
- const newPadding = {
100
- paddingLeft: undefined,
101
- paddingRight: undefined,
102
- };
103
- // Naively assume that if the the type is tel, it is the InputPhoneNumber
104
- if (type === "tel")
105
- return newPadding;
106
- if ((prefixRef === null || prefixRef === void 0 ? void 0 : prefixRef.current) && !hasValue) {
107
- const { offsetWidth } = prefixRef.current;
108
- newPadding.paddingLeft = offset(offsetWidth);
109
- }
110
- if ((suffixRef === null || suffixRef === void 0 ? void 0 : suffixRef.current) && !hasValue) {
111
- const { offsetWidth } = suffixRef.current;
112
- newPadding.paddingRight = offset(offsetWidth);
113
- }
114
- function offset(width) {
115
- return `calc(${width}px + var(--space-smallest)`;
116
- }
117
- return newPadding;
118
- }
119
- }
120
-
121
- function FormFieldPostFix({ variation }) {
122
- return (React__default["default"].createElement("span", { className: styles.postfix }, variation === "select" ? (React__default["default"].createElement(Icon.Icon, { name: "arrowDown" })) : (React__default["default"].createElement(Spinner.Spinner, { size: "small" }))));
123
- }
124
-
125
- // Added 13th statement to accommodate getErrorMessage function
126
- /*eslint max-statements: ["error", 13]*/
127
- function FormField(props) {
128
- var _a, _b;
129
- const { actionsRef, autocomplete = true, children, defaultValue, description, disabled, inputRef, inline, keyboard, max, maxLength, min, name, readonly, rows, loading, type = "text", validations, value, onChange, onEnter, onFocus, onBlur, onValidation, } = props;
130
- const { control, formState: { errors }, setValue, watch, } = reactHookForm.useFormContext() != undefined
131
- ? reactHookForm.useFormContext()
132
- : // If there isn't a Form Context being provided, get a form for this field.
133
- reactHookForm.useForm({ mode: "onTouched" });
134
- const [identifier] = React.useState(uuid.v1());
135
- const [descriptionIdentifier] = React.useState(`descriptionUUID--${uuid.v1()}`);
136
- /**
137
- * Generate a name if one is not supplied, this is the name
138
- * that will be used for react-hook-form and not neccessarily
139
- * attached to the DOM
140
- */
141
- const [controlledName] = React.useState(name ? name : `generatedName--${identifier}`);
142
- React.useEffect(() => {
143
- if (value != undefined) {
144
- setValue(controlledName, value);
145
- }
146
- }, [value, watch(controlledName)]);
147
- React.useImperativeHandle(actionsRef, () => ({
148
- setValue: newValue => {
149
- setValue(controlledName, newValue, { shouldValidate: true });
150
- },
151
- }));
152
- const message = (_a = errors[controlledName]) === null || _a === void 0 ? void 0 : _a.message;
153
- const error = getErrorMessage();
154
- React.useEffect(() => handleValidation(), [error]);
155
- return (React__default["default"].createElement(reactHookForm.Controller, { control: control, name: controlledName, rules: Object.assign({}, validations), defaultValue: (_b = value !== null && value !== void 0 ? value : defaultValue) !== null && _b !== void 0 ? _b : "", render: (_a) => {
156
- var _b = _a.field, { onChange: onControllerChange, onBlur: onControllerBlur, name: controllerName } = _b, rest = tslib_es6.__rest(_b, ["onChange", "onBlur", "name"]);
157
- const fieldProps = Object.assign(Object.assign(Object.assign({}, rest), { id: identifier, className: styles.input, name: (validations || name) && controllerName, disabled: disabled, readOnly: readonly, inputMode: keyboard, onChange: handleChange, onBlur: handleBlur, onFocus: handleFocus }), (description &&
158
- !inline && { "aria-describedby": descriptionIdentifier }));
159
- const textFieldProps = Object.assign(Object.assign({}, fieldProps), { onKeyDown: handleKeyDown });
160
- return (React__default["default"].createElement(FormFieldWrapper, Object.assign({}, props, { value: rest.value, error: error, identifier: identifier, descriptionIdentifier: descriptionIdentifier }), renderField()));
161
- function renderField() {
162
- switch (type) {
163
- case "select":
164
- return (React__default["default"].createElement(React__default["default"].Fragment, null,
165
- React__default["default"].createElement("select", Object.assign({}, fieldProps), children),
166
- React__default["default"].createElement(FormFieldPostFix, { variation: "select" })));
167
- case "textarea":
168
- return (React__default["default"].createElement("textarea", Object.assign({}, textFieldProps, { rows: rows, ref: inputRef })));
169
- default:
170
- return (React__default["default"].createElement(React__default["default"].Fragment, null,
171
- React__default["default"].createElement("input", Object.assign({}, textFieldProps, { autoComplete: setAutocomplete(autocomplete), type: type, maxLength: maxLength, max: max, min: min, ref: inputRef })),
172
- loading && React__default["default"].createElement(FormFieldPostFix, { variation: "spinner" }),
173
- children));
174
- }
175
- }
176
- function handleChange(event) {
177
- let newValue;
178
- newValue = event.currentTarget.value;
179
- if (type === "number" && newValue.length > 0) {
180
- newValue = parseFloat(newValue);
181
- }
182
- onChange && onChange(newValue, event);
183
- onControllerChange(event);
184
- }
185
- function handleKeyDown(event) {
186
- if (!onEnter)
187
- return;
188
- if (event.key !== "Enter")
189
- return;
190
- if (event.shiftKey || event.ctrlKey)
191
- return;
192
- event.preventDefault();
193
- onEnter && onEnter(event);
194
- }
195
- function handleFocus(event) {
196
- const target = event.currentTarget;
197
- if (target.select) {
198
- setTimeout(() => readonly && target.select());
199
- }
200
- onFocus && onFocus();
201
- }
202
- function handleBlur() {
203
- onBlur && onBlur();
204
- onControllerBlur();
205
- }
206
- } }));
207
- function getErrorMessage() {
208
- if (typeof message === "string") {
209
- return message;
210
- }
211
- return "";
212
- }
213
- function handleValidation() {
214
- onValidation && onValidation(error);
215
- }
216
- }
217
- function setAutocomplete(autocompleteSetting) {
218
- if (autocompleteSetting === true) {
219
- return undefined;
220
- }
221
- else if (autocompleteSetting === false) {
222
- return "off";
223
- }
224
- return autocompleteSetting;
225
- }
226
-
227
- exports.FormField = FormField;