@telefonica/mistica 10.15.0 → 10.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [10.16.0](https://github.com/Telefonica/mistica-web/compare/v10.15.0...v10.16.0) (2022-01-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * **Form:** improvements to be able to build custom fields ([cf5de03](https://github.com/Telefonica/mistica-web/commit/cf5de0398c441d943ee417123293450595aa95f5))
7
+
1
8
  # [10.15.0](https://github.com/Telefonica/mistica-web/compare/v10.14.2...v10.15.0) (2022-01-12)
2
9
 
3
10
 
package/dist/index.d.ts CHANGED
@@ -73,7 +73,7 @@ export { default as DecimalField } from './decimal-field';
73
73
  export { default as PasswordField } from './password-field';
74
74
  export { default as DoubleField } from './double-field';
75
75
  export { default as IbanField } from './iban-field';
76
- export { useForm } from './form-context';
76
+ export { useForm, useFieldProps } from './form-context';
77
77
  export { default as IconClose } from './icons/icon-close';
78
78
  export { default as IconInfo } from './icons/icon-info';
79
79
  export { default as IconArrowDown } from './icons/icon-arrow-down';
package/dist/index.js CHANGED
@@ -680,6 +680,12 @@ Object.defineProperty(exports, "useForm", {
680
680
  return _formContext.useForm;
681
681
  }
682
682
  });
683
+ Object.defineProperty(exports, "useFieldProps", {
684
+ enumerable: true,
685
+ get: function() {
686
+ return _formContext.useFieldProps;
687
+ }
688
+ });
683
689
  Object.defineProperty(exports, "IconClose", {
684
690
  enumerable: true,
685
691
  get: function() {
@@ -116,7 +116,7 @@ declare export { default as DecimalField } from "./decimal-field";
116
116
  declare export { default as PasswordField } from "./password-field";
117
117
  declare export { default as DoubleField } from "./double-field";
118
118
  declare export { default as IbanField } from "./iban-field";
119
- declare export { useForm } from "./form-context";
119
+ declare export { useForm, useFieldProps } from "./form-context";
120
120
  declare export { default as IconClose } from "./icons/icon-close";
121
121
  declare export { default as IconInfo } from "./icons/icon-info";
122
122
  declare export { default as IconArrowDown } from "./icons/icon-arrow-down";
package/dist/menu.d.ts CHANGED
@@ -6,7 +6,7 @@ declare type MenuRenderProps = {
6
6
  };
7
7
  declare type TargetRenderProps = {
8
8
  ref: (element: HTMLElement | null) => void;
9
- onPress: (event: React.MouseEvent | React.KeyboardEvent) => void;
9
+ onPress: () => void;
10
10
  isMenuOpen: boolean;
11
11
  };
12
12
  export declare type MenuProps = {
package/dist/menu.js.flow CHANGED
@@ -8,7 +8,7 @@ declare type MenuRenderProps = {
8
8
  };
9
9
  declare type TargetRenderProps = {
10
10
  ref: (element: HTMLElement | null) => void,
11
- onPress: (event: SyntheticMouseEvent<> | SyntheticKeyboardEvent<>) => void,
11
+ onPress: () => void,
12
12
  isMenuOpen: boolean,
13
13
  };
14
14
  export type MenuProps = {
@@ -3,5 +3,5 @@ Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
5
  exports.PACKAGE_VERSION = void 0;
6
- var PACKAGE_VERSION = '10.15.0';
6
+ var PACKAGE_VERSION = '10.16.0';
7
7
  exports.PACKAGE_VERSION = PACKAGE_VERSION;
@@ -315,10 +315,6 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
315
315
  }), _defineProperty(_obj2, "transition", 'opacity 150ms cubic-bezier(0.0, 0, 0.2, 1) 0ms'), _obj2)
316
316
  };
317
317
  });
318
- // Chrome ignores 'off': https://bugs.chromium.org/p/chromium/issues/detail?id=468153#c164
319
- var fixAutoComplete = function fixAutoComplete(platformOverrides, autoComplete) {
320
- return autoComplete === 'off' && (0, _platform).isChrome(platformOverrides) ? 'nope' : autoComplete;
321
- };
322
318
  var TextFieldBaseComponent = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
