/
Radio.js
368 lines (297 loc) · 11.5 KB
/
Radio.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _stringify = require('babel-runtime/core-js/json/stringify');
var _stringify2 = _interopRequireDefault(_stringify);
var _keys = require('babel-runtime/core-js/object/keys');
var _keys2 = _interopRequireDefault(_keys);
var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _redboxReact2 = require('redbox-react');
var _redboxReact3 = _interopRequireDefault(_redboxReact2);
var _react2 = require('react');
var _react3 = _interopRequireDefault(_react2);
var _reactTransformCatchErrors3 = require('react-transform-catch-errors');
var _reactTransformCatchErrors4 = _interopRequireDefault(_reactTransformCatchErrors3);
var _dec, _class, _class2, _temp;
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _Wrap = require('./Wrap');
var _Wrap2 = _interopRequireDefault(_Wrap);
var _reactBootstrap = require('react-bootstrap');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _components = {
RadioType: {
displayName: 'RadioType'
}
};
var _reactTransformCatchErrors2 = (0, _reactTransformCatchErrors4.default)({
filename: 'src/types/Radio.js',
components: _components,
locals: [],
imports: [_react3.default, _redboxReact3.default]
});
function _wrapComponent(id) {
return function (Component) {
return _reactTransformCatchErrors2(Component, id);
};
}
var RadioType = _wrapComponent('RadioType')((_dec = (0, _Wrap2.default)(), _dec(_class = (_temp = _class2 = function (_Component) {
(0, _inherits3.default)(RadioType, _Component);
function RadioType() {
(0, _classCallCheck3.default)(this, RadioType);
var _this = (0, _possibleConstructorReturn3.default)(this, (0, _getPrototypeOf2.default)(RadioType).call(this));
_this.radioButtons = _this.radioButtons.bind(_this);
if (!(typeof _this.radioButtons === 'function')) {
throw new TypeError('Value of "this.radioButtons" violates contract.\n\nExpected:\n() => any\n\nGot:\n' + _inspect(_this.radioButtons));
}
_this.radioButtonList = _this.radioButtonList.bind(_this);
if (!(typeof _this.radioButtonList === 'function')) {
throw new TypeError('Value of "this.radioButtonList" violates contract.\n\nExpected:\n(any, any) => any\n\nGot:\n' + _inspect(_this.radioButtonList));
}
_this.getValue = _this.getValue.bind(_this);
if (!(typeof _this.getValue === 'function')) {
throw new TypeError('Value of "this.getValue" violates contract.\n\nExpected:\n() => any\n\nGot:\n' + _inspect(_this.getValue));
}
_this.filtered = _this.filtered.bind(_this);
if (!(typeof _this.filtered === 'function')) {
throw new TypeError('Value of "this.filtered" violates contract.\n\nExpected:\n(any) => any\n\nGot:\n' + _inspect(_this.filtered));
}
_this.searchBox = _this.searchBox.bind(_this);
if (!(typeof _this.searchBox === 'function')) {
throw new TypeError('Value of "this.searchBox" violates contract.\n\nExpected:\n() => any\n\nGot:\n' + _inspect(_this.searchBox));
}
_this.handleChange = _this.handleChange.bind(_this);
if (!(typeof _this.handleChange === 'function')) {
throw new TypeError('Value of "this.handleChange" violates contract.\n\nExpected:\n(any) => any\n\nGot:\n' + _inspect(_this.handleChange));
}
_this.state = { value: '' };
return _this;
}
(0, _createClass3.default)(RadioType, [{
key: 'filtered',
value: function filtered(options) {
var value = this.state.value;
var strValue = String(value).toLowerCase();
if (value !== '') {
return _lodash2.default.filter(options, function (option) {
return _lodash2.default.includes(String(option.desc).toLowerCase(), strValue);
});
}
return options;
}
}, {
key: 'radioButtonList',
value: function radioButtonList(list, selectedValue) {
var _this2 = this;
return _lodash2.default.map(list, function (option, key) {
return _react3.default.createElement(
_reactBootstrap.Radio,
{
key: key,
name: _this2.props.field.name,
value: option.value,
onChange: _this2.props.properties.onChange,
onFocus: _this2.props.properties.onFocus,
onUpdate: _this2.props.properties.onUpdate,
checked: selectedValue === String(option.value)
},
option.desc
);
});
}
}, {
key: 'radioButtons',
value: function radioButtons() {
var _this3 = this;
var selectedValue = String(_lodash2.default.get(this.props.properties, 'value') || _lodash2.default.get(this.props.properties, 'initialValue'));
var filtered = this.filtered(_lodash2.default.get(this.props.field, 'options', []));
var field = _lodash2.default.get(this.props, 'field');
if (filtered.length === 0) {
return _react3.default.createElement(
_reactBootstrap.Alert,
null,
'Er zijn geen resultaten'
);
}
if (!!field.chunks) {
var _ret = function () {
var split = Math.ceil(filtered.length / field.chunks);
var chunks = function chunks() {
var chunkData = _lodash2.default.chunk(filtered, split);
return _lodash2.default.map(chunkData, function (chunk, key) {
return _react3.default.createElement(
_reactBootstrap.Col,
{ key: key, md: Math.round(12 / field.chunks) },
_this3.radioButtonList(chunk, selectedValue)
);
});
};
return {
v: _react3.default.createElement(
_reactBootstrap.Row,
null,
chunks()
)
};
}();
if ((typeof _ret === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret)) === "object") return _ret.v;
}
return _lodash2.default.map(filtered, function (option, key) {
return _react3.default.createElement(
_reactBootstrap.Radio,
{
key: key,
name: _this3.props.field.name,
value: option.value,
onChange: _this3.props.properties.onChange,
onFocus: _this3.props.properties.onFocus,
onUpdate: _this3.props.properties.onUpdate,
checked: selectedValue === String(option.value)
},
option.desc
);
});
}
}, {
key: 'getValue',
value: function getValue() {
var options = _lodash2.default.get(this.props.field, 'options', []);
var value = String(this.props.properties.initialValue || this.props.properties.value);
var index = _lodash2.default.findIndex(options, ['value', value]);
if (index > -1 && _lodash2.default.has(options, [index, 'desc'])) {
return _react3.default.createElement(
'span',
null,
_react3.default.createElement('i', { className: 'fa fa-dot-circle-o' }),
' ',
_lodash2.default.get(options, [index, 'desc'], '-')
);
}
}
}, {
key: 'handlePrevent',
value: function handlePrevent(e) {
if (e.keyCode === 13) {
e.preventDefault();
e.stopPropagation();
}
}
}, {
key: 'handleChange',
value: function handleChange(e) {
if (e.keyCode === 13) {
e.preventDefault();
e.stopPropagation();
}
this.setState({ value: e.target.value });
}
}, {
key: 'searchBox',
value: function searchBox() {
if (!!this.props.field.searchable && !this.props.static) {
return _react3.default.createElement('input', { type: 'text', placeholder: 'search', defaultValue: this.state.value, onKeyDown: this.handlePrevent, onKeyUp: this.handleChange, className: 'form-control' });
}
}
}, {
key: 'render',
value: function render() {
if (this.props.static === true) {
return _react3.default.createElement(
_reactBootstrap.FormControl.Static,
{ type: 'text', placeholder: _lodash2.default.get(this.props.field, 'placeholder', '')
},
this.getValue()
);
}
return _react3.default.createElement(
'div',
null,
this.searchBox(),
this.radioButtons()
);
}
}]);
return RadioType;
}(_react2.Component), _class2.propTypes = {
'field': _react2.PropTypes.object.isRequired,
'properties': _react2.PropTypes.object.isRequired,
'size': _react2.PropTypes.string,
'addField': _react2.PropTypes.func.isRequired,
'static': _react2.PropTypes.bool
}, _temp)) || _class));
exports.default = RadioType;
function _inspect(input, depth) {
var maxDepth = 4;
var maxKeys = 15;
if (depth === undefined) {
depth = 0;
}
depth += 1;
if (input === null) {
return 'null';
} else if (input === undefined) {
return 'void';
} else if (typeof input === 'string' || typeof input === 'number' || typeof input === 'boolean') {
return typeof input === 'undefined' ? 'undefined' : (0, _typeof3.default)(input);
} else if (Array.isArray(input)) {
if (input.length > 0) {
var _ret2 = function () {
if (depth > maxDepth) return {
v: '[...]'
};
var first = _inspect(input[0], depth);
if (input.every(function (item) {
return _inspect(item, depth) === first;
})) {
return {
v: first.trim() + '[]'
};
} else {
return {
v: '[' + input.slice(0, maxKeys).map(function (item) {
return _inspect(item, depth);
}).join(', ') + (input.length >= maxKeys ? ', ...' : '') + ']'
};
}
}();
if ((typeof _ret2 === 'undefined' ? 'undefined' : (0, _typeof3.default)(_ret2)) === "object") return _ret2.v;
} else {
return 'Array';
}
} else {
var keys = (0, _keys2.default)(input);
if (!keys.length) {
if (input.constructor && input.constructor.name && input.constructor.name !== 'Object') {
return input.constructor.name;
} else {
return 'Object';
}
}
if (depth > maxDepth) return '{...}';
var indent = ' '.repeat(depth - 1);
var entries = keys.slice(0, maxKeys).map(function (key) {
return (/^([A-Z_$][A-Z0-9_$]*)$/i.test(key) ? key : (0, _stringify2.default)(key)) + ': ' + _inspect(input[key], depth) + ';';
}).join('\n ' + indent);
if (keys.length >= maxKeys) {
entries += '\n ' + indent + '...';
}
if (input.constructor && input.constructor.name && input.constructor.name !== 'Object') {
return input.constructor.name + ' {\n ' + indent + entries + '\n' + indent + '}';
} else {
return '{\n ' + indent + entries + '\n' + indent + '}';
}
}
}
module.exports = exports['default'];