native-document 1.0.263 → 1.0.264
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-document",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.264",
|
|
4
4
|
"description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
|
|
5
5
|
"author": "AfroCodeur <https://github.com/afrocodeur>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -72,10 +72,12 @@ RadioField.prototype.constructor = RadioField;
|
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* @param {Array<{ value: *, label: NdChild, props?: GlobalAttributes }>} opts
|
|
75
|
+
* @param {() => ({value: *, label: NdChild, props?: GlobalAttributes})} optionMapper
|
|
75
76
|
* @returns {this}
|
|
76
77
|
*/
|
|
77
|
-
RadioField.prototype.options = function(opts) {
|
|
78
|
+
RadioField.prototype.options = function(opts, optionMapper) {
|
|
78
79
|
this.$description.options = opts;
|
|
80
|
+
this.$description.optionMapper = optionMapper;
|
|
79
81
|
return this;
|
|
80
82
|
};
|
|
81
83
|
|
|
@@ -48,9 +48,11 @@ const buildOptions = ($desc, instance) => {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
const buildOption = ($desc, option) => {
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
const
|
|
51
|
+
const dataSource = $desc.optionMapper ? $desc.optionMapper(option) : option;
|
|
52
|
+
const optValue = dataSource.value ?? option;
|
|
53
|
+
const optLabel = dataSource.label ?? option;
|
|
54
|
+
const optId = ($desc.id || $desc.name).valueOf() + '-' + optValue;
|
|
55
|
+
const $isSelected = isSelected(optValue);
|
|
54
56
|
|
|
55
57
|
const input = Input({
|
|
56
58
|
class: 'field-radio',
|
|
@@ -58,14 +60,14 @@ const buildOptions = ($desc, instance) => {
|
|
|
58
60
|
id: optId,
|
|
59
61
|
name: $desc.name,
|
|
60
62
|
value: optValue,
|
|
61
|
-
checked: isSelected
|
|
63
|
+
checked: $isSelected,
|
|
62
64
|
disabled: $desc.disabled,
|
|
63
65
|
});
|
|
64
66
|
|
|
65
67
|
input.nd.onChange(() => onSelect(optValue));
|
|
66
68
|
|
|
67
69
|
if($desc.renderItem) {
|
|
68
|
-
return Div({class: 'field-radio-wrapper'}, $desc.renderItem(input, option));
|
|
70
|
+
return Div({class: 'field-radio-wrapper'}, $desc.renderItem(input, option, { $isSelected }));
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
return Div({class: 'field-radio-wrapper'}, [
|