@commercetools-uikit/radio-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 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,101 @@
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
+ # RadioField
5
+
6
+ ## Description
7
+
8
+ A controlled radio input component with validation states and a label.
9
+
10
+ ## Installation
11
+
12
+ ```
13
+ yarn add @commercetools-uikit/radio-field
14
+ ```
15
+
16
+ ```
17
+ npm --save install @commercetools-uikit/radio-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 RadioField from '@commercetools-uikit/radio-field';
34
+ import RadioInput from '@commercetools-uikit/radio-input';
35
+
36
+ const Example = () => (
37
+ <RadioField
38
+ title="Fruits"
39
+ name="fruits"
40
+ value="apple"
41
+ onChange={(event) => alert(event.target.value)}
42
+ >
43
+ <RadioInput.Option value="apple">{'Apple'}</RadioInput.Option>
44
+ <RadioInput.Option value="banana">{'Banana'}</RadioInput.Option>
45
+ </RadioField>
46
+ );
47
+
48
+ export default Example;
49
+ ```
50
+
51
+ ## Properties
52
+
53
+ | Props | Type | Required | Default | Description |
54
+ | ---------------------- | -------------------------------------------------------------------------------------- | :------: | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55
+ | `id` | `string` | | | Used as HTML id property. An id is auto-generated when it is not specified. |
56
+ | `horizontalConstraint` | `enum`<br/>Possible values:<br/>`7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto'` | | `'scale'` | Horizontal size limit of the input fields. |
57
+ | `errors` | `object` | | | A map of errors. Error messages for known errors are rendered automatically. Unknown errors will be forwarded to `renderError`. |
58
+ | `errors.missing` | `bool` | | | |
59
+ | `renderError` | `func` | | | Called with custom errors.&#xA;<br/>&#xA;This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.&#xA;<br/>&#xA;Signature: `(key, error) => React.node` |
60
+ | `isRequired` | `bool` | | | Indicates if the value is required. Shows an the "required asterisk" if so. |
61
+ | `touched` | `bool` | | | Indicates whether the field was touched. Errors will only be shown when the field was touched. |
62
+ | `name` | `string` | | | Used as HTML name of the input component. |
63
+ | `value` | `string` | ✅ | | Value of the input component. |
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.&#xA;<br />&#xA;Signature: `(event) => void` |
65
+ | `onBlur` | `func` | | | Called when input is blurred&#xA;<br />&#xA;Signature: `(event) => void` |
66
+ | `onFocus` | `func` | | | Called when input is focused&#xA;<br />&#xA;Signature: `(event) => void` |
67
+ | `isDisabled` | `bool` | | | Indicates that the input cannot be modified (e.g not authorized, or changes currently saving). |
68
+ | `isReadOnly` | `bool` | | | Indicates that the field is displaying read-only content |
69
+ | `direction` | `enum`<br/>Possible values:<br/>`'stack', 'inline'` | | | Rendering direction of the radio `RadioInput.Option`s |
70
+ | `directionProps` | `object` | | | Passes props of the `Spacings.Stack` or `Spacings.Inline`, dependeing on the chosen direction |
71
+ | `children` | `node` | ✅ | | At least one `RadioInput.Option` component or another node (mixed children are allowed) |
72
+ | `title` | `<string, node>` | ✅ | | Title of the label |
73
+ | `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.&#xA;<br />&#xA;Can also receive a `hintIcon`. |
74
+ | `description` | `<string, node>` | | | Provides a description for the title. |
75
+ | `onInfoButtonClick` | `func` | | | Function called when info button is pressed.&#xA;<br />&#xA;Info button will only be visible when this prop is passed.&#xA;<br />&#xA;Signature: `(event) => void` |
76
+ | `hintIcon` | `node` | | | Icon to be displayed beside the hint text.&#xA;<br />&#xA;Will only get rendered when `hint` is passed as well. |
77
+ | `badge` | `node` | | | Badge to be displayed beside the label.&#xA;<br />&#xA;Might be used to display additional information about the content of the field (E.g verified email) |
78
+
79
+ ## `data-*` props
80
+
81
+ The component further forwards all `data-` attributes to the underlying `RadioInput` component.
82
+
83
+ ### RadioInput.Option
84
+
85
+ See `RadioInput` README for the list of props.
86
+
87
+ ## `errors`
88
+
89
+ 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.
90
+
91
+ The `RadioField` 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.
92
+
93
+ When the `key` is known, and when the value is truthy, and when `renderError` returned `undefined` for that error entry, then the `RadioField` will render an appropriate error automatically.
94
+
95
+ Known error keys are:
96
+
97
+ - `missing`: tells the user that this field is required
98
+
99
+ ## Main Functions and use cases are:
100
+
101
+ - Single option selection field in login forms
@@ -0,0 +1,299 @@
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 _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
15
+ var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
16
+ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
17
+ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
18
+ var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
19
+ var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
20
+ var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
21
+ var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
22
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
23
+ var react = require('react');
24
+ var PropTypes = require('prop-types');
25
+ var requiredIf = require('react-required-if');
26
+ var utils = require('@commercetools-uikit/utils');
27
+ var Constraints = require('@commercetools-uikit/constraints');
28
+ var Stack = require('@commercetools-uikit/spacings-stack');
29
+ var FieldLabel = require('@commercetools-uikit/field-label');
30
+ var FieldErrors = require('@commercetools-uikit/field-errors');
31
+ var RadioInput = require('@commercetools-uikit/radio-input');
32
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
33
+
34
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
35
+
36
+ var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
37
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
38
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
39
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
40
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
41
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
42
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
43
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
44
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
45
+ var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
46
+ var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
47
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
48
+ var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
49
+ var requiredIf__default = /*#__PURE__*/_interopDefault(requiredIf);
50
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
51
+ var Stack__default = /*#__PURE__*/_interopDefault(Stack);
52
+ var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
53
+ var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
54
+ var RadioInput__default = /*#__PURE__*/_interopDefault(RadioInput);
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 _context3; _forEachInstanceProperty__default['default'](_context3 = ownKeys(Object(source), true)).call(_context3, 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 _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys(Object(source))).call(_context4, 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('radio-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 RadioField = /*#__PURE__*/function (_Component) {
72
+ _inherits(RadioField, _Component);
73
+
74
+ var _super = _createSuper(RadioField);
75
+
76
+ function RadioField() {
77
+ var _context2;
78
+
79
+ var _this;
80
+
81
+ _classCallCheck(this, RadioField);
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(RadioField, [{
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(Stack__default['default'], {
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
+ id: this.state.id
113
+ }), jsxRuntime.jsx(RadioInput__default['default'].Group, _objectSpread(_objectSpread({
114
+ id: this.state.id,
115
+ name: this.props.name,
116
+ value: this.props.value,
117
+ onChange: this.props.onChange,
118
+ onBlur: this.props.onBlur,
119
+ onFocus: this.props.onFocus,
120
+ isDisabled: this.props.isDisabled,
121
+ isReadOnly: this.props.isReadOnly,
122
+ hasError: hasError,
123
+ horizontalConstraint: this.props.horizontalConstraint,
124
+ direction: this.props.direction,
125
+ directionProps: this.props.directionProps
126
+ }, utils.filterDataAttributes(this.props)), {}, {
127
+ children: this.props.children
128
+ })), jsxRuntime.jsx(FieldErrors__default['default'], {
129
+ errors: this.props.errors,
130
+ isVisible: hasError,
131
+ renderError: this.props.renderError
132
+ })]
133
+ })
134
+ });
135
+ }
136
+ }]);
137
+
138
+ return RadioField;
139
+ }(react.Component);
140
+
141
+ RadioField.displayName = 'RadioField';
142
+ RadioField.defaultProps = {
143
+ horizontalConstraint: 'scale'
144
+ };
145
+
146
+ RadioField.getDerivedStateFromProps = function (props, state) {
147
+ return {
148
+ id: utils.getFieldId(props, state, sequentialId)
149
+ };
150
+ };
151
+
152
+ RadioField.propTypes = process.env.NODE_ENV !== "production" ? {
153
+ // RadioField
154
+
155
+ /**
156
+ * Used as HTML id property. An id is auto-generated when it is not specified.
157
+ */
158
+ id: PropTypes__default['default'].string,
159
+
160
+ /**
161
+ * Horizontal size limit of the input fields.
162
+ */
163
+ horizontalConstraint: PropTypes__default['default'].oneOf([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
164
+
165
+ /**
166
+ * A map of errors. Error messages for known errors are rendered automatically. Unknown errors will be forwarded to `renderError`.
167
+ */
168
+ errors: PropTypes__default['default'].shape({
169
+ missing: PropTypes__default['default'].bool
170
+ }),
171
+
172
+ /**
173
+ * Called with custom errors.
174
+ * <br/>
175
+ * This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
176
+ * <br/>
177
+ * Signature: `(key, error) => React.node`
178
+ */
179
+ renderError: PropTypes__default['default'].func,
180
+
181
+ /**
182
+ * Indicates if the value is required. Shows an the "required asterisk" if so.
183
+ */
184
+ isRequired: PropTypes__default['default'].bool,
185
+
186
+ /**
187
+ * Indicates whether the field was touched. Errors will only be shown when the field was touched.
188
+ */
189
+ touched: PropTypes__default['default'].bool,
190
+ // RadioInput
191
+
192
+ /**
193
+ * Used as HTML name of the input component.
194
+ */
195
+ name: PropTypes__default['default'].string,
196
+
197
+ /**
198
+ * Value of the input component.
199
+ */
200
+ value: PropTypes__default['default'].string.isRequired,
201
+
202
+ /**
203
+ * Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.
204
+ * <br />
205
+ * Signature: `(event) => void`
206
+ */
207
+ onChange: requiredIf__default['default'](PropTypes__default['default'].func, function (props) {
208
+ return !props.isReadOnly;
209
+ }),
210
+
211
+ /**
212
+ * Called when input is blurred
213
+ * <br />
214
+ * Signature: `(event) => void`
215
+ */
216
+ onBlur: PropTypes__default['default'].func,
217
+
218
+ /**
219
+ * Called when input is focused
220
+ * <br />
221
+ * Signature: `(event) => void`
222
+ */
223
+ onFocus: PropTypes__default['default'].func,
224
+
225
+ /**
226
+ * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
227
+ */
228
+ isDisabled: PropTypes__default['default'].bool,
229
+
230
+ /**
231
+ * Indicates that the field is displaying read-only content
232
+ */
233
+ isReadOnly: PropTypes__default['default'].bool,
234
+
235
+ /**
236
+ * Rendering direction of the radio `RadioInput.Option`s
237
+ */
238
+ direction: PropTypes__default['default'].oneOf(['stack', 'inline']),
239
+
240
+ /**
241
+ * Passes props of the `Spacings.Stack` or `Spacings.Inline`, dependeing on the chosen direction
242
+ */
243
+ directionProps: PropTypes__default['default'].object,
244
+
245
+ /**
246
+ * At least one `RadioInput.Option` component or another node (mixed children are allowed)
247
+ */
248
+ children: PropTypes__default['default'].node.isRequired,
249
+ // LabelField
250
+
251
+ /**
252
+ * Title of the label
253
+ */
254
+ title: PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]).isRequired,
255
+
256
+ /**
257
+ * 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.
258
+ * <br />
259
+ * Can also receive a `hintIcon`.
260
+ */
261
+ hint: requiredIf__default['default'](PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]), function (props) {
262
+ return props.hintIcon;
263
+ }),
264
+
265
+ /**
266
+ * Provides a description for the title.
267
+ */
268
+ description: PropTypes__default['default'].oneOfType([PropTypes__default['default'].string, PropTypes__default['default'].node]),
269
+
270
+ /**
271
+ * Function called when info button is pressed.
272
+ * <br />
273
+ * Info button will only be visible when this prop is passed.
274
+ * <br />
275
+ * Signature: `(event) => void`
276
+ */
277
+ onInfoButtonClick: PropTypes__default['default'].func,
278
+
279
+ /**
280
+ * Icon to be displayed beside the hint text.
281
+ * <br />
282
+ * Will only get rendered when `hint` is passed as well.
283
+ */
284
+ hintIcon: PropTypes__default['default'].node,
285
+
286
+ /**
287
+ * Badge to be displayed beside the label.
288
+ * <br />
289
+ * Might be used to display additional information about the content of the field (E.g verified email)
290
+ */
291
+ badge: PropTypes__default['default'].node
292
+ } : {};
293
+ var RadioField$1 = RadioField;
294
+
295
+ // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
296
+ var version = '0.0.0-canary-2021830134526';
297
+
298
+ exports['default'] = RadioField$1;
299
+ exports.version = version;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-uikit-radio-field.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-uikit-radio-field.cjs.dev.js");
7
+ }
@@ -0,0 +1,157 @@
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 _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
15
+ var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
16
+ var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
17
+ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
18
+ var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
19
+ var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
20
+ var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
21
+ var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
22
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
23
+ var react = require('react');
24
+ require('prop-types');
25
+ require('react-required-if');
26
+ var utils = require('@commercetools-uikit/utils');
27
+ var Constraints = require('@commercetools-uikit/constraints');
28
+ var Stack = require('@commercetools-uikit/spacings-stack');
29
+ var FieldLabel = require('@commercetools-uikit/field-label');
30
+ var FieldErrors = require('@commercetools-uikit/field-errors');
31
+ var RadioInput = require('@commercetools-uikit/radio-input');
32
+ var jsxRuntime = require('@emotion/react/jsx-runtime');
33
+
34
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
35
+
36
+ var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
37
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
38
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
39
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
40
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
41
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
42
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
43
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
44
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
45
+ var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
46
+ var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
47
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
48
+ var Constraints__default = /*#__PURE__*/_interopDefault(Constraints);
49
+ var Stack__default = /*#__PURE__*/_interopDefault(Stack);
50
+ var FieldLabel__default = /*#__PURE__*/_interopDefault(FieldLabel);
51
+ var FieldErrors__default = /*#__PURE__*/_interopDefault(FieldErrors);
52
+ var RadioInput__default = /*#__PURE__*/_interopDefault(RadioInput);
53
+
54
+ 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; }
55
+
56
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty__default['default'](_context3 = ownKeys(Object(source), true)).call(_context3, 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 _context4; _forEachInstanceProperty__default['default'](_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty__default['default'](target, key, _Object$getOwnPropertyDescriptor__default['default'](source, key)); }); } } return target; }
57
+
58
+ 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); }; }
59
+
60
+ 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; } }
61
+ var sequentialId = utils.createSequentialId('radio-field-');
62
+
63
+ var hasErrors = function hasErrors(errors) {
64
+ var _context;
65
+
66
+ return errors && _someInstanceProperty__default['default'](_context = _Object$values__default['default'](errors)).call(_context, Boolean);
67
+ };
68
+
69
+ var RadioField = /*#__PURE__*/function (_Component) {
70
+ _inherits(RadioField, _Component);
71
+
72
+ var _super = _createSuper(RadioField);
73
+
74
+ function RadioField() {
75
+ var _context2;
76
+
77
+ var _this;
78
+
79
+ _classCallCheck(this, RadioField);
80
+
81
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
82
+ args[_key] = arguments[_key];
83
+ }
84
+
85
+ _this = _super.call.apply(_super, _concatInstanceProperty__default['default'](_context2 = [this]).call(_context2, args));
86
+ _this.state = {
87
+ // We generate an id in case no id is provided by the parent to attach the
88
+ // label to the input component.
89
+ id: _this.props.id
90
+ };
91
+ return _this;
92
+ }
93
+
94
+ _createClass(RadioField, [{
95
+ key: "render",
96
+ value: function render() {
97
+ var hasError = this.props.touched && hasErrors(this.props.errors);
98
+ return jsxRuntime.jsx(Constraints__default['default'].Horizontal, {
99
+ max: this.props.horizontalConstraint,
100
+ children: jsxRuntime.jsxs(Stack__default['default'], {
101
+ scale: "xs",
102
+ children: [jsxRuntime.jsx(FieldLabel__default['default'], {
103
+ title: this.props.title,
104
+ hint: this.props.hint,
105
+ description: this.props.description,
106
+ onInfoButtonClick: this.props.onInfoButtonClick,
107
+ hintIcon: this.props.hintIcon,
108
+ badge: this.props.badge,
109
+ hasRequiredIndicator: this.props.isRequired,
110
+ id: this.state.id
111
+ }), jsxRuntime.jsx(RadioInput__default['default'].Group, _objectSpread(_objectSpread({
112
+ id: this.state.id,
113
+ name: this.props.name,
114
+ value: this.props.value,
115
+ onChange: this.props.onChange,
116
+ onBlur: this.props.onBlur,
117
+ onFocus: this.props.onFocus,
118
+ isDisabled: this.props.isDisabled,
119
+ isReadOnly: this.props.isReadOnly,
120
+ hasError: hasError,
121
+ horizontalConstraint: this.props.horizontalConstraint,
122
+ direction: this.props.direction,
123
+ directionProps: this.props.directionProps
124
+ }, utils.filterDataAttributes(this.props)), {}, {
125
+ children: this.props.children
126
+ })), jsxRuntime.jsx(FieldErrors__default['default'], {
127
+ errors: this.props.errors,
128
+ isVisible: hasError,
129
+ renderError: this.props.renderError
130
+ })]
131
+ })
132
+ });
133
+ }
134
+ }]);
135
+
136
+ return RadioField;
137
+ }(react.Component);
138
+
139
+ RadioField.displayName = 'RadioField';
140
+ RadioField.defaultProps = {
141
+ horizontalConstraint: 'scale'
142
+ };
143
+
144
+ RadioField.getDerivedStateFromProps = function (props, state) {
145
+ return {
146
+ id: utils.getFieldId(props, state, sequentialId)
147
+ };
148
+ };
149
+
150
+ RadioField.propTypes = {};
151
+ var RadioField$1 = RadioField;
152
+
153
+ // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
154
+ var version = '0.0.0-canary-2021830134526';
155
+
156
+ exports['default'] = RadioField$1;
157
+ exports.version = version;
@@ -0,0 +1,272 @@
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 _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
11
+ import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
12
+ import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
13
+ import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
14
+ import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
15
+ import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
16
+ import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
17
+ import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
18
+ import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
19
+ import { Component } from 'react';
20
+ import PropTypes from 'prop-types';
21
+ import requiredIf from 'react-required-if';
22
+ import { createSequentialId, filterDataAttributes, getFieldId } from '@commercetools-uikit/utils';
23
+ import Constraints from '@commercetools-uikit/constraints';
24
+ import Stack from '@commercetools-uikit/spacings-stack';
25
+ import FieldLabel from '@commercetools-uikit/field-label';
26
+ import FieldErrors from '@commercetools-uikit/field-errors';
27
+ import RadioInput from '@commercetools-uikit/radio-input';
28
+ import { jsx, jsxs } from '@emotion/react/jsx-runtime';
29
+
30
+ 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; }
31
+
32
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
33
+
34
+ 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); }; }
35
+
36
+ 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; } }
37
+ var sequentialId = createSequentialId('radio-field-');
38
+
39
+ var hasErrors = function hasErrors(errors) {
40
+ var _context;
41
+
42
+ return errors && _someInstanceProperty(_context = _Object$values(errors)).call(_context, Boolean);
43
+ };
44
+
45
+ var RadioField = /*#__PURE__*/function (_Component) {
46
+ _inherits(RadioField, _Component);
47
+
48
+ var _super = _createSuper(RadioField);
49
+
50
+ function RadioField() {
51
+ var _context2;
52
+
53
+ var _this;
54
+
55
+ _classCallCheck(this, RadioField);
56
+
57
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
58
+ args[_key] = arguments[_key];
59
+ }
60
+
61
+ _this = _super.call.apply(_super, _concatInstanceProperty(_context2 = [this]).call(_context2, args));
62
+ _this.state = {
63
+ // We generate an id in case no id is provided by the parent to attach the
64
+ // label to the input component.
65
+ id: _this.props.id
66
+ };
67
+ return _this;
68
+ }
69
+
70
+ _createClass(RadioField, [{
71
+ key: "render",
72
+ value: function render() {
73
+ var hasError = this.props.touched && hasErrors(this.props.errors);
74
+ return jsx(Constraints.Horizontal, {
75
+ max: this.props.horizontalConstraint,
76
+ children: jsxs(Stack, {
77
+ scale: "xs",
78
+ children: [jsx(FieldLabel, {
79
+ title: this.props.title,
80
+ hint: this.props.hint,
81
+ description: this.props.description,
82
+ onInfoButtonClick: this.props.onInfoButtonClick,
83
+ hintIcon: this.props.hintIcon,
84
+ badge: this.props.badge,
85
+ hasRequiredIndicator: this.props.isRequired,
86
+ id: this.state.id
87
+ }), jsx(RadioInput.Group, _objectSpread(_objectSpread({
88
+ id: this.state.id,
89
+ name: this.props.name,
90
+ value: this.props.value,
91
+ onChange: this.props.onChange,
92
+ onBlur: this.props.onBlur,
93
+ onFocus: this.props.onFocus,
94
+ isDisabled: this.props.isDisabled,
95
+ isReadOnly: this.props.isReadOnly,
96
+ hasError: hasError,
97
+ horizontalConstraint: this.props.horizontalConstraint,
98
+ direction: this.props.direction,
99
+ directionProps: this.props.directionProps
100
+ }, filterDataAttributes(this.props)), {}, {
101
+ children: this.props.children
102
+ })), jsx(FieldErrors, {
103
+ errors: this.props.errors,
104
+ isVisible: hasError,
105
+ renderError: this.props.renderError
106
+ })]
107
+ })
108
+ });
109
+ }
110
+ }]);
111
+
112
+ return RadioField;
113
+ }(Component);
114
+
115
+ RadioField.displayName = 'RadioField';
116
+ RadioField.defaultProps = {
117
+ horizontalConstraint: 'scale'
118
+ };
119
+
120
+ RadioField.getDerivedStateFromProps = function (props, state) {
121
+ return {
122
+ id: getFieldId(props, state, sequentialId)
123
+ };
124
+ };
125
+
126
+ RadioField.propTypes = process.env.NODE_ENV !== "production" ? {
127
+ // RadioField
128
+
129
+ /**
130
+ * Used as HTML id property. An id is auto-generated when it is not specified.
131
+ */
132
+ id: PropTypes.string,
133
+
134
+ /**
135
+ * Horizontal size limit of the input fields.
136
+ */
137
+ horizontalConstraint: PropTypes.oneOf([7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 'scale', 'auto']),
138
+
139
+ /**
140
+ * A map of errors. Error messages for known errors are rendered automatically. Unknown errors will be forwarded to `renderError`.
141
+ */
142
+ errors: PropTypes.shape({
143
+ missing: PropTypes.bool
144
+ }),
145
+
146
+ /**
147
+ * Called with custom errors.
148
+ * <br/>
149
+ * This function can return a message which will be wrapped in an ErrorMessage. It can also return null to show no error.
150
+ * <br/>
151
+ * Signature: `(key, error) => React.node`
152
+ */
153
+ renderError: PropTypes.func,
154
+
155
+ /**
156
+ * Indicates if the value is required. Shows an the "required asterisk" if so.
157
+ */
158
+ isRequired: PropTypes.bool,
159
+
160
+ /**
161
+ * Indicates whether the field was touched. Errors will only be shown when the field was touched.
162
+ */
163
+ touched: PropTypes.bool,
164
+ // RadioInput
165
+
166
+ /**
167
+ * Used as HTML name of the input component.
168
+ */
169
+ name: PropTypes.string,
170
+
171
+ /**
172
+ * Value of the input component.
173
+ */
174
+ value: PropTypes.string.isRequired,
175
+
176
+ /**
177
+ * Called with an event containing the new value. Required when input is not read only. Parent should pass it back as value.
178
+ * <br />
179
+ * Signature: `(event) => void`
180
+ */
181
+ onChange: requiredIf(PropTypes.func, function (props) {
182
+ return !props.isReadOnly;
183
+ }),
184
+
185
+ /**
186
+ * Called when input is blurred
187
+ * <br />
188
+ * Signature: `(event) => void`
189
+ */
190
+ onBlur: PropTypes.func,
191
+
192
+ /**
193
+ * Called when input is focused
194
+ * <br />
195
+ * Signature: `(event) => void`
196
+ */
197
+ onFocus: PropTypes.func,
198
+
199
+ /**
200
+ * Indicates that the input cannot be modified (e.g not authorized, or changes currently saving).
201
+ */
202
+ isDisabled: PropTypes.bool,
203
+
204
+ /**
205
+ * Indicates that the field is displaying read-only content
206
+ */
207
+ isReadOnly: PropTypes.bool,
208
+
209
+ /**
210
+ * Rendering direction of the radio `RadioInput.Option`s
211
+ */
212
+ direction: PropTypes.oneOf(['stack', 'inline']),
213
+
214
+ /**
215
+ * Passes props of the `Spacings.Stack` or `Spacings.Inline`, dependeing on the chosen direction
216
+ */
217
+ directionProps: PropTypes.object,
218
+
219
+ /**
220
+ * At least one `RadioInput.Option` component or another node (mixed children are allowed)
221
+ */
222
+ children: PropTypes.node.isRequired,
223
+ // LabelField
224
+
225
+ /**
226
+ * Title of the label
227
+ */
228
+ title: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
229
+
230
+ /**
231
+ * 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.
232
+ * <br />
233
+ * Can also receive a `hintIcon`.
234
+ */
235
+ hint: requiredIf(PropTypes.oneOfType([PropTypes.string, PropTypes.node]), function (props) {
236
+ return props.hintIcon;
237
+ }),
238
+
239
+ /**
240
+ * Provides a description for the title.
241
+ */
242
+ description: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
243
+
244
+ /**
245
+ * Function called when info button is pressed.
246
+ * <br />
247
+ * Info button will only be visible when this prop is passed.
248
+ * <br />
249
+ * Signature: `(event) => void`
250
+ */
251
+ onInfoButtonClick: PropTypes.func,
252
+
253
+ /**
254
+ * Icon to be displayed beside the hint text.
255
+ * <br />
256
+ * Will only get rendered when `hint` is passed as well.
257
+ */
258
+ hintIcon: PropTypes.node,
259
+
260
+ /**
261
+ * Badge to be displayed beside the label.
262
+ * <br />
263
+ * Might be used to display additional information about the content of the field (E.g verified email)
264
+ */
265
+ badge: PropTypes.node
266
+ } : {};
267
+ var RadioField$1 = RadioField;
268
+
269
+ // NOTE: This string will be replaced in the `prepare` script by the `scripts/version.js` file.
270
+ var version = '0.0.0-canary-2021830134526';
271
+
272
+ export { RadioField$1 as default, version };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@commercetools-uikit/radio-field",
3
+ "description": "A controlled radio input component with validation states and a label.",
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/radio-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-radio-field.cjs.js",
25
+ "module": "dist/commercetools-uikit-radio-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/radio-input": "0.0.0-canary-2021830134526",
40
+ "@commercetools-uikit/spacings-stack": "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
+ "prop-types": "15.7.2",
45
+ "react-required-if": "1.0.3"
46
+ },
47
+ "devDependencies": {
48
+ "react": "17.0.2"
49
+ },
50
+ "peerDependencies": {
51
+ "react": "17.x"
52
+ }
53
+ }