@telefonica/mistica 16.0.0 → 16.1.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 (152) hide show
  1. package/README.md +11 -9
  2. package/css/mistica.css +1 -1
  3. package/dist/box.d.ts +1 -0
  4. package/dist/box.js +12 -12
  5. package/dist/card.d.ts +14 -2
  6. package/dist/card.js +210 -206
  7. package/dist/credit-card-expiration-field.d.ts +1 -1
  8. package/dist/credit-card-expiration-field.js +53 -52
  9. package/dist/credit-card-number-field.d.ts +1 -1
  10. package/dist/credit-card-number-field.js +47 -45
  11. package/dist/cvv-field.d.ts +1 -1
  12. package/dist/cvv-field.js +38 -37
  13. package/dist/date-field.d.ts +1 -1
  14. package/dist/date-field.js +15 -13
  15. package/dist/date-time-field.d.ts +1 -1
  16. package/dist/date-time-field.js +13 -11
  17. package/dist/decimal-field.d.ts +1 -1
  18. package/dist/decimal-field.js +39 -38
  19. package/dist/email-field.d.ts +1 -1
  20. package/dist/email-field.js +21 -19
  21. package/dist/form-context.d.ts +7 -2
  22. package/dist/form-context.js +69 -62
  23. package/dist/form.d.ts +2 -1
  24. package/dist/form.js +94 -80
  25. package/dist/iban-field.d.ts +1 -1
  26. package/dist/iban-field.js +32 -30
  27. package/dist/index.d.ts +12 -3
  28. package/dist/index.js +19 -8
  29. package/dist/inline.d.ts +2 -1
  30. package/dist/inline.js +16 -15
  31. package/dist/integer-field.d.ts +1 -1
  32. package/dist/integer-field.js +30 -30
  33. package/dist/month-field.d.ts +1 -1
  34. package/dist/month-field.js +15 -13
  35. package/dist/package-version.js +1 -1
  36. package/dist/password-field.d.ts +1 -1
  37. package/dist/password-field.js +24 -22
  38. package/dist/phone-number-field.d.ts +4 -1
  39. package/dist/phone-number-field.js +84 -52
  40. package/dist/pin-field.js +21 -20
  41. package/dist/radio-button.d.ts +1 -0
  42. package/dist/radio-button.js +42 -41
  43. package/dist/rating.css-mistica.js +44 -0
  44. package/dist/rating.css.d.ts +11 -0
  45. package/dist/rating.css.ts.vanilla.css-mistica.js +11 -0
  46. package/dist/rating.d.ts +37 -0
  47. package/dist/rating.js +320 -0
  48. package/dist/search-field.d.ts +1 -0
  49. package/dist/search-field.js +18 -16
  50. package/dist/select.js +36 -33
  51. package/dist/sheet-action-row.css-mistica.js +13 -0
  52. package/dist/sheet-action-row.css.d.ts +1 -0
  53. package/dist/sheet-actions-list.d.ts +26 -0
  54. package/dist/sheet-actions-list.js +147 -0
  55. package/dist/sheet-actions.d.ts +23 -0
  56. package/dist/sheet-actions.js +175 -0
  57. package/dist/{sheet.css-mistica.js → sheet-common.css-mistica.js} +15 -21
  58. package/dist/{sheet.css.d.ts → sheet-common.css.d.ts} +0 -2
  59. package/dist/sheet-common.css.ts.vanilla.css-mistica.js +11 -0
  60. package/dist/sheet-common.d.ts +24 -0
  61. package/dist/sheet-common.js +429 -0
  62. package/dist/sheet-info.css-mistica.js +12 -0
  63. package/dist/sheet-info.css.d.ts +1 -0
  64. package/dist/sheet-info.d.ts +28 -0
  65. package/dist/sheet-info.js +156 -0
  66. package/dist/sheet-native.d.ts +2 -0
  67. package/dist/sheet-native.js +173 -0
  68. package/dist/sheet-radio-list.d.ts +22 -0
  69. package/dist/sheet-radio-list.js +143 -0
  70. package/dist/sheet-root.d.ts +4 -85
  71. package/dist/sheet-root.js +48 -322
  72. package/dist/sheet-types.d.ts +88 -0
  73. package/dist/sheet-web.d.ts +8 -0
  74. package/dist/sheet-web.js +183 -0
  75. package/dist/slider.js +40 -39
  76. package/dist/switch-component.js +18 -17
  77. package/dist/text-field-base.d.ts +3 -1
  78. package/dist/text-field-base.js +74 -66
  79. package/dist/text-field-components.css-mistica.js +14 -14
  80. package/dist/text-field-components.css.d.ts +2 -2
  81. package/dist/text-field-components.js +49 -39
  82. package/dist/text-field.d.ts +1 -0
  83. package/dist/text-field.js +24 -22
  84. package/dist/text-tokens.d.ts +14 -0
  85. package/dist/text-tokens.js +145 -89
  86. package/dist/theme-context-provider.js +6 -5
  87. package/dist/theme.d.ts +2 -0
  88. package/dist/utils/credit-card.d.ts +2 -2
  89. package/dist/utils/credit-card.js +1 -1
  90. package/dist/vivinho-loading-animation/in-lottie.json.js +544 -612
  91. package/dist/vivinho-loading-animation/out-lottie.json.js +828 -896
  92. package/dist/vivinho-loading-animation/pulse-lottie.json.js +798 -866
  93. package/dist/vivinho-loading-animation/wave-lottie.json.js +4303 -4409
  94. package/dist-es/box.js +18 -18
  95. package/dist-es/card.js +305 -301
  96. package/dist-es/credit-card-expiration-field.js +57 -56
  97. package/dist-es/credit-card-number-field.js +74 -72
  98. package/dist-es/cvv-field.js +82 -81
  99. package/dist-es/date-field.js +29 -27
  100. package/dist-es/date-time-field.js +29 -27
  101. package/dist-es/decimal-field.js +46 -45
  102. package/dist-es/email-field.js +26 -24
  103. package/dist-es/form-context.js +70 -63
  104. package/dist-es/form.js +102 -88
  105. package/dist-es/iban-field.js +35 -33
  106. package/dist-es/index.js +1822 -1817
  107. package/dist-es/inline.js +26 -25
  108. package/dist-es/integer-field.js +31 -31
  109. package/dist-es/month-field.js +28 -26
  110. package/dist-es/package-version.js +1 -1
  111. package/dist-es/password-field.js +37 -35
  112. package/dist-es/phone-number-field.js +92 -60
  113. package/dist-es/pin-field.js +32 -31
  114. package/dist-es/radio-button.js +42 -41
  115. package/dist-es/rating.css-mistica.js +6 -0
  116. package/dist-es/rating.css.ts.vanilla.css-mistica.js +2 -0
  117. package/dist-es/rating.js +257 -0
  118. package/dist-es/search-field.js +33 -31
  119. package/dist-es/select.js +49 -46
  120. package/dist-es/sheet-action-row.css-mistica.js +4 -0
  121. package/dist-es/sheet-actions-list.js +92 -0
  122. package/dist-es/sheet-actions.js +125 -0
  123. package/dist-es/sheet-common.css-mistica.js +4 -0
  124. package/dist-es/sheet-common.css.ts.vanilla.css-mistica.js +2 -0
  125. package/dist-es/sheet-common.js +366 -0
  126. package/dist-es/sheet-info.css-mistica.js +3 -0
  127. package/dist-es/sheet-info.js +101 -0
  128. package/dist-es/sheet-native.js +164 -0
  129. package/dist-es/sheet-radio-list.js +88 -0
  130. package/dist-es/sheet-root.js +50 -319
  131. package/dist-es/sheet-web.js +128 -0
  132. package/dist-es/slider.js +49 -48
  133. package/dist-es/style.css +1 -1
  134. package/dist-es/switch-component.js +27 -26
  135. package/dist-es/text-field-base.js +108 -100
  136. package/dist-es/text-field-components.css-mistica.js +2 -2
  137. package/dist-es/text-field-components.js +70 -60
  138. package/dist-es/text-field.js +33 -31
  139. package/dist-es/text-tokens.js +80 -45
  140. package/dist-es/theme-context-provider.js +20 -19
  141. package/dist-es/utils/credit-card.js +1 -1
  142. package/dist-es/vivinho-loading-animation/in-lottie.json.js +534 -599
  143. package/dist-es/vivinho-loading-animation/out-lottie.json.js +821 -886
  144. package/dist-es/vivinho-loading-animation/pulse-lottie.json.js +790 -855
  145. package/dist-es/vivinho-loading-animation/wave-lottie.json.js +4297 -4400
  146. package/package.json +4 -3
  147. package/dist/sheet.d.ts +0 -107
  148. package/dist/sheet.js +0 -642
  149. package/dist-es/sheet.css-mistica.js +0 -4
  150. package/dist-es/sheet.js +0 -567
  151. /package/dist/{sheet.css.ts.vanilla.css-mistica.js → sheet-action-row.css.ts.vanilla.css-mistica.js} +0 -0
  152. /package/dist-es/{sheet.css.ts.vanilla.css-mistica.js → sheet-action-row.css.ts.vanilla.css-mistica.js} +0 -0
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  Object.defineProperty(exports, "default", {
7
7
  enumerable: true,
8
8
  get: function() {
9
- return P;
9
+ return ee;
10
10
  }
11
11
  });