323
319
  var error = _param.error, helperText = _param.helperText, label = _param.label, inputProps = _param.inputProps, inputRef = _param.inputRef, defaultValue = _param.defaultValue, value = _param.value, onFocus = _param.onFocus, onBlur = _param.onBlur, inputComponent = _param.inputComponent, prefix = _param.prefix, startIcon = _param.startIcon, endIcon = _param.endIcon, endIconOverlay = _param.endIconOverlay, shrinkLabelProp = _param.shrinkLabel, _multiline = _param.multiline, multiline = _multiline === void 0 ? false : _multiline, focus = _param.focus, fieldRef = _param.fieldRef, maxLength = _param.maxLength, idProp = _param.id, autoCompleteProp = _param.autoComplete, fullWidth = _param.fullWidth, rest = _objectWithoutProperties(_param, [
324
320
  "error",
@@ -346,7 +342,7 @@ var TextFieldBaseComponent = /*#__PURE__*/ React.forwardRef(function(_param, ref
346
342
  ]);
347
343
  var id = (0, _hooks).useAriaId(idProp);
348
344
  var ref1 = _slicedToArray(React.useState((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) || (value === null || value === void 0 ? void 0 : value.length) ? 'filled' : 'default'), 2), inputState = ref1[0], setInputState = ref1[1];
349
- var ref2 = (0, _hooks).useTheme(), platformOverrides = ref2.platformOverrides, colors = ref2.colors;
345
+ var ref2 = (0, _hooks).useTheme(), colors = ref2.colors;
350
346
  var ref3 = (0, _hooks).useScreenSize(), isTabletOrSmaller = ref3.isTabletOrSmaller;
351
347
  var ref4;
352
348
  var ref5 = _slicedToArray(React.useState((ref4 = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) !== null && ref4 !== void 0 ? ref4 : 0), 2), characterCount = ref5[0], setCharacterCount = ref5[1];
@@ -403,7 +399,7 @@ var TextFieldBaseComponent = /*#__PURE__*/ React.forwardRef(function(_param, ref
403
399
  var props = _objectSpread({
404
400
  }, rest, {
405
401
  maxLength: maxLength,
406
- autoComplete: fixAutoComplete(platformOverrides, autoCompleteProp)
402
+ autoComplete: autoCompleteProp
407
403
  }, inputProps);
408
404
  var isShrinked = shrinkLabel || inputState === 'focused' || inputState === 'filled';
409
405
  var scale = isShrinked ? isTabletOrSmaller ? _textFieldComponents.LABEL_SCALE_MOBILE : _textFieldComponents.LABEL_SCALE_DESKTOP : 1;
@@ -548,7 +544,7 @@ var TextFieldBase = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
548
544
  // while the test is typing, the component could be remounted.
549
545
  // By hiding the label, we ensure that the test selects the loaded component
550
546
  label: (0, _platform).isRunningAcceptanceTest(platformOverrides) ? '' : props.label,
551
- autoComplete: fixAutoComplete(platformOverrides, 'off'),
547
+ autoComplete: "off",
552
548
  ref: ref,
553
549
  id: id
554
550
  })),
@@ -557,7 +553,7 @@ var TextFieldBase = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
557
553
  inputProps: _objectSpread({
558
554
  }, props, {
559
555
  id: id,
560
- autoComplete: fixAutoComplete(platformOverrides, 'off'),
556
+ autoComplete: 'off',
561
557
  // @ts-expect-error Autosuggest expects slightly different types
562
558
  onChange: function onChange(e, param) {
563
559
  var newValue = param.newValue;
@@ -2,10 +2,11 @@ import * as React from 'react';
2
2
  import type { CommonFormFieldProps } from './text-field-base';
3
3
  export interface TextFieldProps extends CommonFormFieldProps {
4
4
  onChangeValue?: (value: string, rawValue: string) => void;
5
+ onPress?: (event: React.MouseEvent) => void;
5
6
  multiline?: boolean;
6
7
  prefix?: React.ReactNode;
7
8
  endIcon?: React.ReactNode;
8
9
  getSuggestions?: (value: string) => Array<string>;
9
10
  }
10
- declare const TextField: React.FC<TextFieldProps>;
11
+ declare const TextField: React.ForwardRefExoticComponent<TextFieldProps & React.RefAttributes<HTMLInputElement>>;
11
12
  export default TextField;
@@ -7,6 +7,7 @@ var _jsxRuntime = require("react/jsx-runtime");
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _formContext = require("./form-context");
9
9
  var _textFieldBase = _interopRequireDefault(require("./text-field-base"));
10
+ var _common = require("./utils/common");
10
11
  function _interopRequireDefault(obj) {
11
12
  return obj && obj.__esModule ? obj : {
12
13
  default: obj
@@ -95,8 +96,8 @@ function _objectWithoutPropertiesLoose(source, excluded) {
95
96
  }
96
97
  return target;
97
98
  }
98
- var TextField = function TextField(_param) {
99
- var disabled = _param.disabled, error = _param.error, helperText = _param.helperText, name = _param.name, optional = _param.optional, validate = _param.validate, onChangeValue = _param.onChangeValue, onChange = _param.onChange, value = _param.value, defaultValue = _param.defaultValue, onBlurProp = _param.onBlur, onFocusProp = _param.onFocus, rest = _objectWithoutProperties(_param, [
99
+ var TextField = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
100
+ var disabled = _param.disabled, error = _param.error, helperText = _param.helperText, name = _param.name, optional = _param.optional, validate = _param.validate, onChangeValue = _param.onChangeValue, onChange = _param.onChange, value = _param.value, defaultValue = _param.defaultValue, onBlurProp = _param.onBlur, onFocusProp = _param.onFocus, onPress = _param.onPress, rest = _objectWithoutProperties(_param, [
100
101
  "disabled",
101
102
  "error",
102
103
  "helperText",
@@ -108,7 +109,8 @@ var TextField = function TextField(_param) {
108
109
  "value",
109
110
  "defaultValue",
110
111
  "onBlur",
111
- "onFocus"
112
+ "onFocus",
113
+ "onPress"
112
114
  ]);
113
115
  var inputRef = React.useRef(null);
114
116
  var processValue = function processValue(v) {
@@ -150,16 +152,13 @@ var TextField = function TextField(_param) {
150
152
  onChange: onChange,
151
153
  onChangeValue: onChangeValue
152
154
  });
153
- var setInputRef = function setInputRef(field) {
154
- inputRef.current = field;
155
- fieldProps.inputRef(field);
156
- };
157
155
  return(/*#__PURE__*/ (0, _jsxRuntime).jsx(_textFieldBase.default, _objectSpread({
158
156
  }, rest, fieldProps, {
159
- inputRef: setInputRef,
157
+ onClick: onPress,
158
+ inputRef: (0, _common).combineRefs(inputRef, fieldProps.inputRef, ref),
160
159
  onFocus: onFocus,
161
160
  type: "text"
162
161
  })));
163
- };
162
+ });
164
163
  var _default = TextField;
165
164
  exports.default = _default;
@@ -6,10 +6,14 @@ export type TextFieldProps = {
6
6
  ...$Exact<CommonFormFieldProps>,
7
7
 
8
8
  onChangeValue?: (value: string, rawValue: string) => void,
9
+ onPress?: (event: SyntheticMouseEvent<>) => void,
9
10
  multiline?: boolean,
10
11
  prefix?: React.Node,
11
12
  endIcon?: React.Node,
12
13
  getSuggestions?: (value: string) => Array<string>,
13
14
  };
14
- declare var TextField: React.ComponentType<TextFieldProps>;
15
+ declare var TextField: React.ComponentType<{
16
+ ...TextFieldProps,
17
+ ref?: React.Ref<HTMLInputElement>,
18
+ }>;
15
19
  declare export default typeof TextField;
package/dist-es/index.js CHANGED
@@ -75,7 +75,7 @@ export { default as DecimalField } from './decimal-field';
75
75
  export { default as PasswordField } from './password-field';
76
76
  export { default as DoubleField } from './double-field';
77
77
  export { default as IbanField } from './iban-field';
78
- export { useForm } from './form-context';
78
+ export { useForm, useFieldProps } from './form-context';
79
79
  // Icons
80
80
  // @deprecated use IconCloseRegular instead
81
81
  export { default as IconClose } from './icons/icon-close';
@@ -1,2 +1,2 @@
1
1
  // DO NOT EDIT THIS FILE. It's autogenerated by set-version.js
2
- export var PACKAGE_VERSION = '10.15.0';
2
+ export var PACKAGE_VERSION = '10.16.0';
@@ -3,7 +3,7 @@ import * as React from 'react';
3
3
  import { createUseStyles } from './jss';
4
4
  import { Label, HelperText, FieldContainer, LABEL_LEFT_POSITION, LABEL_SCALE_MOBILE, LABEL_SCALE_DESKTOP } from './text-field-components';
5
5
  import { Text3 } from './text';
6
- import { isIos, isRunningAcceptanceTest, isChrome, isFirefox } from './utils/platform';
6
+ import { isIos, isRunningAcceptanceTest, isFirefox } from './utils/platform';
7
7
  import { useAriaId, useTheme, useScreenSize } from './hooks';
8
8
  import classNames from 'classnames';
9
9
  import { combineRefs } from './utils/common';
@@ -281,16 +281,12 @@ var useStyles = createUseStyles(function(theme) {
281
281
  }), _defineProperty(_obj2, "transition", 'opacity 150ms cubic-bezier(0.0, 0, 0.2, 1) 0ms'), _obj2)
282
282
  };
283
283
  });
284
- // Chrome ignores 'off': https://bugs.chromium.org/p/chromium/issues/detail?id=468153#c164
285
- var fixAutoComplete = function(platformOverrides, autoComplete) {
286
- return autoComplete === 'off' && isChrome(platformOverrides) ? 'nope' : autoComplete;
287
- };
288
284
  var TextFieldBaseComponent = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
289
285
  var error = _param.error, helperText = _param.helperText, label = _param.label, inputProps = _param.inputProps, inputRef = _param.inputRef, defaultValue = _param.defaultValue, value = _param.value, onFocus = _param.onFocus, onBlur = _param.onBlur, inputComponent = _param.inputComponent, prefix = _param.prefix, startIcon = _param.startIcon, endIcon = _param.endIcon, endIconOverlay = _param.endIconOverlay, shrinkLabelProp = _param.shrinkLabel, _multiline = _param.multiline, multiline = _multiline === void 0 ? false : _multiline, focus = _param.focus, fieldRef = _param.fieldRef, maxLength = _param.maxLength, idProp = _param.id, autoCompleteProp = _param.autoComplete, fullWidth = _param.fullWidth, rest = _objectWithoutProperties(_param, ["error", "helperText", "label", "inputProps", "inputRef", "defaultValue", "value", "onFocus", "onBlur", "inputComponent", "prefix", "startIcon", "endIcon", "endIconOverlay", "shrinkLabel", "multiline", "focus", "fieldRef", "maxLength", "id",
290
286
  "autoComplete", "fullWidth"]);
291
287
  var id = useAriaId(idProp);
292
288
  var ref1 = _slicedToArray(React.useState((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) || (value === null || value === void 0 ? void 0 : value.length) ? 'filled' : 'default'), 2), inputState = ref1[0], setInputState = ref1[1];
293
- var ref2 = useTheme(), platformOverrides = ref2.platformOverrides, colors = ref2.colors;
289
+ var ref2 = useTheme(), colors = ref2.colors;
294
290
  var ref3 = useScreenSize(), isTabletOrSmaller = ref3.isTabletOrSmaller;
295
291
  var ref4;
296
292
  var ref5 = _slicedToArray(React.useState((ref4 = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) !== null && ref4 !== void 0 ? ref4 : 0), 2), characterCount = ref5[0], setCharacterCount = ref5[1];
@@ -347,7 +343,7 @@ var TextFieldBaseComponent = /*#__PURE__*/ React.forwardRef(function(_param, ref
347
343
  var props = _objectSpread({
348
344
  }, rest, {
349
345
  maxLength: maxLength,
350
- autoComplete: fixAutoComplete(platformOverrides, autoCompleteProp)
346
+ autoComplete: autoCompleteProp
351
347
  }, inputProps);
352
348
  var isShrinked = shrinkLabel || inputState === 'focused' || inputState === 'filled';
353
349
  var scale = isShrinked ? isTabletOrSmaller ? LABEL_SCALE_MOBILE : LABEL_SCALE_DESKTOP : 1;
@@ -488,7 +484,7 @@ var TextFieldBase = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
488
484
  // while the test is typing, the component could be remounted.
489
485
  // By hiding the label, we ensure that the test selects the loaded component
490
486
  label: isRunningAcceptanceTest(platformOverrides) ? '' : props.label,
491
- autoComplete: fixAutoComplete(platformOverrides, 'off'),
487
+ autoComplete: "off",
492
488
  ref: ref,
493
489
  id: id
494
490
  })),
@@ -497,7 +493,7 @@ var TextFieldBase = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
497
493
  inputProps: _objectSpread({
498
494
  }, props, {
499
495
  id: id,
500
- autoComplete: fixAutoComplete(platformOverrides, 'off'),
496
+ autoComplete: 'off',
501
497
  // @ts-expect-error Autosuggest expects slightly different types
502
498
  onChange: function(e, param) {
503
499
  var newValue = param.newValue;
@@ -2,6 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
3
  import { useFieldProps } from './form-context';
4
4
  import TextFieldBase from './text-field-base';
5
+ import { combineRefs } from './utils/common';
5
6
  function _defineProperty(obj, key, value) {
6
7
  if (key in obj) {
7
8
  Object.defineProperty(obj, key, {
@@ -61,10 +62,9 @@ function _objectWithoutPropertiesLoose(source, excluded) {
61
62
  }
62
63
  return target;
63
64
  }
64
- var TextField = function(_param) {
65
- var disabled = _param.disabled, error = _param.error, helperText = _param.helperText, name = _param.name, optional = _param.optional, validate = _param.validate, onChangeValue = _param.onChangeValue, onChange = _param.onChange, value = _param.value, defaultValue = _param.defaultValue, onBlurProp = _param.onBlur, onFocusProp = _param.onFocus, rest = _objectWithoutProperties(_param, ["disabled", "error", "helperText", "name", "optional", "validate", "onChangeValue", "onChange", "value", "defaultValue", "onBlur",
66
- "onFocus"
67
- ]);
65
+ var TextField = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
66
+ var disabled = _param.disabled, error = _param.error, helperText = _param.helperText, name = _param.name, optional = _param.optional, validate = _param.validate, onChangeValue = _param.onChangeValue, onChange = _param.onChange, value = _param.value, defaultValue = _param.defaultValue, onBlurProp = _param.onBlur, onFocusProp = _param.onFocus, onPress = _param.onPress, rest = _objectWithoutProperties(_param, ["disabled", "error", "helperText", "name", "optional", "validate", "onChangeValue", "onChange", "value", "defaultValue", "onBlur",
67
+ "onFocus", "onPress"]);
68
68
  var inputRef = React.useRef(null);
69
69
  var processValue = function(v) {
70
70
  return v;
@@ -105,15 +105,12 @@ var TextField = function(_param) {
105
105
  onChange: onChange,
106
106
  onChangeValue: onChangeValue
107
107
  });
108
- var setInputRef = function(field) {
109
- inputRef.current = field;
110
- fieldProps.inputRef(field);
111
- };
112
108
  return(/*#__PURE__*/ _jsx(TextFieldBase, _objectSpread({
113
109
  }, rest, fieldProps, {
114
- inputRef: setInputRef,
110
+ onClick: onPress,
111
+ inputRef: combineRefs(inputRef, fieldProps.inputRef, ref),
115
112
  onFocus: onFocus,
116
113
  type: "text"
117
114
  })));
118
- };
115
+ });
119
116
  export default TextField;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telefonica/mistica",
3
- "version": "10.15.0",
3
+ "version": "10.16.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",