@sb1/ffe-form-react 18.0.4 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/BaseRadioButton.js +35 -95
- package/es/Checkbox.js +43 -49
- package/es/Input.js +25 -26
- package/es/InputGroup.js +91 -109
- package/es/InputTextLike.js +25 -19
- package/es/Label.js +27 -28
- package/es/PhoneNumber.js +48 -158
- package/es/RadioBlock.js +37 -98
- package/es/RadioButton.js +26 -22
- package/es/RadioButtonInputGroup.js +44 -97
- package/es/RadioSwitch.js +38 -64
- package/es/TextArea.js +25 -16
- package/es/ToggleSwitch.js +36 -98
- package/es/Tooltip.js +29 -75
- package/es/i18n/en.js +6 -6
- package/es/i18n/i18n.js +4 -4
- package/es/i18n/nb.js +6 -6
- package/es/i18n/nn.js +6 -6
- package/es/index.js +14 -17
- package/es/message/BaseFieldMessage.js +49 -0
- package/es/message/ErrorFieldMessage.js +28 -0
- package/es/message/InfoFieldMessage.js +28 -0
- package/es/message/SuccessFieldMessage.js +28 -0
- package/es/message/index.js +3 -0
- package/es/types.js +1 -0
- package/lib/BaseRadioButton.js +63 -103
- package/lib/Checkbox.js +72 -56
- package/lib/Input.js +32 -34
- package/lib/InputGroup.js +121 -119
- package/lib/InputTextLike.js +32 -27
- package/lib/Label.js +34 -35
- package/lib/PhoneNumber.js +79 -165
- package/lib/RadioBlock.js +65 -106
- package/lib/RadioButton.js +33 -29
- package/lib/RadioButtonInputGroup.js +51 -104
- package/lib/RadioSwitch.js +44 -73
- package/lib/TextArea.js +32 -24
- package/lib/ToggleSwitch.js +67 -106
- package/lib/Tooltip.js +59 -86
- package/lib/i18n/en.js +8 -12
- package/lib/i18n/i18n.js +12 -14
- package/lib/i18n/nb.js +8 -12
- package/lib/i18n/nn.js +8 -12
- package/lib/index.js +32 -117
- package/lib/message/BaseFieldMessage.js +56 -0
- package/lib/message/ErrorFieldMessage.js +35 -0
- package/lib/message/InfoFieldMessage.js +35 -0
- package/lib/message/SuccessFieldMessage.js +35 -0
- package/lib/message/index.js +9 -0
- package/lib/types.js +2 -0
- package/package.json +5 -4
- package/types/BaseRadioButton.d.ts +14 -0
- package/types/Checkbox.d.ts +13 -0
- package/types/Input.d.ts +8 -0
- package/types/InputGroup.d.ts +36 -0
- package/types/InputTextLike.d.ts +5 -0
- package/types/Label.d.ts +9 -0
- package/types/PhoneNumber.d.ts +40 -0
- package/types/RadioBlock.d.ts +18 -0
- package/types/RadioButton.d.ts +7 -0
- package/types/RadioButtonInputGroup.d.ts +48 -0
- package/types/RadioSwitch.d.ts +23 -0
- package/types/TextArea.d.ts +4 -0
- package/types/ToggleSwitch.d.ts +16 -0
- package/types/Tooltip.d.ts +6 -0
- package/types/i18n/en.d.ts +8 -0
- package/types/i18n/i18n.d.ts +24 -0
- package/types/i18n/nb.d.ts +8 -0
- package/types/i18n/nn.d.ts +8 -0
- package/types/index.d.ts +14 -212
- package/types/message/BaseFieldMessage.d.ts +11 -0
- package/types/message/ErrorFieldMessage.d.ts +6 -0
- package/types/message/InfoFieldMessage.d.ts +6 -0
- package/types/message/SuccessFieldMessage.d.ts +6 -0
- package/types/message/index.d.ts +3 -0
- package/types/types.d.ts +11 -0
- package/es/BaseFieldMessage.js +0 -67
- package/es/ErrorFieldMessage.js +0 -21
- package/es/InfoFieldMessage.js +0 -9
- package/es/SuccessFieldMessage.js +0 -9
- package/es/index.d.js +0 -5
- package/lib/BaseFieldMessage.js +0 -73
- package/lib/ErrorFieldMessage.js +0 -28
- package/lib/InfoFieldMessage.js +0 -16
- package/lib/SuccessFieldMessage.js +0 -16
- package/lib/index.d.js +0 -6
package/es/PhoneNumber.js
CHANGED
|
@@ -1,166 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
3
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
4
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
5
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
6
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
7
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
8
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
9
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
10
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
11
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
-
import React from 'react';
|
|
16
|
-
import { string, bool, func, oneOfType, object, shape, node } from 'prop-types';
|
|
1
|
+
import React, { useRef } from 'react';
|
|
17
2
|
import { v4 as uuid } from 'uuid';
|
|
18
3
|
import classNames from 'classnames';
|
|
19
4
|
import i18n from './i18n/i18n';
|
|
20
|
-
import ErrorFieldMessage from './
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
_classCallCheck(this, PhoneNumber);
|
|
25
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
|
-
args[_key] = arguments[_key];
|
|
27
|
-
}
|
|
28
|
-
_this = _callSuper(this, PhoneNumber, [].concat(args));
|
|
29
|
-
_defineProperty(_this, "numberId", uuid());
|
|
30
|
-
_defineProperty(_this, "countryCodeId", uuid());
|
|
31
|
-
_defineProperty(_this, "fieldMessageId", "input-".concat(uuid(), "-fieldmessage"));
|
|
32
|
-
return _this;
|
|
33
|
-
}
|
|
34
|
-
_inherits(PhoneNumber, _React$Component);
|
|
35
|
-
return _createClass(PhoneNumber, [{
|
|
36
|
-
key: "render",
|
|
37
|
-
value: function render() {
|
|
38
|
-
var _fieldMessage;
|
|
39
|
-
var _this$props = this.props,
|
|
40
|
-
number = _this$props.number,
|
|
41
|
-
_this$props$countryCo = _this$props.countryCode,
|
|
42
|
-
countryCode = _this$props$countryCo === void 0 ? '47' : _this$props$countryCo,
|
|
43
|
-
_this$props$onCountry = _this$props.onCountryCodeChange,
|
|
44
|
-
onCountryCodeChange = _this$props$onCountry === void 0 ? function () {} : _this$props$onCountry,
|
|
45
|
-
_this$props$onNumberC = _this$props.onNumberChange,
|
|
46
|
-
onNumberChange = _this$props$onNumberC === void 0 ? function () {} : _this$props$onNumberC,
|
|
47
|
-
_this$props$onCountry2 = _this$props.onCountryCodeBlur,
|
|
48
|
-
onCountryCodeBlur = _this$props$onCountry2 === void 0 ? function () {} : _this$props$onCountry2,
|
|
49
|
-
_this$props$onNumberB = _this$props.onNumberBlur,
|
|
50
|
-
onNumberBlur = _this$props$onNumberB === void 0 ? function () {} : _this$props$onNumberB,
|
|
51
|
-
disabled = _this$props.disabled,
|
|
52
|
-
countryCodeFieldMessage = _this$props.countryCodeFieldMessage,
|
|
53
|
-
numberFieldMessage = _this$props.numberFieldMessage,
|
|
54
|
-
countryCodeAndNumberFieldMessage = _this$props.countryCodeAndNumberFieldMessage,
|
|
55
|
-
className = _this$props.className,
|
|
56
|
-
_this$props$extraMarg = _this$props.extraMargin,
|
|
57
|
-
extraMargin = _this$props$extraMarg === void 0 ? true : _this$props$extraMarg,
|
|
58
|
-
countryCodeRef = _this$props.countryCodeRef,
|
|
59
|
-
numberRef = _this$props.numberRef,
|
|
60
|
-
_this$props$isMobileN = _this$props.isMobileNumber,
|
|
61
|
-
isMobileNumber = _this$props$isMobileN === void 0 ? false : _this$props$isMobileN,
|
|
62
|
-
_this$props$locale = _this$props.locale,
|
|
63
|
-
locale = _this$props$locale === void 0 ? 'nb' : _this$props$locale;
|
|
64
|
-
var fieldMessage;
|
|
65
|
-
if (countryCodeAndNumberFieldMessage) {
|
|
5
|
+
import { ErrorFieldMessage } from './message';
|
|
6
|
+
var getFieldMessage = function (countryCodeAndNumberFieldMessage, countryCodeFieldMessage, numberFieldMessage) {
|
|
7
|
+
var fieldMessage;
|
|
8
|
+
if (countryCodeAndNumberFieldMessage) {
|
|
66
9
|
fieldMessage = countryCodeAndNumberFieldMessage;
|
|
67
|
-
|
|
10
|
+
}
|
|
11
|
+
else if (countryCodeFieldMessage && numberFieldMessage) {
|
|
68
12
|
console.error('You should use countryCodeAndNumberFieldMessage when both countryCode and number contains an error');
|
|
69
|
-
|
|
13
|
+
}
|
|
14
|
+
else if (countryCodeFieldMessage) {
|
|
70
15
|
fieldMessage = countryCodeFieldMessage;
|
|
71
|
-
|
|
16
|
+
}
|
|
17
|
+
else if (numberFieldMessage) {
|
|
72
18
|
fieldMessage = numberFieldMessage;
|
|
73
|
-
}
|
|
74
|
-
var fieldMessageId = ((_fieldMessage = fieldMessage) === null || _fieldMessage === void 0 || (_fieldMessage = _fieldMessage.props) === null || _fieldMessage === void 0 ? void 0 : _fieldMessage.id) || this.fieldMessageId;
|
|
75
|
-
var supportedLocales = ['nb', 'nn', 'en'];
|
|
76
|
-
var text = i18n[supportedLocales.indexOf(locale) !== -1 ? locale : 'nb'];
|
|
77
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
78
|
-
className: classNames('ffe-phone-number', 'ffe-input-group', {
|
|
79
|
-
'ffe-input-group--message': fieldMessage
|
|
80
|
-
}, {
|
|
81
|
-
'ffe-input-group--no-extra-margin': !extraMargin
|
|
82
|
-
}, className)
|
|
83
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
84
|
-
className: "ffe-phone-number__input-group"
|
|
85
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
86
|
-
className: "ffe-phone-number__country-code"
|
|
87
|
-
}, /*#__PURE__*/React.createElement("label", {
|
|
88
|
-
className: "ffe-form-label",
|
|
89
|
-
htmlFor: this.countryCodeId
|
|
90
|
-
}, text.COUNTRY_CODE), /*#__PURE__*/React.createElement("div", {
|
|
91
|
-
className: "ffe-phone-number__input-group"
|
|
92
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
93
|
-
className: "ffe-phone-number__plus"
|
|
94
|
-
}, "+"), /*#__PURE__*/React.createElement("input", {
|
|
95
|
-
id: this.countryCodeId,
|
|
96
|
-
className: classNames('ffe-input-field', 'ffe-phone-number__country-code-input'),
|
|
97
|
-
type: "tel",
|
|
98
|
-
disabled: disabled,
|
|
99
|
-
value: countryCode,
|
|
100
|
-
"aria-invalid": !!(countryCodeFieldMessage || countryCodeAndNumberFieldMessage),
|
|
101
|
-
"aria-describedby": !!(countryCodeFieldMessage || countryCodeAndNumberFieldMessage) ? fieldMessageId : undefined,
|
|
102
|
-
onChange: onCountryCodeChange,
|
|
103
|
-
onBlur: onCountryCodeBlur,
|
|
104
|
-
ref: countryCodeRef
|
|
105
|
-
}))), /*#__PURE__*/React.createElement("div", {
|
|
106
|
-
className: "ffe-phone-number__number"
|
|
107
|
-
}, /*#__PURE__*/React.createElement("label", {
|
|
108
|
-
className: "ffe-form-label",
|
|
109
|
-
htmlFor: this.numberId
|
|
110
|
-
}, isMobileNumber ? text.MOBILE_NUMBER : text.PHONE_NUMBER), /*#__PURE__*/React.createElement("input", {
|
|
111
|
-
id: this.numberId,
|
|
112
|
-
type: "tel",
|
|
113
|
-
className: classNames('ffe-input-field', 'ffe-phone-number__phone-input'),
|
|
114
|
-
onChange: onNumberChange,
|
|
115
|
-
onBlur: onNumberBlur,
|
|
116
|
-
value: number,
|
|
117
|
-
"aria-invalid": !!(numberFieldMessage || countryCodeAndNumberFieldMessage),
|
|
118
|
-
"aria-describedby": !!(numberFieldMessage || countryCodeAndNumberFieldMessage) ? fieldMessageId : undefined,
|
|
119
|
-
disabled: disabled,
|
|
120
|
-
ref: numberRef
|
|
121
|
-
}))), typeof fieldMessage === 'string' && /*#__PURE__*/React.createElement(ErrorFieldMessage, {
|
|
122
|
-
element: "p",
|
|
123
|
-
id: fieldMessageId
|
|
124
|
-
}, fieldMessage), /*#__PURE__*/React.isValidElement(fieldMessage) && /*#__PURE__*/React.cloneElement(fieldMessage, {
|
|
125
|
-
id: fieldMessageId
|
|
126
|
-
}));
|
|
127
19
|
}
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
export
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
isMobileNumber: bool
|
|
166
|
-
};
|
|
20
|
+
return fieldMessage;
|
|
21
|
+
};
|
|
22
|
+
export var PhoneNumber = function (_a) {
|
|
23
|
+
var _b;
|
|
24
|
+
var number = _a.number, _c = _a.countryCode, countryCode = _c === void 0 ? '47' : _c, _d = _a.onCountryCodeChange, onCountryCodeChange = _d === void 0 ? function () { } : _d, _e = _a.onNumberChange, onNumberChange = _e === void 0 ? function () { } : _e, _f = _a.onCountryCodeBlur, onCountryCodeBlur = _f === void 0 ? function () { } : _f, _g = _a.onNumberBlur, onNumberBlur = _g === void 0 ? function () { } : _g, disabled = _a.disabled, countryCodeFieldMessage = _a.countryCodeFieldMessage, numberFieldMessage = _a.numberFieldMessage, countryCodeAndNumberFieldMessage = _a.countryCodeAndNumberFieldMessage, className = _a.className, _h = _a.extraMargin, extraMargin = _h === void 0 ? true : _h, countryCodeRef = _a.countryCodeRef, numberRef = _a.numberRef, _j = _a.isMobileNumber, isMobileNumber = _j === void 0 ? false : _j, _k = _a.locale, locale = _k === void 0 ? 'nb' : _k;
|
|
25
|
+
var fieldMessage = getFieldMessage(countryCodeAndNumberFieldMessage, countryCodeFieldMessage, numberFieldMessage);
|
|
26
|
+
var numberId = useRef(uuid()).current;
|
|
27
|
+
var countryCodeId = useRef(uuid()).current;
|
|
28
|
+
var fieldMessageId = useRef(React.isValidElement(fieldMessage) ? (_b = fieldMessage === null || fieldMessage === void 0 ? void 0 : fieldMessage.props) === null || _b === void 0 ? void 0 : _b.id : uuid()).current;
|
|
29
|
+
var supportedLocales = ['nb', 'nn', 'en'];
|
|
30
|
+
var text = i18n[supportedLocales.indexOf(locale) !== -1 ? locale : 'nb'];
|
|
31
|
+
return (React.createElement("div", { className: classNames('ffe-phone-number', 'ffe-input-group', { 'ffe-input-group--message': fieldMessage }, { 'ffe-input-group--no-extra-margin': !extraMargin }, className) },
|
|
32
|
+
React.createElement("div", { className: "ffe-phone-number__input-group" },
|
|
33
|
+
React.createElement("div", { className: "ffe-phone-number__country-code" },
|
|
34
|
+
React.createElement("label", { className: "ffe-form-label", htmlFor: countryCodeId }, text.COUNTRY_CODE),
|
|
35
|
+
React.createElement("div", { className: "ffe-phone-number__input-group" },
|
|
36
|
+
React.createElement("span", { className: "ffe-phone-number__plus" }, "+"),
|
|
37
|
+
React.createElement("input", { id: countryCodeId, className: classNames('ffe-input-field', 'ffe-phone-number__country-code-input'), type: "tel", disabled: disabled, value: countryCode, "aria-invalid": !!(countryCodeFieldMessage ||
|
|
38
|
+
countryCodeAndNumberFieldMessage), "aria-describedby": !!(countryCodeFieldMessage ||
|
|
39
|
+
countryCodeAndNumberFieldMessage)
|
|
40
|
+
? fieldMessageId
|
|
41
|
+
: undefined, onChange: onCountryCodeChange, onBlur: onCountryCodeBlur, ref: countryCodeRef }))),
|
|
42
|
+
React.createElement("div", { className: "ffe-phone-number__number" },
|
|
43
|
+
React.createElement("label", { className: "ffe-form-label", htmlFor: numberId }, isMobileNumber
|
|
44
|
+
? text.MOBILE_NUMBER
|
|
45
|
+
: text.PHONE_NUMBER),
|
|
46
|
+
React.createElement("input", { id: numberId, type: "tel", className: classNames('ffe-input-field', 'ffe-phone-number__phone-input'), onChange: onNumberChange, onBlur: onNumberBlur, value: number, "aria-invalid": !!(numberFieldMessage ||
|
|
47
|
+
countryCodeAndNumberFieldMessage), "aria-describedby": !!(numberFieldMessage ||
|
|
48
|
+
countryCodeAndNumberFieldMessage)
|
|
49
|
+
? fieldMessageId
|
|
50
|
+
: undefined, disabled: disabled, ref: numberRef }))),
|
|
51
|
+
typeof fieldMessage === 'string' && (React.createElement(ErrorFieldMessage, { as: "p", id: fieldMessageId }, fieldMessage)),
|
|
52
|
+
React.isValidElement(fieldMessage) &&
|
|
53
|
+
React.cloneElement(fieldMessage, {
|
|
54
|
+
id: fieldMessageId,
|
|
55
|
+
})));
|
|
56
|
+
};
|
package/es/RadioBlock.js
CHANGED
|
@@ -1,100 +1,39 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import React, { useRef } from 'react';
|
|
21
24
|
import classNames from 'classnames';
|
|
22
25
|
import { v4 as uuid } from 'uuid';
|
|
23
|
-
var RadioBlock =
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
value: function render() {
|
|
38
|
-
var _this$props = this.props,
|
|
39
|
-
checked = _this$props.checked,
|
|
40
|
-
children = _this$props.children,
|
|
41
|
-
className = _this$props.className,
|
|
42
|
-
innerRef = _this$props.innerRef,
|
|
43
|
-
label = _this$props.label,
|
|
44
|
-
labelClass = _this$props.labelClass,
|
|
45
|
-
name = _this$props.name,
|
|
46
|
-
selectedValue = _this$props.selectedValue,
|
|
47
|
-
showChildren = _this$props.showChildren,
|
|
48
|
-
value = _this$props.value,
|
|
49
|
-
inputProps = _objectWithoutProperties(_this$props, _excluded);
|
|
50
|
-
var isSelected = checked || selectedValue === value;
|
|
51
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
52
|
-
className: classNames('ffe-radio-block', className)
|
|
53
|
-
}, /*#__PURE__*/React.createElement("input", _extends({
|
|
54
|
-
checked: isSelected,
|
|
55
|
-
className: "ffe-radio-input",
|
|
56
|
-
id: this.id,
|
|
57
|
-
ref: innerRef,
|
|
58
|
-
type: "radio",
|
|
59
|
-
name: name,
|
|
60
|
-
value: value,
|
|
61
|
-
"aria-describedby": children && showChildren || children && isSelected ? "".concat(this.id, "-described") : undefined
|
|
62
|
-
}, inputProps)), /*#__PURE__*/React.createElement("div", {
|
|
63
|
-
className: "ffe-radio-block__content"
|
|
64
|
-
}, /*#__PURE__*/React.createElement("label", {
|
|
65
|
-
className: classNames('ffe-radio-block__header', labelClass),
|
|
66
|
-
htmlFor: this.id
|
|
67
|
-
}, label), (isSelected || showChildren) && /*#__PURE__*/React.createElement("div", {
|
|
68
|
-
className: classNames('ffe-radio-block__wrapper', {
|
|
69
|
-
'ffe-radio-block__wrapper--empty': !children
|
|
70
|
-
}),
|
|
71
|
-
id: "".concat(this.id, "-described")
|
|
72
|
-
}, children)));
|
|
73
|
-
}
|
|
74
|
-
}]);
|
|
75
|
-
}(Component);
|
|
76
|
-
RadioBlock.propTypes = {
|
|
77
|
-
/** Whether or not the radio block is selected */
|
|
78
|
-
checked: bool,
|
|
79
|
-
/** The content rendered when choice is selected */
|
|
80
|
-
children: node,
|
|
81
|
-
/** Additional class names applied to the outer div */
|
|
82
|
-
className: string,
|
|
83
|
-
/** Ref-setting function, or ref created by useRef, passed to the input element */
|
|
84
|
-
innerRef: oneOfType([func, shape({
|
|
85
|
-
current: object
|
|
86
|
-
})]),
|
|
87
|
-
/** The always visible label of the radio block */
|
|
88
|
-
label: oneOfType([node, string]).isRequired,
|
|
89
|
-
/** Additional class names applied to the label element */
|
|
90
|
-
labelClass: string,
|
|
91
|
-
/** The name of the radio button set */
|
|
92
|
-
name: string.isRequired,
|
|
93
|
-
/** The selected value of the radio button set */
|
|
94
|
-
selectedValue: string,
|
|
95
|
-
/** Whether or not children are always visible */
|
|
96
|
-
showChildren: bool,
|
|
97
|
-
/** The value of the radio block */
|
|
98
|
-
value: string.isRequired
|
|
99
|
-
};
|
|
100
|
-
export default RadioBlock;
|
|
26
|
+
export var RadioBlock = React.forwardRef(function (_a, ref) {
|
|
27
|
+
var checked = _a.checked, children = _a.children, className = _a.className, label = _a.label, labelClass = _a.labelClass, name = _a.name, selectedValue = _a.selectedValue, showChildren = _a.showChildren, value = _a.value, inputProps = __rest(_a, ["checked", "children", "className", "label", "labelClass", "name", "selectedValue", "showChildren", "value"]);
|
|
28
|
+
var id = useRef("radio-block-".concat(uuid())).current;
|
|
29
|
+
var isSelected = checked || selectedValue === value;
|
|
30
|
+
return (React.createElement("div", { className: classNames('ffe-radio-block', className) },
|
|
31
|
+
React.createElement("input", __assign({ checked: isSelected, className: "ffe-radio-input", id: id, ref: ref, type: "radio", name: name, value: value, "aria-describedby": (children && showChildren) || (children && isSelected)
|
|
32
|
+
? "".concat(id, "-described")
|
|
33
|
+
: undefined }, inputProps)),
|
|
34
|
+
React.createElement("div", { className: "ffe-radio-block__content" },
|
|
35
|
+
React.createElement("label", { className: classNames('ffe-radio-block__header', labelClass), htmlFor: id }, label),
|
|
36
|
+
(isSelected || showChildren) && (React.createElement("div", { className: classNames('ffe-radio-block__wrapper', {
|
|
37
|
+
'ffe-radio-block__wrapper--empty': !children,
|
|
38
|
+
}), id: "".concat(id, "-described") }, children)))));
|
|
39
|
+
});
|
package/es/RadioButton.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
5
23
|
import React from 'react';
|
|
6
|
-
import { bool, string } from 'prop-types';
|
|
7
24
|
import classNames from 'classnames';
|
|
8
|
-
import BaseRadioButton from './BaseRadioButton';
|
|
9
|
-
var RadioButton = function
|
|
10
|
-
|
|
11
|
-
inline
|
|
12
|
-
rest = _objectWithoutProperties(props, _excluded);
|
|
13
|
-
return /*#__PURE__*/React.createElement(BaseRadioButton, _extends({
|
|
14
|
-
className: classNames('ffe-radio-button', {
|
|
15
|
-
'ffe-radio-button--inline': inline
|
|
16
|
-
}, className)
|
|
17
|
-
}, rest));
|
|
18
|
-
};
|
|
19
|
-
RadioButton.propTypes = {
|
|
20
|
-
/** Additional class names applied to the label */
|
|
21
|
-
className: string,
|
|
22
|
-
/** Indicates whether the radio button is rendered inline or as a block */
|
|
23
|
-
inline: bool
|
|
25
|
+
import { BaseRadioButton } from './BaseRadioButton';
|
|
26
|
+
export var RadioButton = function (_a) {
|
|
27
|
+
var className = _a.className, inline = _a.inline, rest = __rest(_a, ["className", "inline"]);
|
|
28
|
+
return (React.createElement(BaseRadioButton, __assign({ className: classNames('ffe-radio-button', { 'ffe-radio-button--inline': inline }, className) }, rest)));
|
|
24
29
|
};
|
|
25
|
-
export default RadioButton;
|
|
@@ -1,100 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
11
23
|
import React from 'react';
|
|
12
|
-
import { bool, func, oneOfType, oneOf, node, string, number } from 'prop-types';
|
|
13
24
|
import classNames from 'classnames';
|
|
14
|
-
import ErrorFieldMessage from './
|
|
15
|
-
import Tooltip from './Tooltip';
|
|
16
|
-
var RadioButtonInputGroup = function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return f;
|
|
37
|
-
},
|
|
38
|
-
selectedValue: selectedValue
|
|
39
|
-
};
|
|
40
|
-
return /*#__PURE__*/React.createElement("fieldset", _extends({
|
|
41
|
-
className: classNames('ffe-input-group', {
|
|
42
|
-
'ffe-input-group--no-extra-margin': !extraMargin
|
|
43
|
-
}, {
|
|
44
|
-
'ffe-input-group--message': !!fieldMessage
|
|
45
|
-
}, className)
|
|
46
|
-
}, rest), label && /*#__PURE__*/React.createElement("legend", {
|
|
47
|
-
className: classNames('ffe-form-label', 'ffe-form-label--block')
|
|
48
|
-
}, label, typeof tooltip === 'string' && /*#__PURE__*/React.createElement(Tooltip, null, tooltip), /*#__PURE__*/React.isValidElement(tooltip) && tooltip), typeof description === 'string' && /*#__PURE__*/React.createElement("div", {
|
|
49
|
-
className: "ffe-small-text"
|
|
50
|
-
}, description), /*#__PURE__*/React.isValidElement(description) && description, children(_objectSpread({}, buttonProps)), typeof fieldMessage === 'string' && /*#__PURE__*/React.createElement(ErrorFieldMessage, {
|
|
51
|
-
element: "p"
|
|
52
|
-
}, fieldMessage), /*#__PURE__*/React.isValidElement(fieldMessage) && fieldMessage);
|
|
53
|
-
};
|
|
54
|
-
RadioButtonInputGroup.propTypes = {
|
|
55
|
-
/**
|
|
56
|
-
* Indicates whether the radio buttons inside this radio button group is
|
|
57
|
-
* invalid or not. Propagated to all children.
|
|
58
|
-
* */
|
|
59
|
-
'aria-invalid': oneOf(['true', 'false']),
|
|
60
|
-
/**
|
|
61
|
-
* Function receiving props relevant to each radio button as an object
|
|
62
|
-
* argument. Expected to return a set of radio buttons, which should get
|
|
63
|
-
* these properties applied to them.
|
|
64
|
-
* */
|
|
65
|
-
children: func.isRequired,
|
|
66
|
-
/** Additional class names applied to the fieldset */
|
|
67
|
-
className: string,
|
|
68
|
-
/** To just render a static, always visible tooltip, use this. */
|
|
69
|
-
description: oneOfType([node, string]),
|
|
70
|
-
/** Reserve space for showing `fieldMessage`s so content below don't move
|
|
71
|
-
* vertically if an errormessage shows up. Note that this will only reserve
|
|
72
|
-
* space for one line of content, so keep messages short.
|
|
73
|
-
*/
|
|
74
|
-
extraMargin: bool,
|
|
75
|
-
/** String or ErrorFieldMessage component with message */
|
|
76
|
-
fieldMessage: oneOfType([node, string]),
|
|
77
|
-
/**
|
|
78
|
-
* Indicates whether the radio buttons inside this radio button group is
|
|
79
|
-
* rendered inline or as a block.
|
|
80
|
-
* */
|
|
81
|
-
inline: bool,
|
|
82
|
-
/**
|
|
83
|
-
* The text describing the radio button set. Note that if you don't use this
|
|
84
|
-
* prop but provide your own label you should make sure your solution passes
|
|
85
|
-
* acessibility validation using a tool such as aXe DevTools.
|
|
86
|
-
*/
|
|
87
|
-
label: oneOfType([node, string]),
|
|
88
|
-
/** The name of the radio button, required to avoid missing name */
|
|
89
|
-
name: string.isRequired,
|
|
90
|
-
/** Change handler, receives value of selected radio button */
|
|
91
|
-
onChange: func,
|
|
92
|
-
/** The currently selected value */
|
|
93
|
-
selectedValue: oneOfType([bool, string, number]),
|
|
94
|
-
/**
|
|
95
|
-
* String or Tooltip component with further detail about the radio button
|
|
96
|
-
* set
|
|
97
|
-
* */
|
|
98
|
-
tooltip: oneOfType([node, string])
|
|
25
|
+
import { ErrorFieldMessage } from './message';
|
|
26
|
+
import { Tooltip } from './Tooltip';
|
|
27
|
+
export var RadioButtonInputGroup = function (_a) {
|
|
28
|
+
var children = _a.children, className = _a.className, _b = _a.extraMargin, extraMargin = _b === void 0 ? true : _b, description = _a.description, fieldMessage = _a.fieldMessage, inline = _a.inline, label = _a.label, name = _a.name, selectedValue = _a.selectedValue, tooltip = _a.tooltip, onChange = _a.onChange, rest = __rest(_a, ["children", "className", "extraMargin", "description", "fieldMessage", "inline", "label", "name", "selectedValue", "tooltip", "onChange"]);
|
|
29
|
+
if (tooltip && description) {
|
|
30
|
+
throw new Error('Don\'t use both "tooltip" and "description" on an <RadioButtonInputGroup />, pick one of them');
|
|
31
|
+
}
|
|
32
|
+
return (React.createElement("fieldset", __assign({ className: classNames('ffe-input-group', { 'ffe-input-group--no-extra-margin': !extraMargin }, { 'ffe-input-group--message': !!fieldMessage }, className) }, rest),
|
|
33
|
+
label && (React.createElement("legend", { className: classNames('ffe-form-label', 'ffe-form-label--block') },
|
|
34
|
+
label,
|
|
35
|
+
typeof tooltip === 'string' && (React.createElement(Tooltip, null, tooltip)),
|
|
36
|
+
React.isValidElement(tooltip) && tooltip)),
|
|
37
|
+
typeof description === 'string' ? (React.createElement("div", { className: "ffe-small-text" }, description)) : (description),
|
|
38
|
+
children({
|
|
39
|
+
inline: inline,
|
|
40
|
+
name: name,
|
|
41
|
+
onChange: function (e) {
|
|
42
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(e);
|
|
43
|
+
},
|
|
44
|
+
selectedValue: selectedValue,
|
|
45
|
+
}),
|
|
46
|
+
typeof fieldMessage === 'string' ? (React.createElement(ErrorFieldMessage, { as: "p" }, fieldMessage)) : (fieldMessage)));
|
|
99
47
|
};
|
|
100
|
-
export default RadioButtonInputGroup;
|