12
12
  const _jsxruntime = require("react/jsx-runtime");
@@ -147,8 +147,8 @@ function _object_without_properties_loose(source, excluded) {
147
147
  }
148
148
  return target;
149
149
  }
150
- const C = /*#__PURE__*/ _react.lazy(()=>Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require(/* webpackChunkName: "date-time-picker" */ "./date-time-picker.js")))), L = (_param)=>{
151
- var { disabled: F, error: g, helperText: R, name: S, optional: f, validate: m, onChange: O, onChangeValue: n, onBlur: h, value: k, defaultValue: y, min: i, /**
150
+ const L = /*#__PURE__*/ _react.lazy(()=>Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require(/* webpackChunkName: "date-time-picker" */ "./date-time-picker.js")))), M = (_param)=>{
151
+ var { disabled: F, error: g, helperText: R, name: S, label: O, optional: f, validate: m, onChange: h, onChangeValue: n, onBlur: k, value: y, defaultValue: I, min: i, /**
152
152
  * When typing a datetime value into the input field (inside a test for example), some browsers like Chrome
153
153
  * force the year to have exactly 6 digits. In order to prevent this, in case max value was not provided we
154
154
  * set it so that it only accepts datetime values with years having up to 4 digits.
@@ -157,6 +157,7 @@ const C = /*#__PURE__*/ _react.lazy(()=>Promise.resolve().then(()=>/*#__PURE__*/
157
157
  "error",
158
158
  "helperText",
159
159
  "name",
160
+ "label",
160
161
  "optional",
161
162
  "validate",
162
163
  "onChange",
@@ -168,21 +169,22 @@ const C = /*#__PURE__*/ _react.lazy(()=>Promise.resolve().then(()=>/*#__PURE__*/
168
169
  "max",
169
170
  "dataAttributes"
170
171
  ]);
171
- const d = _react.useMemo(()=>(0, _platform.isFirefox)() ? !1 : (0, _dom.isInputTypeSupported)("datetime-local"), []), p = (e)=>d ? e : e.replace(/\s/, "T"), { texts: I, t: v } = (0, _hooks.useTheme)(), a = (e)=>{
172
+ const d = _react.useMemo(()=>(0, _platform.isFirefox)() ? !1 : (0, _dom.isInputTypeSupported)("datetime-local"), []), p = (e)=>d ? e : e.replace(/\s/, "T"), { texts: v, t: x } = (0, _hooks.useTheme)(), a = (e)=>{
172
173
  const t = p(e);
173
174
  return !(i && t && t < (0, _time.getLocalDateTimeString)(i) || s && t && t > (0, _time.getLocalDateTimeString)(s));
174
175
  }, D = (0, _formcontext.useFieldProps)({
175
176
  name: S,
176
- value: k,
177
- defaultValue: y,
177
+ label: O,
178
+ value: y,
179
+ defaultValue: I,
178
180
  processValue: p,
179
181
  helperText: R,
180
182
  optional: f,
181
183
  error: g,
182
184
  disabled: F,
183
- onBlur: h,
184
- validate: (e, t)=>a(e) ? m == null ? void 0 : m(e, t) : I.formDateOutOfRangeError || v(_texttokens.formDateOutOfRangeError),
185
- onChange: O,
185
+ onBlur: k,
186
+ validate: (e, t)=>a(e) ? m == null ? void 0 : m(e, t) : v.formDateOutOfRangeError || x(_texttokens.formDateOutOfRangeError),
187
+ onChange: h,
186
188
  onChangeValue: (e, t)=>{
187
189
  a(e) && (n == null || n(e, t));
188
190
  }
@@ -202,7 +204,7 @@ const C = /*#__PURE__*/ _react.lazy(()=>Promise.resolve().then(()=>/*#__PURE__*/
202
204
  }));
203
205
  return d || (0, _environment.isServerSide)() ? T : /* @__PURE__ */ (0, _jsxruntime.jsx)(_react.Suspense, {
204
206
  fallback: T,
205
- children: /* @__PURE__ */ (0, _jsxruntime.jsx)(C, _object_spread_props(_object_spread({}, u, D), {
207
+ children: /* @__PURE__ */ (0, _jsxruntime.jsx)(L, _object_spread_props(_object_spread({}, u, D), {
206
208
  optional: f,
207
209
  withTime: !0,
208
210
  isValidDate: (e)=>a((0, _time.getLocalDateTimeString)(e.toDate())),
@@ -211,4 +213,4 @@ const C = /*#__PURE__*/ _react.lazy(()=>Promise.resolve().then(()=>/*#__PURE__*/
211
213
  }, l)
212
214
  }))
213
215
  });
214
- }, P = L;
216
+ }, ee = M;
@@ -16,5 +16,5 @@ export interface DecimalFieldProps extends CommonFormFieldProps {
16
16
  /** defaults to Infinity */
17
17
  maxDecimals?: number;
18
18
  }
19
- declare const DecimalField: ({ disabled, error, helperText, name, optional, validate: validateProp, onChange, onChangeValue, onBlur, value, defaultValue, maxDecimals, dataAttributes, ...rest }: DecimalFieldProps) => JSX.Element;
19
+ declare const DecimalField: ({ disabled, error, helperText, name, label, optional, validate, onChange, onChangeValue, onBlur, value, defaultValue, maxDecimals, dataAttributes, ...rest }: DecimalFieldProps) => JSX.Element;
20
20
  export default DecimalField;
@@ -11,10 +11,10 @@ function _export(target, all) {
11
11
  }
12
12
  _export(exports, {
13
13
  DecimalInput: function() {
14
- return B;
14
+ return j;
15
15
  },
16
16
  default: function() {
17
- return J;
17
+ return M;
18
18
  }
19
19
  });
20
20
  const _jsxruntime = require("react/jsx-runtime");
@@ -25,7 +25,6 @@ const _textfieldbase = require("./text-field-base.js");
25
25
  const _dom = require("./utils/dom.js");
26
26
  const _rifm = require("rifm");
27
27
  const _common = require("./utils/common.js");
28
- const _texttokens = require("./text-tokens.js");
29
28
  function _getRequireWildcardCache(nodeInterop) {
30
29
  if (typeof WeakMap !== "function") return null;
31
30
  var cacheBabelInterop = new WeakMap();
@@ -146,48 +145,49 @@ function _object_without_properties_loose(source, excluded) {
146
145
  }
147
146
  return target;
148
147
  }
149
- const j = (o)=>{
148
+ const b = (n)=>{
150
149
  try {
151
- return 1.1.toLocaleString(o.replace("_", "-"))[1];
150
+ return 1.1.toLocaleString(n.replace("_", "-"))[1];
152
151
  } catch (e) {
153
152
  return ".";
154
153
  }
155
- }, A = (o, r)=>{
156
- const s = String(o !== null && o !== void 0 ? o : "").replace(/[^.,\d]/g, ""), e = /[.,]/.exec(s), t = s.split(/[.,]/);
157
- return t.length === 0 ? "" : e && r > 0 ? t.shift() + e[0] + t.join("").slice(0, r) : t[0];
158
- }, B = (_param)=>{
159
- var { inputRef: o, value: r, defaultValue: s, onChange: e, maxDecimals: t } = _param, c = _object_without_properties(_param, [
154
+ }, v = (n, t)=>{
155
+ const c = String(n !== null && n !== void 0 ? n : "").replace(/[^.,\d]/g, ""), e = /[.,]/.exec(c), r = c.split(/[.,]/);
156
+ return r.length === 0 ? "" : e && t > 0 ? r.shift() + e[0] + r.join("").slice(0, t) : r[0];
157
+ }, j = (_param)=>{
158
+ var { inputRef: n, value: t, defaultValue: c, onChange: e, maxDecimals: r } = _param, l = _object_without_properties(_param, [
160
159
  "inputRef",
161
160
  "value",
162
161
  "defaultValue",
163
162
  "onChange",
164
163
  "maxDecimals"
165
164
  ]);
166
- const { i18n: u } = (0, _hooks.useTheme)(), f = j(u.locale), p = (n)=>String(n !== null && n !== void 0 ? n : "").replace(/[.,]/g, f), [d, g] = _react.useState(s !== null && s !== void 0 ? s : ""), i = _react.useRef(null), l = typeof r < "u", h = l ? r : d, y = _react.useCallback((n)=>{
167
- l || g(n), i.current && (e == null || e((0, _dom.createChangeEvent)(i.current, n)));
165
+ const { i18n: a } = (0, _hooks.useTheme)(), u = b(a.locale), p = (o)=>String(o !== null && o !== void 0 ? o : "").replace(/[.,]/g, u), [m, f] = _react.useState(c !== null && c !== void 0 ? c : ""), s = _react.useRef(null), i = typeof t < "u", d = i ? t : m, g = _react.useCallback((o)=>{
166
+ i || f(o), s.current && (e == null || e((0, _dom.createChangeEvent)(s.current, o)));
168
167
  }, [
169
- l,
168
+ i,
170
169
  e
171
- ]), a = (0, _rifm.useRifm)({
172
- format: (n)=>A(n, t),
170
+ ]), h = (0, _rifm.useRifm)({
171
+ format: (o)=>v(o, r),
173
172
  replace: p,
174
- value: h,
175
- onChange: y,
173
+ value: d,
174
+ onChange: g,
176
175
  accept: /[\d.,]+/g
177
176
  });
178
- return /* @__PURE__ */ (0, _jsxruntime.jsx)("input", _object_spread_props(_object_spread({}, c), {
177
+ return /* @__PURE__ */ (0, _jsxruntime.jsx)("input", _object_spread_props(_object_spread({}, l), {
179
178
  type: "text",
180
179
  inputMode: "decimal",
181
- value: a.value,
182
- onChange: a.onChange,
183
- ref: (0, _common.combineRefs)(o, i)
180
+ value: h.value,
181
+ onChange: h.onChange,
182
+ ref: (0, _common.combineRefs)(n, s)
184
183
  }));
185
- }, L = (_param)=>{
186
- var { disabled: o, error: r, helperText: s, name: e, optional: t, validate: c, onChange: u, onChangeValue: f, onBlur: p, value: d, defaultValue: g, maxDecimals: i = 1 / 0, dataAttributes: l } = _param, h = _object_without_properties(_param, [
184
+ }, A = (_param)=>{
185
+ var { disabled: n, error: t, helperText: c, name: e, label: r, optional: l, validate: a, onChange: u, onChangeValue: p, onBlur: m, value: f, defaultValue: s, maxDecimals: i = 1 / 0, dataAttributes: d } = _param, g = _object_without_properties(_param, [
187
186
  "disabled",
188
187
  "error",
189
188
  "helperText",
190
189
  "name",
190
+ "label",
191
191
  "optional",
192
192
  "validate",
193
193
  "onChange",
@@ -198,27 +198,28 @@ const j = (o)=>{
198
198
  "maxDecimals",
199
199
  "dataAttributes"
200
200
  ]);
201
- const { texts: y, t: a } = (0, _hooks.useTheme)(), C = (0, _formcontext.useFieldProps)({
201
+ const o = (0, _formcontext.useFieldProps)({
202
202
  name: e,
203
- value: d,
204
- defaultValue: g,
205
- processValue: (m)=>m.trim(),
206
- helperText: s,
207
- optional: t,
208
- error: r,
209
- disabled: o,
210
- onBlur: p,
211
- validate: (m, D)=>m ? c == null ? void 0 : c(m, D) : t ? "" : y.formFieldErrorIsMandatory || a(_texttokens.formFieldErrorIsMandatory),
203
+ label: r,
204
+ value: f,
205
+ defaultValue: s,
206
+ processValue: (C)=>C.trim(),
207
+ helperText: c,
208
+ optional: l,
209
+ error: t,
210
+ disabled: n,
211
+ onBlur: m,
212
+ validate: a,
212
213
  onChange: u,
213
- onChangeValue: f
214
+ onChangeValue: p
214
215
  });
215
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_textfieldbase.TextFieldBaseAutosuggest, _object_spread_props(_object_spread({}, h, C), {
216
- inputComponent: B,
216
+ return /* @__PURE__ */ (0, _jsxruntime.jsx)(_textfieldbase.TextFieldBaseAutosuggest, _object_spread_props(_object_spread({}, g, o), {
217
+ inputComponent: j,
217
218
  inputProps: {
218
219
  maxDecimals: i
219
220
  },
220
221
  dataAttributes: _object_spread({
221
222
  "component-name": "DecimalField"
222
- }, l)
223
+ }, d)
223
224
  }));
224
- }, J = L;
225
+ }, M = A;
@@ -4,5 +4,5 @@ export interface EmailFieldProps extends CommonFormFieldProps {
4
4
  onChangeValue?: (value: string, rawValue: string) => void;
5
5
  getSuggestions?: (value: string) => Array<string>;
6
6
  }
7
- declare const EmailField: ({ disabled, error, helperText, name, optional, validate: validateProp, onChange, onChangeValue, onBlur, value, autoComplete, defaultValue, dataAttributes, ...rest }: EmailFieldProps) => JSX.Element;
7
+ declare const EmailField: ({ disabled, error, helperText, name, label, optional, validate: validateProp, onChange, onChangeValue, onBlur, value, autoComplete, defaultValue, dataAttributes, ...rest }: EmailFieldProps) => JSX.Element;
8
8
  export default EmailField;
@@ -93,12 +93,13 @@ function _object_without_properties_loose(source, excluded) {
93
93
  }
94
94
  return target;
95
95
  }
96
- const $ = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, b = (_param)=>{
97
- var { disabled: m, error: i, helperText: n, name: a, optional: e, validate: t, onChange: l, onChangeValue: f, onBlur: d, value: u, autoComplete: E = "email", defaultValue: c, dataAttributes: p } = _param, F = _object_without_properties(_param, [
96
+ const h = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, j = (_param)=>{
97
+ var { disabled: r, error: o, helperText: s, name: m, label: i, optional: l, validate: e, onChange: n, onChangeValue: a, onBlur: u, value: c, autoComplete: f = "email", defaultValue: p, dataAttributes: E } = _param, d = _object_without_properties(_param, [
98
98
  "disabled",
99
99
  "error",
100
100
  "helperText",
101
101
  "name",
102
+ "label",
102
103
  "optional",
103
104
  "validate",
104
105
  "onChange",
@@ -109,26 +110,27 @@ const $ = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, b = (_param)=>{
109
110
  "defaultValue",
110
111
  "dataAttributes"
111
112
  ]);
112
- const { texts: o, t: s } = (0, _hooks.useTheme)(), x = (0, _formcontext.useFieldProps)({
113
- name: a,
114
- value: u,
115
- defaultValue: c,
116
- processValue: (r)=>r.trim(),
117
- helperText: n,
118
- optional: e,
119
- error: i,
120
- disabled: m,
121
- onBlur: d,
122
- validate: (r, M)=>r ? $.test(r) ? t == null ? void 0 : t(r, M) : o.formEmailError || s(_texttokens.formEmailError) : e ? "" : o.formFieldErrorIsMandatory || s(_texttokens.formFieldErrorIsMandatory),
123
- onChange: l,
124
- onChangeValue: f
113
+ const { texts: F, t: x } = (0, _hooks.useTheme)(), A = (0, _formcontext.useFieldProps)({
114
+ name: m,
115
+ label: i,
116
+ value: c,
117
+ defaultValue: p,
118
+ processValue: (t)=>t.trim(),
119
+ helperText: s,
120
+ optional: l,
121
+ error: o,
122
+ disabled: r,
123
+ onBlur: u,
124
+ validate: (t, g)=>h.test(t !== null && t !== void 0 ? t : "") ? e == null ? void 0 : e(t, g) : F.formEmailError || x(_texttokens.formEmailError),
125
+ onChange: n,
126
+ onChangeValue: a
125
127
  });
126
- return /* @__PURE__ */ (0, _jsxruntime.jsx)(_textfieldbase.TextFieldBaseAutosuggest, _object_spread_props(_object_spread({}, F, x), {
128
+ return /* @__PURE__ */ (0, _jsxruntime.jsx)(_textfieldbase.TextFieldBaseAutosuggest, _object_spread_props(_object_spread({}, d, A), {
127
129
  type: "email",
128
130
  inputMode: "email",
129
- autoComplete: E,
131
+ autoComplete: f,
130
132
  dataAttributes: _object_spread({
131
133
  "component-name": "EmailField"
132
- }, p)
134
+ }, E)
133
135
  }));
134
- }, q = b;
136
+ }, q = j;
@@ -8,6 +8,7 @@ export type FieldRegistration = {
8
8
  input?: HTMLInputElement | HTMLSelectElement | null;
9
9
  validator?: FieldValidator;
10
10
  focusableElement?: HTMLDivElement | HTMLSelectElement | null;
11
+ label?: string;
11
12
  };
12
13
  type Context = {
13
14
  rawValues: {
@@ -38,22 +39,25 @@ type Context = {
38
39
  };
39
40
  export declare const FormContext: React.Context<Context>;
40
41
  export declare const useForm: () => Context;
41
- export declare const useControlProps: <T>({ name, value, defaultValue, onChange, disabled, }: {
42
+ export declare const useControlProps: <T>({ name, label, value, defaultValue, onChange, disabled, }: {
42
43
  name: string;
44
+ label?: string;
43
45
  value: undefined | T;
44
46
  defaultValue: undefined | T;
45
47
  onChange: undefined | ((value: T) => void);
46
48
  disabled?: boolean;
47
49
  }) => {
48
50
  name: string;
51
+ label?: string;
49
52
  value?: T;
50
53
  defaultValue?: T;
51
54
  onChange: (value: T) => void;
52
55
  focusableRef: (focusableElement: HTMLDivElement | null) => void;
53
56
  disabled: boolean | undefined;
54
57
  };
55
- export declare const useFieldProps: ({ name, value, defaultValue, processValue, helperText, optional, error, disabled, onBlur, validate, onChange, onChangeValue, }: {
58
+ export declare const useFieldProps: ({ name, label, value, defaultValue, processValue, helperText, optional, error, disabled, onBlur, validate, onChange, onChangeValue, }: {
56
59
  name: string;
60
+ label: string;
57
61
  value?: string;
58
62
  defaultValue?: string;
59
63
  processValue: (value: string) => unknown;
@@ -69,6 +73,7 @@ export declare const useFieldProps: ({ name, value, defaultValue, processValue,
69
73
  value?: string;
70
74
  defaultValue?: string;
71
75
  name: string;
76
+ label: string;
72
77
  helperText?: string;
73
78
  required: boolean;
74
79
  error: boolean;
@@ -11,19 +11,21 @@ function _export(target, all) {
11
11
  }
12
12
  _export(exports, {
13
13
  FormContext: function() {
14
- return k;
14
+ return D;
15
15
  },
16
16
  useControlProps: function() {
17
- return y;
17
+ return J;
18
18
  },
19
19
  useFieldProps: function() {
20
- return z;
20
+ return K;
21
21
  },
22
22
  useForm: function() {
23
- return P;
23
+ return M;
24
24
  }
25
25
  });
26
26
  const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
27
+ const _hooks = require("./hooks.js");
28
+ const _texttokens = require("./text-tokens.js");
27
29
  function _getRequireWildcardCache(nodeInterop) {
28
30
  if (typeof WeakMap !== "function") return null;
29
31
  var cacheBabelInterop = new WeakMap();
@@ -65,7 +67,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
65
67
  }
66
68
  return newObj;
67
69
  }
68
- const k = /*#__PURE__*/ _react.createContext({
70
+ const D = /*#__PURE__*/ _react.createContext({
69
71
  values: {},
70
72
  setValue: ()=>{},
71
73
  rawValues: {},
@@ -78,107 +80,112 @@ const k = /*#__PURE__*/ _react.createContext({
78
80
  submit: ()=>{},
79
81
  validate: ()=>({}),
80
82
  formId: ""
81
- }), P = ()=>_react.useContext(k), y = (param)=>{
82
- let { name: r, value: t, defaultValue: e, onChange: u, disabled: p } = param;
83
- const { setRawValue: l, setValue: w, rawValues: o, setFormError: E, register: f, formStatus: R } = P();
83
+ }), M = ()=>_react.useContext(D), J = (param)=>{
84
+ let { name: r, label: d, value: s, defaultValue: u, onChange: f, disabled: x } = param;
85
+ const { setRawValue: i, setValue: v, rawValues: o, setFormError: E, register: p, formStatus: w } = M();
84
86
  var _o_r;
85
87
  return _react.useEffect(()=>{
86
88
  if (o[r] === void 0) {
87
89
  var _ref;
88
- const s = (_ref = t !== null && t !== void 0 ? t : e) !== null && _ref !== void 0 ? _ref : !1;
89
- w({
90
+ const t = (_ref = s !== null && s !== void 0 ? s : u) !== null && _ref !== void 0 ? _ref : !1;
91
+ v({
90
92
  name: r,
91
- value: s
92
- }), l({
93
+ value: t
94
+ }), i({
93
95
  name: r,
94
- value: s
96
+ value: t
95
97
  });
96
98
  }
97
99
  }, [
98
- t,
100
+ s,
99
101
  r,
100
- e,
102
+ u,
101
103
  o,
102
- w,
103
- l
104
+ v,
105
+ i
104
106
  ]), {
105
107
  name: r,
106
- value: t,
107
- defaultValue: e !== null && e !== void 0 ? e : t === void 0 ? (_o_r = o[r]) !== null && _o_r !== void 0 ? _o_r : !1 : void 0,
108
- focusableRef: (s)=>f(r, {
109
- focusableElement: s
108
+ label: d,
109
+ value: s,
110
+ defaultValue: u !== null && u !== void 0 ? u : s === void 0 ? (_o_r = o[r]) !== null && _o_r !== void 0 ? _o_r : !1 : void 0,
111
+ focusableRef: (t)=>p(r, {
112
+ focusableElement: t,
113
+ label: d
110
114
  }),
111
- onChange: (s)=>{
112
- l({
115
+ onChange: (t)=>{
116
+ i({
113
117
  name: r,
114
- value: s
115
- }), w({
118
+ value: t
119
+ }), v({
116
120
  name: r,
117
- value: s
121
+ value: t
118
122
  }), E({
119
123
  name: r,
120
124
  error: ""
121
- }), u == null || u(s);
125
+ }), f == null || f(t);
122
126
  },
123
- disabled: R === "sending" || p
127
+ disabled: w === "sending" || x
124
128
  };
125
- }, z = (param)=>{
126
- let { name: r, value: t, defaultValue: e, processValue: u, helperText: p, optional: l, error: w, disabled: o, onBlur: E, validate: f, onChange: R, onChangeValue: s } = param;
129
+ }, K = (param)=>{
130
+ let { name: r, label: d, value: s, defaultValue: u, processValue: f, helperText: x, optional: i, error: v, disabled: o, onBlur: E, validate: p, onChange: w, onChangeValue: t } = param;
127
131
  var _ref, _ref1;
128
- const { setRawValue: v, setValue: V, rawValues: x, values: j, formErrors: T, formStatus: q, setFormError: d, register: I } = P(), F = (_ref1 = (_ref = t !== null && t !== void 0 ? t : e) !== null && _ref !== void 0 ? _ref : x[r]) !== null && _ref1 !== void 0 ? _ref1 : "", N = _react.useRef(u);
129
- var _x_r;
132
+ const { texts: P, t: j } = (0, _hooks.useTheme)(), { setRawValue: V, setValue: T, rawValues: F, values: q, formErrors: S, formStatus: N, setFormError: R, register: b } = M(), I = (_ref1 = (_ref = s !== null && s !== void 0 ? s : u) !== null && _ref !== void 0 ? _ref : F[r]) !== null && _ref1 !== void 0 ? _ref1 : "", k = _react.useRef(f);
133
+ var _F_r;
130
134
  return _react.useEffect(()=>{
131
- v({
135
+ V({
132
136
  name: r,
133
- value: F
134
- }), V({
137
+ value: I
138
+ }), T({
135
139
  name: r,
136
- value: N.current(F)
140
+ value: k.current(I)
137
141
  });
138
142
  }, [
139
143
  r,
140
- F,
141
- v,
142
- V
144
+ I,
145
+ V,
146
+ T
143
147
  ]), _react.useEffect(()=>{
144
- o && d({
148
+ o && R({
145
149
  name: r,
146
150
  error: void 0
147
151
  });
148
152
  }, [
149
153
  o,
150
154
  r,
151
- d
155
+ R
152
156
  ]), {
153
- value: t,
154
- defaultValue: e !== null && e !== void 0 ? e : t === void 0 ? (_x_r = x[r]) !== null && _x_r !== void 0 ? _x_r : "" : void 0,
157
+ value: s,
158
+ defaultValue: u !== null && u !== void 0 ? u : s === void 0 ? (_F_r = F[r]) !== null && _F_r !== void 0 ? _F_r : "" : void 0,
155
159
  name: r,
156
- helperText: T[r] || p,
157
- required: !l,
158
- error: w || !!T[r],
159
- disabled: o || q === "sending",
160
- onBlur: (i)=>{
161
- d({
160
+ label: d,
161
+ helperText: S[r] || x,
162
+ required: !i,
163
+ error: v || !!S[r],
164
+ disabled: o || N === "sending",
165
+ onBlur: (c)=>{
166
+ let e;
167
+ !F[r] && !i ? e = P.formFieldErrorIsMandatory || j(_texttokens.formFieldErrorIsMandatory) : p && (e = p(q[r], F[r])), R({
162
168
  name: r,
163
- error: f == null ? void 0 : f(j[r], x[r])
164
- }), E == null || E(i);
169
+ error: e
170
+ }), E == null || E(c);
165
171
  },
166
- inputRef: (i)=>I(r, {
167
- input: i,
168
- validator: f
172
+ inputRef: (c)=>b(r, {
173
+ input: c,
174
+ validator: p,
175
+ label: d
169
176
  }),
170
- onChange: (i)=>{
171
- const S = i.currentTarget.value, b = u(S);
172
- v({
177
+ onChange: (c)=>{
178
+ const e = c.currentTarget.value, y = f(e);
179
+ V({
173
180
  name: r,
174
- value: S
175
- }), V({
181
+ value: e
182
+ }), T({
176
183
  name: r,
177
- value: b
178
- }), d({
184
+ value: y
185
+ }), R({
179
186
  name: r,
180
187
  error: ""
181
- }), R == null || R(i), s == null || s(b, S);
188
+ }), w == null || w(c), t == null || t(y, e);
182
189
  }
183
190
  };
184
191
  };
package/dist/form.d.ts CHANGED
@@ -10,7 +10,8 @@ type FormProps = {
10
10
  autoJump?: boolean;
11
11
  children: React.ReactNode;
12
12
  onValidationErrors?: (errors: FormErrors) => void;
13
+ getErrorMessageForScreenReader?: (errors: FormErrors) => string;
13
14
  className?: string;
14
15
  };
15
- declare const Form: ({ children, className, onSubmit, initialValues, autoJump, onValidationErrors, id: idProp, }: FormProps) => JSX.Element;
16
+ declare const Form: ({ children, className, onSubmit, initialValues, autoJump, onValidationErrors, getErrorMessageForScreenReader, id: idProp, }: FormProps) => JSX.Element;
16
17
  export default Form;