@commercetools-uikit/localized-text-field 0.0.0-canary-2021830134526
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/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/commercetools-uikit-localized-text-field.cjs.dev.js +334 -0
- package/dist/commercetools-uikit-localized-text-field.cjs.js +7 -0
- package/dist/commercetools-uikit-localized-text-field.cjs.prod.js +162 -0
- package/dist/commercetools-uikit-localized-text-field.esm.js +307 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 commercetools GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<!-- THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -->
|
|
2
|
+
<!-- This file is created by the `yarn generate-readme` script. -->
|
|
3
|
+
|
|
4
|
+
# LocalizedTextField
|
|
5
|
+
|
|
6
|
+
## Description
|
|
7
|
+
|
|
8
|
+
A controlled text input component for localized single-line strings with validation states.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
yarn add @commercetools-uikit/localized-text-field
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
npm --save install @commercetools-uikit/localized-text-field
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Additionally install the peer dependencies (if not present)
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
yarn add react
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
npm --save install react
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
```jsx
|
|
33
|
+
import LocalizedTextField from '@commercetools-uikit/localized-text-field';
|
|
34
|
+
|
|
35
|
+
const Example = () => (
|
|
36
|
+
<LocalizedTextField
|
|
37
|
+
title="Description"
|
|
38
|
+
value={{
|
|
39
|
+
en: 'Parrot that knows how to party',
|
|
40
|
+
de: 'Papagei der ordentlich abfeiert',
|
|
41
|
+
}}
|
|
42
|
+
selectedLanguage="en"
|
|
43
|
+
onChange={(event) => alert(event.target.value)}
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export default Example;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Properties
|
|
51
|
+
|
|
52
|
+
| Props | Type | Required | Default | Description |
|
|
53
|
+
| ------------------------------- | ----------------------------------------------------------------------------------------- | :------: | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
|
|
55
|
+
| `horizontalConstraint` | `enum`<br/>Possible values:<br/>`6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
|
|
56
|
+
| `errors` | `object` | | | A map of errors. Error messages for known errors are rendered automatically.
<br />
Unknown errors will be forwarded to `renderError` |
|
|
57
|
+
| `errors.missing` | `bool` | | | |
|
|
58
|
+
| `renderError` | `func` | | | Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
<br />
Signature: `(key, error) => React.node` |
|
|
59
|
+
| `isRequired` | `bool` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
|
|
60
|
+
| `touched` | `bool` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
|
|
61
|
+
| `autoComplete` | `string` | | | Used as HTML `autocomplete` of the input component. property |
|
|
62
|
+
| `name` | `string` | | | Used as HTML name of the input component. property |
|
|
63
|
+
| `value` | `objectOf(string)` | ✅ | | Values to use.
<br />
Keyed by language, the values are the actual values, e.g. `{ en: 'Horse', de: 'Pferd' }` |
|
|
64
|
+
| `onChange` | `custom` | | | Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.
<br />
Signature: `(event) => void` |
|
|
65
|
+
| `selectedLanguage` | `string` | ✅ | | Specifies which language will be shown in case the `LocalizedTextInput` is collapsed. |
|
|
66
|
+
| `onBlur` | `func` | | | Called when input is blurred |
|
|
67
|
+
| `onFocus` | `func` | | | Called when input is focused |
|
|
68
|
+
| `hideLanguageExpansionControls` | `bool` | | | Will hide the language expansion controls when set to `true`. All languages will be shown when set to `true`. |
|
|
69
|
+
| `defaultExpandLanguages` | `custom` | | | Controls whether one or all languages are visible by default |
|
|
70
|
+
| `isAutofocussed` | `bool` | | | Focus the input on initial render |
|
|
71
|
+
| `isDisabled` | `bool` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
|
|
72
|
+
| `isReadOnly` | `bool` | | | Indicates that the field is displaying read-only content |
|
|
73
|
+
| `placeholder` | `objectOf(string)` | | | Placeholders for each language. Object of the same shape as `value`. |
|
|
74
|
+
| `errorsByLanguage` | `objectOf(node)` | | | Errors for each translation. These are forwarded to the `errors` prop of `LocalizedTextInput`. |
|
|
75
|
+
| `title` | `<string, node>` | ✅ | | Title of the label |
|
|
76
|
+
| `hint` | `custom` | | | Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`. |
|
|
77
|
+
| `description` | `<string, node>` | | | Provides a description for the title. |
|
|
78
|
+
| `onInfoButtonClick` | `func` | | | Function called when info button is pressed.
<br />
Info button will only be visible when this prop is passed.
<br />
Signature: `(event) => void` |
|
|
79
|
+
| `hintIcon` | `node` | | | Icon to be displayed beside the hint text.
<br />
Will only get rendered when `hint` is passed as well. |
|
|
80
|
+
| `badge` | `node` | | | Badge to be displayed beside the label.
<br />
Might be used to display additional information about the content of the field (E.g verified email) |
|
|
81
|
+
|
|
82
|
+
## `data-*` props
|
|
83
|
+
|
|
84
|
+
The component further forwards all `data-` attributes to the underlying `input` component.
|
|
85
|
+
|
|
86
|
+
## `errors`
|
|
87
|
+
|
|
88
|
+
This object is a key-value map. The `renderError` prop will be called for each entry with the key and the value. The return value will be rendered inside an `ErrorMessage` component underneath the input.
|
|
89
|
+
|
|
90
|
+
The `LocalizedTextField` supports some errors out of the box. Return `undefined` from `renderError` for these and the default errors will be shown instead. This prevents consumers from having to reimplement the same error messages for known errors while still keeping the flexibility of showing custom error messages for them.
|
|
91
|
+
|
|
92
|
+
When the `key` is known, and when the value is truthy, and when `renderError` returned `undefined` for that error entry, then the `LocalizedTextField` will render an appropriate error automatically.
|
|
93
|
+
|
|
94
|
+
Known error keys are:
|
|
95
|
+
|
|
96
|
+
- `missing`: tells the user that this field is required
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
6
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
10
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
12
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
13
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
14
|
+
var _taggedTemplateLiteral = require('@babel/runtime-corejs3/helpers/taggedTemplateLiteral');
|
|
15
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
16
|
+
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
17
|
+
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
18
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
19
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
20
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
21
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
22
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
23
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
24
|
+
var react = require('react');
|
|
25
|
+
var PropTypes = require('prop-types');
|
|
26
|
+
var requiredIf = require('react-required-if');
|
|
27
|
+
var commonTags = require('common-tags');
|
|
28
|
+
var utils = require('@commercetools-uikit/utils');
|
|
29
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
30
|
+
var Spacings = require('@commercetools-uikit/spacings');
|
|
31
|
+
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
32
|
+
var LocalizedTextInput = require('@commercetools-uikit/localized-text-input');
|
|
33
|
+
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
34
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
35
|
+
|
|
36
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
37
|
+
|
|
38
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
39
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
40
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
41
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
43
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
44
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
45
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
46
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
47
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
48
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
49
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
50
|
+
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
51
|
+
var requiredIf__default = /*#__PURE__*/_interopDefault(requiredIf);
|
|
52
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
53
|
+
var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
54
|
+
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
55
|
+
var LocalizedTextInput__default = /*#__PURE__*/_interopDefault(LocalizedTextInput);
|
|
56
|
+
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
57
|
+
|
|
58
|
+
var _templateObject;
|
|
59
|
+
|
|
60
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default['default'](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default['default'](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
61
|
+
|
|
62
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context5; _forEachInstanceProperty__default['default'](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
|
|
63
|
+
|
|
64
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
65
|
+
|
|
66
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default['default'](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
67
|
+
var sequentialId = utils.createSequentialId('localized-text-field-');
|
|
68
|
+
|
|
69
|
+
var hasErrors = function hasErrors(errors) {
|
|
70
|
+
var _context;
|
|
71
|
+
|
|
72
|
+
return errors && _someInstanceProperty__default['default'](_context = _Object$values__default['default'](errors)).call(_context, Boolean);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
76
|
+
_inherits(LocalizedTextField, _Component);
|
|
77
|
+
|
|
78
|
+
var _super = _createSuper(LocalizedTextField);
|
|
79
|
+
|
|
80
|
+
function LocalizedTextField() {
|
|
81
|
+
var _context2;
|
|
82
|
+
|
|
83
|
+
var _this;
|
|
84
|
+
|
|
85
|
+
_classCallCheck(this, LocalizedTextField);
|
|
86
|
+
|
|
87
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
88
|
+
args[_key] = arguments[_key];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
_this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context2 = [this]).call(_context2, args));
|
|
92
|
+
_this.state = {
|
|
93
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
94
|
+
// label to the input component.
|
|
95
|
+
id: _this.props.id
|
|
96
|
+
};
|
|
97
|
+
return _this;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_createClass(LocalizedTextField, [{
|
|
101
|
+
key: "render",
|
|
102
|
+
value: function render() {
|
|
103
|
+
var hasError = this.props.touched && hasErrors(this.props.errors);
|
|
104
|
+
return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
|
|
105
|
+
max: this.props.horizontalConstraint,
|
|
106
|
+
children: jsxRuntime.jsxs(Spacings__default['default'].Stack, {
|
|
107
|
+
scale: "xs",
|
|
108
|
+
children: [jsxRuntime.jsx(FieldLabel__default['default'], {
|
|
109
|
+
title: this.props.title,
|
|
110
|
+
hint: this.props.hint,
|
|
111
|
+
description: this.props.description,
|
|
112
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
113
|
+
hintIcon: this.props.hintIcon,
|
|
114
|
+
badge: this.props.badge,
|
|
115
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
116
|
+
htmlFor: this.state.id
|
|
117
|
+
}), jsxRuntime.jsx(LocalizedTextInput__default['default'], _objectSpread({
|
|
118
|
+
autoComplete: this.props.autoComplete,
|
|
119
|
+
id: this.state.id,
|
|
120
|
+
name: this.props.name,
|
|
121
|
+
value: this.props.value,
|
|
122
|
+
onChange: this.props.onChange,
|
|
123
|
+
selectedLanguage: this.props.selectedLanguage,
|
|
124
|
+
onBlur: this.props.onBlur,
|
|
125
|
+
onFocus: this.props.onFocus,
|
|
126
|
+
hideLanguageExpansionControls: this.props.hideLanguageExpansionControls,
|
|
127
|
+
defaultExpandLanguages: this.props.defaultExpandLanguages,
|
|
128
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
129
|
+
isDisabled: this.props.isDisabled,
|
|
130
|
+
isReadOnly: this.props.isReadOnly,
|
|
131
|
+
errors: this.props.errorsByLanguage,
|
|
132
|
+
hasError: hasError,
|
|
133
|
+
placeholder: this.props.placeholder,
|
|
134
|
+
horizontalConstraint: "scale"
|
|
135
|
+
}, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default['default'], {
|
|
136
|
+
errors: this.props.errors,
|
|
137
|
+
isVisible: hasError,
|
|
138
|
+
renderError: this.props.renderError
|
|
139
|
+
})]
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}]);
|
|
144
|
+
|
|
145
|
+
return LocalizedTextField;
|
|
146
|
+
}(react.Component);
|
|
147
|
+
|
|
148
|
+
LocalizedTextField.displayName = 'LocalizedTextField';
|
|
149
|
+
LocalizedTextField.defaultProps = {
|
|
150
|
+
horizontalConstraint: 'scale'
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
LocalizedTextField.getDerivedStateFromProps = function (props, state) {
|
|
154
|
+
return {
|
|
155
|
+
id: utils.getFieldId(props, state, sequentialId)
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
160
|
+
// LocalizedTextField
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Used as HTML id property. An id is auto-generated when it is not specified.
|
|
164
|
+
*/
|
|
165
|
+
id: PropTypes__default['default'].string,
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Horizontal size limit of the input fields.
|
|
169
|
+
*/
|
|
170
|
+
horizontalConstraint: PropTypes__default['default'].oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A map of errors. Error messages for known errors are rendered automatically.
|
|
174
|
+
* <br />
|
|
175
|
+
* Unknown errors will be forwarded to `renderError`
|
|
176
|
+
*/
|
|
177
|
+
errors: PropTypes__default['default'].shape({
|
|
178
|
+
missing: PropTypes__default['default'].bool
|
|
179
|
+
}),
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
|
|
183
|
+
* <br />
|
|
184
|
+
* Signature: `(key, error) => React.node`
|
|
185
|
+
*/
|
|
186
|
+
renderError: PropTypes__default['default'].func,
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Indicates if the value is required. Shows an the "required asterisk" if so.
|
|
190
|
+
*/
|
|
191
|
+
isRequired: PropTypes__default['default'].bool,
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Indicates whether the field was touched. Errors will only be shown when the field was touched.
|
|
195
|
+
*/
|
|
196
|
+
touched: PropTypes__default['default'].bool,
|
|
197
|
+
// LocalizedTextInput
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Used as HTML `autocomplete` of the input component. property
|
|
201
|
+
*/
|
|
202
|
+
autoComplete: PropTypes__default['default'].string,
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Used as HTML name of the input component. property
|
|
206
|
+
*/
|
|
207
|
+
name: PropTypes__default['default'].string,
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Values to use.
|
|
211
|
+
* <br />
|
|
212
|
+
Keyed by language, the values are the actual values, e.g. `{ en: 'Horse', de: 'Pferd' }`
|
|
213
|
+
*/
|
|
214
|
+
value: PropTypes__default['default'].objectOf(PropTypes__default['default'].string).isRequired,
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.
|
|
218
|
+
* <br />
|
|
219
|
+
* Signature: `(event) => void`
|
|
220
|
+
*/
|
|
221
|
+
onChange: requiredIf__default['default'](PropTypes__default['default'].func, function (props) {
|
|
222
|
+
return !props.isReadOnly;
|
|
223
|
+
}),
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Specifies which language will be shown in case the `LocalizedTextInput` is collapsed.
|
|
227
|
+
*/
|
|
228
|
+
selectedLanguage: PropTypes__default['default'].string.isRequired,
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Called when input is blurred
|
|
232
|
+
*/
|
|
233
|
+
onBlur: PropTypes__default['default'].func,
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Called when input is focused
|
|
237
|
+
*/
|
|
238
|
+
onFocus: PropTypes__default['default'].func,
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Will hide the language expansion controls when set to `true`. All languages will be shown when set to `true`.
|
|
242
|
+
*/
|
|
243
|
+
hideLanguageExpansionControls: PropTypes__default['default'].bool,
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Controls whether one or all languages are visible by default
|
|
247
|
+
*/
|
|
248
|
+
defaultExpandLanguages: function defaultExpandLanguages(props, propName, componentName) {
|
|
249
|
+
var _context3;
|
|
250
|
+
|
|
251
|
+
if (props.hideLanguageExpansionControls && typeof props[propName] === 'boolean') {
|
|
252
|
+
throw new Error(commonTags.oneLine(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ": \"", "\" does not have any effect when\n \"hideLanguageExpansionControls\" is set.\n "])), componentName, propName));
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (var _len2 = arguments.length, rest = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
256
|
+
rest[_key2 - 3] = arguments[_key2];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return PropTypes__default['default'].bool.apply(PropTypes__default['default'], _concatInstanceProperty__default['default'](_context3 = [props, propName, componentName]).call(_context3, rest));
|
|
260
|
+
},
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Focus the input on initial render
|
|
264
|
+
*/
|
|
265
|
+
isAutofocussed: PropTypes__default['default'].bool,
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
|
|
269
|
+
*/
|
|
270
|
+
isDisabled: PropTypes__default['default'].bool,
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Indicates that the field is displaying read-only content
|
|
274
|
+
*/
|
|
275
|
+
isReadOnly: PropTypes__default['default'].bool,
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Placeholders for each language. Object of the same shape as `value`.
|
|
279
|
+
*/
|
|
280
|
+
placeholder: PropTypes__default['default'].objectOf(PropTypes__default['default'].string),
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Errors for each translation. These are forwarded to the `errors` prop of `LocalizedTextInput`.
|
|
284
|
+
*/
|
|
285
|
+
errorsByLanguage: PropTypes__default['default'].objectOf(PropTypes__default['default'].node),
|
|
286
|
+
// LabelField
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Title of the label
|
|
290
|
+
*/
|
|
291
|
+
title: PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]).isRequired,
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`.
|
|
295
|
+
*/
|
|
296
|
+
hint: requiredIf__default['default'](PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]), function (props) {
|
|
297
|
+
return props.hintIcon;
|
|
298
|
+
}),
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Provides a description for the title.
|
|
302
|
+
*/
|
|
303
|
+
description: PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]),
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Function called when info button is pressed.
|
|
307
|
+
* <br />
|
|
308
|
+
* Info button will only be visible when this prop is passed.
|
|
309
|
+
* <br />
|
|
310
|
+
* Signature: `(event) => void`
|
|
311
|
+
*/
|
|
312
|
+
onInfoButtonClick: PropTypes__default['default'].func,
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Icon to be displayed beside the hint text.
|
|
316
|
+
* <br />
|
|
317
|
+
* Will only get rendered when `hint` is passed as well.
|
|
318
|
+
*/
|
|
319
|
+
hintIcon: PropTypes__default['default'].node,
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Badge to be displayed beside the label.
|
|
323
|
+
* <br />
|
|
324
|
+
* Might be used to display additional information about the content of the field (E.g verified email)
|
|
325
|
+
*/
|
|
326
|
+
badge: PropTypes__default['default'].node
|
|
327
|
+
} : {};
|
|
328
|
+
var LocalizedTextField$1 = LocalizedTextField;
|
|
329
|
+
|
|
330
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
331
|
+
var version = '0.0.0-canary-2021830134526';
|
|
332
|
+
|
|
333
|
+
exports['default'] = LocalizedTextField$1;
|
|
334
|
+
exports.version = version;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
6
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
7
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
8
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
9
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
10
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
11
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
12
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
13
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
14
|
+
require('@babel/runtime-corejs3/helpers/taggedTemplateLiteral');
|
|
15
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
16
|
+
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
17
|
+
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
18
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
19
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
20
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
21
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
22
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
23
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
24
|
+
var react = require('react');
|
|
25
|
+
require('prop-types');
|
|
26
|
+
require('react-required-if');
|
|
27
|
+
require('common-tags');
|
|
28
|
+
var utils = require('@commercetools-uikit/utils');
|
|
29
|
+
var Constraints = require('@commercetools-uikit/constraints');
|
|
30
|
+
var Spacings = require('@commercetools-uikit/spacings');
|
|
31
|
+
var FieldLabel = require('@commercetools-uikit/field-label');
|
|
32
|
+
var LocalizedTextInput = require('@commercetools-uikit/localized-text-input');
|
|
33
|
+
var FieldErrors = require('@commercetools-uikit/field-errors');
|
|
34
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
35
|
+
|
|
36
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
37
|
+
|
|
38
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
39
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
40
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
41
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
42
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
43
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
44
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
45
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
46
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
47
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
48
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
49
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
50
|
+
var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
|
|
51
|
+
var Spacings__default = /*#__PURE__*/_interopDefault(Spacings);
|
|
52
|
+
var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
|
|
53
|
+
var LocalizedTextInput__default = /*#__PURE__*/_interopDefault(LocalizedTextInput);
|
|
54
|
+
var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
|
|
55
|
+
|
|
56
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default['default'](object); if (_Object$getOwnPropertySymbols__default['default']) { var symbols = _Object$getOwnPropertySymbols__default['default'](object); if (enumerableOnly) { symbols = _filterInstanceProperty__default['default'](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default['default'](object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
57
|
+
|
|
58
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors__default['default']) { _Object$defineProperties__default['default'](target, _Object$getOwnPropertyDescriptors__default['default'](source)); } else { var _context5; _forEachInstanceProperty__default['default'](_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
|
|
59
|
+
|
|
60
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default['default'](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
61
|
+
|
|
62
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default['default']) return false; if (_Reflect$construct__default['default'].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default['default'](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
63
|
+
var sequentialId = utils.createSequentialId('localized-text-field-');
|
|
64
|
+
|
|
65
|
+
var hasErrors = function hasErrors(errors) {
|
|
66
|
+
var _context;
|
|
67
|
+
|
|
68
|
+
return errors && _someInstanceProperty__default['default'](_context = _Object$values__default['default'](errors)).call(_context, Boolean);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
72
|
+
_inherits(LocalizedTextField, _Component);
|
|
73
|
+
|
|
74
|
+
var _super = _createSuper(LocalizedTextField);
|
|
75
|
+
|
|
76
|
+
function LocalizedTextField() {
|
|
77
|
+
var _context2;
|
|
78
|
+
|
|
79
|
+
var _this;
|
|
80
|
+
|
|
81
|
+
_classCallCheck(this, LocalizedTextField);
|
|
82
|
+
|
|
83
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
84
|
+
args[_key] = arguments[_key];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
_this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context2 = [this]).call(_context2, args));
|
|
88
|
+
_this.state = {
|
|
89
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
90
|
+
// label to the input component.
|
|
91
|
+
id: _this.props.id
|
|
92
|
+
};
|
|
93
|
+
return _this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
_createClass(LocalizedTextField, [{
|
|
97
|
+
key: "render",
|
|
98
|
+
value: function render() {
|
|
99
|
+
var hasError = this.props.touched && hasErrors(this.props.errors);
|
|
100
|
+
return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
|
|
101
|
+
max: this.props.horizontalConstraint,
|
|
102
|
+
children: jsxRuntime.jsxs(Spacings__default['default'].Stack, {
|
|
103
|
+
scale: "xs",
|
|
104
|
+
children: [jsxRuntime.jsx(FieldLabel__default['default'], {
|
|
105
|
+
title: this.props.title,
|
|
106
|
+
hint: this.props.hint,
|
|
107
|
+
description: this.props.description,
|
|
108
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
109
|
+
hintIcon: this.props.hintIcon,
|
|
110
|
+
badge: this.props.badge,
|
|
111
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
112
|
+
htmlFor: this.state.id
|
|
113
|
+
}), jsxRuntime.jsx(LocalizedTextInput__default['default'], _objectSpread({
|
|
114
|
+
autoComplete: this.props.autoComplete,
|
|
115
|
+
id: this.state.id,
|
|
116
|
+
name: this.props.name,
|
|
117
|
+
value: this.props.value,
|
|
118
|
+
onChange: this.props.onChange,
|
|
119
|
+
selectedLanguage: this.props.selectedLanguage,
|
|
120
|
+
onBlur: this.props.onBlur,
|
|
121
|
+
onFocus: this.props.onFocus,
|
|
122
|
+
hideLanguageExpansionControls: this.props.hideLanguageExpansionControls,
|
|
123
|
+
defaultExpandLanguages: this.props.defaultExpandLanguages,
|
|
124
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
125
|
+
isDisabled: this.props.isDisabled,
|
|
126
|
+
isReadOnly: this.props.isReadOnly,
|
|
127
|
+
errors: this.props.errorsByLanguage,
|
|
128
|
+
hasError: hasError,
|
|
129
|
+
placeholder: this.props.placeholder,
|
|
130
|
+
horizontalConstraint: "scale"
|
|
131
|
+
}, utils.filterDataAttributes(this.props))), jsxRuntime.jsx(FieldErrors__default['default'], {
|
|
132
|
+
errors: this.props.errors,
|
|
133
|
+
isVisible: hasError,
|
|
134
|
+
renderError: this.props.renderError
|
|
135
|
+
})]
|
|
136
|
+
})
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}]);
|
|
140
|
+
|
|
141
|
+
return LocalizedTextField;
|
|
142
|
+
}(react.Component);
|
|
143
|
+
|
|
144
|
+
LocalizedTextField.displayName = 'LocalizedTextField';
|
|
145
|
+
LocalizedTextField.defaultProps = {
|
|
146
|
+
horizontalConstraint: 'scale'
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
LocalizedTextField.getDerivedStateFromProps = function (props, state) {
|
|
150
|
+
return {
|
|
151
|
+
id: utils.getFieldId(props, state, sequentialId)
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
LocalizedTextField.propTypes = {};
|
|
156
|
+
var LocalizedTextField$1 = LocalizedTextField;
|
|
157
|
+
|
|
158
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
159
|
+
var version = '0.0.0-canary-2021830134526';
|
|
160
|
+
|
|
161
|
+
exports['default'] = LocalizedTextField$1;
|
|
162
|
+
exports.version = version;
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import _Reflect$construct from '@babel/runtime-corejs3/core-js-stable/reflect/construct';
|
|
2
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
3
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
4
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
5
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
6
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
7
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
8
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
9
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
10
|
+
import _taggedTemplateLiteral from '@babel/runtime-corejs3/helpers/esm/taggedTemplateLiteral';
|
|
11
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
12
|
+
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
13
|
+
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
14
|
+
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
15
|
+
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
16
|
+
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
17
|
+
import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
|
|
18
|
+
import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
|
|
19
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
20
|
+
import { Component } from 'react';
|
|
21
|
+
import PropTypes from 'prop-types';
|
|
22
|
+
import requiredIf from 'react-required-if';
|
|
23
|
+
import { oneLine } from 'common-tags';
|
|
24
|
+
import { createSequentialId, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
|
|
25
|
+
import Constraints from '@commercetools-uikit/constraints';
|
|
26
|
+
import Spacings from '@commercetools-uikit/spacings';
|
|
27
|
+
import FieldLabel from '@commercetools-uikit/field-label';
|
|
28
|
+
import LocalizedTextInput from '@commercetools-uikit/localized-text-input';
|
|
29
|
+
import FieldErrors from '@commercetools-uikit/field-errors';
|
|
30
|
+
import { jsx, jsxs } from '@emotion/react/jsx-runtime';
|
|
31
|
+
|
|
32
|
+
var _templateObject;
|
|
33
|
+
|
|
34
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
+
|
|
36
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context5; _forEachInstanceProperty(_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
37
|
+
|
|
38
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
39
|
+
|
|
40
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
|
+
var sequentialId = createSequentialId('localized-text-field-');
|
|
42
|
+
|
|
43
|
+
var hasErrors = function hasErrors(errors) {
|
|
44
|
+
var _context;
|
|
45
|
+
|
|
46
|
+
return errors && _someInstanceProperty(_context = _Object$values(errors)).call(_context, Boolean);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var LocalizedTextField = /*#__PURE__*/function (_Component) {
|
|
50
|
+
_inherits(LocalizedTextField, _Component);
|
|
51
|
+
|
|
52
|
+
var _super = _createSuper(LocalizedTextField);
|
|
53
|
+
|
|
54
|
+
function LocalizedTextField() {
|
|
55
|
+
var _context2;
|
|
56
|
+
|
|
57
|
+
var _this;
|
|
58
|
+
|
|
59
|
+
_classCallCheck(this, LocalizedTextField);
|
|
60
|
+
|
|
61
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
62
|
+
args[_key] = arguments[_key];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
_this = _super.call.apply(_super, _concatInstanceProperty(_context2 = [this]).call(_context2, args));
|
|
66
|
+
_this.state = {
|
|
67
|
+
// We generate an id in case no id is provided by the parent to attach the
|
|
68
|
+
// label to the input component.
|
|
69
|
+
id: _this.props.id
|
|
70
|
+
};
|
|
71
|
+
return _this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_createClass(LocalizedTextField, [{
|
|
75
|
+
key: "render",
|
|
76
|
+
value: function render() {
|
|
77
|
+
var hasError = this.props.touched && hasErrors(this.props.errors);
|
|
78
|
+
return jsx(Constraints.Horizontal, {
|
|
79
|
+
max: this.props.horizontalConstraint,
|
|
80
|
+
children: jsxs(Spacings.Stack, {
|
|
81
|
+
scale: "xs",
|
|
82
|
+
children: [jsx(FieldLabel, {
|
|
83
|
+
title: this.props.title,
|
|
84
|
+
hint: this.props.hint,
|
|
85
|
+
description: this.props.description,
|
|
86
|
+
onInfoButtonClick: this.props.onInfoButtonClick,
|
|
87
|
+
hintIcon: this.props.hintIcon,
|
|
88
|
+
badge: this.props.badge,
|
|
89
|
+
hasRequiredIndicator: this.props.isRequired,
|
|
90
|
+
htmlFor: this.state.id
|
|
91
|
+
}), jsx(LocalizedTextInput, _objectSpread({
|
|
92
|
+
autoComplete: this.props.autoComplete,
|
|
93
|
+
id: this.state.id,
|
|
94
|
+
name: this.props.name,
|
|
95
|
+
value: this.props.value,
|
|
96
|
+
onChange: this.props.onChange,
|
|
97
|
+
selectedLanguage: this.props.selectedLanguage,
|
|
98
|
+
onBlur: this.props.onBlur,
|
|
99
|
+
onFocus: this.props.onFocus,
|
|
100
|
+
hideLanguageExpansionControls: this.props.hideLanguageExpansionControls,
|
|
101
|
+
defaultExpandLanguages: this.props.defaultExpandLanguages,
|
|
102
|
+
isAutofocussed: this.props.isAutofocussed,
|
|
103
|
+
isDisabled: this.props.isDisabled,
|
|
104
|
+
isReadOnly: this.props.isReadOnly,
|
|
105
|
+
errors: this.props.errorsByLanguage,
|
|
106
|
+
hasError: hasError,
|
|
107
|
+
placeholder: this.props.placeholder,
|
|
108
|
+
horizontalConstraint: "scale"
|
|
109
|
+
}, filterDataAttributes(this.props))), jsx(FieldErrors, {
|
|
110
|
+
errors: this.props.errors,
|
|
111
|
+
isVisible: hasError,
|
|
112
|
+
renderError: this.props.renderError
|
|
113
|
+
})]
|
|
114
|
+
})
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
}]);
|
|
118
|
+
|
|
119
|
+
return LocalizedTextField;
|
|
120
|
+
}(Component);
|
|
121
|
+
|
|
122
|
+
LocalizedTextField.displayName = 'LocalizedTextField';
|
|
123
|
+
LocalizedTextField.defaultProps = {
|
|
124
|
+
horizontalConstraint: 'scale'
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
LocalizedTextField.getDerivedStateFromProps = function (props, state) {
|
|
128
|
+
return {
|
|
129
|
+
id: getFieldId(props, state, sequentialId)
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
LocalizedTextField.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
134
|
+
// LocalizedTextField
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Used as HTML id property. An id is auto-generated when it is not specified.
|
|
138
|
+
*/
|
|
139
|
+
id: PropTypes.string,
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Horizontal size limit of the input fields.
|
|
143
|
+
*/
|
|
144
|
+
horizontalConstraint: PropTypes.oneOf([6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* A map of errors. Error messages for known errors are rendered automatically.
|
|
148
|
+
* <br />
|
|
149
|
+
* Unknown errors will be forwarded to `renderError`
|
|
150
|
+
*/
|
|
151
|
+
errors: PropTypes.shape({
|
|
152
|
+
missing: PropTypes.bool
|
|
153
|
+
}),
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Called with custom errors. This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
|
|
157
|
+
* <br />
|
|
158
|
+
* Signature: `(key, error) => React.node`
|
|
159
|
+
*/
|
|
160
|
+
renderError: PropTypes.func,
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Indicates if the value is required. Shows an the "required asterisk" if so.
|
|
164
|
+
*/
|
|
165
|
+
isRequired: PropTypes.bool,
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Indicates whether the field was touched. Errors will only be shown when the field was touched.
|
|
169
|
+
*/
|
|
170
|
+
touched: PropTypes.bool,
|
|
171
|
+
// LocalizedTextInput
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Used as HTML `autocomplete` of the input component. property
|
|
175
|
+
*/
|
|
176
|
+
autoComplete: PropTypes.string,
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Used as HTML name of the input component. property
|
|
180
|
+
*/
|
|
181
|
+
name: PropTypes.string,
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Values to use.
|
|
185
|
+
* <br />
|
|
186
|
+
Keyed by language, the values are the actual values, e.g. `{ en: 'Horse', de: 'Pferd' }`
|
|
187
|
+
*/
|
|
188
|
+
value: PropTypes.objectOf(PropTypes.string).isRequired,
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.
|
|
192
|
+
* <br />
|
|
193
|
+
* Signature: `(event) => void`
|
|
194
|
+
*/
|
|
195
|
+
onChange: requiredIf(PropTypes.func, function (props) {
|
|
196
|
+
return !props.isReadOnly;
|
|
197
|
+
}),
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Specifies which language will be shown in case the `LocalizedTextInput` is collapsed.
|
|
201
|
+
*/
|
|
202
|
+
selectedLanguage: PropTypes.string.isRequired,
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Called when input is blurred
|
|
206
|
+
*/
|
|
207
|
+
onBlur: PropTypes.func,
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Called when input is focused
|
|
211
|
+
*/
|
|
212
|
+
onFocus: PropTypes.func,
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Will hide the language expansion controls when set to `true`. All languages will be shown when set to `true`.
|
|
216
|
+
*/
|
|
217
|
+
hideLanguageExpansionControls: PropTypes.bool,
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Controls whether one or all languages are visible by default
|
|
221
|
+
*/
|
|
222
|
+
defaultExpandLanguages: function defaultExpandLanguages(props, propName, componentName) {
|
|
223
|
+
var _context3;
|
|
224
|
+
|
|
225
|
+
if (props.hideLanguageExpansionControls && typeof props[propName] === 'boolean') {
|
|
226
|
+
throw new Error(oneLine(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", ": \"", "\" does not have any effect when\n \"hideLanguageExpansionControls\" is set.\n "])), componentName, propName));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
for (var _len2 = arguments.length, rest = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
230
|
+
rest[_key2 - 3] = arguments[_key2];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return PropTypes.bool.apply(PropTypes, _concatInstanceProperty(_context3 = [props, propName, componentName]).call(_context3, rest));
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Focus the input on initial render
|
|
238
|
+
*/
|
|
239
|
+
isAutofocussed: PropTypes.bool,
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
|
|
243
|
+
*/
|
|
244
|
+
isDisabled: PropTypes.bool,
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Indicates that the field is displaying read-only content
|
|
248
|
+
*/
|
|
249
|
+
isReadOnly: PropTypes.bool,
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Placeholders for each language. Object of the same shape as `value`.
|
|
253
|
+
*/
|
|
254
|
+
placeholder: PropTypes.objectOf(PropTypes.string),
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Errors for each translation. These are forwarded to the `errors` prop of `LocalizedTextInput`.
|
|
258
|
+
*/
|
|
259
|
+
errorsByLanguage: PropTypes.objectOf(PropTypes.node),
|
|
260
|
+
// LabelField
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Title of the label
|
|
264
|
+
*/
|
|
265
|
+
title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Hint for the label. Provides a supplementary but important information regarding the behaviour of the input (e.g warn about uniqueness of a field, when it can only be set once), whereas `description` can describe it in more depth. Can also receive a `hintIcon`.
|
|
269
|
+
*/
|
|
270
|
+
hint: requiredIf(PropTypes.oneOfType([PropTypes.string, PropTypes.node]), function (props) {
|
|
271
|
+
return props.hintIcon;
|
|
272
|
+
}),
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Provides a description for the title.
|
|
276
|
+
*/
|
|
277
|
+
description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Function called when info button is pressed.
|
|
281
|
+
* <br />
|
|
282
|
+
* Info button will only be visible when this prop is passed.
|
|
283
|
+
* <br />
|
|
284
|
+
* Signature: `(event) => void`
|
|
285
|
+
*/
|
|
286
|
+
onInfoButtonClick: PropTypes.func,
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Icon to be displayed beside the hint text.
|
|
290
|
+
* <br />
|
|
291
|
+
* Will only get rendered when `hint` is passed as well.
|
|
292
|
+
*/
|
|
293
|
+
hintIcon: PropTypes.node,
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Badge to be displayed beside the label.
|
|
297
|
+
* <br />
|
|
298
|
+
* Might be used to display additional information about the content of the field (E.g verified email)
|
|
299
|
+
*/
|
|
300
|
+
badge: PropTypes.node
|
|
301
|
+
} : {};
|
|
302
|
+
var LocalizedTextField$1 = LocalizedTextField;
|
|
303
|
+
|
|
304
|
+
// NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
|
|
305
|
+
var version = '0.0.0-canary-2021830134526';
|
|
306
|
+
|
|
307
|
+
export { LocalizedTextField$1 as default, version };
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@commercetools-uikit/localized-text-field",
|
|
3
|
+
"description": "A controlled text input component for localized single-line strings with validation states.",
|
|
4
|
+
"version": "0.0.0-canary-2021830134526",
|
|
5
|
+
"bugs": "https://github.com/commercetools/ui-kit/issues",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/commercetools/ui-kit.git",
|
|
9
|
+
"directory": "packages/components/fields/localized-text-field"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://uikit.commercetools.com",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"javascript",
|
|
14
|
+
"design system",
|
|
15
|
+
"react",
|
|
16
|
+
"uikit"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"private": false,
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"main": "dist/commercetools-uikit-localized-text-field.cjs.js",
|
|
25
|
+
"module": "dist/commercetools-uikit-localized-text-field.esm.js",
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"prepare": "../../../../scripts/version.js replace"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@babel/runtime": "7.14.8",
|
|
34
|
+
"@babel/runtime-corejs3": "7.14.9",
|
|
35
|
+
"@commercetools-uikit/constraints": "0.0.0-canary-2021830134526",
|
|
36
|
+
"@commercetools-uikit/design-system": "0.0.0-canary-2021830134526",
|
|
37
|
+
"@commercetools-uikit/field-errors": "0.0.0-canary-2021830134526",
|
|
38
|
+
"@commercetools-uikit/field-label": "0.0.0-canary-2021830134526",
|
|
39
|
+
"@commercetools-uikit/localized-text-input": "0.0.0-canary-2021830134526",
|
|
40
|
+
"@commercetools-uikit/spacings": "0.0.0-canary-2021830134526",
|
|
41
|
+
"@commercetools-uikit/utils": "12.2.0",
|
|
42
|
+
"@emotion/react": "^11.4.0",
|
|
43
|
+
"@emotion/styled": "^11.3.0",
|
|
44
|
+
"common-tags": "1.8.0",
|
|
45
|
+
"prop-types": "15.7.2",
|
|
46
|
+
"react-required-if": "1.0.3"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"react": "17.0.2"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": "17.x"
|
|
53
|
+
}
|
|
54
|
+
}
|