@sb1/ffe-form-react 18.0.4 → 19.0.1
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 +47 -98
- 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 +75 -103
- 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 +6 -5
- 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/lib/PhoneNumber.js
CHANGED
|
@@ -1,172 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _propTypes = require("prop-types");
|
|
9
|
-
var _uuid = require("uuid");
|
|
10
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
-
var _i18n = _interopRequireDefault(require("./i18n/i18n"));
|
|
12
|
-
var _ErrorFieldMessage = _interopRequireDefault(require("./ErrorFieldMessage"));
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
15
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
-
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); } }
|
|
17
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
19
|
-
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); }
|
|
20
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
21
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
23
|
-
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); }
|
|
24
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
25
|
-
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; }
|
|
26
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
27
|
-
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); }
|
|
28
|
-
var PhoneNumber = exports.default = /*#__PURE__*/function (_React$Component) {
|
|
29
|
-
function PhoneNumber() {
|
|
30
|
-
var _this;
|
|
31
|
-
_classCallCheck(this, PhoneNumber);
|
|
32
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
33
|
-
args[_key] = arguments[_key];
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
7
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
countryCodeRef = _this$props.countryCodeRef,
|
|
66
|
-
numberRef = _this$props.numberRef,
|
|
67
|
-
_this$props$isMobileN = _this$props.isMobileNumber,
|
|
68
|
-
isMobileNumber = _this$props$isMobileN === void 0 ? false : _this$props$isMobileN,
|
|
69
|
-
_this$props$locale = _this$props.locale,
|
|
70
|
-
locale = _this$props$locale === void 0 ? 'nb' : _this$props$locale;
|
|
71
|
-
var fieldMessage;
|
|
72
|
-
if (countryCodeAndNumberFieldMessage) {
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.PhoneNumber = void 0;
|
|
30
|
+
var react_1 = __importStar(require("react"));
|
|
31
|
+
var uuid_1 = require("uuid");
|
|
32
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
33
|
+
var i18n_1 = __importDefault(require("./i18n/i18n"));
|
|
34
|
+
var message_1 = require("./message");
|
|
35
|
+
var getFieldMessage = function (countryCodeAndNumberFieldMessage, countryCodeFieldMessage, numberFieldMessage) {
|
|
36
|
+
var fieldMessage;
|
|
37
|
+
if (countryCodeAndNumberFieldMessage) {
|
|
73
38
|
fieldMessage = countryCodeAndNumberFieldMessage;
|
|
74
|
-
|
|
39
|
+
}
|
|
40
|
+
else if (countryCodeFieldMessage && numberFieldMessage) {
|
|
75
41
|
console.error('You should use countryCodeAndNumberFieldMessage when both countryCode and number contains an error');
|
|
76
|
-
|
|
42
|
+
}
|
|
43
|
+
else if (countryCodeFieldMessage) {
|
|
77
44
|
fieldMessage = countryCodeFieldMessage;
|
|
78
|
-
|
|
45
|
+
}
|
|
46
|
+
else if (numberFieldMessage) {
|
|
79
47
|
fieldMessage = numberFieldMessage;
|
|
80
|
-
}
|
|
81
|
-
var fieldMessageId = ((_fieldMessage = fieldMessage) === null || _fieldMessage === void 0 || (_fieldMessage = _fieldMessage.props) === null || _fieldMessage === void 0 ? void 0 : _fieldMessage.id) || this.fieldMessageId;
|
|
82
|
-
var supportedLocales = ['nb', 'nn', 'en'];
|
|
83
|
-
var text = _i18n.default[supportedLocales.indexOf(locale) !== -1 ? locale : 'nb'];
|
|
84
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
85
|
-
className: (0, _classnames.default)('ffe-phone-number', 'ffe-input-group', {
|
|
86
|
-
'ffe-input-group--message': fieldMessage
|
|
87
|
-
}, {
|
|
88
|
-
'ffe-input-group--no-extra-margin': !extraMargin
|
|
89
|
-
}, className)
|
|
90
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
91
|
-
className: "ffe-phone-number__input-group"
|
|
92
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
93
|
-
className: "ffe-phone-number__country-code"
|
|
94
|
-
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
95
|
-
className: "ffe-form-label",
|
|
96
|
-
htmlFor: this.countryCodeId
|
|
97
|
-
}, text.COUNTRY_CODE), /*#__PURE__*/_react.default.createElement("div", {
|
|
98
|
-
className: "ffe-phone-number__input-group"
|
|
99
|
-
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
100
|
-
className: "ffe-phone-number__plus"
|
|
101
|
-
}, "+"), /*#__PURE__*/_react.default.createElement("input", {
|
|
102
|
-
id: this.countryCodeId,
|
|
103
|
-
className: (0, _classnames.default)('ffe-input-field', 'ffe-phone-number__country-code-input'),
|
|
104
|
-
type: "tel",
|
|
105
|
-
disabled: disabled,
|
|
106
|
-
value: countryCode,
|
|
107
|
-
"aria-invalid": !!(countryCodeFieldMessage || countryCodeAndNumberFieldMessage),
|
|
108
|
-
"aria-describedby": !!(countryCodeFieldMessage || countryCodeAndNumberFieldMessage) ? fieldMessageId : undefined,
|
|
109
|
-
onChange: onCountryCodeChange,
|
|
110
|
-
onBlur: onCountryCodeBlur,
|
|
111
|
-
ref: countryCodeRef
|
|
112
|
-
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
113
|
-
className: "ffe-phone-number__number"
|
|
114
|
-
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
115
|
-
className: "ffe-form-label",
|
|
116
|
-
htmlFor: this.numberId
|
|
117
|
-
}, isMobileNumber ? text.MOBILE_NUMBER : text.PHONE_NUMBER), /*#__PURE__*/_react.default.createElement("input", {
|
|
118
|
-
id: this.numberId,
|
|
119
|
-
type: "tel",
|
|
120
|
-
className: (0, _classnames.default)('ffe-input-field', 'ffe-phone-number__phone-input'),
|
|
121
|
-
onChange: onNumberChange,
|
|
122
|
-
onBlur: onNumberBlur,
|
|
123
|
-
value: number,
|
|
124
|
-
"aria-invalid": !!(numberFieldMessage || countryCodeAndNumberFieldMessage),
|
|
125
|
-
"aria-describedby": !!(numberFieldMessage || countryCodeAndNumberFieldMessage) ? fieldMessageId : undefined,
|
|
126
|
-
disabled: disabled,
|
|
127
|
-
ref: numberRef
|
|
128
|
-
}))), typeof fieldMessage === 'string' && /*#__PURE__*/_react.default.createElement(_ErrorFieldMessage.default, {
|
|
129
|
-
element: "p",
|
|
130
|
-
id: fieldMessageId
|
|
131
|
-
}, fieldMessage), /*#__PURE__*/_react.default.isValidElement(fieldMessage) && /*#__PURE__*/_react.default.cloneElement(fieldMessage, {
|
|
132
|
-
id: fieldMessageId
|
|
133
|
-
}));
|
|
134
48
|
}
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
PhoneNumber
|
|
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
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
49
|
+
return fieldMessage;
|
|
50
|
+
};
|
|
51
|
+
var PhoneNumber = function (_a) {
|
|
52
|
+
var _b;
|
|
53
|
+
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;
|
|
54
|
+
var fieldMessage = getFieldMessage(countryCodeAndNumberFieldMessage, countryCodeFieldMessage, numberFieldMessage);
|
|
55
|
+
var numberId = (0, react_1.useRef)((0, uuid_1.v4)()).current;
|
|
56
|
+
var countryCodeId = (0, react_1.useRef)((0, uuid_1.v4)()).current;
|
|
57
|
+
var fieldMessageId = (0, react_1.useRef)(react_1.default.isValidElement(fieldMessage) ? (_b = fieldMessage === null || fieldMessage === void 0 ? void 0 : fieldMessage.props) === null || _b === void 0 ? void 0 : _b.id : (0, uuid_1.v4)()).current;
|
|
58
|
+
var supportedLocales = ['nb', 'nn', 'en'];
|
|
59
|
+
var text = i18n_1.default[supportedLocales.indexOf(locale) !== -1 ? locale : 'nb'];
|
|
60
|
+
return (react_1.default.createElement("div", { className: (0, classnames_1.default)('ffe-phone-number', 'ffe-input-group', { 'ffe-input-group--message': fieldMessage }, { 'ffe-input-group--no-extra-margin': !extraMargin }, className) },
|
|
61
|
+
react_1.default.createElement("div", { className: "ffe-phone-number__input-group" },
|
|
62
|
+
react_1.default.createElement("div", { className: "ffe-phone-number__country-code" },
|
|
63
|
+
react_1.default.createElement("label", { className: "ffe-form-label", htmlFor: countryCodeId }, text.COUNTRY_CODE),
|
|
64
|
+
react_1.default.createElement("div", { className: "ffe-phone-number__input-group" },
|
|
65
|
+
react_1.default.createElement("span", { className: "ffe-phone-number__plus" }, "+"),
|
|
66
|
+
react_1.default.createElement("input", { id: countryCodeId, className: (0, classnames_1.default)('ffe-input-field', 'ffe-phone-number__country-code-input'), type: "tel", disabled: disabled, value: countryCode, "aria-invalid": !!(countryCodeFieldMessage ||
|
|
67
|
+
countryCodeAndNumberFieldMessage), "aria-describedby": !!(countryCodeFieldMessage ||
|
|
68
|
+
countryCodeAndNumberFieldMessage)
|
|
69
|
+
? fieldMessageId
|
|
70
|
+
: undefined, onChange: onCountryCodeChange, onBlur: onCountryCodeBlur, ref: countryCodeRef }))),
|
|
71
|
+
react_1.default.createElement("div", { className: "ffe-phone-number__number" },
|
|
72
|
+
react_1.default.createElement("label", { className: "ffe-form-label", htmlFor: numberId }, isMobileNumber
|
|
73
|
+
? text.MOBILE_NUMBER
|
|
74
|
+
: text.PHONE_NUMBER),
|
|
75
|
+
react_1.default.createElement("input", { id: numberId, type: "tel", className: (0, classnames_1.default)('ffe-input-field', 'ffe-phone-number__phone-input'), onChange: onNumberChange, onBlur: onNumberBlur, value: number, "aria-invalid": !!(numberFieldMessage ||
|
|
76
|
+
countryCodeAndNumberFieldMessage), "aria-describedby": !!(numberFieldMessage ||
|
|
77
|
+
countryCodeAndNumberFieldMessage)
|
|
78
|
+
? fieldMessageId
|
|
79
|
+
: undefined, disabled: disabled, ref: numberRef }))),
|
|
80
|
+
typeof fieldMessage === 'string' && (react_1.default.createElement(message_1.ErrorFieldMessage, { as: "p", id: fieldMessageId }, fieldMessage)),
|
|
81
|
+
react_1.default.isValidElement(fieldMessage) &&
|
|
82
|
+
react_1.default.cloneElement(fieldMessage, {
|
|
83
|
+
id: fieldMessageId,
|
|
84
|
+
})));
|
|
85
|
+
};
|
|
86
|
+
exports.PhoneNumber = PhoneNumber;
|
package/lib/RadioBlock.js
CHANGED
|
@@ -1,109 +1,68 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
|
|
19
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
-
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); } }
|
|
21
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
22
|
-
function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
|
|
23
|
-
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); }
|
|
24
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
25
|
-
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
26
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
27
|
-
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); }
|
|
28
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
|
-
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; }
|
|
30
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
31
|
-
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); }
|
|
32
|
-
var RadioBlock = /*#__PURE__*/function (_Component) {
|
|
33
|
-
function RadioBlock() {
|
|
34
|
-
var _this;
|
|
35
|
-
_classCallCheck(this, RadioBlock);
|
|
36
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
37
|
-
args[_key] = arguments[_key];
|
|
38
|
-
}
|
|
39
|
-
_this = _callSuper(this, RadioBlock, [].concat(args));
|
|
40
|
-
_defineProperty(_this, "id", "radio-block-".concat((0, _uuid.v4)()));
|
|
41
|
-
return _this;
|
|
42
|
-
}
|
|
43
|
-
_inherits(RadioBlock, _Component);
|
|
44
|
-
return _createClass(RadioBlock, [{
|
|
45
|
-
key: "render",
|
|
46
|
-
value: function render() {
|
|
47
|
-
var _this$props = this.props,
|
|
48
|
-
checked = _this$props.checked,
|
|
49
|
-
children = _this$props.children,
|
|
50
|
-
className = _this$props.className,
|
|
51
|
-
innerRef = _this$props.innerRef,
|
|
52
|
-
label = _this$props.label,
|
|
53
|
-
labelClass = _this$props.labelClass,
|
|
54
|
-
name = _this$props.name,
|
|
55
|
-
selectedValue = _this$props.selectedValue,
|
|
56
|
-
showChildren = _this$props.showChildren,
|
|
57
|
-
value = _this$props.value,
|
|
58
|
-
inputProps = _objectWithoutProperties(_this$props, _excluded);
|
|
59
|
-
var isSelected = checked || selectedValue === value;
|
|
60
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
61
|
-
className: (0, _classnames.default)('ffe-radio-block', className)
|
|
62
|
-
}, /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
63
|
-
checked: isSelected,
|
|
64
|
-
className: "ffe-radio-input",
|
|
65
|
-
id: this.id,
|
|
66
|
-
ref: innerRef,
|
|
67
|
-
type: "radio",
|
|
68
|
-
name: name,
|
|
69
|
-
value: value,
|
|
70
|
-
"aria-describedby": children && showChildren || children && isSelected ? "".concat(this.id, "-described") : undefined
|
|
71
|
-
}, inputProps)), /*#__PURE__*/_react.default.createElement("div", {
|
|
72
|
-
className: "ffe-radio-block__content"
|
|
73
|
-
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
74
|
-
className: (0, _classnames.default)('ffe-radio-block__header', labelClass),
|
|
75
|
-
htmlFor: this.id
|
|
76
|
-
}, label), (isSelected || showChildren) && /*#__PURE__*/_react.default.createElement("div", {
|
|
77
|
-
className: (0, _classnames.default)('ffe-radio-block__wrapper', {
|
|
78
|
-
'ffe-radio-block__wrapper--empty': !children
|
|
79
|
-
}),
|
|
80
|
-
id: "".concat(this.id, "-described")
|
|
81
|
-
}, children)));
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
82
18
|
}
|
|
83
|
-
|
|
84
|
-
}(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
labelClass: _propTypes.string,
|
|
100
|
-
/** The name of the radio button set */
|
|
101
|
-
name: _propTypes.string.isRequired,
|
|
102
|
-
/** The selected value of the radio button set */
|
|
103
|
-
selectedValue: _propTypes.string,
|
|
104
|
-
/** Whether or not children are always visible */
|
|
105
|
-
showChildren: _propTypes.bool,
|
|
106
|
-
/** The value of the radio block */
|
|
107
|
-
value: _propTypes.string.isRequired
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
108
35
|
};
|
|
109
|
-
var
|
|
36
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
37
|
+
var t = {};
|
|
38
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
39
|
+
t[p] = s[p];
|
|
40
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
41
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
42
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
43
|
+
t[p[i]] = s[p[i]];
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
};
|
|
47
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
48
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
49
|
+
};
|
|
50
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
+
exports.RadioBlock = void 0;
|
|
52
|
+
var react_1 = __importStar(require("react"));
|
|
53
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
54
|
+
var uuid_1 = require("uuid");
|
|
55
|
+
exports.RadioBlock = react_1.default.forwardRef(function (_a, ref) {
|
|
56
|
+
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"]);
|
|
57
|
+
var id = (0, react_1.useRef)("radio-block-".concat((0, uuid_1.v4)())).current;
|
|
58
|
+
var isSelected = checked || selectedValue === value;
|
|
59
|
+
return (react_1.default.createElement("div", { className: (0, classnames_1.default)('ffe-radio-block', className) },
|
|
60
|
+
react_1.default.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)
|
|
61
|
+
? "".concat(id, "-described")
|
|
62
|
+
: undefined }, inputProps)),
|
|
63
|
+
react_1.default.createElement("div", { className: "ffe-radio-block__content" },
|
|
64
|
+
react_1.default.createElement("label", { className: (0, classnames_1.default)('ffe-radio-block__header', labelClass), htmlFor: id }, label),
|
|
65
|
+
(isSelected || showChildren) && (react_1.default.createElement("div", { className: (0, classnames_1.default)('ffe-radio-block__wrapper', {
|
|
66
|
+
'ffe-radio-block__wrapper--empty': !children,
|
|
67
|
+
}), id: "".concat(id, "-described") }, children)))));
|
|
68
|
+
});
|
package/lib/RadioButton.js
CHANGED
|
@@ -1,32 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
14
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } } return target; }
|
|
16
|
-
var RadioButton = function RadioButton(props) {
|
|
17
|
-
var className = props.className,
|
|
18
|
-
inline = props.inline,
|
|
19
|
-
rest = _objectWithoutProperties(props, _excluded);
|
|
20
|
-
return /*#__PURE__*/_react.default.createElement(_BaseRadioButton.default, _extends({
|
|
21
|
-
className: (0, _classnames.default)('ffe-radio-button', {
|
|
22
|
-
'ffe-radio-button--inline': inline
|
|
23
|
-
}, className)
|
|
24
|
-
}, rest));
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
25
12
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
31
23
|
};
|
|
32
|
-
var
|
|
24
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.RadioButton = void 0;
|
|
29
|
+
var react_1 = __importDefault(require("react"));
|
|
30
|
+
var classnames_1 = __importDefault(require("classnames"));
|
|
31
|
+
var BaseRadioButton_1 = require("./BaseRadioButton");
|
|
32
|
+
var RadioButton = function (_a) {
|
|
33
|
+
var className = _a.className, inline = _a.inline, rest = __rest(_a, ["className", "inline"]);
|
|
34
|
+
return (react_1.default.createElement(BaseRadioButton_1.BaseRadioButton, __assign({ className: (0, classnames_1.default)('ffe-radio-button', { 'ffe-radio-button--inline': inline }, className) }, rest)));
|
|
35
|
+
};
|
|
36
|
+
exports.RadioButton = RadioButton;
|